| OLD | NEW |
| 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/LayoutBlock.h" | 5 #include "core/layout/LayoutBlock.h" |
| 6 #include "core/layout/LayoutInline.h" | 6 #include "core/layout/LayoutInline.h" |
| 7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/paint/PaintLayer.h" | 8 #include "core/paint/PaintLayer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class PaintContainmentTest : public RenderingTest { | 13 class PaintContainmentTest : public RenderingTest { |
| 14 private: | 14 private: |
| 15 void SetUp() override { | 15 void SetUp() override { |
| 16 RenderingTest::SetUp(); | 16 RenderingTest::SetUp(); |
| 17 enableCompositing(); | 17 enableCompositing(); |
| 18 } | 18 } |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 static void checkIsClippingStackingContextAndContainer( | 21 static void checkIsClippingStackingContextAndContainer( |
| 22 LayoutBoxModelObject& obj) { | 22 LayoutBoxModelObject& obj) { |
| 23 EXPECT_TRUE(obj.canContainFixedPositionObjects()); | 23 EXPECT_TRUE(obj.canContainFixedPositionObjects()); |
| 24 EXPECT_TRUE(obj.hasClipRelatedProperty()); | 24 EXPECT_TRUE(obj.hasClipRelatedProperty()); |
| 25 EXPECT_TRUE(obj.style()->containsPaint()); | 25 EXPECT_TRUE(obj.style()->containsPaint()); |
| 26 | 26 |
| 27 // TODO(leviw): Ideally, we wouldn't require a paint layer to handle the | 27 // TODO(leviw): Ideally, we wouldn't require a paint layer to handle the |
| 28 // clipping and stacking performed by paint containment. | 28 // clipping and stacking performed by paint containment. |
| 29 ASSERT(obj.layer()); | 29 DCHECK(obj.layer()); |
| 30 PaintLayer* layer = obj.layer(); | 30 PaintLayer* layer = obj.layer(); |
| 31 EXPECT_TRUE(layer->stackingNode() && | 31 EXPECT_TRUE(layer->stackingNode() && |
| 32 layer->stackingNode()->isStackingContext()); | 32 layer->stackingNode()->isStackingContext()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST_F(PaintContainmentTest, BlockPaintContainment) { | 35 TEST_F(PaintContainmentTest, BlockPaintContainment) { |
| 36 setBodyInnerHTML("<div id='div' style='contain: paint'></div>"); | 36 setBodyInnerHTML("<div id='div' style='contain: paint'></div>"); |
| 37 Element* div = document().getElementById(AtomicString("div")); | 37 Element* div = document().getElementById(AtomicString("div")); |
| 38 ASSERT(div); | 38 DCHECK(div); |
| 39 LayoutObject* obj = div->layoutObject(); | 39 LayoutObject* obj = div->layoutObject(); |
| 40 ASSERT(obj && obj->isLayoutBlock()); | 40 DCHECK(obj); |
| 41 DCHECK(obj->isLayoutBlock()); |
| 41 LayoutBlock& block = toLayoutBlock(*obj); | 42 LayoutBlock& block = toLayoutBlock(*obj); |
| 42 EXPECT_TRUE(block.createsNewFormattingContext()); | 43 EXPECT_TRUE(block.createsNewFormattingContext()); |
| 43 EXPECT_FALSE(block.canBeScrolledAndHasScrollableArea()); | 44 EXPECT_FALSE(block.canBeScrolledAndHasScrollableArea()); |
| 44 checkIsClippingStackingContextAndContainer(block); | 45 checkIsClippingStackingContextAndContainer(block); |
| 45 } | 46 } |
| 46 | 47 |
| 47 TEST_F(PaintContainmentTest, InlinePaintContainment) { | 48 TEST_F(PaintContainmentTest, InlinePaintContainment) { |
| 48 setBodyInnerHTML( | 49 setBodyInnerHTML( |
| 49 "<div><span id='test' style='contain: paint'>Foo</span></div>"); | 50 "<div><span id='test' style='contain: paint'>Foo</span></div>"); |
| 50 Element* span = document().getElementById(AtomicString("test")); | 51 Element* span = document().getElementById(AtomicString("test")); |
| 51 ASSERT(span); | 52 DCHECK(span); |
| 52 // The inline should have been coerced into a block in StyleAdjuster. | 53 // The inline should have been coerced into a block in StyleAdjuster. |
| 53 LayoutObject* obj = span->layoutObject(); | 54 LayoutObject* obj = span->layoutObject(); |
| 54 ASSERT(obj && obj->isLayoutBlock()); | 55 DCHECK(obj); |
| 56 DCHECK(obj->isLayoutBlock()); |
| 55 LayoutBlock& layoutBlock = toLayoutBlock(*obj); | 57 LayoutBlock& layoutBlock = toLayoutBlock(*obj); |
| 56 checkIsClippingStackingContextAndContainer(layoutBlock); | 58 checkIsClippingStackingContextAndContainer(layoutBlock); |
| 57 } | 59 } |
| 58 | 60 |
| 59 TEST_F(PaintContainmentTest, SvgWithContainmentShouldNotCrash) { | 61 TEST_F(PaintContainmentTest, SvgWithContainmentShouldNotCrash) { |
| 60 // SVG doesn't currently support PaintLayers and should not crash with | 62 // SVG doesn't currently support PaintLayers and should not crash with |
| 61 // layer-related properties. | 63 // layer-related properties. |
| 62 setBodyInnerHTML("<svg><text y='20' style='contain: paint'>Foo</text></svg>"); | 64 setBodyInnerHTML("<svg><text y='20' style='contain: paint'>Foo</text></svg>"); |
| 63 setBodyInnerHTML( | 65 setBodyInnerHTML( |
| 64 "<svg><foreignObject style='contain: paint'>Foo</foreignObject></svg>"); | 66 "<svg><foreignObject style='contain: paint'>Foo</foreignObject></svg>"); |
| 65 setBodyInnerHTML( | 67 setBodyInnerHTML( |
| 66 "<svg><foreignObject><span style='contain: " | 68 "<svg><foreignObject><span style='contain: " |
| 67 "paint'>Foo</span></foreignObject></svg>"); | 69 "paint'>Foo</span></foreignObject></svg>"); |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |