| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/paint/PaintLayerClipper.h" | 5 #include "core/paint/PaintLayerClipper.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBoxModelObject.h" | 7 #include "core/layout/LayoutBoxModelObject.h" |
| 8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
| 9 #include "core/layout/LayoutView.h" | 9 #include "core/layout/LayoutView.h" |
| 10 #include "core/paint/PaintLayer.h" | 10 #include "core/paint/PaintLayer.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 Element* target = document().getElementById("target"); | 51 Element* target = document().getElementById("target"); |
| 52 PaintLayer* targetPaintLayer = | 52 PaintLayer* targetPaintLayer = |
| 53 toLayoutBoxModelObject(target->layoutObject())->layer(); | 53 toLayoutBoxModelObject(target->layoutObject())->layer(); |
| 54 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); | 54 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); |
| 55 // When RLS is enabled, the LayoutView will have a composited scrolling layer, | 55 // When RLS is enabled, the LayoutView will have a composited scrolling layer, |
| 56 // so don't apply an overflow clip. | 56 // so don't apply an overflow clip. |
| 57 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 57 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
| 58 context.setIgnoreOverflowClip(); | 58 context.setIgnoreOverflowClip(); |
| 59 LayoutRect layerBounds; | 59 LayoutRect layerBounds; |
| 60 ClipRect backgroundRect, foregroundRect; | 60 ClipRect backgroundRect, foregroundRect; |
| 61 targetPaintLayer->clipper().calculateRects( | 61 |
| 62 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 63 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 64 option = PaintLayer::UseGeometryMapper; |
| 65 targetPaintLayer->clipper(option).calculateRects( |
| 62 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 66 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 63 backgroundRect, foregroundRect); | 67 backgroundRect, foregroundRect); |
| 64 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); | 68 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); |
| 65 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); | 69 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); |
| 66 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); | 70 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); |
| 67 } | 71 } |
| 68 | 72 |
| 69 TEST_P(PaintLayerClipperTest, ControlClip) { | 73 TEST_P(PaintLayerClipperTest, ControlClip) { |
| 70 setBodyInnerHTML( | 74 setBodyInnerHTML( |
| 71 "<!DOCTYPE html>" | 75 "<!DOCTYPE html>" |
| 72 "<input id=target style='position:absolute; width: 200px; height: 300px'" | 76 "<input id=target style='position:absolute; width: 200px; height: 300px'" |
| 73 " type=button>"); | 77 " type=button>"); |
| 74 Element* target = document().getElementById("target"); | 78 Element* target = document().getElementById("target"); |
| 75 PaintLayer* targetPaintLayer = | 79 PaintLayer* targetPaintLayer = |
| 76 toLayoutBoxModelObject(target->layoutObject())->layer(); | 80 toLayoutBoxModelObject(target->layoutObject())->layer(); |
| 77 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); | 81 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); |
| 78 // When RLS is enabled, the LayoutView will have a composited scrolling layer, | 82 // When RLS is enabled, the LayoutView will have a composited scrolling layer, |
| 79 // so don't apply an overflow clip. | 83 // so don't apply an overflow clip. |
| 80 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 84 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
| 81 context.setIgnoreOverflowClip(); | 85 context.setIgnoreOverflowClip(); |
| 82 LayoutRect layerBounds; | 86 LayoutRect layerBounds; |
| 83 ClipRect backgroundRect, foregroundRect; | 87 ClipRect backgroundRect, foregroundRect; |
| 84 targetPaintLayer->clipper().calculateRects( | 88 |
| 89 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 90 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 91 option = PaintLayer::UseGeometryMapper; |
| 92 targetPaintLayer->clipper(option).calculateRects( |
| 85 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 93 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 86 backgroundRect, foregroundRect); | 94 backgroundRect, foregroundRect); |
| 87 #if OS(MACOSX) | 95 #if OS(MACOSX) |
| 88 // If the PaintLayer clips overflow, the background rect is intersected with | 96 // If the PaintLayer clips overflow, the background rect is intersected with |
| 89 // the PaintLayer bounds... | 97 // the PaintLayer bounds... |
| 90 EXPECT_EQ(LayoutRect(3, 4, 210, 28), backgroundRect.rect()); | 98 EXPECT_EQ(LayoutRect(3, 4, 210, 28), backgroundRect.rect()); |
| 91 // and the foreground rect is intersected with the control clip in this case. | 99 // and the foreground rect is intersected with the control clip in this case. |
| 92 EXPECT_EQ(LayoutRect(8, 8, 200, 18), foregroundRect.rect()); | 100 EXPECT_EQ(LayoutRect(8, 8, 200, 18), foregroundRect.rect()); |
| 93 EXPECT_EQ(LayoutRect(8, 8, 200, 18), layerBounds); | 101 EXPECT_EQ(LayoutRect(8, 8, 200, 18), layerBounds); |
| 94 #else | 102 #else |
| (...skipping 17 matching lines...) Expand all Loading... |
| 112 PaintLayer* targetPaintLayer = | 120 PaintLayer* targetPaintLayer = |
| 113 toLayoutBoxModelObject(target->layoutObject())->layer(); | 121 toLayoutBoxModelObject(target->layoutObject())->layer(); |
| 114 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); | 122 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); |
| 115 // When RLS is enabled, the LayoutView will have a composited scrolling layer, | 123 // When RLS is enabled, the LayoutView will have a composited scrolling layer, |
| 116 // so don't apply an overflow clip. | 124 // so don't apply an overflow clip. |
| 117 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 125 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
| 118 context.setIgnoreOverflowClip(); | 126 context.setIgnoreOverflowClip(); |
| 119 | 127 |
| 120 LayoutRect layerBounds; | 128 LayoutRect layerBounds; |
| 121 ClipRect backgroundRect, foregroundRect; | 129 ClipRect backgroundRect, foregroundRect; |
| 122 targetPaintLayer->clipper().calculateRects( | 130 |
| 131 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 132 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 133 option = PaintLayer::UseGeometryMapper; |
| 134 targetPaintLayer->clipper(option).calculateRects( |
| 123 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 135 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 124 backgroundRect, foregroundRect); | 136 backgroundRect, foregroundRect); |
| 125 | 137 |
| 126 // Only the foreground rect gets hasRadius set for overflow clipping | 138 // Only the foreground rect gets hasRadius set for overflow clipping |
| 127 // of descendants. | 139 // of descendants. |
| 128 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); | 140 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); |
| 129 EXPECT_FALSE(backgroundRect.hasRadius()); | 141 EXPECT_FALSE(backgroundRect.hasRadius()); |
| 130 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); | 142 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); |
| 131 EXPECT_TRUE(foregroundRect.hasRadius()); | 143 EXPECT_TRUE(foregroundRect.hasRadius()); |
| 132 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); | 144 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 147 toLayoutBoxModelObject(parent->layoutObject())->layer(); | 159 toLayoutBoxModelObject(parent->layoutObject())->layer(); |
| 148 | 160 |
| 149 Element* child = document().getElementById("child"); | 161 Element* child = document().getElementById("child"); |
| 150 PaintLayer* childPaintLayer = | 162 PaintLayer* childPaintLayer = |
| 151 toLayoutBoxModelObject(child->layoutObject())->layer(); | 163 toLayoutBoxModelObject(child->layoutObject())->layer(); |
| 152 | 164 |
| 153 ClipRectsContext context(parentPaintLayer, UncachedClipRects); | 165 ClipRectsContext context(parentPaintLayer, UncachedClipRects); |
| 154 | 166 |
| 155 LayoutRect layerBounds; | 167 LayoutRect layerBounds; |
| 156 ClipRect backgroundRect, foregroundRect; | 168 ClipRect backgroundRect, foregroundRect; |
| 157 childPaintLayer->clipper().calculateRects( | 169 |
| 170 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 171 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 172 option = PaintLayer::UseGeometryMapper; |
| 173 childPaintLayer->clipper(option).calculateRects( |
| 158 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 174 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 159 backgroundRect, foregroundRect); | 175 backgroundRect, foregroundRect); |
| 160 | 176 |
| 161 EXPECT_EQ(LayoutRect(0, 0, 200, 300), backgroundRect.rect()); | 177 EXPECT_EQ(LayoutRect(0, 0, 200, 300), backgroundRect.rect()); |
| 162 EXPECT_TRUE(backgroundRect.hasRadius()); | 178 EXPECT_TRUE(backgroundRect.hasRadius()); |
| 163 EXPECT_EQ(LayoutRect(0, 0, 200, 300), foregroundRect.rect()); | 179 EXPECT_EQ(LayoutRect(0, 0, 200, 300), foregroundRect.rect()); |
| 164 EXPECT_TRUE(foregroundRect.hasRadius()); | 180 EXPECT_TRUE(foregroundRect.hasRadius()); |
| 165 EXPECT_EQ(LayoutRect(0, 0, 500, 500), layerBounds); | 181 EXPECT_EQ(LayoutRect(0, 0, 500, 500), layerBounds); |
| 166 } | 182 } |
| 167 | 183 |
| 168 TEST_P(PaintLayerClipperTest, ControlClipSelect) { | 184 TEST_P(PaintLayerClipperTest, ControlClipSelect) { |
| 169 setBodyInnerHTML( | 185 setBodyInnerHTML( |
| 170 "<select id='target' style='position: relative; width: 100px; " | 186 "<select id='target' style='position: relative; width: 100px; " |
| 171 " background: none; border: none; padding: 0px 15px 0px 5px;'>" | 187 " background: none; border: none; padding: 0px 15px 0px 5px;'>" |
| 172 " <option>" | 188 " <option>" |
| 173 " Test long texttttttttttttttttttttttttttttttt" | 189 " Test long texttttttttttttttttttttttttttttttt" |
| 174 " </option>" | 190 " </option>" |
| 175 "</select>"); | 191 "</select>"); |
| 176 Element* target = document().getElementById("target"); | 192 Element* target = document().getElementById("target"); |
| 177 PaintLayer* targetPaintLayer = | 193 PaintLayer* targetPaintLayer = |
| 178 toLayoutBoxModelObject(target->layoutObject())->layer(); | 194 toLayoutBoxModelObject(target->layoutObject())->layer(); |
| 179 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); | 195 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); |
| 180 // When RLS is enabled, the LayoutView will have a composited scrolling layer, | 196 // When RLS is enabled, the LayoutView will have a composited scrolling layer, |
| 181 // so don't apply an overflow clip. | 197 // so don't apply an overflow clip. |
| 182 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 198 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
| 183 context.setIgnoreOverflowClip(); | 199 context.setIgnoreOverflowClip(); |
| 184 LayoutRect layerBounds; | 200 LayoutRect layerBounds; |
| 185 ClipRect backgroundRect, foregroundRect; | 201 ClipRect backgroundRect, foregroundRect; |
| 186 targetPaintLayer->clipper().calculateRects( | 202 |
| 203 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 204 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 205 option = PaintLayer::UseGeometryMapper; |
| 206 targetPaintLayer->clipper(option).calculateRects( |
| 187 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 207 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 188 backgroundRect, foregroundRect); | 208 backgroundRect, foregroundRect); |
| 189 // The control clip for a select excludes the area for the down arrow. | 209 // The control clip for a select excludes the area for the down arrow. |
| 190 #if OS(MACOSX) | 210 #if OS(MACOSX) |
| 191 EXPECT_EQ(LayoutRect(16, 9, 79, 13), foregroundRect.rect()); | 211 EXPECT_EQ(LayoutRect(16, 9, 79, 13), foregroundRect.rect()); |
| 192 #elif OS(WIN) | 212 #elif OS(WIN) |
| 193 EXPECT_EQ(LayoutRect(17, 9, 60, 16), foregroundRect.rect()); | 213 EXPECT_EQ(LayoutRect(17, 9, 60, 16), foregroundRect.rect()); |
| 194 #else | 214 #else |
| 195 EXPECT_EQ(LayoutRect(17, 9, 60, 15), foregroundRect.rect()); | 215 EXPECT_EQ(LayoutRect(17, 9, 60, 15), foregroundRect.rect()); |
| 196 #endif | 216 #endif |
| 197 } | 217 } |
| 198 | 218 |
| 199 TEST_P(PaintLayerClipperTest, LayoutSVGRootChild) { | 219 TEST_P(PaintLayerClipperTest, LayoutSVGRootChild) { |
| 200 setBodyInnerHTML( | 220 setBodyInnerHTML( |
| 201 "<svg width=200 height=300 style='position: relative'>" | 221 "<svg width=200 height=300 style='position: relative'>" |
| 202 " <foreignObject width=400 height=500>" | 222 " <foreignObject width=400 height=500>" |
| 203 " <div id=target xmlns='http://www.w3.org/1999/xhtml' " | 223 " <div id=target xmlns='http://www.w3.org/1999/xhtml' " |
| 204 "style='position: relative'></div>" | 224 "style='position: relative'></div>" |
| 205 " </foreignObject>" | 225 " </foreignObject>" |
| 206 "</svg>"); | 226 "</svg>"); |
| 207 | 227 |
| 208 Element* target = document().getElementById("target"); | 228 Element* target = document().getElementById("target"); |
| 209 PaintLayer* targetPaintLayer = | 229 PaintLayer* targetPaintLayer = |
| 210 toLayoutBoxModelObject(target->layoutObject())->layer(); | 230 toLayoutBoxModelObject(target->layoutObject())->layer(); |
| 211 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); | 231 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); |
| 212 LayoutRect layerBounds; | 232 LayoutRect layerBounds; |
| 213 ClipRect backgroundRect, foregroundRect; | 233 ClipRect backgroundRect, foregroundRect; |
| 214 targetPaintLayer->clipper().calculateRects( | 234 |
| 235 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 236 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 237 option = PaintLayer::UseGeometryMapper; |
| 238 targetPaintLayer->clipper(option).calculateRects( |
| 215 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 239 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 216 backgroundRect, foregroundRect); | 240 backgroundRect, foregroundRect); |
| 217 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); | 241 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); |
| 218 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); | 242 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); |
| 219 EXPECT_EQ(LayoutRect(8, 8, 400, 0), layerBounds); | 243 EXPECT_EQ(LayoutRect(8, 8, 400, 0), layerBounds); |
| 220 } | 244 } |
| 221 | 245 |
| 222 TEST_P(PaintLayerClipperTest, ContainPaintClip) { | 246 TEST_P(PaintLayerClipperTest, ContainPaintClip) { |
| 223 setBodyInnerHTML( | 247 setBodyInnerHTML( |
| 224 "<div id='target'" | 248 "<div id='target'" |
| 225 " style='contain: paint; width: 200px; height: 200px; overflow: auto'>" | 249 " style='contain: paint; width: 200px; height: 200px; overflow: auto'>" |
| 226 " <div style='height: 400px'></div>" | 250 " <div style='height: 400px'></div>" |
| 227 "</div>"); | 251 "</div>"); |
| 228 | 252 |
| 229 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); | 253 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); |
| 230 PaintLayer* layer = | 254 PaintLayer* layer = |
| 231 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); | 255 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); |
| 232 ClipRectsContext context(layer, PaintingClipRectsIgnoringOverflowClip); | 256 ClipRectsContext context(layer, PaintingClipRectsIgnoringOverflowClip); |
| 233 LayoutRect layerBounds; | 257 LayoutRect layerBounds; |
| 234 ClipRect backgroundRect, foregroundRect; | 258 ClipRect backgroundRect, foregroundRect; |
| 235 layer->clipper().calculateRects(context, infiniteRect, layerBounds, | 259 |
| 236 backgroundRect, foregroundRect); | 260 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 261 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 262 option = PaintLayer::UseGeometryMapper; |
| 263 layer->clipper(option).calculateRects(context, infiniteRect, layerBounds, |
| 264 backgroundRect, foregroundRect); |
| 237 EXPECT_GE(backgroundRect.rect().size().width().toInt(), 33554422); | 265 EXPECT_GE(backgroundRect.rect().size().width().toInt(), 33554422); |
| 238 EXPECT_GE(backgroundRect.rect().size().height().toInt(), 33554422); | 266 EXPECT_GE(backgroundRect.rect().size().height().toInt(), 33554422); |
| 239 EXPECT_EQ(backgroundRect.rect(), foregroundRect.rect()); | 267 EXPECT_EQ(backgroundRect.rect(), foregroundRect.rect()); |
| 240 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); | 268 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); |
| 241 | 269 |
| 242 ClipRectsContext contextClip(layer, PaintingClipRects); | 270 ClipRectsContext contextClip(layer, PaintingClipRects); |
| 243 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds, | 271 |
| 244 backgroundRect, foregroundRect); | 272 layer->clipper(option).calculateRects(contextClip, infiniteRect, layerBounds, |
| 273 backgroundRect, foregroundRect); |
| 245 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); | 274 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); |
| 246 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); | 275 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); |
| 247 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); | 276 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); |
| 248 } | 277 } |
| 249 | 278 |
| 250 TEST_P(PaintLayerClipperTest, NestedContainPaintClip) { | 279 TEST_P(PaintLayerClipperTest, NestedContainPaintClip) { |
| 251 setBodyInnerHTML( | 280 setBodyInnerHTML( |
| 252 "<div style='contain: paint; width: 200px; height: 200px; overflow: " | 281 "<div style='contain: paint; width: 200px; height: 200px; overflow: " |
| 253 "auto'>" | 282 "auto'>" |
| 254 " <div id='target' style='contain: paint; height: 400px'>" | 283 " <div id='target' style='contain: paint; height: 400px'>" |
| 255 " </div>" | 284 " </div>" |
| 256 "</div>"); | 285 "</div>"); |
| 257 | 286 |
| 258 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); | 287 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); |
| 259 PaintLayer* layer = | 288 PaintLayer* layer = |
| 260 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); | 289 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); |
| 261 ClipRectsContext context(layer->parent(), | 290 ClipRectsContext context(layer->parent(), |
| 262 PaintingClipRectsIgnoringOverflowClip); | 291 PaintingClipRectsIgnoringOverflowClip); |
| 263 LayoutRect layerBounds; | 292 LayoutRect layerBounds; |
| 264 ClipRect backgroundRect, foregroundRect; | 293 ClipRect backgroundRect, foregroundRect; |
| 265 layer->clipper().calculateRects(context, infiniteRect, layerBounds, | 294 |
| 266 backgroundRect, foregroundRect); | 295 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 296 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 297 option = PaintLayer::UseGeometryMapper; |
| 298 layer->clipper(option).calculateRects(context, infiniteRect, layerBounds, |
| 299 backgroundRect, foregroundRect); |
| 267 EXPECT_EQ(LayoutRect(0, 0, 200, 400), backgroundRect.rect()); | 300 EXPECT_EQ(LayoutRect(0, 0, 200, 400), backgroundRect.rect()); |
| 268 EXPECT_EQ(LayoutRect(0, 0, 200, 400), foregroundRect.rect()); | 301 EXPECT_EQ(LayoutRect(0, 0, 200, 400), foregroundRect.rect()); |
| 269 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); | 302 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); |
| 270 | 303 |
| 271 ClipRectsContext contextClip(layer->parent(), PaintingClipRects); | 304 ClipRectsContext contextClip(layer->parent(), PaintingClipRects); |
| 272 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds, | 305 |
| 273 backgroundRect, foregroundRect); | 306 layer->clipper(option).calculateRects(contextClip, infiniteRect, layerBounds, |
| 307 backgroundRect, foregroundRect); |
| 274 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); | 308 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); |
| 275 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); | 309 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); |
| 276 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); | 310 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); |
| 277 } | 311 } |
| 278 | 312 |
| 279 TEST_P(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) { | 313 TEST_P(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) { |
| 280 setBodyInnerHTML( | 314 setBodyInnerHTML( |
| 281 "<div id='transformed'" | 315 "<div id='transformed'" |
| 282 " style='will-change: transform; width: 100px; height: 100px;" | 316 " style='will-change: transform; width: 100px; height: 100px;" |
| 283 " overflow: hidden'>" | 317 " overflow: hidden'>" |
| 284 " <div id='fixed' " | 318 " <div id='fixed' " |
| 285 " style='position: fixed; width: 100px; height: 100px;" | 319 " style='position: fixed; width: 100px; height: 100px;" |
| 286 " top: -50px'>" | 320 " top: -50px'>" |
| 287 " </div>" | 321 " </div>" |
| 288 "</div>"); | 322 "</div>"); |
| 289 | 323 |
| 290 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); | 324 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); |
| 291 PaintLayer* transformed = | 325 PaintLayer* transformed = |
| 292 toLayoutBoxModelObject(getLayoutObjectByElementId("transformed")) | 326 toLayoutBoxModelObject(getLayoutObjectByElementId("transformed")) |
| 293 ->layer(); | 327 ->layer(); |
| 294 PaintLayer* fixed = | 328 PaintLayer* fixed = |
| 295 toLayoutBoxModelObject(getLayoutObjectByElementId("fixed"))->layer(); | 329 toLayoutBoxModelObject(getLayoutObjectByElementId("fixed"))->layer(); |
| 296 | 330 |
| 331 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 332 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 333 option = PaintLayer::UseGeometryMapper; |
| 297 EXPECT_EQ(LayoutRect(0, 0, 100, 100), | 334 EXPECT_EQ(LayoutRect(0, 0, 100, 100), |
| 298 transformed->clipper().localClipRect(*transformed)); | 335 transformed->clipper(option).localClipRect(*transformed)); |
| 299 EXPECT_EQ(LayoutRect(0, 50, 100, 100), | 336 EXPECT_EQ(LayoutRect(0, 50, 100, 100), |
| 300 fixed->clipper().localClipRect(*transformed)); | 337 fixed->clipper(option).localClipRect(*transformed)); |
| 301 } | 338 } |
| 302 | 339 |
| 303 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursive) { | 340 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursive) { |
| 304 // SPv2 will re-use a global GeometryMapper, so this | 341 // SPv2 will re-use a global GeometryMapper, so this |
| 305 // logic does not apply. | 342 // logic does not apply. |
| 306 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 343 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 307 return; | 344 return; |
| 308 | 345 |
| 309 setBodyInnerHTML( | 346 setBodyInnerHTML( |
| 310 "<style>" | 347 "<style>" |
| 311 "div { " | 348 "div { " |
| 312 " width: 5px; height: 5px; background: blue; overflow: hidden;" | 349 " width: 5px; height: 5px; background: blue; overflow: hidden;" |
| 313 " position: relative;" | 350 " position: relative;" |
| 314 "}" | 351 "}" |
| 315 "</style>" | 352 "</style>" |
| 316 "<div id='parent'>" | 353 "<div id='parent'>" |
| 317 " <div id='child'>" | 354 " <div id='child'>" |
| 318 " <div id='grandchild'></div>" | 355 " <div id='grandchild'></div>" |
| 319 " </div>" | 356 " </div>" |
| 320 "</div>"); | 357 "</div>"); |
| 321 | 358 |
| 322 PaintLayer* parent = | 359 PaintLayer* parent = |
| 323 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); | 360 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); |
| 324 PaintLayer* child = | 361 PaintLayer* child = |
| 325 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); | 362 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); |
| 326 | 363 |
| 327 EXPECT_TRUE(parent->clipRectsCache()); | 364 EXPECT_TRUE(parent->clipRectsCache()); |
| 328 EXPECT_TRUE(child->clipRectsCache()); | 365 EXPECT_TRUE(child->clipRectsCache()); |
| 329 | 366 |
| 330 parent->clipper().clearClipRectsIncludingDescendants(); | 367 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 368 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 369 option = PaintLayer::UseGeometryMapper; |
| 370 parent->clipper(option).clearClipRectsIncludingDescendants(); |
| 331 | 371 |
| 332 EXPECT_FALSE(parent->clipRectsCache()); | 372 EXPECT_FALSE(parent->clipRectsCache()); |
| 333 EXPECT_FALSE(child->clipRectsCache()); | 373 EXPECT_FALSE(child->clipRectsCache()); |
| 334 } | 374 } |
| 335 | 375 |
| 336 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveChild) { | 376 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveChild) { |
| 337 // SPv2 will re-use a global GeometryMapper, so this | 377 // SPv2 will re-use a global GeometryMapper, so this |
| 338 // logic does not apply. | 378 // logic does not apply. |
| 339 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 379 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 340 return; | 380 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 353 "</div>"); | 393 "</div>"); |
| 354 | 394 |
| 355 PaintLayer* parent = | 395 PaintLayer* parent = |
| 356 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); | 396 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); |
| 357 PaintLayer* child = | 397 PaintLayer* child = |
| 358 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); | 398 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); |
| 359 | 399 |
| 360 EXPECT_TRUE(parent->clipRectsCache()); | 400 EXPECT_TRUE(parent->clipRectsCache()); |
| 361 EXPECT_TRUE(child->clipRectsCache()); | 401 EXPECT_TRUE(child->clipRectsCache()); |
| 362 | 402 |
| 363 child->clipper().clearClipRectsIncludingDescendants(); | 403 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 404 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 405 option = PaintLayer::UseGeometryMapper; |
| 406 child->clipper(option).clearClipRectsIncludingDescendants(); |
| 364 | 407 |
| 365 EXPECT_TRUE(parent->clipRectsCache()); | 408 EXPECT_TRUE(parent->clipRectsCache()); |
| 366 EXPECT_FALSE(child->clipRectsCache()); | 409 EXPECT_FALSE(child->clipRectsCache()); |
| 367 } | 410 } |
| 368 | 411 |
| 369 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveOneType) { | 412 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveOneType) { |
| 370 // SPv2 will re-use a global GeometryMapper, so this | 413 // SPv2 will re-use a global GeometryMapper, so this |
| 371 // logic does not apply. | 414 // logic does not apply. |
| 372 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 415 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 373 return; | 416 return; |
| 374 | 417 |
| 375 setBodyInnerHTML( | 418 setBodyInnerHTML( |
| 376 "<style>" | 419 "<style>" |
| 377 "div { " | 420 "div { " |
| 378 " width: 5px; height: 5px; background: blue;" | 421 " width: 5px; height: 5px; background: blue;" |
| 379 " position: relative;" | 422 " position: relative;" |
| 380 "}" | 423 "}" |
| 381 "</style>" | 424 "</style>" |
| 382 "<div id='parent'>" | 425 "<div id='parent'>" |
| 383 " <div id='child'>" | 426 " <div id='child'>" |
| 384 " <div id='grandchild'></div>" | 427 " <div id='grandchild'></div>" |
| 385 " </div>" | 428 " </div>" |
| 386 "</div>"); | 429 "</div>"); |
| 387 | 430 |
| 388 PaintLayer* parent = | 431 PaintLayer* parent = |
| 389 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); | 432 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); |
| 390 PaintLayer* child = | 433 PaintLayer* child = |
| 391 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); | 434 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); |
| 392 | 435 |
| 393 EXPECT_TRUE(parent->clipRectsCache()); | 436 EXPECT_TRUE(parent->clipRectsCache()); |
| 394 EXPECT_TRUE(child->clipRectsCache()); | 437 EXPECT_TRUE(child->clipRectsCache()); |
| 395 EXPECT_TRUE(parent->clipRectsCache()->get(AbsoluteClipRects).root); | 438 EXPECT_TRUE(parent->clipRectsCache()->get(AbsoluteClipRects).root); |
| 396 EXPECT_TRUE(child->clipRectsCache()->get(AbsoluteClipRects).root); | 439 EXPECT_TRUE(child->clipRectsCache()->get(AbsoluteClipRects).root); |
| 397 | 440 |
| 398 parent->clipper().clearClipRectsIncludingDescendants(AbsoluteClipRects); | 441 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 442 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 443 option = PaintLayer::UseGeometryMapper; |
| 444 parent->clipper(option).clearClipRectsIncludingDescendants(AbsoluteClipRects); |
| 399 | 445 |
| 400 EXPECT_TRUE(parent->clipRectsCache()); | 446 EXPECT_TRUE(parent->clipRectsCache()); |
| 401 EXPECT_TRUE(child->clipRectsCache()); | 447 EXPECT_TRUE(child->clipRectsCache()); |
| 402 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); | 448 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); |
| 403 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); | 449 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); |
| 404 } | 450 } |
| 405 | 451 |
| 406 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |