nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &result)); if (NS_SUCCEEDED(result)) { if (mReflowCountMgr != nsnull) {
if (mReflowCountMgr) {  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefBranch) {
PresShell::Init(nsIDocument* aDocument,                nsIPresContext* aPresContext,                nsIViewManager* aViewManager,                nsIStyleSet* 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 = dont_QueryInterface(aDocument);  mViewManager = aViewManager;  // The document viewer owns both view manager and pres shell.  mViewManager->SetViewObserver(this);  // Bind the context to the presentation shell.  mPresContext = aPresContext;  aPresContext->SetShell(this);  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);  mHistoryState = nsnull;  nsresult result = nsComponentManager::CreateInstance(kFrameSelectionCID, nsnull,                                                 NS_GET_IID(nsIFrameSelection),                                                 getter_AddRefs(mSelection));  if (NS_FAILED(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, nsnull);  if (NS_FAILED(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){          SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);        }      }          }  }    mEventQueueService = do_GetService(kEventQueueServiceCID, &result);  if (!mEventQueueService) {    NS_WARNING("couldn't get event queue service");    return NS_ERROR_FAILURE;  }  if (gMaxRCProcessingTime == -1) {    // First, set the defaults    gMaxRCProcessingTime = NS_MAX_REFLOW_TIME;    gAsyncReflowDuringDocLoad = PR_TRUE;    // Get the prefs service    nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &result));    if (NS_SUCCEEDED(result)) {      prefs->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime);      prefs->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad);    }  }  // cache the observation service  mObserverService = do_GetService("@mozilla.org/observer-service;1",                                   &result);  if (NS_FAILED(result)) {    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    // Get the prefs service    nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &result));    if (NS_SUCCEEDED(result)) {      if (mReflowCountMgr != nsnull) {        PRBool paintFrameCounts       = PR_FALSE;        PRBool dumpFrameCounts        = PR_FALSE;        PRBool dumpFrameByFrameCounts = PR_FALSE;        prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts);        prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts);        prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts);        mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts);        mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts);        mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts);      }    }#endif  return NS_OK;}