nsCOMPtr<nsIDOMHTMLElement> body; htmlDoc->GetBody(getter_AddRefs(body)); nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);          if (bodyContent) { nsCOMPtr<nsIPresShell> shell; aPresContext->GetShell(getter_AddRefs(shell)); nsIFrame *bodyFrame; nsresult rv = shell->GetPrimaryFrameFor(bodyContent, &bodyFrame); if (NS_SUCCEEDED(rv) && bodyFrame) result = bodyFrame->GetStyleBackground();
PRInt32 namespaceID; content->GetNameSpaceID(&namespaceID); if (namespaceID == kNameSpaceID_None) { nsCOMPtr<nsIDOMHTMLElement> body; htmlDoc->GetBody(getter_AddRefs(body)); nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);          if (bodyContent) { nsCOMPtr<nsIPresShell> shell; aPresContext->GetShell(getter_AddRefs(shell)); nsIFrame *bodyFrame; nsresult rv = shell->GetPrimaryFrameFor(bodyContent, &bodyFrame); if (NS_SUCCEEDED(rv) && bodyFrame) result = bodyFrame->GetStyleBackground(); }
FindCanvasBackground(nsIPresContext* aPresContext,                     nsIFrame* aForFrame,                     const nsStyleBackground** aBackground){  // XXXldb What if the root element is positioned, etc.?  (We don't  // allow that yet, do we?)  nsIFrame *firstChild;  aForFrame->FirstChild(aPresContext, nsnull, &firstChild);  if (firstChild) {    const nsStyleBackground* result = firstChild->GetStyleBackground();      // for printing and print preview.. this should be a pageContentFrame    nsCOMPtr<nsIAtom> frameType;    nsStyleContext* parentContext;    firstChild->GetFrameType(getter_AddRefs(frameType));    if ( (frameType == nsLayoutAtoms::pageContentFrame) ){      // we have to find the background style ourselves.. since the       // pageContentframe does not have content      while(firstChild){        for (nsIFrame* kidFrame = firstChild; nsnull != kidFrame; ) {          parentContext = kidFrame->GetStyleContext();          result = parentContext->GetStyleBackground();          if (!result->IsTransparent()) {            *aBackground = kidFrame->GetStyleBackground();            return PR_TRUE;          } else {            kidFrame = kidFrame->GetNextSibling();           }        }        firstChild->FirstChild(aPresContext, nsnull, &firstChild);      }      return PR_FALSE;    // nothing found for this    }    // Check if we need to do propagation from BODY rather than HTML.    if (result->IsTransparent()) {      nsIContent* content = aForFrame->GetContent();      if (content) {        nsCOMPtr<nsIDOMNode> node( do_QueryInterface(content) );        // Use |GetOwnerDocument| so it works during destruction.        nsCOMPtr<nsIDOMDocument> doc;        node->GetOwnerDocument(getter_AddRefs(doc));        nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);        if (htmlDoc) {          nsCOMPtr<nsIDOMHTMLElement> body;          htmlDoc->GetBody(getter_AddRefs(body));          nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);          // We need to null check the body node (bug 118829) since          // there are cases, thanks to the fix for bug 5569, where we          // will reflow a document with no body.  In particular, if a          // SCRIPT element in the head blocks the parser and then has a          // SCRIPT that does "document.location.href = 'foo'", then          // nsParser::Terminate will call |DidBuildModel| methods          // through to the content sink, which will call |StartLayout|          // and thus |InitialReflow| on the pres shell.  See bug 119351          // for the ugly details.          if (bodyContent) {            nsCOMPtr<nsIPresShell> shell;            aPresContext->GetShell(getter_AddRefs(shell));            nsIFrame *bodyFrame;            nsresult rv = shell->GetPrimaryFrameFor(bodyContent, &bodyFrame);            if (NS_SUCCEEDED(rv) && bodyFrame)              result = bodyFrame->GetStyleBackground();          }        }      }    }    *aBackground = result;  } else {    // This should always give transparent, so we'll fill it in with the    // default color if needed.  This seems to happen a bit while a page is    // being loaded.    *aBackground = aForFrame->GetStyleBackground();  }    return PR_TRUE;}