Bug 486933 - image-rendering does not work on body or root CSS background images. r+sr=roc

This commit is contained in:
Robert Longson 2009-04-06 22:00:29 +01:00
parent 749e0df085
commit fba54c0496
6 changed files with 110 additions and 51 deletions

View File

@ -904,6 +904,59 @@ nsCSSRendering::FindNonTransparentBackground(nsStyleContext* aContext,
}
// Returns true if aFrame is a canvas frame.
// We need to treat the viewport as canvas because, even though
// it does not actually paint a background, we need to get the right
// background style so we correctly detect transparent documents.
PRBool
nsCSSRendering::IsCanvasFrame(nsIFrame *aFrame)
{
nsIAtom* frameType = aFrame->GetType();
return frameType == nsGkAtoms::canvasFrame ||
frameType == nsGkAtoms::rootFrame ||
frameType == nsGkAtoms::pageFrame ||
frameType == nsGkAtoms::pageContentFrame ||
frameType == nsGkAtoms::viewportFrame;
}
nsIFrame*
nsCSSRendering::FindRootFrame(nsIFrame *aForFrame)
{
const nsStyleBackground* result = aForFrame->GetStyleBackground();
// Check if we need to do propagation from BODY rather than HTML.
if (result->IsTransparent()) {
nsIContent* content = aForFrame->GetContent();
// The root element content can't be null. We wouldn't know what
// frame to create for aFrame.
// Use |GetOwnerDoc| so it works during destruction.
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
// 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) {
nsIFrame *bodyFrame = aForFrame->PresContext()->GetPresShell()->
GetPrimaryFrameFor(bodyContent);
if (bodyFrame) {
return bodyFrame;
}
}
}
}
return aForFrame;
}
/**
* |FindBackground| finds the correct style data to use to paint the
* background. It is responsible for handling the following two
@ -933,56 +986,10 @@ nsCSSRendering::FindNonTransparentBackground(nsStyleContext* aContext,
* whether the frame is the canvas frame, because PaintBackground must
* propagate that frame's background color to the view manager.
*/
// Returns true if aFrame is a canvas frame.
// We need to treat the viewport as canvas because, even though
// it does not actually paint a background, we need to get the right
// background style so we correctly detect transparent documents.
PRBool
nsCSSRendering::IsCanvasFrame(nsIFrame *aFrame)
{
nsIAtom* frameType = aFrame->GetType();
return frameType == nsGkAtoms::canvasFrame ||
frameType == nsGkAtoms::rootFrame ||
frameType == nsGkAtoms::pageFrame ||
frameType == nsGkAtoms::pageContentFrame ||
frameType == nsGkAtoms::viewportFrame;
}
const nsStyleBackground*
nsCSSRendering::FindRootFrameBackground(nsIFrame* aForFrame)
{
const nsStyleBackground* result = aForFrame->GetStyleBackground();
// Check if we need to do propagation from BODY rather than HTML.
if (result->IsTransparent()) {
nsIContent* content = aForFrame->GetContent();
// The root element content can't be null. We wouldn't know what
// frame to create for aForFrame.
// Use |GetOwnerDoc| so it works during destruction.
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
// 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) {
nsIFrame *bodyFrame = aForFrame->PresContext()->GetPresShell()->
GetPrimaryFrameFor(bodyContent);
if (bodyFrame)
result = bodyFrame->GetStyleBackground();
}
}
}
return result;
return FindRootFrame(aForFrame)->GetStyleBackground();
}
inline void

View File

@ -119,7 +119,12 @@ struct nsCSSRendering {
nscolor aColor);
/**
* @return PR_TRUE if |aForFrame| is a canvas frame, in the CSS sense.
* Gets the root frame for the frame
*/
static nsIFrame* FindRootFrame(nsIFrame* aForFrame);
/**
* @return PR_TRUE if |aFrame| is a canvas frame, in the CSS sense.
*/
static PRBool IsCanvasFrame(nsIFrame* aFrame);

View File

@ -2669,10 +2669,13 @@ nsLayoutUtils::GetClosestLayer(nsIFrame* aFrame)
}
gfxPattern::GraphicsFilter
nsLayoutUtils::GetGraphicsFilterForFrame(nsIFrame* aFrame)
nsLayoutUtils::GetGraphicsFilterForFrame(nsIFrame* aForFrame)
{
#ifdef MOZ_SVG
switch (aFrame->GetStyleSVG()->mImageRendering) {
nsIFrame *frame = nsCSSRendering::IsCanvasFrame(aForFrame) ?
nsCSSRendering::FindRootFrame(aForFrame) : aForFrame;
switch (frame->GetStyleSVG()->mImageRendering) {
case NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED:
return gfxPattern::FILTER_FAST;
case NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY:

View File

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<html>
<head>
<title>reference background-image-rendering: -moz-crisp-edges</title>
<style>
html
{
background-image: url('big.png');
background-attachment:fixed;
background-position: 20px 20px;
background-repeat: no-repeat;
}
</style>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE HTML>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<html reftest-zoom="5">
<head>
<title>test background-image-rendering: -moz-crisp-edges</title>
<style>
html
{
background-image: url('small.png');
image-rendering: -moz-crisp-edges;
background-attachment:fixed;
background-position: 4px 4px;
background-repeat: no-repeat;
}
</style>
</head>
<body>
</body>
</html>

View File

@ -1 +1,2 @@
== image-zoom-1.html image-zoom-1-ref.html
== background-image-zoom-1.html background-image-zoom-1-ref.html
== image-zoom-1.html image-zoom-1-ref.html