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

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 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 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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 BackgroundImageGeometry geometry; 1170 BackgroundImageGeometry geometry;
1182 BoxPainter::calculateBackgroundImageGeometry(*this, 0, style()->backgroundLa yers(), backgroundRect, geometry); 1171 BoxPainter::calculateBackgroundImageGeometry(*this, 0, style()->backgroundLa yers(), backgroundRect, geometry);
1183 if (geometry.hasNonLocalGeometry()) 1172 if (geometry.hasNonLocalGeometry())
1184 return false; 1173 return false;
1185 paintedExtent = LayoutRect(geometry.destRect()); 1174 paintedExtent = LayoutRect(geometry.destRect());
1186 return true; 1175 return true;
1187 } 1176 }
1188 1177
1189 bool LayoutBox::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) c onst 1178 bool LayoutBox::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) c onst
1190 { 1179 {
1191 if (isBody() && skipBodyBackground(this)) 1180 if (backgroundStolenForBeingBody())
1192 return false; 1181 return false;
1193 1182
1194 Color backgroundColor = resolveColor(CSSPropertyBackgroundColor); 1183 Color backgroundColor = resolveColor(CSSPropertyBackgroundColor);
1195 if (backgroundColor.hasAlpha()) 1184 if (backgroundColor.hasAlpha())
1196 return false; 1185 return false;
1197 1186
1198 // If the element has appearance, it might be painted by theme. 1187 // If the element has appearance, it might be painted by theme.
1199 // We cannot be sure if theme paints the background opaque. 1188 // We cannot be sure if theme paints the background opaque.
1200 // In this case it is safe to not assume opaqueness. 1189 // In this case it is safe to not assume opaqueness.
1201 // FIXME: May be ask theme if it paints opaque. 1190 // FIXME: May be ask theme if it paints opaque.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 return false; 1311 return false;
1323 } 1312 }
1324 1313
1325 void LayoutBox::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset) 1314 void LayoutBox::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset)
1326 { 1315 {
1327 BoxPainter(*this).paintMask(paintInfo, paintOffset); 1316 BoxPainter(*this).paintMask(paintInfo, paintOffset);
1328 } 1317 }
1329 1318
1330 void LayoutBox::imageChanged(WrappedImagePtr image, const IntRect*) 1319 void LayoutBox::imageChanged(WrappedImagePtr image, const IntRect*)
1331 { 1320 {
1332 if (!parent()) 1321 if (!parent() && !isLayoutView())
1333 return; 1322 return;
1334 1323
1335 // TODO(chrishtr): support PaintInvalidationDelayedFull for animated border images. 1324 // TODO(chrishtr): support PaintInvalidationDelayedFull for animated border images.
1336 if ((style()->borderImage().image() && style()->borderImage().image()->data( ) == image) 1325 if ((style()->borderImage().image() && style()->borderImage().image()->data( ) == image)
1337 || (style()->maskBoxImage().image() && style()->maskBoxImage().image()-> data() == image)) { 1326 || (style()->maskBoxImage().image() && style()->maskBoxImage().image()-> data() == image)) {
1338 setShouldDoFullPaintInvalidation(); 1327 setShouldDoFullPaintInvalidation();
1339 return; 1328 return;
1340 } 1329 }
1341 1330
1342 ShapeValue* shapeOutsideValue = style()->shapeOutside(); 1331 ShapeValue* shapeOutsideValue = style()->shapeOutside();
1343 if (!frameView()->isInPerformLayout() && isFloating() && shapeOutsideValue & & shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) { 1332 if (!frameView()->isInPerformLayout() && isFloating() && shapeOutsideValue & & shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) {
1344 ShapeOutsideInfo& info = ShapeOutsideInfo::ensureInfo(*this); 1333 ShapeOutsideInfo& info = ShapeOutsideInfo::ensureInfo(*this);
1345 if (!info.isComputingShape()) { 1334 if (!info.isComputingShape()) {
1346 info.markShapeAsDirty(); 1335 info.markShapeAsDirty();
1347 markShapeOutsideDependentsForLayout(); 1336 markShapeOutsideDependentsForLayout();
1348 } 1337 }
1349 } 1338 }
1350 1339
1351 if (!paintInvalidationLayerRectsForImage(image, style()->backgroundLayers(), true)) 1340 if (!paintInvalidationLayerRectsForImage(image, style()->backgroundLayers(), true))
1352 paintInvalidationLayerRectsForImage(image, style()->maskLayers(), false) ; 1341 paintInvalidationLayerRectsForImage(image, style()->maskLayers(), false) ;
1353 } 1342 }
1354 1343
1355 bool LayoutBox::paintInvalidationLayerRectsForImage(WrappedImagePtr image, const FillLayer& layers, bool drawingBackground) 1344 bool LayoutBox::paintInvalidationLayerRectsForImage(WrappedImagePtr image, const FillLayer& layers, bool drawingBackground)
Xianzhu 2015/05/20 16:14:44 BTW this function can be renamed to 'invalidatePai
1356 { 1345 {
1357 Vector<LayoutObject*> layerLayoutObjects; 1346 if (drawingBackground && (isDocumentElement() || backgroundStolenForBeingBod y()))
1358 1347 return false;
1359 // A background of the body or document must extend to the total visible siz e of the document. This means the union of the
1360 // view and document bounds, since it can be the case that the view is large r than the document and vice-versa.
1361 // http://dev.w3.org/csswg/css-backgrounds/#the-background
1362 if (drawingBackground && (isDocumentElement() || (isBody() && !document().do cumentElement()->layoutObject()->hasBackground()))) {
1363 layerLayoutObjects.append(document().documentElement()->layoutObject());
1364 layerLayoutObjects.append(view());
1365 if (view()->frameView())
1366 view()->frameView()->setNeedsFullPaintInvalidation();
1367 } else {
1368 layerLayoutObjects.append(this);
1369 }
1370 for (const FillLayer* curLayer = &layers; curLayer; curLayer = curLayer->nex t()) { 1348 for (const FillLayer* curLayer = &layers; curLayer; curLayer = curLayer->nex t()) {
1371 if (curLayer->image() && image == curLayer->image()->data() && curLayer- >image()->canRender(*this, style()->effectiveZoom())) { 1349 if (curLayer->image() && image == curLayer->image()->data()) {
1372 for (LayoutObject* layerLayoutObject : layerLayoutObjects) { 1350 bool maybeAnimated = curLayer->image()->cachedImage() && curLayer->i mage()->cachedImage()->image() && curLayer->image()->cachedImage()->image()->may beAnimated();
1373 // For now, only support delayed paint invalidation for animated background images. 1351 if (maybeAnimated && drawingBackground)
1374 bool maybeAnimated = curLayer->image()->cachedImage() && curLaye r->image()->cachedImage()->image() && curLayer->image()->cachedImage()->image()- >maybeAnimated(); 1352 setShouldDoFullPaintInvalidation(PaintInvalidationDelayedFull);
1375 if (maybeAnimated && drawingBackground) 1353 else
1376 layerLayoutObject->setShouldDoFullPaintInvalidation(PaintInv alidationDelayedFull); 1354 setShouldDoFullPaintInvalidation();
1377 else
1378 layerLayoutObject->setShouldDoFullPaintInvalidation(PaintInv alidationFull);
1379 }
1380 return true; 1355 return true;
1381 } 1356 }
1382 } 1357 }
1383 return false; 1358 return false;
1384 } 1359 }
1385 1360
1386 bool LayoutBox::intersectsVisibleViewport() 1361 bool LayoutBox::intersectsVisibleViewport()
1387 { 1362 {
1388 LayoutRect rect = visualOverflowRect(); 1363 LayoutRect rect = visualOverflowRect();
1389 LayoutView* layoutView = view(); 1364 LayoutView* layoutView = view();
(...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after
4794 bool LayoutBox::canRenderBorderImage() const 4769 bool LayoutBox::canRenderBorderImage() const
4795 { 4770 {
4796 if (!style()->hasBorder()) 4771 if (!style()->hasBorder())
4797 return false; 4772 return false;
4798 4773
4799 StyleImage* borderImage = style()->borderImage().image(); 4774 StyleImage* borderImage = style()->borderImage().image();
4800 return borderImage && borderImage->canRender(*this, style()->effectiveZoom() ) && borderImage->isLoaded(); 4775 return borderImage && borderImage->canRender(*this, style()->effectiveZoom() ) && borderImage->isLoaded();
4801 } 4776 }
4802 4777
4803 } // namespace blink 4778 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698