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

Side by Side Diff: third_party/WebKit/Source/core/layout/compositing/CompositingReasonFinder.cpp

Issue 2716583005: Do not promote position sticky or fixed elements unless they move with scroll. (Closed)
Patch Set: Avoid computing constraints for non-anchored sticky and add/update tests. Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/compositing/CompositingReasonFinder.h" 5 #include "core/layout/compositing/CompositingReasonFinder.h"
6 6
7 #include "core/CSSPropertyNames.h" 7 #include "core/CSSPropertyNames.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
(...skipping 19 matching lines...) Expand all
30 m_compositingTriggers |= OverflowScrollTrigger; 30 m_compositingTriggers |= OverflowScrollTrigger;
31 m_compositingTriggers |= ViewportConstrainedPositionedTrigger; 31 m_compositingTriggers |= ViewportConstrainedPositionedTrigger;
32 } 32 }
33 } 33 }
34 34
35 bool CompositingReasonFinder::isMainFrame() const { 35 bool CompositingReasonFinder::isMainFrame() const {
36 return m_layoutView.document().isInMainFrame(); 36 return m_layoutView.document().isInMainFrame();
37 } 37 }
38 38
39 CompositingReasons CompositingReasonFinder::directReasons( 39 CompositingReasons CompositingReasonFinder::directReasons(
40 const PaintLayer* layer) const { 40 const PaintLayer* layer,
41 bool ignoreLCDText) const {
41 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 42 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
42 return CompositingReasonNone; 43 return CompositingReasonNone;
43 44
44 DCHECK_EQ(potentialCompositingReasonsFromStyle(layer->layoutObject()), 45 DCHECK_EQ(potentialCompositingReasonsFromStyle(layer->layoutObject()),
45 layer->potentialCompositingReasonsFromStyle()); 46 layer->potentialCompositingReasonsFromStyle());
46 CompositingReasons styleDeterminedDirectCompositingReasons = 47 CompositingReasons styleDeterminedDirectCompositingReasons =
47 layer->potentialCompositingReasonsFromStyle() & 48 layer->potentialCompositingReasonsFromStyle() &
48 CompositingReasonComboAllDirectStyleDeterminedReasons; 49 CompositingReasonComboAllDirectStyleDeterminedReasons;
49 50
50 return styleDeterminedDirectCompositingReasons | 51 return styleDeterminedDirectCompositingReasons |
51 nonStyleDeterminedDirectReasons(layer); 52 nonStyleDeterminedDirectReasons(layer, ignoreLCDText);
52 } 53 }
53 54
54 // This information doesn't appear to be incorporated into CompositingReasons. 55 // This information doesn't appear to be incorporated into CompositingReasons.
55 bool CompositingReasonFinder::requiresCompositingForScrollableFrame() const { 56 bool CompositingReasonFinder::requiresCompositingForScrollableFrame() const {
56 // Need this done first to determine overflow. 57 // Need this done first to determine overflow.
57 DCHECK(!m_layoutView.needsLayout()); 58 DCHECK(!m_layoutView.needsLayout());
58 if (isMainFrame()) 59 if (isMainFrame())
59 return false; 60 return false;
60 61
61 if (!(m_compositingTriggers & ScrollableInnerFrameTrigger)) 62 if (!(m_compositingTriggers & ScrollableInnerFrameTrigger))
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool CompositingReasonFinder::requiresCompositingForTransform( 135 bool CompositingReasonFinder::requiresCompositingForTransform(
135 const LayoutObject& layoutObject) { 136 const LayoutObject& layoutObject) {
136 // Note that we ask the layoutObject if it has a transform, because the style 137 // Note that we ask the layoutObject if it has a transform, because the style
137 // may have transforms, but the layoutObject may be an inline that doesn't 138 // may have transforms, but the layoutObject may be an inline that doesn't
138 // support them. 139 // support them.
139 return layoutObject.hasTransformRelatedProperty() && 140 return layoutObject.hasTransformRelatedProperty() &&
140 layoutObject.styleRef().has3DTransform(); 141 layoutObject.styleRef().has3DTransform();
141 } 142 }
142 143
143 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons( 144 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons(
144 const PaintLayer* layer) const { 145 const PaintLayer* layer,
146 bool ignoreLCDText) const {
145 CompositingReasons directReasons = CompositingReasonNone; 147 CompositingReasons directReasons = CompositingReasonNone;
146 LayoutObject& layoutObject = layer->layoutObject(); 148 LayoutObject& layoutObject = layer->layoutObject();
147 149
148 if (m_compositingTriggers & OverflowScrollTrigger && layer->clipParent()) 150 if (m_compositingTriggers & OverflowScrollTrigger && layer->clipParent())
149 directReasons |= CompositingReasonOutOfFlowClipping; 151 directReasons |= CompositingReasonOutOfFlowClipping;
150 152
151 if (layer->needsCompositedScrolling()) 153 if (layer->needsCompositedScrolling())
152 directReasons |= CompositingReasonOverflowScrollingTouch; 154 directReasons |= CompositingReasonOverflowScrollingTouch;
153 155
154 // Composite |layer| if it is inside of an ancestor scrolling layer, but that 156 // Composite |layer| if it is inside of an ancestor scrolling layer, but that
155 // scrolling layer is not on the stacking context ancestor chain of |layer|. 157 // scrolling layer is not on the stacking context ancestor chain of |layer|.
156 // See the definition of the scrollParent property in Layer for more detail. 158 // See the definition of the scrollParent property in Layer for more detail.
157 if (const PaintLayer* scrollingAncestor = layer->ancestorScrollingLayer()) { 159 if (const PaintLayer* scrollingAncestor = layer->ancestorScrollingLayer()) {
158 if (scrollingAncestor->needsCompositedScrolling() && layer->scrollParent()) 160 if (scrollingAncestor->needsCompositedScrolling() && layer->scrollParent())
159 directReasons |= CompositingReasonOverflowScrollingParent; 161 directReasons |= CompositingReasonOverflowScrollingParent;
160 } 162 }
161 163
162 // TODO(flackr): Rename functions and variables to include sticky position 164 if (requiresCompositingForScrollDependentPosition(layer, ignoreLCDText))
163 // (i.e. ScrollDependentPosition rather than PositionFixed).
164 if (requiresCompositingForScrollDependentPosition(layer))
165 directReasons |= CompositingReasonScrollDependentPosition; 165 directReasons |= CompositingReasonScrollDependentPosition;
166 166
167 directReasons |= layoutObject.additionalCompositingReasons(); 167 directReasons |= layoutObject.additionalCompositingReasons();
168 168
169 DCHECK(!(directReasons & CompositingReasonComboAllStyleDeterminedReasons)); 169 DCHECK(!(directReasons & CompositingReasonComboAllStyleDeterminedReasons));
170 return directReasons; 170 return directReasons;
171 } 171 }
172 172
173 bool CompositingReasonFinder::requiresCompositingForAnimation( 173 bool CompositingReasonFinder::requiresCompositingForAnimation(
174 const ComputedStyle& style) { 174 const ComputedStyle& style) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 bool CompositingReasonFinder::requiresCompositingForTransformAnimation( 209 bool CompositingReasonFinder::requiresCompositingForTransformAnimation(
210 const ComputedStyle& style) { 210 const ComputedStyle& style) {
211 return style.subtreeWillChangeContents() 211 return style.subtreeWillChangeContents()
212 ? style.isRunningTransformAnimationOnCompositor() 212 ? style.isRunningTransformAnimationOnCompositor()
213 : style.hasCurrentTransformAnimation(); 213 : style.hasCurrentTransformAnimation();
214 } 214 }
215 215
216 bool CompositingReasonFinder::requiresCompositingForScrollDependentPosition( 216 bool CompositingReasonFinder::requiresCompositingForScrollDependentPosition(
217 const PaintLayer* layer) const { 217 const PaintLayer* layer,
218 if (layer->layoutObject().style()->position() != EPosition::kFixed && 218 bool ignoreLCDText) const {
219 layer->layoutObject().style()->position() != EPosition::kSticky) 219 if (!layer->layoutObject().style()->hasViewportConstrainedPosition() &&
220 !layer->layoutObject().style()->hasStickyConstrainedPosition())
220 return false; 221 return false;
221 222
222 if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger) && 223 if (!(ignoreLCDText ||
224 (m_compositingTriggers & ViewportConstrainedPositionedTrigger)) &&
223 (!RuntimeEnabledFeatures::compositeOpaqueFixedPositionEnabled() || 225 (!RuntimeEnabledFeatures::compositeOpaqueFixedPositionEnabled() ||
224 !layer->backgroundIsKnownToBeOpaqueInRect( 226 !layer->backgroundIsKnownToBeOpaqueInRect(
225 LayoutRect(layer->boundingBoxForCompositing())) || 227 LayoutRect(layer->boundingBoxForCompositing())) ||
226 layer->compositesWithTransform() || layer->compositesWithOpacity())) { 228 layer->compositesWithTransform() || layer->compositesWithOpacity())) {
227 return false; 229 return false;
228 } 230 }
229 // Don't promote fixed position elements that are descendants of a non-view 231 // Don't promote fixed position elements that are descendants of a non-view
230 // container, e.g. transformed elements. They will stay fixed wrt the 232 // container, e.g. transformed elements. They will stay fixed wrt the
231 // container rather than the enclosing frame. 233 // container rather than the enclosing frame.
232 if (layer->sticksToViewport()) 234 EPosition position = layer->layoutObject().style()->position();
233 return m_layoutView.frameView()->isScrollable(); 235 if (position == EPosition::kFixed)
234 236 return layer->fixedToViewport() && m_layoutView.frameView()->isScrollable();
235 if (layer->layoutObject().style()->position() != EPosition::kSticky) 237 DCHECK(position == EPosition::kSticky);
236 return false;
237 238
238 // Don't promote nested sticky elements; the compositor can't handle them. 239 // Don't promote nested sticky elements; the compositor can't handle them.
239 // TODO(smcgruer): Add cc nested sticky support (http://crbug.com/672710) 240 // TODO(smcgruer): Add cc nested sticky support (http://crbug.com/672710)
240 PaintLayerScrollableArea* scrollableArea = 241 PaintLayerScrollableArea* scrollableArea =
241 layer->ancestorOverflowLayer()->getScrollableArea(); 242 layer->ancestorOverflowLayer()->getScrollableArea();
242 DCHECK(scrollableArea->stickyConstraintsMap().contains( 243 DCHECK(scrollableArea->stickyConstraintsMap().contains(
243 const_cast<PaintLayer*>(layer))); 244 const_cast<PaintLayer*>(layer)));
245 if (scrollableArea->stickyConstraintsMap()
246 .at(const_cast<PaintLayer*>(layer))
247 .hasAncestorStickyElement())
248 return false;
244 249
245 return layer->ancestorOverflowLayer()->scrollsOverflow() && 250 // Don't promote sticky position elements that cannot move with scrolls.
246 !scrollableArea->stickyConstraintsMap() 251 if (!layer->sticksToScroller())
247 .at(const_cast<PaintLayer*>(layer)) 252 return false;
248 .hasAncestorStickyElement(); 253 if (layer->ancestorOverflowLayer()->isRootLayer())
254 return m_layoutView.frameView()->isScrollable();
255 return layer->ancestorOverflowLayer()->scrollsOverflow();
249 } 256 }
250 257
251 } // namespace blink 258 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698