Only propagate the body background to the canvas in HTML documents; don't do it

for XHTML.   Bug 214969, r+sr=dbaron
This commit is contained in:
bzbarsky@mit.edu
2003-10-15 02:48:25 +00:00
parent f0b6893e06
commit 0f6cfe86d1
2 changed files with 58 additions and 38 deletions

View File

@@ -65,6 +65,7 @@
#include "nsIDOMHTMLBodyElement.h"
#include "nsIDOMHTMLDocument.h"
#include "nsLayoutUtils.h"
#include "nsINameSpaceManager.h"
#define BORDER_FULL 0 //entire side
#define BORDER_INSIDE 1 //inside half
@@ -2695,25 +2696,29 @@ FindCanvasBackground(nsIPresContext* aPresContext,
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();
PRInt32 namespaceID;
content->GetNameSpaceID(&namespaceID);
if (namespaceID == kNameSpaceID_None) { // HTML, not XHTML
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();
}
}
}
}
@@ -2750,6 +2755,11 @@ FindElementBackground(nsIPresContext* aPresContext,
nsIContent* content = aForFrame->GetContent();
if (!content || !content->IsContentOfType(nsIContent::eHTML))
return PR_TRUE; // not frame for an HTML element
PRInt32 namespaceID;
content->GetNameSpaceID(&namespaceID);
if (namespaceID != kNameSpaceID_None) // This is XHTML, not HTML
return PR_TRUE;
if (!parentFrame)
return PR_TRUE; // no parent to look at