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); } } } }
SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
PresShell::Init(nsIDocument* aDocument,                nsPresContext* 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, this);  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);  // Create our reflow command hashtable  static PLDHashTableOps reflowCommandOps =    {      PL_DHashAllocTable,      PL_DHashFreeTable,      ReflowCommandHashGetKey,      ReflowCommandHashHashKey,      ReflowCommandHashMatchEntry,      PL_DHashMoveEntryStub,      PL_DHashClearEntryStub,      PL_DHashFinalizeStub    };  if (!PL_DHashTableInit(&mReflowCommandTable, &reflowCommandOps,                         nsnull, sizeof(ReflowCommandEntry), 16)) {    mReflowCommandTable.ops = nsnull;    return NS_ERROR_OUT_OF_MEMORY;  }    // 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);  result = CallCreateInstance(kFrameSelectionCID, &mSelection);  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(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);        }      }          }  }    if (gMaxRCProcessingTime == -1) {    gMaxRCProcessingTime =      nsContentUtils::GetIntPref("layout.reflow.timeslice",                                 NS_MAX_REFLOW_TIME);    gAsyncReflowDuringDocLoad =      nsContentUtils::GetBoolPref("layout.reflow.async.duringDocLoad",                                  PR_TRUE);  }  {    nsCOMPtr<nsIObserverService> os =      do_GetService("@mozilla.org/observer-service;1", &result);    if (os) {      os->AddObserver(this, NS_LINK_VISITED_EVENT_TOPIC, PR_FALSE);#ifdef MOZ_XUL      os->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);#endif    }  }  // 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) {      PRBool paintFrameCounts =        nsContentUtils::GetBoolPref("layout.reflow.showframecounts");      PRBool dumpFrameCounts =        nsContentUtils::GetBoolPref("layout.reflow.dumpframecounts");      PRBool dumpFrameByFrameCounts =        nsContentUtils::GetBoolPref("layout.reflow.dumpframebyframecounts");      mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts);      mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts);      mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts);    }#endif  return NS_OK;}