PresShell* ps = NS_REINTERPRET_CAST(PresShell*, presShell.get()); PRBool isBatching; ps->ClearReflowEventStatus(); ps->GetReflowBatchingStatus(&isBatching); if (!isBatching) {   nsCOMPtr<nsIViewManager> viewManager = presShell->GetViewManager(); ps->ProcessReflowCommands(PR_TRUE);   presShell = nsnull; viewManager = nsnull; } } else mPresShell = 0; }
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(); } } return NS_OK; }  nsIFrame* frame = NS_STATIC_CAST(nsIFrame*, aView->GetClientData());  nsresult rv = NS_OK;  if (frame) { PushCurrentEventInfo(nsnull, nsnull);   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)) {       nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mDocument->GetScriptGlobalObject()); if (ourWindow) { nsCOMPtr<nsIFocusController> focusController; ourWindow->GetRootFocusController(getter_AddRefs(focusController)); if (focusController) { PRBool active = PR_FALSE;  focusController->GetActive(&active); if (!active) {  nsCOMPtr<nsIDOMElement> focusedElement; focusController->GetFocusedElement(getter_AddRefs(focusedElement)); if (focusedElement) {  CallQueryInterface(focusedElement, &mCurrentEventContent); } } } } } #endif  if (!mCurrentEventContent) { NS_IF_ADDREF(mCurrentEventContent = mDocument->GetRootContent()); } mCurrentEventFrame = nsnull; } if (mCurrentEventContent && InZombieDocument(mCurrentEventContent)) { return RetargetEventToParent(aView, aEvent, aEventStatus, aForceHandle, aHandled, mCurrentEventContent); } } else if (!InClipRect(frame, aEvent->point)) {     if (aForceHandle) { mCurrentEventFrame = frame; } else { mCurrentEventFrame = nsnull; } aHandled = PR_FALSE; rv = NS_OK; } else {       nsPoint eventPoint = frame->GetPosition(); eventPoint += aEvent->point;  nsPoint originOffset; nsIView *view = nsnull; frame->GetOriginToViewOffset(mPresContext, originOffset, &view);  NS_ASSERTION(view == aView, "view != aView"); 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_FLOATS, &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 (targetElement) {         while (targetElement && !targetElement->IsContentOfType(nsIContent::eELEMENT)) { targetElement = targetElement->GetParent(); }   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;  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 {    if (!NS_EVENT_NEEDS_FRAME(aEvent)) { mCurrentEventFrame = nsnull; return HandleEventInternal(aEvent, aView, NS_EVENT_FLAG_INIT, aEventStatus); } else if (NS_IS_KEY_EVENT(aEvent)) {   return RetargetEventToParent(aView, aEvent, aEventStatus, aForceHandle, aHandled, mCurrentEventContent); }  aHandled = PR_FALSE; }  return rv; }
  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", (void*)presShell.get(), (void*)this);      }#endif      // XXX Statically cast the pres shell pointer so that we can call      // protected methods on the pres shell. (the ReflowEvent struct      // is a friend of the PresShell class)      PresShell* ps = NS_REINTERPRET_CAST(PresShell*, presShell.get());      PRBool isBatching;      ps->ClearReflowEventStatus();      ps->GetReflowBatchingStatus(&isBatching);      if (!isBatching) {        // Set a kung fu death grip on the view manager associated with the pres shell        // before processing that pres shell's reflow commands.  Fixes bug 54868.        nsCOMPtr<nsIViewManager> viewManager = presShell->GetViewManager();        ps->ProcessReflowCommands(PR_TRUE);        // Now, explicitly release the pres shell before the view manager        presShell = nsnull;        viewManager = nsnull;      }    }    else      mPresShell = 0;  }