| 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" |
| 11 #include "platform/LayoutTestSupport.h" | 11 #include "platform/LayoutTestSupport.h" |
| 12 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 12 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 13 #include "platform/testing/UnitTestHelpers.h" | 13 #include "platform/testing/UnitTestHelpers.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class PaintLayerClipperTest : public ::testing::WithParamInterface<bool>, | 17 class PaintLayerClipperTest : public ::testing::WithParamInterface<bool>, |
| 18 private ScopedSlimmingPaintV2ForTest, | 18 private ScopedSlimmingPaintInvalidationForTest, |
| 19 public RenderingTest { | 19 public RenderingTest { |
| 20 public: | 20 public: |
| 21 PaintLayerClipperTest() | 21 PaintLayerClipperTest() |
| 22 : ScopedSlimmingPaintV2ForTest(GetParam()), | 22 : ScopedSlimmingPaintInvalidationForTest(GetParam()), |
| 23 RenderingTest(EmptyLocalFrameClient::create()) {} | 23 RenderingTest(EmptyLocalFrameClient::create()) {} |
| 24 | 24 |
| 25 void SetUp() override { | 25 void SetUp() override { |
| 26 LayoutTestSupport::setMockThemeEnabledForTest(true); | 26 LayoutTestSupport::setMockThemeEnabledForTest(true); |
| 27 RenderingTest::SetUp(); | 27 RenderingTest::SetUp(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void TearDown() override { | 30 void TearDown() override { |
| 31 LayoutTestSupport::setMockThemeEnabledForTest(false); | 31 LayoutTestSupport::setMockThemeEnabledForTest(false); |
| 32 RenderingTest::TearDown(); | 32 RenderingTest::TearDown(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 56 context.setIgnoreOverflowClip(); | 56 context.setIgnoreOverflowClip(); |
| 57 LayoutRect layerBounds; | 57 LayoutRect layerBounds; |
| 58 ClipRect backgroundRect, foregroundRect; | 58 ClipRect backgroundRect, foregroundRect; |
| 59 | 59 |
| 60 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; | 60 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 61 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) | 61 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 62 option = PaintLayer::UseGeometryMapper; | 62 option = PaintLayer::UseGeometryMapper; |
| 63 targetPaintLayer->clipper(option).calculateRects( | 63 targetPaintLayer->clipper(option).calculateRects( |
| 64 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, | 64 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, |
| 65 backgroundRect, foregroundRect); | 65 backgroundRect, foregroundRect); |
| 66 EXPECT_EQ(LayoutRect(FloatRect(8.25, 8.35, 200, 300)), backgroundRect.rect()); | 66 // TODO(chrishtr): investigate why these differences exist. |
| 67 EXPECT_EQ(LayoutRect(FloatRect(8.25, 8.35, 200, 300)), foregroundRect.rect()); | 67 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) { |
| 68 EXPECT_EQ(LayoutRect(FloatRect(8.25, 8.35, 200, 300)), |
| 69 backgroundRect.rect()); |
| 70 EXPECT_EQ(LayoutRect(FloatRect(8.25, 8.35, 200, 300)), |
| 71 foregroundRect.rect()); |
| 72 } else { |
| 73 EXPECT_EQ(LayoutRect(FloatRect(8, 8, 200, 300)), backgroundRect.rect()); |
| 74 EXPECT_EQ(LayoutRect(FloatRect(8, 8, 200, 300)), foregroundRect.rect()); |
| 75 } |
| 68 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); | 76 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); |
| 69 } | 77 } |
| 70 | 78 |
| 71 TEST_P(PaintLayerClipperTest, ControlClip) { | 79 TEST_P(PaintLayerClipperTest, ControlClip) { |
| 72 setBodyInnerHTML( | 80 setBodyInnerHTML( |
| 73 "<!DOCTYPE html>" | 81 "<!DOCTYPE html>" |
| 74 "<input id=target style='position:absolute; width: 200px; height: 300px'" | 82 "<input id=target style='position:absolute; width: 200px; height: 300px'" |
| 75 " type=button>"); | 83 " type=button>"); |
| 76 Element* target = document().getElementById("target"); | 84 Element* target = document().getElementById("target"); |
| 77 PaintLayer* targetPaintLayer = | 85 PaintLayer* targetPaintLayer = |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) | 448 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 441 option = PaintLayer::UseGeometryMapper; | 449 option = PaintLayer::UseGeometryMapper; |
| 442 parent->clipper(option).clearClipRectsIncludingDescendants(AbsoluteClipRects); | 450 parent->clipper(option).clearClipRectsIncludingDescendants(AbsoluteClipRects); |
| 443 | 451 |
| 444 EXPECT_TRUE(parent->clipRectsCache()); | 452 EXPECT_TRUE(parent->clipRectsCache()); |
| 445 EXPECT_TRUE(child->clipRectsCache()); | 453 EXPECT_TRUE(child->clipRectsCache()); |
| 446 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); | 454 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); |
| 447 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); | 455 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); |
| 448 } | 456 } |
| 449 | 457 |
| 458 TEST_P(PaintLayerClipperTest, CSSClip) { |
| 459 setBodyInnerHTML( |
| 460 "<style>" |
| 461 " #target { " |
| 462 " width: 400px; height: 400px; position: absolute;" |
| 463 " clip: rect(0, 50px, 100px, 0); " |
| 464 " }" |
| 465 "</style>" |
| 466 "<div id='target'></div>"); |
| 467 |
| 468 PaintLayer* target = |
| 469 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); |
| 470 ClipRectsContext context(target, UncachedClipRects); |
| 471 PaintLayer::GeometryMapperOption option = PaintLayer::DoNotUseGeometryMapper; |
| 472 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 473 option = PaintLayer::UseGeometryMapper; |
| 474 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); |
| 475 LayoutRect layerBounds(infiniteRect); |
| 476 ClipRect backgroundRect(infiniteRect); |
| 477 ClipRect foregroundRect(infiniteRect); |
| 478 target->clipper(option).calculateRects(context, infiniteRect, layerBounds, |
| 479 backgroundRect, foregroundRect); |
| 480 |
| 481 EXPECT_EQ(LayoutRect(0, 0, 50, 100), backgroundRect.rect()); |
| 482 EXPECT_EQ(LayoutRect(0, 0, 50, 100), foregroundRect.rect()); |
| 483 } |
| 484 |
| 450 } // namespace blink | 485 } // namespace blink |
| OLD | NEW |