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

Side by Side Diff: Source/core/layout/LayoutBox.cpp

Issue 1145993002: Refactor root element background painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase & revise expectation 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 static OverrideSizeMap* gOverrideContainingBlockLogicalWidthMap = 0; 82 static OverrideSizeMap* gOverrideContainingBlockLogicalWidthMap = 0;
83 static OverrideSizeMap* gExtraInlineOffsetMap = 0; 83 static OverrideSizeMap* gExtraInlineOffsetMap = 0;
84 static OverrideSizeMap* gExtraBlockOffsetMap = 0; 84 static OverrideSizeMap* gExtraBlockOffsetMap = 0;
85 85
86 86
87 // Size of border belt for autoscroll. When mouse pointer in border belt, 87 // Size of border belt for autoscroll. When mouse pointer in border belt,
88 // autoscroll is started. 88 // autoscroll is started.
89 static const int autoscrollBeltSize = 20; 89 static const int autoscrollBeltSize = 20;
90 static const unsigned backgroundObscurationTestMaxDepth = 4; 90 static const unsigned backgroundObscurationTestMaxDepth = 4;
91 91
92 static bool skipBodyBackground(const LayoutBox* bodyElementLayoutObject)
93 {
94 ASSERT(bodyElementLayoutObject->isBody());
95 // The <body> only paints its background if the root element has defined a b ackground independent of the body,
96 // or if the <body>'s parent is not the document element's layoutObject (e.g . inside SVG foreignObject).
97 LayoutObject* documentElementLayoutObject = bodyElementLayoutObject->documen t().documentElement()->layoutObject();
98 return documentElementLayoutObject
99 && !documentElementLayoutObject->hasBackground()
100 && (documentElementLayoutObject == bodyElementLayoutObject->parent());
101 }
102
103 LayoutBox::LayoutBox(ContainerNode* node) 92 LayoutBox::LayoutBox(ContainerNode* node)
104 : LayoutBoxModelObject(node) 93 : LayoutBoxModelObject(node)
105 , m_intrinsicContentLogicalHeight(-1) 94 , m_intrinsicContentLogicalHeight(-1)
106 , m_minPreferredLogicalWidth(-1) 95 , m_minPreferredLogicalWidth(-1)
107 , m_maxPreferredLogicalWidth(-1) 96 , m_maxPreferredLogicalWidth(-1)
108 { 97 {
109 setIsBox(); 98 setIsBox();
110 } 99 }
111 100
112 DeprecatedPaintLayerType LayoutBox::layerTypeRequired() const 101 DeprecatedPaintLayerType LayoutBox::layerTypeRequired() const
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item). 286 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item).
298 // For now, it's more simple to just always recompute the grid. 287 // For now, it's more simple to just always recompute the grid.
299 toLayoutGrid(parent())->dirtyGrid(); 288 toLayoutGrid(parent())->dirtyGrid();
300 } 289 }
301 290
302 void LayoutBox::updateFromStyle() 291 void LayoutBox::updateFromStyle()
303 { 292 {
304 LayoutBoxModelObject::updateFromStyle(); 293 LayoutBoxModelObject::updateFromStyle();
305 294
306 const ComputedStyle& styleToUse = styleRef(); 295 const ComputedStyle& styleToUse = styleRef();
307 bool isRootObject = isDocumentElement();
308 bool isViewObject = isLayoutView(); 296 bool isViewObject = isLayoutView();
309 bool rootLayerScrolls = document().settings() && document().settings()->root LayerScrolls(); 297 bool rootLayerScrolls = document().settings() && document().settings()->root LayerScrolls();
310 298
311 // The root and the LayoutView always paint their backgrounds/borders. 299 // LayoutView of the main frame is resposible from painting base background.
312 if (isRootObject || isViewObject) 300 if (isViewObject && !document().ownerElement())
313 setHasBoxDecorationBackground(true); 301 setHasBoxDecorationBackground(true);
314 302
315 setFloating(!isOutOfFlowPositioned() && styleToUse.isFloating()); 303 setFloating(!isOutOfFlowPositioned() && styleToUse.isFloating());
316 304
317 bool boxHasOverflowClip = false; 305 bool boxHasOverflowClip = false;
318 if (!styleToUse.isOverflowVisible() && isLayoutBlock() && (rootLayerScrolls || !isViewObject)) { 306 if (!styleToUse.isOverflowVisible() && isLayoutBlock() && (rootLayerScrolls || !isViewObject)) {
319 // If overflow has been propagated to the viewport, it has no effect her e. 307 // If overflow has been propagated to the viewport, it has no effect her e.
320 if (node() != document().viewportDefiningElement()) 308 if (node() != document().viewportDefiningElement())
321 boxHasOverflowClip = true; 309 boxHasOverflowClip = true;
322 } 310 }
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 BackgroundImageGeometry geometry; 1161 BackgroundImageGeometry geometry;
1174 BoxPainter::calculateBackgroundImageGeometry(*this, 0, style()->backgroundLa yers(), backgroundRect, geometry); 1162 BoxPainter::calculateBackgroundImageGeometry(*this, 0, style()->backgroundLa yers(), backgroundRect, geometry);
1175 if (geometry.hasNonLocalGeometry()) 1163 if (geometry.hasNonLocalGeometry())
1176 return false; 1164 return false;
1177 paintedExtent = LayoutRect(geometry.destRect()); 1165 paintedExtent = LayoutRect(geometry.destRect());
1178 return true; 1166 return true;
1179 } 1167 }
1180 1168
1181 bool LayoutBox::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) c onst 1169 bool LayoutBox::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) c onst
1182 { 1170 {
1183 if (isBody() && skipBodyBackground(this)) 1171 if (isDocumentElement() || backgroundStolenForBeingBody())
1184 return false; 1172 return false;
1185 1173
1186 Color backgroundColor = resolveColor(CSSPropertyBackgroundColor); 1174 Color backgroundColor = resolveColor(CSSPropertyBackgroundColor);
1187 if (backgroundColor.hasAlpha()) 1175 if (backgroundColor.hasAlpha())
1188 return false; 1176 return false;
1189 1177
1190 // If the element has appearance, it might be painted by theme. 1178 // If the element has appearance, it might be painted by theme.
1191 // We cannot be sure if theme paints the background opaque. 1179 // We cannot be sure if theme paints the background opaque.
1192 // In this case it is safe to not assume opaqueness. 1180 // In this case it is safe to not assume opaqueness.
1193 // FIXME: May be ask theme if it paints opaque. 1181 // FIXME: May be ask theme if it paints opaque.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 return false; 1302 return false;
1315 } 1303 }
1316 1304
1317 void LayoutBox::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset) 1305 void LayoutBox::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset)
1318 { 1306 {
1319 BoxPainter(*this).paintMask(paintInfo, paintOffset); 1307 BoxPainter(*this).paintMask(paintInfo, paintOffset);
1320 } 1308 }
1321 1309
1322 void LayoutBox::imageChanged(WrappedImagePtr image, const IntRect*) 1310 void LayoutBox::imageChanged(WrappedImagePtr image, const IntRect*)
1323 { 1311 {
1324 if (!parent()) 1312 if (!parent() && !isLayoutView())
1325 return; 1313 return;
1326 1314
1327 // TODO(chrishtr): support PaintInvalidationDelayedFull for animated border images. 1315 // TODO(chrishtr): support PaintInvalidationDelayedFull for animated border images.
1328 if ((style()->borderImage().image() && style()->borderImage().image()->data( ) == image) 1316 if ((style()->borderImage().image() && style()->borderImage().image()->data( ) == image)
1329 || (style()->maskBoxImage().image() && style()->maskBoxImage().image()-> data() == image)) { 1317 || (style()->maskBoxImage().image() && style()->maskBoxImage().image()-> data() == image)) {
1330 setShouldDoFullPaintInvalidation(); 1318 setShouldDoFullPaintInvalidation();
1331 return; 1319 return;
1332 } 1320 }
1333 1321
1334 ShapeValue* shapeOutsideValue = style()->shapeOutside(); 1322 ShapeValue* shapeOutsideValue = style()->shapeOutside();
1335 if (!frameView()->isInPerformLayout() && isFloating() && shapeOutsideValue & & shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) { 1323 if (!frameView()->isInPerformLayout() && isFloating() && shapeOutsideValue & & shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) {
1336 ShapeOutsideInfo& info = ShapeOutsideInfo::ensureInfo(*this); 1324 ShapeOutsideInfo& info = ShapeOutsideInfo::ensureInfo(*this);
1337 if (!info.isComputingShape()) { 1325 if (!info.isComputingShape()) {
1338 info.markShapeAsDirty(); 1326 info.markShapeAsDirty();
1339 markShapeOutsideDependentsForLayout(); 1327 markShapeOutsideDependentsForLayout();
1340 } 1328 }
1341 } 1329 }
1342 1330
1343 if (!paintInvalidationLayerRectsForImage(image, style()->backgroundLayers(), true)) 1331 if (!paintInvalidationLayerRectsForImage(image, style()->backgroundLayers(), true))
1344 paintInvalidationLayerRectsForImage(image, style()->maskLayers(), false) ; 1332 paintInvalidationLayerRectsForImage(image, style()->maskLayers(), false) ;
1345 } 1333 }
1346 1334
1347 bool LayoutBox::paintInvalidationLayerRectsForImage(WrappedImagePtr image, const FillLayer& layers, bool drawingBackground) 1335 bool LayoutBox::paintInvalidationLayerRectsForImage(WrappedImagePtr image, const FillLayer& layers, bool drawingBackground)
trchen 2015/06/02 21:33:36 Acknowledged. Will update this in next CL upload.
1348 { 1336 {
1349 Vector<LayoutObject*> layerLayoutObjects; 1337 if (drawingBackground && (isDocumentElement() || backgroundStolenForBeingBod y()))
1350 1338 return false;
1351 // A background of the body or document must extend to the total visible siz e of the document. This means the union of the
1352 // view and document bounds, since it can be the case that the view is large r than the document and vice-versa.
1353 // http://dev.w3.org/csswg/css-backgrounds/#the-background
1354 if (drawingBackground && (isDocumentElement() || (isBody() && !document().do cumentElement()->layoutObject()->hasBackground()))) {
1355 layerLayoutObjects.append(document().documentElement()->layoutObject());
1356 layerLayoutObjects.append(view());
1357 if (view()->frameView())
1358 view()->frameView()->setNeedsFullPaintInvalidation();
1359 } else {
1360 layerLayoutObjects.append(this);
1361 }
1362 for (const FillLayer* curLayer = &layers; curLayer; curLayer = curLayer->nex t()) { 1339 for (const FillLayer* curLayer = &layers; curLayer; curLayer = curLayer->nex t()) {
1363 if (curLayer->image() && image == curLayer->image()->data() && curLayer- >image()->canRender(*this, style()->effectiveZoom())) { 1340 if (curLayer->image() && image == curLayer->image()->data()) {
1364 for (LayoutObject* layerLayoutObject : layerLayoutObjects) { 1341 bool maybeAnimated = curLayer->image()->cachedImage() && curLayer->i mage()->cachedImage()->image() && curLayer->image()->cachedImage()->image()->may beAnimated();
1365 // For now, only support delayed paint invalidation for animated background images. 1342 if (maybeAnimated && drawingBackground)
1366 bool maybeAnimated = curLayer->image()->cachedImage() && curLaye r->image()->cachedImage()->image() && curLayer->image()->cachedImage()->image()- >maybeAnimated(); 1343 setShouldDoFullPaintInvalidation(PaintInvalidationDelayedFull);
1367 if (maybeAnimated && drawingBackground) 1344 else
1368 layerLayoutObject->setShouldDoFullPaintInvalidation(PaintInv alidationDelayedFull); 1345 setShouldDoFullPaintInvalidation();
1369 else
1370 layerLayoutObject->setShouldDoFullPaintInvalidation(PaintInv alidationFull);
1371 }
1372 return true; 1346 return true;
1373 } 1347 }
1374 } 1348 }
1375 return false; 1349 return false;
1376 } 1350 }
1377 1351
1378 bool LayoutBox::intersectsVisibleViewport() 1352 bool LayoutBox::intersectsVisibleViewport()
1379 { 1353 {
1380 LayoutRect rect = visualOverflowRect(); 1354 LayoutRect rect = visualOverflowRect();
1381 LayoutView* layoutView = view(); 1355 LayoutView* layoutView = view();
(...skipping 3439 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 bool LayoutBox::canRenderBorderImage() const 4795 bool LayoutBox::canRenderBorderImage() const
4822 { 4796 {
4823 if (!style()->hasBorder()) 4797 if (!style()->hasBorder())
4824 return false; 4798 return false;
4825 4799
4826 StyleImage* borderImage = style()->borderImage().image(); 4800 StyleImage* borderImage = style()->borderImage().image();
4827 return borderImage && borderImage->canRender(*this, style()->effectiveZoom() ) && borderImage->isLoaded(); 4801 return borderImage && borderImage->canRender(*this, style()->effectiveZoom() ) && borderImage->isLoaded();
4828 } 4802 }
4829 4803
4830 } // namespace blink 4804 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698