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

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

Issue 1145993002: Refactor root element background painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix DocumentLifecycle error 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (!style()->isHorizontalWritingMode()) 188 if (!style()->isHorizontalWritingMode())
189 return true; 189 return true;
190 190
191 // The width/height checks below assume horizontal writing mode. 191 // The width/height checks below assume horizontal writing mode.
192 ASSERT(style()->isHorizontalWritingMode()); 192 ASSERT(style()->isHorizontalWritingMode());
193 193
194 if (size().width() != viewLogicalWidthForBoxSizing()) 194 if (size().width() != viewLogicalWidthForBoxSizing())
195 return true; 195 return true;
196 196
197 if (size().height() != viewLogicalHeightForBoxSizing()) { 197 if (size().height() != viewLogicalHeightForBoxSizing()) {
198 if (LayoutObject* backgroundLayoutObject = this->backgroundLayoutObject( )) { 198 // When background-attachment is 'fixed', we treat the viewport (instead of the 'root'
199 // When background-attachment is 'fixed', we treat the viewport (ins tead of the 'root' 199 // i.e. html or body) as the background positioning area, and we should full paint invalidation
200 // i.e. html or body) as the background positioning area, and we sho uld full paint invalidation 200 // viewport resize if the background image is not composited and needs f ull paint invalidation on
201 // viewport resize if the background image is not composited and nee ds full paint invalidation on 201 // background positioning area resize.
202 // background positioning area resize. 202 if (!m_compositor || !m_compositor->needsFixedRootBackgroundLayer(layer( ))) {
203 if (!m_compositor || !m_compositor->needsFixedRootBackgroundLayer(la yer())) { 203 if (style()->hasFixedBackgroundImage()
204 if (backgroundLayoutObject->style()->hasFixedBackgroundImage() 204 && mustInvalidateFillLayersPaintOnHeightChange(style()->backgrou ndLayers()))
205 && mustInvalidateFillLayersPaintOnHeightChange(backgroundLay outObject->style()->backgroundLayers())) 205 return true;
206 return true;
207 }
208 } 206 }
209 } 207 }
210 208
211 return false; 209 return false;
212 } 210 }
213 211
214 void LayoutView::layout() 212 void LayoutView::layout()
215 { 213 {
216 if (!document().paginated()) 214 if (!document().paginated())
217 setPageLogicalHeight(0); 215 setPageLogicalHeight(0);
218 216
219 if (shouldUsePrintingLayout()) 217 if (shouldUsePrintingLayout())
220 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth() ; 218 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth() ;
221 219
222 SubtreeLayoutScope layoutScope(*this); 220 SubtreeLayoutScope layoutScope(*this);
223 221
224 LayoutRect oldLayoutOverflowRect = layoutOverflowRect();
225
226 // Use calcWidth/Height to get the new width/height, since this will take th e full page zoom factor into account. 222 // Use calcWidth/Height to get the new width/height, since this will take th e full page zoom factor into account.
227 bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView 223 bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView
228 || logicalWidth() != viewLogicalWidthForBoxSizing() 224 || logicalWidth() != viewLogicalWidthForBoxSizing()
229 || logicalHeight() != viewLogicalHeightForBoxSizing()); 225 || logicalHeight() != viewLogicalHeightForBoxSizing());
230 if (relayoutChildren) { 226 if (relayoutChildren) {
231 layoutScope.setChildNeedsLayout(this); 227 layoutScope.setChildNeedsLayout(this);
232 for (LayoutObject* child = firstChild(); child; child = child->nextSibli ng()) { 228 for (LayoutObject* child = firstChild(); child; child = child->nextSibli ng()) {
233 if (child->isSVGRoot()) 229 if (child->isSVGRoot())
234 continue; 230 continue;
235 231
(...skipping 11 matching lines...) Expand all
247 ASSERT(!m_layoutState); 243 ASSERT(!m_layoutState);
248 if (!needsLayout()) 244 if (!needsLayout())
249 return; 245 return;
250 246
251 LayoutState rootLayoutState(pageLogicalHeight(), pageLogicalHeightChanged(), *this); 247 LayoutState rootLayoutState(pageLogicalHeight(), pageLogicalHeightChanged(), *this);
252 248
253 m_pageLogicalHeightChanged = false; 249 m_pageLogicalHeightChanged = false;
254 250
255 layoutContent(); 251 layoutContent();
256 252
257 if (RuntimeEnabledFeatures::slimmingPaintEnabled() && layoutOverflowRect() ! = oldLayoutOverflowRect) {
258 // The document element paints the viewport background, so we need to in validate it when
259 // layout overflow changes.
260 // FIXME: Improve viewport background styling/invalidation/painting. crb ug.com/475115
261 if (Element* documentElement = document().documentElement()) {
262 if (LayoutObject* rootObject = documentElement->layoutObject())
263 rootObject->setShouldDoFullPaintInvalidation();
264 }
265 }
266
267 #if ENABLE(ASSERT) 253 #if ENABLE(ASSERT)
268 checkLayoutState(); 254 checkLayoutState();
269 #endif 255 #endif
270 clearNeedsLayout(); 256 clearNeedsLayout();
271 } 257 }
272 258
259 void LayoutView::styleDidChange(StyleDifference diff, const ComputedStyle* oldSt yle)
260 {
261 const ComputedStyle& newStyle = styleRef();
262
263 if (oldStyle && oldStyle->hasEntirelyFixedBackground() != newStyle.hasEntire lyFixedBackground())
264 compositor()->setNeedsUpdateFixedBackground();
265
266 LayoutBlockFlow::styleDidChange(diff, oldStyle);
267 }
268
269 void LayoutView::getBackgroundPositioningFromDocumentElement(BackgroundPositioni ng& position) const
270 {
271 const LayoutObject* rootObject = document().documentElement() ? document().d ocumentElement()->layoutObject() : nullptr;
272 if (!rootObject || !rootObject->isBox())
273 return;
274
275 const LayoutBox& rootBox = toLayoutBox(*rootObject);
276 position.borderBoxSize = rootBox.size();
277 position.paddingBoxRect = rootBox.paddingBoxRect();
278 position.contentBoxRect = rootBox.contentBoxRect();
279 if (rootBox.hasLayer()) {
280 const DeprecatedPaintLayer& rootLayer = *rootBox.layer();
281 LayoutPoint offset;
282 rootLayer.convertToLayerCoords(nullptr, offset);
283 position.transform.translate(offset.x(), offset.y());
284 position.transform.multiply(rootLayer.currentTransform());
285 }
286 }
287
288 PaintInvalidationReason LayoutView::paintInvalidationReason(const LayoutBoxModel Object& paintInvalidationContainer,
289 const LayoutRect& oldBounds, const LayoutPoint& oldLocation,
290 const LayoutRect& newBounds, const LayoutPoint& newLocation) const
291 {
292 const BackgroundPositioning& oldPosition = m_previousRootBackgroundPositioni ng;
293 BackgroundPositioning newPosition;
294 getBackgroundPositioningFromDocumentElement(newPosition);
295
296 if (oldPosition.transform != newPosition.transform)
297 return PaintInvalidationLocationChange;
298
299 const FillLayer& backgroundLayers = style()->backgroundLayers();
300 if (mustInvalidateFillLayersPaintOnWidthChange(backgroundLayers) || mustInva lidateFillLayersPaintOnHeightChange(backgroundLayers)) {
301 if (oldPosition.borderBoxSize != newPosition.borderBoxSize
302 || oldPosition.paddingBoxRect != newPosition.paddingBoxRect
303 || oldPosition.contentBoxRect != newPosition.contentBoxRect) {
304 return PaintInvalidationBorderBoxChange;
305 }
306 }
307
308 return LayoutBlockFlow::paintInvalidationReason(paintInvalidationContainer, oldBounds, oldLocation, newBounds, newLocation);
309 }
310
311 PaintInvalidationReason LayoutView::invalidatePaintIfNeeded(PaintInvalidationSta te& paintInvalidationState, const LayoutBoxModelObject& newPaintInvalidationCont ainer)
312 {
313 getBackgroundPositioningFromDocumentElement(m_previousRootBackgroundPosition ing);
Xianzhu 2015/06/05 05:08:28 This seems incorrect. m_previousRootBackgroundPosi
314
315 return LayoutBlockFlow::invalidatePaintIfNeeded(paintInvalidationState, newP aintInvalidationContainer);
316 }
317
273 void LayoutView::mapLocalToContainer(const LayoutBoxModelObject* paintInvalidati onContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* was Fixed, const PaintInvalidationState* paintInvalidationState) const 318 void LayoutView::mapLocalToContainer(const LayoutBoxModelObject* paintInvalidati onContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* was Fixed, const PaintInvalidationState* paintInvalidationState) const
274 { 319 {
275 ASSERT_UNUSED(wasFixed, !wasFixed || *wasFixed == static_cast<bool>(mode & I sFixed)); 320 ASSERT_UNUSED(wasFixed, !wasFixed || *wasFixed == static_cast<bool>(mode & I sFixed));
276 321
277 if (!paintInvalidationContainer && mode & UseTransforms && shouldUseTransfor mFromContainer(0)) { 322 if (!paintInvalidationContainer && mode & UseTransforms && shouldUseTransfor mFromContainer(0)) {
278 TransformationMatrix t; 323 TransformationMatrix t;
279 getTransformFromContainer(0, LayoutSize(), t); 324 getTransformFromContainer(0, LayoutSize(), t);
280 transformState.applyTransform(t); 325 transformState.applyTransform(t);
281 } 326 }
282 327
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 882
838 IntRect LayoutView::unscaledDocumentRect() const 883 IntRect LayoutView::unscaledDocumentRect() const
839 { 884 {
840 LayoutRect overflowRect(layoutOverflowRect()); 885 LayoutRect overflowRect(layoutOverflowRect());
841 flipForWritingMode(overflowRect); 886 flipForWritingMode(overflowRect);
842 return pixelSnappedIntRect(overflowRect); 887 return pixelSnappedIntRect(overflowRect);
843 } 888 }
844 889
845 bool LayoutView::rootBackgroundIsEntirelyFixed() const 890 bool LayoutView::rootBackgroundIsEntirelyFixed() const
846 { 891 {
847 if (LayoutObject* backgroundLayoutObject = this->backgroundLayoutObject()) 892 return style()->hasEntirelyFixedBackground();
848 return backgroundLayoutObject->style()->hasEntirelyFixedBackground();
849 return false;
850 }
851
852 LayoutObject* LayoutView::backgroundLayoutObject() const
853 {
854 if (Element* documentElement = document().documentElement()) {
855 if (LayoutObject* rootObject = documentElement->layoutObject())
856 return rootObject->layoutObjectForRootBackground();
857 }
858 return 0;
859 } 893 }
860 894
861 LayoutRect LayoutView::backgroundRect(LayoutBox* backgroundLayoutObject) const 895 LayoutRect LayoutView::backgroundRect(LayoutBox* backgroundLayoutObject) const
862 { 896 {
863 return LayoutRect(unscaledDocumentRect()); 897 return LayoutRect(unscaledDocumentRect());
864 } 898 }
865 899
866 IntRect LayoutView::documentRect() const 900 IntRect LayoutView::documentRect() const
867 { 901 {
868 FloatRect overflowRect(unscaledDocumentRect()); 902 FloatRect overflowRect(unscaledDocumentRect());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 return viewHeight(IncludeScrollbars) / scale; 1008 return viewHeight(IncludeScrollbars) / scale;
975 } 1009 }
976 1010
977 void LayoutView::willBeDestroyed() 1011 void LayoutView::willBeDestroyed()
978 { 1012 {
979 LayoutBlockFlow::willBeDestroyed(); 1013 LayoutBlockFlow::willBeDestroyed();
980 m_compositor.clear(); 1014 m_compositor.clear();
981 } 1015 }
982 1016
983 } // namespace blink 1017 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutView.h ('k') | Source/core/layout/compositing/CompositedDeprecatedPaintLayerMapping.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698