result = (nsStyleBackground*)parentContext->GetStyleData(eStyleStruct_Background); if (!result->BackgroundIsTransparent()){
::GetStyleData(parentContext, &result); if (!result->IsTransparent()) {
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;    GetStyleData(firstChild, &result);      // for printing and print preview.. this should be a pageContentFrame    nsCOMPtr<nsIAtom> frameType;    nsCOMPtr<nsIStyleContext> 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; ) {          kidFrame->GetStyleContext(getter_AddRefs(parentContext));          result = (nsStyleBackground*)parentContext->GetStyleData(eStyleStruct_Background);          if (!result->BackgroundIsTransparent()){            GetStyleData(kidFrame, aBackground);            return PR_TRUE;          } else {            kidFrame->GetNextSibling(&kidFrame);           }        }        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->BackgroundIsTransparent()) {      nsCOMPtr<nsIContent> content;      aForFrame->GetContent(getter_AddRefs(content));      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)              ::GetStyleData(bodyFrame, &result);          }        }      }    }    *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.    GetStyleData(aForFrame, aBackground);  }    return PR_TRUE;}