mIsAccessibilityActive = PR_TRUE;
PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView,                               PRUint32 aFlags, nsEventStatus* aStatus){#ifdef ACCESSIBILITY  if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT)  {    nsCOMPtr<nsIAccessibilityService> accService =       do_GetService("@mozilla.org/accessibilityService;1");    if (accService) {      nsIAccessible* acc;      nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mDocument));      NS_ASSERTION(domNode, "No dom node for doc");      accService->GetAccessibleInShell(domNode, this, &acc);      // Addref this - it's not a COM Ptr      // We'll make sure the right number of Addref's occur before      // handing this back to the accessibility client      NS_STATIC_CAST(nsAccessibleEvent*, aEvent)->accessible = acc;      return NS_OK;    }  }#endif  nsCOMPtr<nsIEventStateManager> manager = mPresContext->EventStateManager();  nsresult rv = NS_OK;  // Grab the offset of aView from our root view.  We can use this to adjust  // coordinates as needed.  Note that we can't just adjust them later, because  // event dispatch can destroy aView.  Also note that at times aView is null  // here.  When that happens, there isn't much we can do about getting  // coordinates right....  nsPoint offsetOfaView(0,0);  if (aView) {    nsIView* rootView;    mViewManager->GetRootView(rootView);    offsetOfaView = aView->GetOffsetTo(rootView);  }  if (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame()) {    PRBool isHandlingUserInput = PR_FALSE;    if (aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) {      switch (aEvent->message) {      case NS_GOTFOCUS:      case NS_LOSTFOCUS:      case NS_ACTIVATE:      case NS_DEACTIVATE:        // Treat focus/blur events as user input if they happen while        // executing trusted script, or no script at all. If they        // happen during execution of non-trusted script, then they        // should not be considerd user input.        if (!nsContentUtils::IsCallerChrome()) {          break;        }      case NS_MOUSE_LEFT_BUTTON_DOWN:      case NS_MOUSE_MIDDLE_BUTTON_DOWN:      case NS_MOUSE_RIGHT_BUTTON_DOWN:      case NS_MOUSE_LEFT_BUTTON_UP:      case NS_MOUSE_RIGHT_BUTTON_UP:      case NS_MOUSE_MIDDLE_BUTTON_UP:      case NS_KEY_PRESS:      case NS_KEY_DOWN:      case NS_KEY_UP:        isHandlingUserInput = PR_TRUE;      }    }    nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput);    nsAutoPopupStatePusher popupStatePusher(nsDOMEvent::GetEventPopupControlState(aEvent));    // 1. Give event to event manager for pre event state changes and    //    generation of synthetic events.    rv = manager->PreHandleEvent(mPresContext, aEvent, mCurrentEventFrame,                                 aStatus, aView);    // 2. Give event to the DOM for third party and JS use.    if ((GetCurrentEventFrame()) && NS_SUCCEEDED(rv) &&         // We want synthesized mouse moves to cause mouseover and mouseout         // DOM events (PreHandleEvent above), but not mousemove DOM events.         !IsSynthesizedMouseMove(aEvent)) {      if (mCurrentEventContent) {        rv = mCurrentEventContent->HandleDOMEvent(mPresContext, aEvent, nsnull,                                                  aFlags, aStatus);      }      else {        nsCOMPtr<nsIContent> targetContent;        rv = mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent,                                                    getter_AddRefs(targetContent));        if (NS_SUCCEEDED(rv) && targetContent) {          rv = targetContent->HandleDOMEvent(mPresContext, aEvent, nsnull,                                              aFlags, aStatus);        }      }      // Continue with second dispatch to system event handlers.      // Stopping propagation in the default group does not affect      // propagation in the system event group.      // (see also section 1.2.2.6 of the DOM3 Events Working Draft)      aEvent->flags &= ~NS_EVENT_FLAG_STOP_DISPATCH;      // Need to null check mCurrentEventContent and mCurrentEventFrame      // since the previous dispatch could have nuked them.      if (mCurrentEventContent) {        rv = mCurrentEventContent->HandleDOMEvent(mPresContext, aEvent, nsnull,                                                  aFlags | NS_EVENT_FLAG_SYSTEM_EVENT,                                                  aStatus);      }      else if (mCurrentEventFrame) {        nsCOMPtr<nsIContent> targetContent;        rv = mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent,                                                    getter_AddRefs(targetContent));        if (NS_SUCCEEDED(rv) && targetContent) {          rv = targetContent->HandleDOMEvent(mPresContext, aEvent, nsnull,                                              aFlags | NS_EVENT_FLAG_SYSTEM_EVENT,                                             aStatus);        }      }      // 3. Give event to the Frames for browser default processing.      if (GetCurrentEventFrame() && NS_SUCCEEDED (rv) &&          aEvent->eventStructType != NS_EVENT) {        // If aView is non-null, adjust coordinates of aEvent to be in the        // coordinate system of mCurrentEventFrame's closest view.  Don't use        // aView here, since it may be dead by now.        nsPoint offset(0,0);        if (aView) {          NS_ASSERTION(mViewManager,                       "How did GetCurrentEventFrame() succeed?");          nsIView* rootView;          mViewManager->GetRootView(rootView);          nsIView* frameView;          nsPoint pt;          mCurrentEventFrame->GetOffsetFromView(pt, &frameView);          offset = frameView->GetOffsetTo(rootView) - offsetOfaView;        }        // Transform aEvent->point from aView's coordinate system to        // that of mCurrentEventFrame's closest view        aEvent->point -= offset;                rv = mCurrentEventFrame->HandleEvent(mPresContext, (nsGUIEvent*)aEvent,                                             aStatus);        // Now transform back        aEvent->point += offset;      }      // 4. Give event to event manager for post event state changes and      //    generation of synthetic events.      if (NS_SUCCEEDED (rv) &&          (GetCurrentEventFrame() || !NS_EVENT_NEEDS_FRAME(aEvent))) {        rv = manager->PostHandleEvent(mPresContext, aEvent, mCurrentEventFrame,                                      aStatus, aView);      }    }  }  return rv;}