PresShell::HandleEvent(nsIView         *aView, nsGUIEvent*     aEvent, nsEventStatus*  aEventStatus) { void*     clientData; nsIFrame* frame; nsresult  rv = NS_OK;  NS_ASSERTION(!(nsnull == aView), "null view");  if (mIsDestroying || mReflowLockCount > 0) { return NS_OK;
void HandleEvent() { nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell); if (presShell) { #ifdef DEBUG if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) { printf("\n*** Handling reflow event: PresShell=%p, event=%p\n", presShell.get(), this); } #endif PRBool isBatching; presShell->SetReflowEventStatus(PR_FALSE); presShell->EnterReflowLock(); presShell->GetReflowBatchingStatus(&isBatching); if (!isBatching) presShell->ProcessReflowCommands(PR_TRUE); presShell->ExitReflowLock(PR_FALSE); } else mPresShell = 0;
PresShell::HandleEvent(nsIView         *aView,                       nsGUIEvent*     aEvent,                       nsEventStatus*  aEventStatus){  void*     clientData;  nsIFrame* frame;  nsresult  rv = NS_OK;    NS_ASSERTION(!(nsnull == aView), "null view");  if (mIsDestroying || mReflowLockCount > 0) {    return NS_OK;  }  aView->GetClientData(clientData);  frame = (nsIFrame *)clientData;/*  if (mSelection && aEvent->eventStructType == NS_KEY_EVENT)  {//KEY HANDLERS WILL GET RID OF THIS     if (mDisplayNonTextSelection && NS_SUCCEEDED(mSelection->HandleKeyEvent(mPresContext, aEvent)))    {        return NS_OK;    }  }*/  if (nsnull != frame) {    PushCurrentEventFrame();    nsIEventStateManager *manager;    nsIContent* focusContent = nsnull;    if (NS_OK == mPresContext->GetEventStateManager(&manager)) {      if (NS_IS_KEY_EVENT(aEvent)) {        //Key events go to the focused frame, not point based.        manager->GetFocusedContent(&focusContent);        if (focusContent)          GetPrimaryFrameFor(focusContent, &mCurrentEventFrame);        else frame->GetFrameForPoint(mPresContext, aEvent->point, &mCurrentEventFrame);      }      else {        frame->GetFrameForPoint(mPresContext, aEvent->point, &mCurrentEventFrame);      }      NS_IF_RELEASE(mCurrentEventContent);      if (GetCurrentEventFrame() || focusContent) {      //Once we have the targetFrame, handle the event in this order        //1. Give event to event manager for pre event state changes and generation of synthetic events.        rv = manager->PreHandleEvent(mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView);        //2. Give event to the DOM for third party and JS use.        if ((GetCurrentEventFrame() || focusContent) && NS_OK == rv) {          if (focusContent) {            rv = focusContent->HandleDOMEvent(mPresContext, (nsEvent*)aEvent, nsnull,                                                NS_EVENT_FLAG_INIT, aEventStatus);          }          else {            nsIContent* targetContent;            if (NS_OK == mCurrentEventFrame->GetContent(&targetContent) && nsnull != targetContent) {              rv = targetContent->HandleDOMEvent(mPresContext, (nsEvent*)aEvent, nsnull,                                                  NS_EVENT_FLAG_INIT, aEventStatus);              NS_RELEASE(targetContent);            }          }          //3. Give event to the Frames for browser default processing.          // XXX The event isn't translated into the local coordinate space          // of the frame...          if (GetCurrentEventFrame() && NS_OK == rv) {            rv = mCurrentEventFrame->HandleEvent(mPresContext, aEvent, aEventStatus);          }          //4. Give event to event manager for post event state changes and generation of synthetic events.          if ((GetCurrentEventFrame() || focusContent) && NS_OK == rv) {            rv = manager->PostHandleEvent(mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView);          }        }      }      NS_RELEASE(manager);      NS_IF_RELEASE(focusContent);    }#ifdef NS_DEBUG    if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (GetCurrentEventFrame())) {      nsIView *oldView = mCurrentTargetView;      nsPoint offset(0,0);      nsRect oldTargetRect(mCurrentTargetRect);      mCurrentEventFrame->GetRect(mCurrentTargetRect);      mCurrentEventFrame->GetView(mPresContext, &mCurrentTargetView);      if ( ! mCurrentTargetView ) {        mCurrentEventFrame->GetOffsetFromView(mPresContext, offset, &mCurrentTargetView);      }      if (mCurrentTargetView) {        mCurrentTargetRect.x = offset.x;        mCurrentTargetRect.y = offset.y;        // use aView or mCurrentTargetView??        if ( (mCurrentTargetRect != oldTargetRect) || (mCurrentTargetView != oldView)) {          nsIViewManager *vm;          if ((NS_OK == GetViewManager(&vm)) && vm) {            vm->UpdateView(mCurrentTargetView,mCurrentTargetRect,0);            if (oldView)              vm->UpdateView(oldView,oldTargetRect,0);            NS_IF_RELEASE(vm);          }        }      }    }#endif    PopCurrentEventFrame();  }  else {    rv = NS_OK;  }  return rv;}