nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefBranch) { prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad); }
gAsyncReflowDuringDocLoad = nsContentUtils::GetBoolPref("layout.reflow.async.duringDocLoad", PR_TRUE);
PresShell::Init(nsIDocument* aDocument,                nsIPresContext* aPresContext,                nsIViewManager* aViewManager,                nsStyleSet* aStyleSet,                nsCompatibility aCompatMode){  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 = aDocument;  NS_ADDREF(mDocument);  mViewManager = aViewManager;  // Create our frame constructor.  mFrameConstructor = new nsCSSFrameConstructor(mDocument);  NS_ENSURE_TRUE(mFrameConstructor, NS_ERROR_OUT_OF_MEMORY);  // The document viewer owns both view manager and pres shell.  mViewManager->SetViewObserver(this);  // Bind the context to the presentation shell.  mPresContext = aPresContext;  NS_ADDREF(mPresContext);  aPresContext->SetShell(this);  // Now we can initialize the style set.  nsresult result = aStyleSet->Init(aPresContext);  NS_ENSURE_SUCCESS(result, result);  // From this point on, any time we return an error we need to make  // sure to null out mStyleSet first, since an error return from this  // method will cause the caller to delete the style set, so we don't  // want to delete it in our destructor.  mStyleSet = aStyleSet;  // Set the compatibility mode after attaching the pres context and  // style set, but before creating any frames.  mPresContext->SetCompatibilityMode(aCompatMode);  // setup the preference style rules (no forced reflow), and do it  // before creating any frames.  SetPreferenceStyleRules(PR_FALSE);  mSelection = do_CreateInstance(kFrameSelectionCID, &result);  if (NS_FAILED(result)) {    mStyleSet = nsnull;    return result;  }  // Create and initialize the frame manager  result = FrameManager()->Init(this, mStyleSet);  if (NS_FAILED(result)) {    NS_WARNING("Frame manager initialization failed");    mStyleSet = nsnull;    return result;  }  result = mSelection->Init((nsIFocusTracker *) this, nsnull);  if (NS_FAILED(result)) {    mStyleSet = nsnull;    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 = aPresContext->GetContainer();  if (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){          SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);        }      }          }  }    mEventQueueService = do_GetService(kEventQueueServiceCID, &result);  if (!mEventQueueService) {    NS_WARNING("couldn't get event queue service");    mStyleSet = nsnull;    return NS_ERROR_FAILURE;  }  if (gMaxRCProcessingTime == -1) {    // First, set the defaults    gMaxRCProcessingTime = NS_MAX_REFLOW_TIME;    gAsyncReflowDuringDocLoad = PR_TRUE;    // Get the prefs service    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));    if (prefBranch) {      prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime);      prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad",                              &gAsyncReflowDuringDocLoad);    }  }  // cache the observation service  mObserverService = do_GetService("@mozilla.org/observer-service;1",                                   &result);  if (NS_FAILED(result)) {    mStyleSet = nsnull;    return result;  }  // cache the drag service so we can check it during reflows  mDragService = do_GetService("@mozilla.org/widget/dragservice;1");#ifdef IBMBIDI  mBidiKeyboard = do_GetService("@mozilla.org/widget/bidikeyboard;1");#endif#ifdef MOZ_REFLOW_PERF    if (mReflowCountMgr) {      // Get the prefs service      nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));      if (prefBranch) {        PRBool paintFrameCounts       = PR_FALSE;        PRBool dumpFrameCounts        = PR_FALSE;        PRBool dumpFrameByFrameCounts = PR_FALSE;        prefBranch->GetBoolPref("layout.reflow.showframecounts",                                &paintFrameCounts);        prefBranch->GetBoolPref("layout.reflow.dumpframecounts",                                &dumpFrameCounts);        prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts",                                &dumpFrameByFrameCounts);        mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts);        mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts);        mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts);      }    }#endif  return NS_OK;}