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

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 Created 5 years, 7 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
Index: Source/core/layout/LayoutBoxModelObject.cpp
diff --git a/Source/core/layout/LayoutBoxModelObject.cpp b/Source/core/layout/LayoutBoxModelObject.cpp
index a1c4e4474400ed203df6ee7e345912cc5a26177a..ce05ee9f53e9ba2256d32ad05a54e00dfc855111 100644
--- a/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/Source/core/layout/LayoutBoxModelObject.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "core/layout/LayoutBoxModelObject.h"
+#include "core/dom/NodeComputedStyle.h"
#include "core/layout/ImageQualityController.h"
#include "core/layout/LayoutBlock.h"
#include "core/layout/LayoutFlowThread.h"
@@ -249,6 +250,21 @@ void LayoutBoxModelObject::styleDidChange(StyleDifference diff, const ComputedSt
invalidateDisplayItemClientForNonCompositingDescendants();
}
+ if (isDocumentElement() && isHTMLHtmlElement(node())) {
+ // Refers to backgroundStolenForBeingBody().
+ bool newStyleHasBackground = style()->hasBackground();
+ bool oldStyleHasBackground = oldStyle && oldStyle->hasBackground();
+ if (newStyleHasBackground != oldStyleHasBackground) {
+ Element* body = document().body();
+ LayoutObject* bodyLayout = isHTMLBodyElement(body) ? body->layoutObject() : nullptr;
+ if (bodyLayout) {
+ const ComputedStyle* bodyStyle = bodyLayout->style();
+ if (bodyStyle && bodyStyle->hasBackground())
+ bodyLayout-> setShouldDoFullPaintInvalidation();
+ }
+ }
+ }
+
if (FrameView *frameView = view()->frameView()) {
bool newStyleIsViewportConstained = style()->hasViewportConstrainedPosition();
bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportConstrainedPosition();
@@ -709,6 +725,11 @@ bool LayoutBoxModelObject::boxShadowShouldBeAppliedToBackground(BackgroundBleedA
if (backgroundColor.hasAlpha())
return false;
+ // TODO(trchen): Mask layers are painted with the same code path as background layers.
+ // We shouldn't paint shadow to the mask by accident.
+ if (style()->maskImage())
+ return false;
+
const FillLayer* lastBackgroundLayer = &style()->backgroundLayers();
for (const FillLayer* next = lastBackgroundLayer->next(); next; next = lastBackgroundLayer->next())
lastBackgroundLayer = next;
@@ -944,4 +965,22 @@ void LayoutBoxModelObject::moveChildrenTo(LayoutBoxModelObject* toBoxModelObject
}
}
+bool LayoutBoxModelObject::backgroundStolenForBeingBody() 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) || rootElement->ensureComputedStyle()->hasBackground())
+ return false;
+
+ if (node() != document().body())
+ return false;
+
+ return true;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698