nsIFrame* docElementFrame;
nsIFrame*       docElementFrame; nsAbsoluteItems fixedItems(pageFrame);
HTMLStyleSheetImpl::ConstructRootFrame(nsIPresContext* aPresContext,                                       nsIContent*     aDocElement,                                       nsIFrame*&      aNewFrame){#ifdef NS_DEBUG  nsIDocument*  doc;  nsIContent*   rootContent;  // Verify that the content object is really the root content object  aDocElement->GetDocument(doc);  rootContent = doc->GetRootContent();  NS_RELEASE(doc);  NS_ASSERTION(rootContent == aDocElement, "unexpected content");  NS_RELEASE(rootContent);#endif  nsIFrame*         viewportFrame;  nsIStyleContext*  rootPseudoStyle;  // Create the viewport frame  NS_NewViewportFrame(viewportFrame);  // Create a pseudo element style context  // XXX Use a different pseudo style context...  rootPseudoStyle = aPresContext->ResolvePseudoStyleContextFor(nsnull,                       nsHTMLAtoms::rootPseudo, nsnull);  // Initialize the viewport frame. It has a NULL content object  viewportFrame->Init(*aPresContext, nsnull, nsnull, rootPseudoStyle);  // Bind the viewport frame to the root view  nsIPresShell*   presShell = aPresContext->GetShell();  nsIViewManager* viewManager = presShell->GetViewManager();  nsIView*        rootView;  NS_RELEASE(presShell);  viewManager->GetRootView(rootView);  viewportFrame->SetView(rootView);  NS_RELEASE(viewManager);  // As long as the webshell doesn't prohibit it, create a scroll frame  // that will act as the scolling mechanism for the viewport  // XXX We should only do this when presenting to the screen, i.e., for galley  // mode and print-preview, but not when printing  PRBool       isScrollable = PR_TRUE;  nsISupports* container;  if (nsnull != aPresContext) {    aPresContext->GetContainer(&container);    if (nsnull != container) {      nsIWebShell* webShell = nsnull;      container->QueryInterface(kIWebShellIID, (void**) &webShell);      if (nsnull != webShell) {        PRInt32 scrolling = -1;        webShell->GetScrolling(scrolling);        if (NS_STYLE_OVERFLOW_HIDDEN == scrolling) {          isScrollable = PR_FALSE;        }        NS_RELEASE(webShell);      }      NS_RELEASE(container);    }  }  // If the viewport should offer a scrolling mechanism, then create a  // scroll frame  nsIFrame* scrollFrame;  if (isScrollable) {    NS_NewScrollFrame(scrollFrame);    scrollFrame->Init(*aPresContext, nsnull, viewportFrame, rootPseudoStyle);  }  if (aPresContext->IsPaginated()) {    nsIFrame* pageSequenceFrame;    // Create a page sequence frame    NS_NewSimplePageSequenceFrame(pageSequenceFrame);    pageSequenceFrame->Init(*aPresContext, nsnull, isScrollable ? scrollFrame :                            viewportFrame, rootPseudoStyle);    if (isScrollable) {      nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, pageSequenceFrame,                                               rootPseudoStyle, PR_TRUE);    }    // Create the first page    nsIFrame* pageFrame;    NS_NewPageFrame(pageFrame);    // Initialize the page and force it to have a view. This makes printing of    // the pages easier and faster.    // XXX Use a PAGE style context...    pageFrame->Init(*aPresContext, nsnull, pageSequenceFrame, rootPseudoStyle);    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, pageFrame,                                             rootPseudoStyle, PR_TRUE);    // Create frames for the document element and its child elements    nsIFrame* docElementFrame;    ConstructDocElementFrame(aPresContext, aDocElement, pageFrame,                             rootPseudoStyle, docElementFrame);    NS_RELEASE(rootPseudoStyle);    // Set the initial child lists    pageFrame->SetInitialChildList(*aPresContext, nsnull, docElementFrame);    pageSequenceFrame->SetInitialChildList(*aPresContext, nsnull, pageFrame);    if (isScrollable) {      scrollFrame->SetInitialChildList(*aPresContext, nsnull, pageSequenceFrame);      viewportFrame->SetInitialChildList(*aPresContext, nsnull, scrollFrame);    } else {      viewportFrame->SetInitialChildList(*aPresContext, nsnull, pageSequenceFrame);    }    } else {    // Create the root frame. The document element's frame is a child of the    // root frame.    //    // Note: the major reason we need the root frame is to implement margins for    // the document element's frame. If we didn't need to support margins on the    // document element's frame, then we could eliminate the root frame and make    // the document element frame a child of the viewport (or its scroll frame)    nsIFrame* rootFrame;    NS_NewRootFrame(rootFrame);    rootFrame->Init(*aPresContext, nsnull, isScrollable ? scrollFrame :                    viewportFrame, rootPseudoStyle);    if (isScrollable) {      nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, rootFrame,                                               rootPseudoStyle, PR_TRUE);    }    // Create frames for the document element and its child elements    nsIFrame* docElementFrame;    ConstructDocElementFrame(aPresContext, aDocElement, rootFrame,                             rootPseudoStyle, docElementFrame);    NS_RELEASE(rootPseudoStyle);    // Set the initial child lists    rootFrame->SetInitialChildList(*aPresContext, nsnull, docElementFrame);    if (isScrollable) {      scrollFrame->SetInitialChildList(*aPresContext, nsnull, rootFrame);      viewportFrame->SetInitialChildList(*aPresContext, nsnull, scrollFrame);    } else {      viewportFrame->SetInitialChildList(*aPresContext, nsnull, rootFrame);    }  }  aNewFrame = viewportFrame;  return NS_OK;  }