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

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 #if DCHECK_IS_ON()
109 #ifdef CHECK_CACHED_CLIP_RECTS 112 DCHECK(entry.overlayScrollbarClipBehavior == context.overlayScrollbarClipBeh avior);
110 // 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);
112 tempContext.cacheSlot = UncachedClipRects;
113 RefPtr<ClipRects> clipRects = ClipRects::create();
114 calculateClipRects(tempContext, *clipRects);
115 ASSERT(clipRects == *entry.clipRects);
116 #endif 113 #endif
117 return entry.clipRects.get(); 114 return entry.clipRects.get();
118 } 115 }
119 116
120 ClipRects& PaintLayerClipper::storeClipRectsInCache(const ClipRectsContext& cont ext, ClipRects* parentClipRects, const ClipRects& clipRects) const 117 ClipRects& PaintLayerClipper::storeClipRectsInCache(const ClipRectsContext& cont ext, ClipRects* parentClipRects, const ClipRects& clipRects) const
121 { 118 {
122 ClipRectsCache::Entry& entry = m_layer.ensureClipRectsCache().get(context.ca cheSlot()); 119 ClipRectsCache::Entry& entry = m_layer.ensureClipRectsCache().get(context.ca cheSlot());
123 entry.root = context.rootLayer; 120 entry.root = context.rootLayer;
124 #if ENABLE(ASSERT) 121 #if DCHECK_IS_ON()
125 entry.overlayScrollbarClipBehavior = context.overlayScrollbarClipBehavior; 122 entry.overlayScrollbarClipBehavior = context.overlayScrollbarClipBehavior;
126 #endif 123 #endif
127 if (parentClipRects) { 124 if (parentClipRects) {
128 // If our clip rects match the clip rects of our parent, we share storag e. 125 // If our clip rects match the clip rects of our parent, we share storag e.
129 if (clipRects == *parentClipRects) { 126 if (clipRects == *parentClipRects) {
130 entry.clipRects = parentClipRects; 127 entry.clipRects = parentClipRects;
131 return *parentClipRects; 128 return *parentClipRects;
132 } 129 }
133 } 130 }
134 entry.clipRects = ClipRects::create(clipRects); 131 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; 251 PaintLayer* parentLayer = !isClippingRoot ? m_layer.parent() : nullptr;
255 // Ensure that our parent's clip has been calculated so that we can examine the values. 252 // Ensure that our parent's clip has been calculated so that we can examine the values.
256 if (parentLayer) { 253 if (parentLayer) {
257 parentLayer->clipper().getOrCalculateClipRects(context, clipRects); 254 parentLayer->clipper().getOrCalculateClipRects(context, clipRects);
258 } else { 255 } else {
259 clipRects.reset(LayoutRect(LayoutRect::infiniteIntRect())); 256 clipRects.reset(LayoutRect(LayoutRect::infiniteIntRect()));
260 } 257 }
261 258
262 adjustClipRectsForChildren(layoutObject, clipRects); 259 adjustClipRectsForChildren(layoutObject, clipRects);
263 260
264 if ((layoutObject.hasOverflowClip() && shouldRespectOverflowClip(context)) | | layoutObject.hasClip() || layoutObject.styleRef().containsPaint()) { 261 if ((layoutObject.hasOverflowClip() && shouldRespectOverflowClip(context))
262 || (layoutObject.isSVGRoot() && toLayoutSVGRoot(&layoutObject)->shouldAp plyViewportClip())
263 || layoutObject.hasClip() || layoutObject.styleRef().containsPaint()) {
265 // This offset cannot use convertToLayerCoords, because sometimes our ro otLayer may be across 264 // 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 265 // some transformed layer boundary, for example, in the PaintLayerCompos itor overlapMap, where
267 // clipRects are needed in view space. 266 // clipRects are needed in view space.
268 applyClipRects(context, layoutObject, roundedLayoutPoint(layoutObject.lo calToAncestorPoint(FloatPoint(), context.rootLayer->layoutObject())), clipRects) ; 267 applyClipRects(context, layoutObject, roundedLayoutPoint(layoutObject.lo calToAncestorPoint(FloatPoint(), context.rootLayer->layoutObject())), clipRects) ;
269 } 268 }
270 } 269 }
271 270
272 static ClipRect backgroundClipRectForPosition(const ClipRects& parentRects, EPos ition position) 271 static ClipRect backgroundClipRectForPosition(const ClipRects& parentRects, EPos ition position)
273 { 272 {
274 if (position == FixedPosition) 273 if (position == FixedPosition)
275 return parentRects.fixedClipRect(); 274 return parentRects.fixedClipRect();
276 275
277 if (position == AbsolutePosition) 276 if (position == AbsolutePosition)
278 return parentRects.posClipRect(); 277 return parentRects.posClipRect();
279 278
280 return parentRects.overflowClipRect(); 279 return parentRects.overflowClipRect();
281 } 280 }
282 281
283 ClipRect PaintLayerClipper::backgroundClipRect(const ClipRectsContext& context) const 282 ClipRect PaintLayerClipper::backgroundClipRect(const ClipRectsContext& context) const
284 { 283 {
285 ASSERT(m_layer.parent()); 284 DCHECK(m_layer.parent());
286 LayoutView* layoutView = m_layer.layoutObject()->view(); 285 LayoutView* layoutView = m_layer.layoutObject()->view();
287 ASSERT(layoutView); 286 DCHECK(layoutView);
288 287
289 RefPtr<ClipRects> parentClipRects = ClipRects::create(); 288 RefPtr<ClipRects> parentClipRects = ClipRects::create();
290 if (&m_layer == context.rootLayer) 289 if (&m_layer == context.rootLayer)
291 parentClipRects->reset(LayoutRect(LayoutRect::infiniteIntRect())); 290 parentClipRects->reset(LayoutRect(LayoutRect::infiniteIntRect()));
292 else 291 else
293 m_layer.parent()->clipper().getOrCalculateClipRects(context, *parentClip Rects); 292 m_layer.parent()->clipper().getOrCalculateClipRects(context, *parentClip Rects);
294 293
295 ClipRect result = backgroundClipRectForPosition(*parentClipRects, m_layer.la youtObject()->styleRef().position()); 294 ClipRect result = backgroundClipRectForPosition(*parentClipRects, m_layer.la youtObject()->styleRef().position());
296 295
297 // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite. 296 // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite.
(...skipping 27 matching lines...) Expand all
325 324
326 ClipRects& PaintLayerClipper::paintingClipRects(const PaintLayer* rootLayer, Sho uldRespectOverflowClipType respectOverflowClip, const LayoutSize& subpixelAccumu lation) const 325 ClipRects& PaintLayerClipper::paintingClipRects(const PaintLayer* rootLayer, Sho uldRespectOverflowClipType respectOverflowClip, const LayoutSize& subpixelAccumu lation) const
327 { 326 {
328 ClipRectsContext context(rootLayer, PaintingClipRects, IgnoreOverlayScrollba rSize, subpixelAccumulation); 327 ClipRectsContext context(rootLayer, PaintingClipRects, IgnoreOverlayScrollba rSize, subpixelAccumulation);
329 if (respectOverflowClip == IgnoreOverflowClip) 328 if (respectOverflowClip == IgnoreOverflowClip)
330 context.setIgnoreOverflowClip(); 329 context.setIgnoreOverflowClip();
331 return getClipRects(context); 330 return getClipRects(context);
332 } 331 }
333 332
334 } // namespace blink 333 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698