if (gMaxRCProcessingTime == -1) {
if (gMaxRCProcessingTime == (PRTime) -1) {
PresShell::Init(nsIDocument* aDocument,                nsIPresContext* aPresContext,                nsIViewManager* aViewManager,                nsIStyleSet* aStyleSet){  NS_PRECONDITION(nsnull != aDocument, "null ptr");  NS_PRECONDITION(nsnull != aPresContext, "null ptr");  NS_PRECONDITION(nsnull != aViewManager, "null ptr");  if ((nsnull == aDocument) || (nsnull == aPresContext) ||      (nsnull == aViewManager)) {    return NS_ERROR_NULL_POINTER;  }  if (mDocument) {    return NS_ERROR_ALREADY_INITIALIZED;  }  mDocument = dont_QueryInterface(aDocument);  mViewManager = aViewManager;  //doesn't add a ref since we own it... MMP  mViewManager->SetViewObserver((nsIViewObserver *)this);  // Bind the context to the presentation shell.  mPresContext = dont_QueryInterface(aPresContext);  aPresContext->SetShell(this);  mStyleSet = dont_QueryInterface(aStyleSet);  mHistoryState = nsnull;  nsresult result = nsComponentManager::CreateInstance(kFrameSelectionCID, nsnull,                                                 nsIFrameSelection::GetIID(),                                                 getter_AddRefs(mSelection));  if (!NS_SUCCEEDED(result))    return result;  // Create and initialize the frame manager  result = NS_NewFrameManager(&mFrameManager);  if (NS_FAILED(result)) {    return result;  }  result = mFrameManager->Init(this, mStyleSet);  if (NS_FAILED(result)) {    return result;  }  result = mSelection->Init((nsIFocusTracker *) this);  if (!NS_SUCCEEDED(result))    return result;  // Important: this has to happen after the selection has been set up#ifdef SHOW_CARET  // make the caret  nsresult  err = NS_NewCaret(getter_AddRefs(mCaret));  if (NS_SUCCEEDED(err))  {    mCaret->Init(this);  }  //SetCaretEnabled(PR_TRUE);			// make it show in browser windows#endif  //set up selection to be displayed in document  nsCOMPtr<nsISupports> container;  result = aPresContext->GetContainer(getter_AddRefs(container));  if (NS_SUCCEEDED(result) && container) {    nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));    if (NS_SUCCEEDED(result) && docShell){      PRInt32 docShellType;      result = docShell->GetItemType(&docShellType);      if (NS_SUCCEEDED(result)){        if (nsIDocShellTreeItem::typeContent == docShellType){          mDocument->SetDisplaySelection(PR_TRUE);        }      }          }  }    // Cache the event queue of the current UI thread  NS_WITH_SERVICE(nsIEventQueueService, eventService, kEventQueueServiceCID, &result);  if (NS_SUCCEEDED(result))                    // XXX this implies that the UI is the current thread.    result = eventService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue));    if (gMaxRCProcessingTime == -1) {    // First, set the defaults    gMaxRCProcessingTime = NS_MAX_REFLOW_TIME;    gDoAsyncReflow = PR_FALSE;    // Get the prefs service    NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &result);    if (NS_SUCCEEDED(result)) {      PRInt32 timeSlice;      prefs->GetIntPref("layout.reflow.timeslice", &timeSlice);      LL_I2L(gMaxRCProcessingTime, timeSlice);      prefs->GetBoolPref("layout.reflow.async", &gDoAsyncReflow);    }  }  return NS_OK;}