if (res == IncrementalReflow::eCancel) delete command;
PresShell::ProcessReflowCommands(PRBool aInterruptible){  MOZ_TIMER_DEBUGLOG(("Start: Reflow: PresShell::ProcessReflowCommands(), this=%p\n", this));  MOZ_TIMER_START(mReflowWatch);    if (0 != mReflowCommands.Count()) {    nsHTMLReflowMetrics   desiredSize(nsnull);    nsIRenderingContext*  rcx;    nsIFrame*             rootFrame;            mFrameManager->GetRootFrame(&rootFrame);    nsSize          maxSize = rootFrame->GetSize();    nsresult rv=CreateRenderingContext(rootFrame, &rcx);    if (NS_FAILED(rv)) return rv;#ifdef DEBUG    if (GetVerifyReflowEnable()) {      if (VERIFY_REFLOW_ALL & gVerifyReflowFlags) {        printf("ProcessReflowCommands: begin incremental reflow\n");      }    }    if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {         PRInt32 i, n = mReflowCommands.Count();      printf("\nPresShell::ProcessReflowCommands: this=%p, count=%d\n", (void*)this, n);      for (i = 0; i < n; i++) {        nsHTMLReflowCommand* rc = (nsHTMLReflowCommand*)          mReflowCommands.ElementAt(i);        rc->List(stdout);      }    }#endif    // If reflow is interruptible, then make a note of our deadline.    PRIntervalTime deadline;    if (aInterruptible)      deadline = PR_IntervalNow() + PR_MicrosecondsToInterval(gMaxRCProcessingTime);    // force flushing of any pending notifications    mDocument->BeginUpdate(UPDATE_ALL);    mDocument->EndUpdate(UPDATE_ALL);    mIsReflowing = PR_TRUE;    do {      // Coalesce the reflow commands into a tree.      IncrementalReflow reflow;      for (PRInt32 i = mReflowCommands.Count() - 1; i >= 0; --i) {        nsHTMLReflowCommand *command =          NS_STATIC_CAST(nsHTMLReflowCommand *, mReflowCommands[i]);        if (reflow.AddCommand(mPresContext, command)) {          // Remove the command from the queue.          mReflowCommands.RemoveElementAt(i);          ReflowCommandRemoved(command);        }        else {          // The reflow command couldn't be added to the tree; leave          // it in the queue, and we'll handle it next time.#ifdef DEBUG          printf("WARNING: Couldn't add reflow command, so splitting.\n");#endif        }      }#ifdef DEBUG      if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) {        printf("Incremental reflow tree:\n");        reflow.Dump(mPresContext);      }#endif      // Dispatch an incremental reflow.      reflow.Dispatch(mPresContext, desiredSize, maxSize, *rcx);      // Keep going until we're out of reflow commands, or we've run      // past our deadline.    } while (mReflowCommands.Count() &&             (!aInterruptible || PR_IntervalNow() < deadline));    // XXXwaterson for interruptible reflow, examine the tree and    // re-enqueue any unflowed reflow targets.    mIsReflowing = PR_FALSE;    NS_IF_RELEASE(rcx);    // If any new reflow commands were enqueued during the reflow,    // schedule another reflow event to process them.    if (mReflowCommands.Count())      PostReflowEvent();    #ifdef DEBUG    if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {      printf("\nPresShell::ProcessReflowCommands() finished: this=%p\n", (void*)this);    }    if (nsIFrameDebug::GetVerifyTreeEnable()) {      nsIFrameDebug*  frameDebug;      if (NS_SUCCEEDED(rootFrame->QueryInterface(NS_GET_IID(nsIFrameDebug),                                                 (void**)&frameDebug))) {        frameDebug->VerifyTree();      }    }    if (GetVerifyReflowEnable()) {      // First synchronously render what we have so far so that we can      // see it.      nsIView* rootView;      mViewManager->GetRootView(rootView);      mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE);      mInVerifyReflow = PR_TRUE;      PRBool ok = VerifyIncrementalReflow();      mInVerifyReflow = PR_FALSE;      if (VERIFY_REFLOW_ALL & gVerifyReflowFlags) {        printf("ProcessReflowCommands: finished (%s)\n",               ok ? "ok" : "failed");      }      if (0 != mReflowCommands.Count()) {        printf("XXX yikes! reflow commands queued during verify-reflow\n");      }    }#endif    // If there are no more reflow commands in the queue, we'll want    // to remove the ``dummy request''.    DoneRemovingReflowCommands();  }    MOZ_TIMER_DEBUGLOG(("Stop: Reflow: PresShell::ProcessReflowCommands(), this=%p\n", this));  MOZ_TIMER_STOP(mReflowWatch);    HandlePostedDOMEvents();  HandlePostedAttributeChanges();  HandlePostedReflowCallbacks();  if (mShouldUnsuppressPainting && mReflowCommands.Count() == 0) {    // We only unlock if we're out of reflows.  It's pointless    // to unlock if reflows are still pending, since reflows    // are just going to thrash the frames around some more.  By    // waiting we avoid an overeager "jitter" effect.    mShouldUnsuppressPainting = PR_FALSE;    UnsuppressAndInvalidate();  }  return NS_OK;}