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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintLayerClipper.cpp

Issue 2371523002: Apply SVG root viewport clips in PaintLayerClipper. (Closed)
Patch Set: none Created 4 years, 2 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu> 7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu> 8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de> 9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 28 matching lines...) Expand all
39 * other provisions required by the MPL or the GPL, as the case may be. 39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your 40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL. 41 * version of this file under any of the LGPL, the MPL or the GPL.
42 */ 42 */
43 43
44 #include "core/paint/PaintLayerClipper.h" 44 #include "core/paint/PaintLayerClipper.h"
45 45
46 #include "core/frame/FrameView.h" 46 #include "core/frame/FrameView.h"
47 #include "core/frame/Settings.h" 47 #include "core/frame/Settings.h"
48 #include "core/layout/LayoutView.h" 48 #include "core/layout/LayoutView.h"
49 #include "core/layout/svg/LayoutSVGRoot.h"
49 #include "core/paint/PaintLayer.h" 50 #include "core/paint/PaintLayer.h"
50 51
51 namespace blink { 52 namespace blink {
52 53
53 static void adjustClipRectsForChildren(const LayoutBoxModelObject& layoutObject, ClipRects& clipRects) 54 static void adjustClipRectsForChildren(const LayoutBoxModelObject& layoutObject, ClipRects& clipRects)
54 { 55 {
55 EPosition position = layoutObject.styleRef().position(); 56 EPosition position = layoutObject.styleRef().position();
56 // A fixed object is essentially the root of its containing block hierarchy, so when 57 // A fixed object is essentially the root of its containing block hierarchy, so when
57 // we encounter such an object, we reset our clip rects to the fixedClipRect . 58 // we encounter such an object, we reset our clip rects to the fixedClipRect .
58 if (position == FixedPosition) { 59 if (position == FixedPosition) {
59 clipRects.setPosClipRect(clipRects.fixedClipRect()); 60 clipRects.setPosClipRect(clipRects.fixedClipRect());
60 clipRects.setOverflowClipRect(clipRects.fixedClipRect()); 61 clipRects.setOverflowClipRect(clipRects.fixedClipRect());
61 clipRects.setFixed(true); 62 clipRects.setFixed(true);
62 } else if (position == RelativePosition) { 63 } else if (position == RelativePosition) {
63 clipRects.setPosClipRect(clipRects.overflowClipRect()); 64 clipRects.setPosClipRect(clipRects.overflowClipRect());
64 } else if (position == AbsolutePosition) { 65 } else if (position == AbsolutePosition) {
65 clipRects.setOverflowClipRect(clipRects.posClipRect()); 66 clipRects.setOverflowClipRect(clipRects.posClipRect());
66 } 67 }
67 } 68 }
68 69
69 static void applyClipRects(const ClipRectsContext& context, const LayoutBoxModel Object& layoutObject, LayoutPoint offset, ClipRects& clipRects) 70 static void applyClipRects(const ClipRectsContext& context, const LayoutBoxModel Object& layoutObject, LayoutPoint offset, ClipRects& clipRects)
70 { 71 {
71 ASSERT(layoutObject.hasClipRelatedProperty()); 72 DCHECK(layoutObject.hasClipRelatedProperty() || (layoutObject.isSVGRoot() && toLayoutSVGRoot(&layoutObject)->shouldApplyViewportClip()));
72 LayoutView* view = layoutObject.view(); 73 LayoutView* view = layoutObject.view();
73 ASSERT(view); 74 DCHECK(view);
74 if (clipRects.fixed() && context.rootLayer->layoutObject() == view) 75 if (clipRects.fixed() && context.rootLayer->layoutObject() == view)
75 offset -= toIntSize(view->frameView()->scrollPosition()); 76 offset -= toIntSize(view->frameView()->scrollPosition());
76 if (layoutObject.hasOverflowClip() || (layoutObject.styleRef().containsPaint () && layoutObject.isBox())) { 77 if (layoutObject.hasOverflowClip()
78 || (layoutObject.isSVGRoot() && toLayoutSVGRoot(&layoutObject)->shouldAp plyViewportClip())
79 || (layoutObject.styleRef().containsPaint() && layoutObject.isBox())) {
77 ClipRect newOverflowClip = toLayoutBox(layoutObject).overflowClipRect(of fset, context.overlayScrollbarClipBehavior); 80 ClipRect newOverflowClip = toLayoutBox(layoutObject).overflowClipRect(of fset, context.overlayScrollbarClipBehavior);
78 newOverflowClip.setHasRadius(layoutObject.styleRef().hasBorderRadius()); 81 newOverflowClip.setHasRadius(layoutObject.styleRef().hasBorderRadius());
79 clipRects.setOverflowClipRect(intersection(newOverflowClip, clipRects.ov erflowClipRect())); 82 clipRects.setOverflowClipRect(intersection(newOverflowClip, clipRects.ov erflowClipRect()));
80 if (layoutObject.isPositioned()) 83 if (layoutObject.isPositioned())
81 clipRects.setPosClipRect(intersection(newOverflowClip, clipRects.pos ClipRect())); 84 clipRects.setPosClipRect(intersection(newOverflowClip, clipRects.pos ClipRect()));
82 if (layoutObject.isLayoutView()) 85 if (layoutObject.isLayoutView())
83 clipRects.setFixedClipRect(intersection(newOverflowClip, clipRects.f ixedClipRect())); 86 clipRects.setFixedClipRect(intersection(newOverflowClip, clipRects.f ixedClipRect()));
84 if (layoutObject.styleRef().containsPaint()) { 87 if (layoutObject.styleRef().containsPaint()) {
85 clipRects.setPosClipRect(intersection(newOverflowClip, clipRects.pos ClipRect())); 88 clipRects.setPosClipRect(intersection(newOverflowClip, clipRects.pos ClipRect()));
86 clipRects.setFixedClipRect(intersection(newOverflowClip, clipRects.f ixedClipRect())); 89 clipRects.setFixedClipRect(intersection(newOverflowClip, clipRects.f ixedClipRect()));
87 } 90 }
88 } 91 }
89 if (layoutObject.hasClip()) { 92 if (layoutObject.hasClip()) {
90 LayoutRect newClip = toLayoutBox(layoutObject).clipRect(offset); 93 LayoutRect newClip = toLayoutBox(layoutObject).clipRect(offset);
91 clipRects.setPosClipRect(intersection(newClip, clipRects.posClipRect()). setIsClippedByClipCss()); 94 clipRects.setPosClipRect(intersection(newClip, clipRects.posClipRect()). setIsClippedByClipCss());
92 clipRects.setOverflowClipRect(intersection(newClip, clipRects.overflowCl ipRect()).setIsClippedByClipCss()); 95 clipRects.setOverflowClipRect(intersection(newClip, clipRects.overflowCl ipRect()).setIsClippedByClipCss());
93 clipRects.setFixedClipRect(intersection(newClip, clipRects.fixedClipRect ()).setIsClippedByClipCss()); 96 clipRects.setFixedClipRect(intersection(newClip, clipRects.fixedClipRect ()).setIsClippedByClipCss());
94 } 97 }
95 } 98 }
96 99
97 ClipRects* PaintLayerClipper::clipRectsIfCached(const ClipRectsContext& context) const 100 ClipRects* PaintLayerClipper::clipRectsIfCached(const ClipRectsContext& context) const
98 { 101 {
99 ASSERT(context.usesCache()); 102 DCHECK(context.usesCache());
100 if (!m_layer.clipRectsCache()) 103 if (!m_layer.clipRectsCache())
101 return nullptr; 104 return nullptr;
102 ClipRectsCache::Entry& entry = m_layer.clipRectsCache()->get(context.cacheSl ot()); 105 ClipRectsCache::Entry& entry = m_layer.clipRectsCache()->get(context.cacheSl ot());
103 // FIXME: We used to ASSERT that we always got a consistent root layer. 106 // FIXME: We used to ASSERT that we always got a consistent root layer.
104 // We should add a test that has an inconsistent root. See 107 // We should add a test that has an inconsistent root. See
105 // http://crbug.com/366118 for an example. 108 // http://crbug.com/366118 for an example.
106 if (context.rootLayer != entry.root) 109 if (context.rootLayer != entry.root)
107 return 0; 110 return 0;
108 ASSERT(entry.overlayScrollbarClipBehavior == context.overlayScrollbarClipBeh avior); 111 DCHECK(entry.overlayScrollbarClipBehavior == context.overlayScrollbarClipBeh avior);
109 #ifdef CHECK_CACHED_CLIP_RECTS 112 #ifdef CHECK_CACHED_CLIP_RECTS
110 // This code is useful to check cached clip rects, but is too expensive to l eave enabled in debug builds by default. 113 // This code is useful to check cached clip rects, but is too expensive to l eave enabled in debug builds by default.
111 ClipRectsContext tempContext(context); 114 ClipRectsContext tempContext(context);
112 tempContext.cacheSlot = UncachedClipRects; 115 tempContext.cacheSlot = UncachedClipRects;
113 RefPtr<ClipRects> clipRects = ClipRects::create(); 116 RefPtr<ClipRects> clipRects = ClipRects::create();
114 calculateClipRects(tempContext, *clipRects); 117 calculateClipRects(tempContext, *clipRects);
115 ASSERT(clipRects == *entry.clipRects); 118 DCHECK(clipRects == *entry.clipRects);
116 #endif 119 #endif
117 return entry.clipRects.get(); 120 return entry.clipRects.get();
118 } 121 }
119 122
120 ClipRects& PaintLayerClipper::storeClipRectsInCache(const ClipRectsContext& cont ext, ClipRects* parentClipRects, const ClipRects& clipRects) const 123 ClipRects& PaintLayerClipper::storeClipRectsInCache(const ClipRectsContext& cont ext, ClipRects* parentClipRects, const ClipRects& clipRects) const
121 { 124 {
122 ClipRectsCache::Entry& entry = m_layer.ensureClipRectsCache().get(context.ca cheSlot()); 125 ClipRectsCache::Entry& entry = m_layer.ensureClipRectsCache().get(context.ca cheSlot());
123 entry.root = context.rootLayer; 126 entry.root = context.rootLayer;
124 #if ENABLE(ASSERT) 127 #if DCHECK_IS_ON()
125 entry.overlayScrollbarClipBehavior = context.overlayScrollbarClipBehavior; 128 entry.overlayScrollbarClipBehavior = context.overlayScrollbarClipBehavior;
126 #endif 129 #endif
127 if (parentClipRects) { 130 if (parentClipRects) {
128 // If our clip rects match the clip rects of our parent, we share storag e. 131 // If our clip rects match the clip rects of our parent, we share storag e.
129 if (clipRects == *parentClipRects) { 132 if (clipRects == *parentClipRects) {
130 entry.clipRects = parentClipRects; 133 entry.clipRects = parentClipRects;
131 return *parentClipRects; 134 return *parentClipRects;
132 } 135 }
133 } 136 }
134 entry.clipRects = ClipRects::create(clipRects); 137 entry.clipRects = ClipRects::create(clipRects);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 PaintLayer* parentLayer = !isClippingRoot ? m_layer.parent() : nullptr; 257 PaintLayer* parentLayer = !isClippingRoot ? m_layer.parent() : nullptr;
255 // Ensure that our parent's clip has been calculated so that we can examine the values. 258 // Ensure that our parent's clip has been calculated so that we can examine the values.
256 if (parentLayer) { 259 if (parentLayer) {
257 parentLayer->clipper().getOrCalculateClipRects(context, clipRects); 260 parentLayer->clipper().getOrCalculateClipRects(context, clipRects);
258 } else { 261 } else {
259 clipRects.reset(LayoutRect(LayoutRect::infiniteIntRect())); 262 clipRects.reset(LayoutRect(LayoutRect::infiniteIntRect()));
260 } 263 }
261 264
262 adjustClipRectsForChildren(layoutObject, clipRects); 265 adjustClipRectsForChildren(layoutObject, clipRects);
263 266
264 if ((layoutObject.hasOverflowClip() && shouldRespectOverflowClip(context)) | | layoutObject.hasClip() || layoutObject.styleRef().containsPaint()) { 267 if ((layoutObject.hasOverflowClip() && shouldRespectOverflowClip(context))
268 || (layoutObject.isSVGRoot() && toLayoutSVGRoot(&layoutObject)->shouldAp plyViewportClip())
269 || layoutObject.hasClip() || layoutObject.styleRef().containsPaint()) {
265 // This offset cannot use convertToLayerCoords, because sometimes our ro otLayer may be across 270 // This offset cannot use convertToLayerCoords, because sometimes our ro otLayer may be across
266 // some transformed layer boundary, for example, in the PaintLayerCompos itor overlapMap, where 271 // some transformed layer boundary, for example, in the PaintLayerCompos itor overlapMap, where
267 // clipRects are needed in view space. 272 // clipRects are needed in view space.
268 applyClipRects(context, layoutObject, roundedLayoutPoint(layoutObject.lo calToAncestorPoint(FloatPoint(), context.rootLayer->layoutObject())), clipRects) ; 273 applyClipRects(context, layoutObject, roundedLayoutPoint(layoutObject.lo calToAncestorPoint(FloatPoint(), context.rootLayer->layoutObject())), clipRects) ;
269 } 274 }
270 } 275 }
271 276
272 static ClipRect backgroundClipRectForPosition(const ClipRects& parentRects, EPos ition position) 277 static ClipRect backgroundClipRectForPosition(const ClipRects& parentRects, EPos ition position)
273 { 278 {
274 if (position == FixedPosition) 279 if (position == FixedPosition)
275 return parentRects.fixedClipRect(); 280 return parentRects.fixedClipRect();
276 281
277 if (position == AbsolutePosition) 282 if (position == AbsolutePosition)
278 return parentRects.posClipRect(); 283 return parentRects.posClipRect();
279 284
280 return parentRects.overflowClipRect(); 285 return parentRects.overflowClipRect();
281 } 286 }
282 287
283 ClipRect PaintLayerClipper::backgroundClipRect(const ClipRectsContext& context) const 288 ClipRect PaintLayerClipper::backgroundClipRect(const ClipRectsContext& context) const
284 { 289 {
285 ASSERT(m_layer.parent()); 290 DCHECK(m_layer.parent());
286 LayoutView* layoutView = m_layer.layoutObject()->view(); 291 LayoutView* layoutView = m_layer.layoutObject()->view();
287 ASSERT(layoutView); 292 DCHECK(layoutView);
288 293
289 RefPtr<ClipRects> parentClipRects = ClipRects::create(); 294 RefPtr<ClipRects> parentClipRects = ClipRects::create();
290 if (&m_layer == context.rootLayer) 295 if (&m_layer == context.rootLayer)
291 parentClipRects->reset(LayoutRect(LayoutRect::infiniteIntRect())); 296 parentClipRects->reset(LayoutRect(LayoutRect::infiniteIntRect()));
292 else 297 else
293 m_layer.parent()->clipper().getOrCalculateClipRects(context, *parentClip Rects); 298 m_layer.parent()->clipper().getOrCalculateClipRects(context, *parentClip Rects);
294 299
295 ClipRect result = backgroundClipRectForPosition(*parentClipRects, m_layer.la youtObject()->styleRef().position()); 300 ClipRect result = backgroundClipRectForPosition(*parentClipRects, m_layer.la youtObject()->styleRef().position());
296 301
297 // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite. 302 // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite.
(...skipping 27 matching lines...) Expand all
325 330
326 ClipRects& PaintLayerClipper::paintingClipRects(const PaintLayer* rootLayer, Sho uldRespectOverflowClipType respectOverflowClip, const LayoutSize& subpixelAccumu lation) const 331 ClipRects& PaintLayerClipper::paintingClipRects(const PaintLayer* rootLayer, Sho uldRespectOverflowClipType respectOverflowClip, const LayoutSize& subpixelAccumu lation) const
327 { 332 {
328 ClipRectsContext context(rootLayer, PaintingClipRects, IgnoreOverlayScrollba rSize, subpixelAccumulation); 333 ClipRectsContext context(rootLayer, PaintingClipRects, IgnoreOverlayScrollba rSize, subpixelAccumulation);
329 if (respectOverflowClip == IgnoreOverflowClip) 334 if (respectOverflowClip == IgnoreOverflowClip)
330 context.setIgnoreOverflowClip(); 335 context.setIgnoreOverflowClip();
331 return getClipRects(context); 336 return getClipRects(context);
332 } 337 }
333 338
334 } // namespace blink 339 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698