PresShell* ps = NS_REINTERPRET_CAST(PresShell*, presShell.get()); PRBool isBatching; ps->SetReflowEventStatus(PR_FALSE); ps->GetReflowBatchingStatus(&isBatching); if (!isBatching) { nsCOMPtr<nsIViewManager> viewManager;   presShell->GetViewManager(getter_AddRefs(viewManager)); 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; if ((NS_SUCCEEDED(GetViewManager(&vm))) && vm) {     nsIView *view; vm->GetRootView(view); if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged(); } } return NS_OK; }        if (aEvent->message == NS_GOTFOCUS && !mDidInitialReflow && mDocument) { nsCOMPtr<nsIScriptGlobalObject> sgo; mDocument->GetScriptGlobalObject(getter_AddRefs(sgo)); if (sgo) { nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(sgo); if (pWindow) { nsCOMPtr<nsIFocusController> controller; pWindow->GetRootFocusController(getter_AddRefs(controller)); if (controller) { nsCOMPtr<nsIDOMWindowInternal> domWin = do_QueryInterface(sgo); controller->SetFocusedWindow(domWin); controller->SetFocusedElement(nsnull); } } } }  aView->GetClientData(clientData); frame = (nsIFrame *)clientData;   if (nsnull != frame) { PushCurrentEventInfo(nsnull, nsnull);  nsIEventStateManager *manager; if (NS_OK == mPresContext->GetEventStateManager(&manager)) {  if (NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) || aEvent->message == NS_CONTEXTMENU_KEY) {  manager->GetFocusedContent(&mCurrentEventContent); if (mCurrentEventContent) GetPrimaryFrameFor(mCurrentEventContent, &mCurrentEventFrame); else {                 mDocument->GetRootContent(&mCurrentEventContent); mCurrentEventFrame = nsnull;  } } else if (!InClipRect(frame, aEvent->point)) {    if (aForceHandle) { mCurrentEventFrame = frame; } else { mCurrentEventFrame = nsnull; } aHandled = PR_FALSE; rv = NS_OK; } else {       nsPoint eventPoint; frame->GetOrigin(eventPoint); eventPoint += aEvent->point;  nsPoint originOffset; nsIView *view = nsnull; frame->GetOriginToViewOffset(mPresContext, originOffset, &view);  #ifdef DEBUG_kin NS_ASSERTION(view == aView, "view != aView"); #endif  if (view == aView) eventPoint -= originOffset;  rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FOREGROUND, &mCurrentEventFrame); if (rv != NS_OK) { rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FLOATERS, &mCurrentEventFrame); if (rv != NS_OK) { rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_BACKGROUND, &mCurrentEventFrame); if (rv != NS_OK) { if (aForceHandle) { mCurrentEventFrame = frame; } else { mCurrentEventFrame = nsnull; } aHandled = PR_FALSE; rv = NS_OK; } } } } if (GetCurrentEventFrame()) { rv = HandleEventInternal(aEvent, aView, NS_EVENT_FLAG_INIT, aEventStatus); } NS_RELEASE(manager); } #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;  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 PopCurrentEventInfo(); } else { aHandled = PR_FALSE; rv = NS_OK; }  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->SetReflowEventStatus(PR_FALSE);      ps->GetReflowBatchingStatus(&isBatching);      if (!isBatching) {        nsCOMPtr<nsIViewManager> viewManager;        // 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.        presShell->GetViewManager(getter_AddRefs(viewManager));        ps->ProcessReflowCommands(PR_TRUE);        // Now, explicitly release the pres shell before the view manager        presShell = nsnull;        viewManager = nsnull;      }    }    else      mPresShell = 0;  }