if (mIsDestroying || mIsReflowing) { return NS_OK; }  #ifdef ACCESSIBILITY if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT) { return HandleEventInternal(aEvent, aView, NS_EVENT_FLAG_INIT, aEventStatus); } #endif   if (aEvent->message == NS_THEMECHANGED && mPresContext) { return mPresContext->ThemeChanged(); }    if ((aEvent->message == NS_SYSCOLORCHANGED) && mPresContext) { nsIViewManager* vm = GetViewManager(); if (vm) {     nsIView *view; vm->GetRootView(view); if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged();
presShell = nsnull; viewManager = nsnull;
PresShell::HandleEvent(nsIView         *aView,                       nsGUIEvent*     aEvent,                       nsEventStatus*  aEventStatus,                       PRBool          aForceHandle,                       PRBool&         aHandled){  NS_ASSERTION(aView, "null view");  aHandled = PR_TRUE;  if (mIsDestroying || mIsReflowing) {    return NS_OK;  }#ifdef ACCESSIBILITY  if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT) {    return HandleEventInternal(aEvent, aView,                               NS_EVENT_FLAG_INIT, aEventStatus);  }#endif  // Check for a theme change up front, since the frame type is irrelevant  if (aEvent->message == NS_THEMECHANGED && mPresContext) {    return mPresContext->ThemeChanged();  }  // Check for a system color change up front, since the frame type is  // irrelevant  if ((aEvent->message == NS_SYSCOLORCHANGED) && mPresContext) {    nsIViewManager* vm = GetViewManager();    if (vm) {      // Only dispatch system color change when the message originates from      // from the root views widget. This is necessary to prevent us from       // dispatching the SysColorChanged notification for each child window       // which may be redundant.      nsIView *view;      vm->GetRootView(view);      if (view == aView) {        aHandled = PR_TRUE;        *aEventStatus = nsEventStatus_eConsumeDoDefault;        return mPresContext->SysColorChanged();      }    }    return NS_OK;  }  nsIFrame* frame = NS_STATIC_CAST(nsIFrame*, aView->GetClientData());  nsresult rv = NS_OK;    if (frame) {    PushCurrentEventInfo(nsnull, nsnull);    // key and IME events go to the focused frame    nsCOMPtr<nsIEventStateManager> manager;    if ((NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) ||         aEvent->message == NS_CONTEXTMENU_KEY) &&        NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(manager)))) {      manager->GetFocusedFrame(&mCurrentEventFrame);      if (!mCurrentEventFrame) {#if defined(MOZ_X11)        if (NS_IS_IME_EVENT(aEvent)) {          // bug 52416          // Lookup region (candidate window) of UNIX IME grabs          // input focus from Mozilla but wants to send IME event          // to redraw pre-edit (composed) string          // If Mozilla does not have input focus and event is IME,          // sends IME event to pre-focused element          nsCOMPtr<nsIScriptGlobalObject> ourGlobal;          mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));          nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);          if (ourWindow) {            nsCOMPtr<nsIFocusController> focusController;            ourWindow->GetRootFocusController(getter_AddRefs(focusController));            if (focusController) {              PRBool active = PR_FALSE;              // check input focus is in Mozilla              focusController->GetActive(&active);              if (!active) {                // if not, search for pre-focused element                nsCOMPtr<nsIDOMElement> focusedElement;                focusController->GetFocusedElement(getter_AddRefs(focusedElement));                if (focusedElement) {                  // get mCurrentEventContent from focusedElement                  CallQueryInterface(focusedElement, &mCurrentEventContent);                }              }            }          }        }#endif /* defined(MOZ_X11) */        if (!mCurrentEventContent) {          mDocument->GetRootContent(&mCurrentEventContent);        }        mCurrentEventFrame = nsnull;      }      if (mCurrentEventContent && InZombieDocument(mCurrentEventContent)) {        return RetargetEventToParent(aView, aEvent, aEventStatus, aForceHandle,                                     aHandled, mCurrentEventContent);      }    }    else if (!InClipRect(frame, aEvent->point)) {      // we only check for the clip rect on this frame ... all frames with clip      // have views so any viewless children of this frame cannot have clip.       // Furthermore if the event is not in the clip for this frame, then none      // of the children can get it either.      if (aForceHandle) {        mCurrentEventFrame = frame;      }      else {        mCurrentEventFrame = nsnull;      }      aHandled = PR_FALSE;      rv = NS_OK;    } else {      // aEvent->point is relative to aView's upper left corner. We need      // a point that is in the same coordinate system as frame's rect      // so that the frame->mRect.Contains(aPoint) calls in       // GetFrameForPoint() work. The assumption here is that frame->GetView()      // will return aView, and frame's parent view is aView's parent.      nsPoint eventPoint = frame->GetPosition();      eventPoint += aEvent->point;      nsPoint originOffset;      nsIView *view = nsnull;      frame->GetOriginToViewOffset(mPresContext, originOffset, &view);#ifdef DEBUG_kin      NS_ASSERTION(view == aView, "view != aView");#endif // DEBUG_kin      if (view == aView)        eventPoint -= originOffset;      rv = frame->GetFrameForPoint(mPresContext, eventPoint,                                   NS_FRAME_PAINT_LAYER_FOREGROUND,                                   &mCurrentEventFrame);      if (NS_FAILED(rv)) {        rv = frame->GetFrameForPoint(mPresContext, eventPoint,                                     NS_FRAME_PAINT_LAYER_FLOATERS,                                     &mCurrentEventFrame);        if (NS_FAILED(rv)) {          rv = frame->GetFrameForPoint(mPresContext, eventPoint,                                       NS_FRAME_PAINT_LAYER_BACKGROUND,                                       &mCurrentEventFrame);          if (NS_FAILED (rv)) {            if (aForceHandle) {              mCurrentEventFrame = frame;            }            else {              mCurrentEventFrame = nsnull;            }            aHandled = PR_FALSE;            rv = NS_OK;          }        }      }      if (mCurrentEventFrame) {        nsCOMPtr<nsIContent> targetElement;        mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent,                                               getter_AddRefs(targetElement));        // If there is no content for this frame, target it anyway.  Some        // frames can be targeted but do not have content, particularly        // windows with scrolling off.        if (targetElement) {          // Bug 103055, bug 185889: mouse events apply to *elements*, not all          // nodes.  Thus we get the nearest element parent here.          // XXX we leave the frame the same even if we find an element          // parent, so that the text frame will receive the event (selection          // and friends are the ones who care about that anyway)          //          // We use weak pointers because during this tight loop, the node          // will *not* go away.  And this happens on every mousemove.          while (targetElement &&                 !targetElement->IsContentOfType(nsIContent::eELEMENT)) {            targetElement = targetElement->GetParent();          }          // If we found an element, target it.  Otherwise, target *nothing*.          if (!targetElement) {            NS_IF_RELEASE(mCurrentEventContent);            mCurrentEventFrame = nsnull;          } else if (targetElement != mCurrentEventContent) {            NS_IF_RELEASE(mCurrentEventContent);            mCurrentEventContent = targetElement;            NS_ADDREF(mCurrentEventContent);          }        }      }    }    if (GetCurrentEventFrame()) {      rv = HandleEventInternal(aEvent, aView,                               NS_EVENT_FLAG_INIT, aEventStatus);    }#ifdef NS_DEBUG    if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) &&        (GetCurrentEventFrame())) {      nsIView *oldView = mCurrentTargetView;      nsPoint offset(0,0);      nsRect oldTargetRect(mCurrentTargetRect);      mCurrentTargetRect = mCurrentEventFrame->GetRect();      mCurrentTargetView = mCurrentEventFrame->GetView();      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 = GetViewManager();          if (vm) {            vm->UpdateView(mCurrentTargetView,mCurrentTargetRect,0);            if (oldView)              vm->UpdateView(oldView,oldTargetRect,0);          }        }      }    }#endif    PopCurrentEventInfo();  }  else {    // Focus events need to be dispatched even if no frame was found, since    // we don't want the focus controller to be out of sync.    if (!NS_EVENT_NEEDS_FRAME(aEvent)) {      mCurrentEventFrame = nsnull;      return HandleEventInternal(aEvent, aView,                                 NS_EVENT_FLAG_INIT, aEventStatus);    }    else if (NS_IS_KEY_EVENT(aEvent)) {      // Keypress events in new blank tabs should not be completely thrown away.      // Retarget them -- the parent chrome shell might make use of them.      return RetargetEventToParent(aView, aEvent, aEventStatus, aForceHandle,                                   aHandled, mCurrentEventContent);    }    aHandled = PR_FALSE;  }  return rv;}