parentAsNode->AddChild(docShellAsItem);   nsIWebShellContainer* outerContainer = nsnull; container->QueryInterface(kIWebShellContainerIID, (void**) &outerContainer); if (nsnull != outerContainer) { mWebShell->SetContainer(outerContainer); NS_RELEASE(outerContainer); }  #ifdef INCLUDE_XUL
nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,                                      const nsSize& aSize){  nsresult rv;  nsIContent* content;  GetParentContent(content);  mWebShell = do_CreateInstance(kWebShellCID);  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebShell));  NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);    // pass along marginwidth, marginheight, scrolling so sub document can use it  mWebShell->SetMarginWidth(GetMarginWidth(aPresContext, content));  mWebShell->SetMarginHeight(GetMarginHeight(aPresContext, content));  nsCompatibility mode;  aPresContext->GetCompatibilityMode(&mode);  mWebShell->SetScrolling(GetScrolling(content, mode));  nsString frameName;  if (GetName(content, frameName)) {    docShellAsItem->SetName(frameName.GetUnicode());  }  // If our container is a web-shell, inform it that it has a new  // child. If it's not a web-shell then some things will not operate  // properly.  nsISupports* container;  aPresContext->GetContainer(&container);  if (nsnull != container) {    nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container));    if (parentAsNode) {      parentAsNode->AddChild(docShellAsItem);      // connect the container...      nsIWebShellContainer* outerContainer = nsnull;      container->QueryInterface(kIWebShellContainerIID, (void**) &outerContainer);      if (nsnull != outerContainer) {        mWebShell->SetContainer(outerContainer);        NS_RELEASE(outerContainer);      }#ifdef INCLUDE_XUL      nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode));      PRInt32 parentType;      parentAsItem->GetItemType(&parentType);      nsIAtom* typeAtom = NS_NewAtom("type");      nsAutoString value, valuePiece;      PRBool isContent;      isContent = PR_FALSE;      if (NS_SUCCEEDED(content->GetAttribute(kNameSpaceID_None, typeAtom, value))) {        // we accept "content" and "content-xxx" values.        // at time of writing, we expect "xxx" to be "primary", but        // someday it might be an integer expressing priority        value.Left(valuePiece, 7);        if (valuePiece.EqualsIgnoreCase("content") &&           (value.Length() == 7 ||              value.Mid(valuePiece, 7, 1) == 1 && valuePiece.Equals("-")))            isContent = PR_TRUE;      }      if (isContent) {        // The web shell's type is content.        docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent);        nsCOMPtr<nsIWebShellContainer> shellAsContainer(do_QueryInterface(mWebShell));        shellAsContainer->ContentShellAdded(mWebShell, content);      } else {        // Inherit our type from our parent webshell.  If it is        // chrome, we'll be chrome.  If it is content, we'll be        // content.        docShellAsItem->SetItemType(parentType);      }      // Make sure all shells have links back to the content element in the      // nearest enclosing chrome shell.      nsCOMPtr<nsIDocShell> parentShell(do_QueryInterface(parentAsNode));      nsCOMPtr<nsIChromeEventHandler> chromeEventHandler;      if (parentType == nsWebShellChrome) {        // Our parent shell is a chrome shell. It is therefore our nearest        // enclosing chrome shell.        chromeEventHandler = do_QueryInterface(mContent);        NS_WARN_IF_FALSE(chromeEventHandler, "This mContent should implement this.");      }      else {        // Our parent shell is a content shell. Get the chrome info from        // it and use that for our shell as well.        parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler));      }      mWebShell->SetChromeEventHandler(chromeEventHandler);      #endif // INCLUDE_XUL       nsCOMPtr<nsIPref> parentPrefs; // connect the prefs      parentShell->GetPrefs(getter_AddRefs(parentPrefs));      if (parentPrefs) {        mWebShell->SetPrefs(parentPrefs);      }     }    NS_RELEASE(container);  }  float t2p;  aPresContext->GetTwipsToPixels(&t2p);  nsCOMPtr<nsIPresShell> presShell;  aPresContext->GetShell(getter_AddRefs(presShell));       // create, init, set the parent of the view  nsIView* view;  rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, kIViewIID,                                        (void **)&view);  if (NS_OK != rv) {    NS_ASSERTION(0, "Could not create view for nsHTMLFrame");    return rv;  }  nsIView* parView;  nsPoint origin;  GetOffsetFromView(aPresContext, origin, &parView);    nsRect viewBounds(origin.x, origin.y, aSize.width, aSize.height);  nsCOMPtr<nsIViewManager> viewMan;  presShell->GetViewManager(getter_AddRefs(viewMan));    rv = view->Init(viewMan, viewBounds, parView);  viewMan->InsertChild(parView, view, 0);  rv = view->CreateWidget(kCChildCID);  SetView(aPresContext, view);  // if the visibility is hidden, reflect that in the view  const nsStyleDisplay* display;  GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display));  if (NS_STYLE_VISIBILITY_VISIBLE != display->mVisible) {    view->SetVisibility(nsViewVisibility_kHide);  }  nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));  NS_ENSURE_TRUE(webShellWin, NS_ERROR_FAILURE);  nsCOMPtr<nsIWidget> widget;  view->GetWidget(*getter_AddRefs(widget));  nsRect webBounds(0, 0, NSToCoordRound(aSize.width * t2p),                    NSToCoordRound(aSize.height * t2p));  mWebShell->Init(widget->GetNativeData(NS_NATIVE_WIDGET),                   webBounds.x, webBounds.y,                  webBounds.width, webBounds.height);                  //GetScrolling(content, PR_FALSE));  NS_RELEASE(content);  webShellWin->SetVisibility(PR_TRUE);  return NS_OK;}