Bug 574621. Ensure that the prescontext DefaultBackgroundColor is painted on the background of root content documents. r=tnikkel

This commit is contained in:
Timothy Nikkel 2010-08-26 22:01:43 -05:00
parent 4de08cf5af
commit deb3dacf04
6 changed files with 115 additions and 9 deletions

View File

@ -5776,22 +5776,41 @@ nsresult PresShell::AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
new (&aBuilder) nsDisplaySolidColor(&aBuilder, aFrame, aBounds, bgcolor));
}
static PRBool IsTransparentContainerElement(nsPresContext* aPresContext)
{
nsCOMPtr<nsISupports> container = aPresContext->GetContainerInternal();
nsCOMPtr<nsIDocShellTreeItem> docShellItem = do_QueryInterface(container);
nsCOMPtr<nsPIDOMWindow> pwin(do_GetInterface(docShellItem));
if (!pwin)
return PR_FALSE;
nsCOMPtr<nsIContent> containerElement =
do_QueryInterface(pwin->GetFrameElementInternal());
return containerElement &&
containerElement->HasAttr(kNameSpaceID_None, nsGkAtoms::transparent);
}
void PresShell::UpdateCanvasBackground()
{
// If we have a frame tree and it has style information that
// specifies the background color of the canvas, update our local
// cache of that color.
nsIFrame* rootFrame = FrameConstructor()->GetRootElementStyleFrame();
if (rootFrame) {
nsIFrame* rootStyleFrame = FrameConstructor()->GetRootElementStyleFrame();
if (rootStyleFrame) {
nsStyleContext* bgStyle =
nsCSSRendering::FindRootFrameBackground(rootFrame);
nsCSSRendering::FindRootFrameBackground(rootStyleFrame);
// XXX We should really be passing the canvasframe, not the root element
// style frame but we don't have access to the canvasframe here. It isn't
// a problem because only a few frames can return something other than true
// and none of them would be a canvas frame or root element style frame.
mCanvasBackgroundColor =
nsCSSRendering::DetermineBackgroundColor(GetPresContext(), bgStyle,
rootFrame);
nsCSSRendering::DetermineBackgroundColor(mPresContext, bgStyle,
rootStyleFrame);
if (nsLayoutUtils::GetCrossDocParentFrame(FrameManager()->GetRootFrame()) &&
!nsContentUtils::IsChildOfSameType(mDocument) &&
!IsTransparentContainerElement(mPresContext)) {
mCanvasBackgroundColor =
NS_ComposeColors(mPresContext->DefaultBackgroundColor(), mCanvasBackgroundColor);
}
}
// If the root element of the document (ie html) has style 'display: none'

View File

@ -53,6 +53,8 @@ _CHROME_FILES = \
bug551434_childframe.html \
test_chrome_content_integration.xul \
chrome_content_integration_window.xul \
test_default_background.xul \
default_background_window.xul \
test_printpreview.xul \
printpreview_helper.xul \
test_printpreview_bug396024.xul \

View File

@ -25,8 +25,6 @@
window[import] = window.opener.wrappedJSObject[import];
}
var HTMLNS = "http://www.w3.org/1999/xhtml";
function runTests() {
var testCanvas = snapshotWindow(window);
@ -37,8 +35,6 @@
var comparison = compareSnapshots(testCanvas, refCanvas, true);
ok(comparison[0], "Rendering OK, got " + comparison[1] + ", expected " + comparison[2]);
dump(comparison[1] + "\n");
dump(comparison[2] + "\n");
var tester = window.SimpleTest;
window.close();

View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTests()">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
<iframe type="content" id="f" src="about:blank" style="border:1px solid black;"/>
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
var imports = [ "SimpleTest", "is", "isnot", "ok" ];
for each (var import in imports) {
window[import] = window.opener.wrappedJSObject[import];
}
function snapshot(win) {
var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
el.width = win.innerWidth;
el.height = win.innerHeight;
var ctx = el.getContext("2d");
ctx.drawWindow(win, 0, 0,
win.innerWidth, win.innerHeight,
"rgba(0,0,0,0)", 0);
return el;
}
var color = '#2468AC';
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.display.background_color', color);
function runTests() {
var f = document.getElementById("f");
var testCanvas = snapshot(f.contentWindow);
prefs.clearUserPref('browser.display.background_color');
var refCanvas = snapshot(f.contentWindow);
var ctx = refCanvas.getContext('2d');
ctx.fillStyle = color;
ctx.fillRect(0, 0, refCanvas.width, refCanvas.height);
var comparison = compareSnapshots(testCanvas, refCanvas, true);
ok(comparison[0], "Rendering OK, got " + comparison[1] + ", expected " + comparison[2]);
var tester = window.SimpleTest;
window.close();
tester.finish();
}
]]>
</script>
</window>

View File

@ -16,6 +16,8 @@
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
// Run the test in a separate window so that the test runs as a chrome
// window
window.open("chrome_content_integration_window.xul", "chrome_content_integration",
"chrome,width=200,height=300");
]]>

View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
// Run the test in a separate window so that the test runs as a chrome
// window
window.open("default_background_window.xul", "default_background",
"chrome,width=200,height=300");
]]>
</script>
</window>