nsCOMPtr<nsIPresShell> shell; aPresContext->GetShell(getter_AddRefs(shell)); nsIFrame *bodyFrame; shell->GetPrimaryFrameFor(bodyContent, &bodyFrame); if (bodyFrame) ::GetStyleData(bodyFrame, &result);
NS_ASSERTION(bodyContent, "no body node"); 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); }
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);    // 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<nsIDocument> doc;        content->GetDocument(*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);          nsCOMPtr<nsIPresShell> shell;          aPresContext->GetShell(getter_AddRefs(shell));          nsIFrame *bodyFrame;          shell->GetPrimaryFrameFor(bodyContent, &bodyFrame);          if (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;}