Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1042)

Unified Diff: Source/core/layout/LayoutBoxModelObject.cpp

Issue 1145993002: Refactor root element background painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase, adding back TestExpectation Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/layout/LayoutBoxModelObject.h ('k') | Source/core/layout/LayoutObject.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/LayoutBoxModelObject.cpp
diff --git a/Source/core/layout/LayoutBoxModelObject.cpp b/Source/core/layout/LayoutBoxModelObject.cpp
index 67cde61c9df5f6c595539c009fad0fe541b46535..0ede20bb48886f0899303a9591bdc06d1a5b0dd6 100644
--- a/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/Source/core/layout/LayoutBoxModelObject.cpp
@@ -26,6 +26,8 @@
#include "config.h"
#include "core/layout/LayoutBoxModelObject.h"
+#include "core/dom/NodeComputedStyle.h"
+#include "core/html/HTMLBodyElement.h"
#include "core/layout/ImageQualityController.h"
#include "core/layout/LayoutBlock.h"
#include "core/layout/LayoutFlowThread.h"
@@ -249,6 +251,23 @@ void LayoutBoxModelObject::styleDidChange(StyleDifference diff, const ComputedSt
invalidateDisplayItemClientForNonCompositingDescendants();
}
+ // The used style for body background may change due to computed style change
+ // on the document element because of background stealing.
+ // Refer to backgroundStolenForBeingBody() and
+ // http://www.w3.org/TR/css3-background/#body-background for more info.
+ if (isDocumentElement()) {
+ HTMLBodyElement* body = document().firstBodyElement();
+ LayoutObject* bodyLayout = body ? body->layoutObject() : nullptr;
+ if (bodyLayout && bodyLayout->isBoxModelObject()) {
+ bool newStoleBodyBackground = toLayoutBoxModelObject(bodyLayout)->backgroundStolenForBeingBody(style());
+ bool oldStoleBodyBackground = oldStyle && toLayoutBoxModelObject(bodyLayout)->backgroundStolenForBeingBody(oldStyle);
+ if (newStoleBodyBackground != oldStoleBodyBackground
+ && bodyLayout->style() && bodyLayout->style()->hasBackground()) {
+ bodyLayout->setShouldDoFullPaintInvalidation();
+ }
+ }
+ }
+
if (FrameView *frameView = view()->frameView()) {
bool newStyleIsViewportConstained = style()->hasViewportConstrainedPosition();
bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportConstrainedPosition();
@@ -937,4 +956,27 @@ void LayoutBoxModelObject::moveChildrenTo(LayoutBoxModelObject* toBoxModelObject
}
}
+bool LayoutBoxModelObject::backgroundStolenForBeingBody(const ComputedStyle* rootElementStyle) const
+{
+ // http://www.w3.org/TR/css3-background/#body-background
+ // If the root element is <html> with no background, and a <body> child element exists,
+ // the root element steals the first <body> child element's background.
+ if (!isBody())
+ return false;
+
+ Element* rootElement = document().documentElement();
+ if (!isHTMLHtmlElement(rootElement))
+ return false;
+
+ if (!rootElementStyle)
+ rootElementStyle = rootElement->ensureComputedStyle();
+ if (rootElementStyle->hasBackground())
+ return false;
+
+ if (node() != document().firstBodyElement())
+ return false;
+
+ return true;
+}
+
} // namespace blink
« no previous file with comments | « Source/core/layout/LayoutBoxModelObject.h ('k') | Source/core/layout/LayoutObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698