result = domselection->QueryInterface(kIDOMSelectionIID,
result = domselection->QueryInterface(kIFrameSelectionIID,
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 (nsnull != mDocument) {    return NS_ERROR_ALREADY_INITIALIZED;  }  mDocument = aDocument;  NS_ADDREF(aDocument);  mViewManager = aViewManager;  NS_ADDREF(mViewManager);  //doesn't add a ref since we own it... MMP  mViewManager->SetViewObserver((nsIViewObserver *)this);  // Bind the context to the presentation shell.  mPresContext = aPresContext;  NS_ADDREF(aPresContext);  aPresContext->SetShell(this);  mStyleSet = aStyleSet;  NS_ADDREF(aStyleSet);  nsCOMPtr<nsIDOMSelection>domselection;  nsresult result = nsRepository::CreateInstance(kRangeListCID, nsnull,                                                 kIDOMSelectionIID,                                                 getter_AddRefs(domselection));  if (!NS_SUCCEEDED(result))    return result;  result = domselection->QueryInterface(kIDOMSelectionIID,                                        getter_AddRefs(mSelection));  if (!NS_SUCCEEDED(result))    return result;  // XXX This code causes the document object (and the entire content model) to be leaked...#if 0  nsCOMPtr<nsIDOMRange>range;  if (NS_SUCCEEDED(nsRepository::CreateInstance(kCRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange    nsCOMPtr<nsIDocument>doc(GetDocument());    nsCOMPtr<nsIDOMDocument>domDoc(doc);    if (domDoc){      nsCOMPtr<nsIDOMElement> domElement;      if (NS_SUCCEEDED(domDoc->GetDocumentElement(getter_AddRefs(domElement)))) {//get the first element from the dom        nsCOMPtr<nsIDOMNode>domNode(domElement);        if (domNode) {//get the node interface for the range object          range->SetStart(domNode,0);          range->SetEnd(domNode,0);          nsCOMPtr<nsISupports>rangeISupports(range);          if (rangeISupports) {            selection->AddItem(rangeISupports);          }        }      }    }  } #endif  mCaretEnabled = PR_FALSE;    // Important: this has to happen after the selection has been set up#ifdef SHOW_CARET  nsCaretProperties  *caretProperties = NewCaretProperties();    // make the caret  nsresult  err = NS_NewCaret(getter_AddRefs(mCaret));  if (NS_SUCCEEDED(err))    mCaret->Init(this, caretProperties);    delete caretProperties;  caretProperties = nsnull;#endif    return NS_OK;}