OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/layout/LayoutTreeAsText.h" |
| 9 #include "core/layout/LayoutView.h" |
| 10 #include "core/paint/ObjectPaintProperties.h" |
| 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 12 #include "platform/text/TextStream.h" |
| 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebUnitTestSupport.h" |
| 15 #include "wtf/HashMap.h" |
| 16 #include "wtf/Vector.h" |
| 17 #include <gtest/gtest.h> |
| 18 |
| 19 namespace blink { |
| 20 |
| 21 class PaintPropertyTreeBuilderTest : public RenderingTest { |
| 22 public: |
| 23 PaintPropertyTreeBuilderTest() |
| 24 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint
V2Enabled()) { } |
| 25 |
| 26 void loadTestData(const char* fileName) |
| 27 { |
| 28 String fullPath(Platform::current()->unitTestSupport()->webKitRootDir())
; |
| 29 fullPath.append("/Source/core/paint/test_data/"); |
| 30 fullPath.append(fileName); |
| 31 WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFi
le(fullPath); |
| 32 setBodyInnerHTML(String(inputBuffer.data(), inputBuffer.size())); |
| 33 } |
| 34 |
| 35 private: |
| 36 void SetUp() override |
| 37 { |
| 38 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
| 39 Settings::setMockScrollbarsEnabled(true); |
| 40 |
| 41 RenderingTest::SetUp(); |
| 42 enableCompositing(); |
| 43 } |
| 44 |
| 45 void TearDown() override |
| 46 { |
| 47 RenderingTest::TearDown(); |
| 48 |
| 49 Settings::setMockScrollbarsEnabled(false); |
| 50 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain
tV2Enabled); |
| 51 } |
| 52 |
| 53 bool m_originalSlimmingPaintV2Enabled; |
| 54 }; |
| 55 |
| 56 TEST_F(PaintPropertyTreeBuilderTest, FixedPosition) |
| 57 { |
| 58 loadTestData("fixed-position.html"); |
| 59 |
| 60 // target1 is a fixed-position element inside an absolute-position scrolling
element. |
| 61 // It should be attached under the viewport to skip scrolling and offset of
the parent. |
| 62 Element* target1 = document().getElementById("target1"); |
| 63 ObjectPaintProperties* target1Properties = target1->layoutObject()->objectPa
intProperties(); |
| 64 EXPECT_EQ(TransformationMatrix().translate(200, 150), target1Properties->pai
ntOffsetTranslation()->matrix()); |
| 65 EXPECT_EQ(document().view()->preTranslation(), target1Properties->paintOffse
tTranslation()->parent()); |
| 66 |
| 67 // target2 is a fixed-position element inside a transformed scrolling elemen
t. |
| 68 // It should be attached under the scrolled box of the transformed element. |
| 69 Element* target2 = document().getElementById("target2"); |
| 70 ObjectPaintProperties* target2Properties = target2->layoutObject()->objectPa
intProperties(); |
| 71 Element* scroller = document().getElementById("scroller"); |
| 72 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object
PaintProperties(); |
| 73 EXPECT_EQ(TransformationMatrix().translate(200, 150), target2Properties->pai
ntOffsetTranslation()->matrix()); |
| 74 EXPECT_EQ(scrollerProperties->scrollTranslation(), target2Properties->paintO
ffsetTranslation()->parent()); |
| 75 } |
| 76 |
| 77 TEST_F(PaintPropertyTreeBuilderTest, PositionAndScroll) |
| 78 { |
| 79 loadTestData("position-and-scroll.html"); |
| 80 |
| 81 Element* scroller = document().getElementById("scroller"); |
| 82 scroller->scrollTo(0, 100); |
| 83 FrameView* frameView = document().view(); |
| 84 frameView->updateAllLifecyclePhases(); |
| 85 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object
PaintProperties(); |
| 86 EXPECT_EQ(TransformationMatrix().translate(0, -100), scrollerProperties->scr
ollTranslation()->matrix()); |
| 87 EXPECT_EQ(frameView->scrollTranslation(), scrollerProperties->scrollTranslat
ion()->parent()); |
| 88 |
| 89 // The relative-positioned element should have accumulated box offset (exclu
de scrolling), |
| 90 // and should be affected by ancestor scroll transforms. |
| 91 Element* relPos = document().getElementById("rel-pos"); |
| 92 ObjectPaintProperties* relPosProperties = relPos->layoutObject()->objectPain
tProperties(); |
| 93 EXPECT_EQ(TransformationMatrix().translate(680, 1120), relPosProperties->pai
ntOffsetTranslation()->matrix()); |
| 94 EXPECT_EQ(scrollerProperties->scrollTranslation(), relPosProperties->paintOf
fsetTranslation()->parent()); |
| 95 |
| 96 // The absolute-positioned element should not be affected by non-positioned
scroller at all. |
| 97 Element* absPos = document().getElementById("abs-pos"); |
| 98 ObjectPaintProperties* absPosProperties = absPos->layoutObject()->objectPain
tProperties(); |
| 99 EXPECT_EQ(TransformationMatrix().translate(123, 456), absPosProperties->pain
tOffsetTranslation()->matrix()); |
| 100 EXPECT_EQ(frameView->scrollTranslation(), absPosProperties->paintOffsetTrans
lation()->parent()); |
| 101 } |
| 102 |
| 103 TEST_F(PaintPropertyTreeBuilderTest, FrameScrollingTraditional) |
| 104 { |
| 105 setBodyInnerHTML("<style> body { height: 10000px; } </style>"); |
| 106 |
| 107 document().domWindow()->scrollTo(0, 100); |
| 108 |
| 109 FrameView* frameView = document().view(); |
| 110 frameView->updateAllLifecyclePhases(); |
| 111 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); |
| 112 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); |
| 113 EXPECT_EQ(TransformationMatrix().translate(0, -100), frameView->scrollTransl
ation()->matrix()); |
| 114 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren
t()); |
| 115 |
| 116 LayoutView* layoutView = document().layoutView(); |
| 117 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert
ies(); |
| 118 EXPECT_EQ(nullptr, layoutViewProperties); |
| 119 } |
| 120 |
| 121 // TODO(trchen): Settings::rootLayerScrolls cannot be switched after main frame
being created. |
| 122 // Need to set it during test setup. Besides that, the test still won't work bec
ause |
| 123 // root layer scrolling mode is not compatible with SPv2 at this moment. |
| 124 // (Duplicate display item ID for FrameView and LayoutView.) |
| 125 TEST_F(PaintPropertyTreeBuilderTest, DISABLED_FrameScrollingRootLayerScrolls) |
| 126 { |
| 127 document().settings()->setRootLayerScrolls(true); |
| 128 |
| 129 setBodyInnerHTML("<style> body { height: 10000px; } </style>"); |
| 130 |
| 131 document().domWindow()->scrollTo(0, 100); |
| 132 |
| 133 FrameView* frameView = document().view(); |
| 134 frameView->updateAllLifecyclePhases(); |
| 135 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); |
| 136 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); |
| 137 EXPECT_EQ(TransformationMatrix(), frameView->scrollTranslation()->matrix()); |
| 138 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren
t()); |
| 139 |
| 140 LayoutView* layoutView = document().layoutView(); |
| 141 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert
ies(); |
| 142 EXPECT_EQ(TransformationMatrix().translate(0, -100), layoutViewProperties->s
crollTranslation()->matrix()); |
| 143 EXPECT_EQ(frameView->scrollTranslation(), layoutViewProperties->scrollTransl
ation()->parent()); |
| 144 } |
| 145 |
| 146 TEST_F(PaintPropertyTreeBuilderTest, Perspective) |
| 147 { |
| 148 loadTestData("perspective.html"); |
| 149 |
| 150 Element* perspective = document().getElementById("perspective"); |
| 151 ObjectPaintProperties* perspectiveProperties = perspective->layoutObject()->
objectPaintProperties(); |
| 152 EXPECT_EQ(TransformationMatrix().applyPerspective(100), perspectivePropertie
s->perspective()->matrix()); |
| 153 // The perspective origin is the center of the border box plus accumulated p
aint offset. |
| 154 EXPECT_EQ(FloatPoint3D(250, 250, 0), perspectiveProperties->perspective()->o
rigin()); |
| 155 EXPECT_EQ(document().view()->scrollTranslation(), perspectiveProperties->per
spective()->parent()); |
| 156 |
| 157 // Adding perspective doesn't clear paint offset. The paint offset will be p
assed down to children. |
| 158 Element* inner = document().getElementById("inner"); |
| 159 ObjectPaintProperties* innerProperties = inner->layoutObject()->objectPaintP
roperties(); |
| 160 EXPECT_EQ(TransformationMatrix().translate(50, 100), innerProperties->paintO
ffsetTranslation()->matrix()); |
| 161 EXPECT_EQ(perspectiveProperties->perspective(), innerProperties->paintOffset
Translation()->parent()); |
| 162 } |
| 163 |
| 164 TEST_F(PaintPropertyTreeBuilderTest, Transform) |
| 165 { |
| 166 loadTestData("transform.html"); |
| 167 |
| 168 Element* transform = document().getElementById("transform"); |
| 169 ObjectPaintProperties* transformProperties = transform->layoutObject()->obje
ctPaintProperties(); |
| 170 EXPECT_EQ(TransformationMatrix().translate3d(123, 456, 789), transformProper
ties->transform()->matrix()); |
| 171 EXPECT_EQ(FloatPoint3D(200, 150, 0), transformProperties->transform()->origi
n()); |
| 172 EXPECT_EQ(transformProperties->paintOffsetTranslation(), transformProperties
->transform()->parent()); |
| 173 EXPECT_EQ(TransformationMatrix().translate(50, 100), transformProperties->pa
intOffsetTranslation()->matrix()); |
| 174 EXPECT_EQ(document().view()->scrollTranslation(), transformProperties->paint
OffsetTranslation()->parent()); |
| 175 } |
| 176 |
| 177 TEST_F(PaintPropertyTreeBuilderTest, RelativePositionInline) |
| 178 { |
| 179 loadTestData("relative-position-inline.html"); |
| 180 |
| 181 Element* inlineBlock = document().getElementById("inline-block"); |
| 182 ObjectPaintProperties* inlineBlockProperties = inlineBlock->layoutObject()->
objectPaintProperties(); |
| 183 EXPECT_EQ(TransformationMatrix().translate(135, 490), inlineBlockProperties-
>paintOffsetTranslation()->matrix()); |
| 184 EXPECT_EQ(document().view()->scrollTranslation(), inlineBlockProperties->pai
ntOffsetTranslation()->parent()); |
| 185 } |
| 186 |
| 187 } // namespace blink |
OLD | NEW |