Chromium Code Reviews| 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 { | |
| 65 TransformationMatrix matrix; | |
| 66 matrix.translate(200, 150); | |
| 67 EXPECT_EQ(matrix, target1Properties->paintOffsetTranslation()->matrix()) ; | |
|
jbroman
2015/10/21 15:33:35
nit: missed one of the TransformationMatrix things
trchen
2015/10/21 22:21:14
Done.
| |
| 68 } | |
| 69 EXPECT_EQ(document().view()->preTranslation(), target1Properties->paintOffse tTranslation()->parent()); | |
| 70 | |
| 71 // target2 is a fixed-position element inside a transformed scrolling elemen t. | |
| 72 // It should be attached under the scrolled box of the transformed element. | |
| 73 Element* target2 = document().getElementById("target2"); | |
| 74 ObjectPaintProperties* target2Properties = target2->layoutObject()->objectPa intProperties(); | |
| 75 Element* scroller = document().getElementById("scroller"); | |
| 76 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object PaintProperties(); | |
| 77 EXPECT_EQ(TransformationMatrix().translate(200, 150), target2Properties->pai ntOffsetTranslation()->matrix()); | |
| 78 EXPECT_EQ(scrollerProperties->scrollTranslation(), target2Properties->paintO ffsetTranslation()->parent()); | |
| 79 } | |
| 80 | |
| 81 TEST_F(PaintPropertyTreeBuilderTest, PositionAndScroll) | |
| 82 { | |
| 83 loadTestData("position-and-scroll.html"); | |
| 84 | |
| 85 Element* scroller = document().getElementById("scroller"); | |
| 86 scroller->scrollTo(0, 100); | |
| 87 FrameView* frameView = document().view(); | |
| 88 frameView->updateAllLifecyclePhases(); | |
| 89 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object PaintProperties(); | |
| 90 EXPECT_EQ(TransformationMatrix().translate(0, -100), scrollerProperties->scr ollTranslation()->matrix()); | |
| 91 EXPECT_EQ(frameView->scrollTranslation(), scrollerProperties->scrollTranslat ion()->parent()); | |
| 92 | |
| 93 // The relative-positioned element should have accumulated box offset (exclu de scrolling), | |
| 94 // and should be affected by ancestor scroll transforms. | |
| 95 Element* relPos = document().getElementById("rel-pos"); | |
| 96 ObjectPaintProperties* relPosProperties = relPos->layoutObject()->objectPain tProperties(); | |
| 97 EXPECT_EQ(TransformationMatrix().translate(680, 1120), relPosProperties->pai ntOffsetTranslation()->matrix()); | |
| 98 EXPECT_EQ(scrollerProperties->scrollTranslation(), relPosProperties->paintOf fsetTranslation()->parent()); | |
| 99 | |
| 100 // The absolute-positioned element should not be affected by non-positioned scroller at all. | |
| 101 Element* absPos = document().getElementById("abs-pos"); | |
| 102 ObjectPaintProperties* absPosProperties = absPos->layoutObject()->objectPain tProperties(); | |
| 103 EXPECT_EQ(TransformationMatrix().translate(123, 456), absPosProperties->pain tOffsetTranslation()->matrix()); | |
| 104 EXPECT_EQ(frameView->scrollTranslation(), absPosProperties->paintOffsetTrans lation()->parent()); | |
| 105 } | |
| 106 | |
| 107 TEST_F(PaintPropertyTreeBuilderTest, FrameScrollingTraditional) | |
| 108 { | |
| 109 setBodyInnerHTML("<style> body { height: 10000px; } </style>"); | |
| 110 | |
| 111 document().domWindow()->scrollTo(0, 100); | |
| 112 | |
| 113 FrameView* frameView = document().view(); | |
| 114 frameView->updateAllLifecyclePhases(); | |
| 115 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); | |
| 116 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); | |
| 117 EXPECT_EQ(TransformationMatrix().translate(0, -100), frameView->scrollTransl ation()->matrix()); | |
| 118 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren t()); | |
| 119 | |
| 120 LayoutView* layoutView = document().layoutView(); | |
| 121 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert ies(); | |
| 122 EXPECT_EQ(nullptr, layoutViewProperties); | |
| 123 } | |
| 124 | |
| 125 // TODO(trchen): Settings::rootLayerScrolls cannot be switched after main frame being created. | |
| 126 // Need to set it during test setup. Besides that, the test still won't work bec ause | |
| 127 // root layer scrolling mode is not compatible with SPv2 at this moment. | |
| 128 // (Duplicate display item ID for FrameView and LayoutView.) | |
| 129 TEST_F(PaintPropertyTreeBuilderTest, DISABLED_FrameScrollingRootLayerScrolls) | |
| 130 { | |
| 131 document().settings()->setRootLayerScrolls(true); | |
| 132 | |
| 133 setBodyInnerHTML("<style> body { height: 10000px; } </style>"); | |
| 134 | |
| 135 document().domWindow()->scrollTo(0, 100); | |
| 136 | |
| 137 FrameView* frameView = document().view(); | |
| 138 frameView->updateAllLifecyclePhases(); | |
| 139 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); | |
| 140 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); | |
| 141 EXPECT_EQ(TransformationMatrix(), frameView->scrollTranslation()->matrix()); | |
| 142 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren t()); | |
| 143 | |
| 144 LayoutView* layoutView = document().layoutView(); | |
| 145 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert ies(); | |
| 146 EXPECT_EQ(TransformationMatrix().translate(0, -100), layoutViewProperties->s crollTranslation()->matrix()); | |
| 147 EXPECT_EQ(frameView->scrollTranslation(), layoutViewProperties->scrollTransl ation()->parent()); | |
| 148 } | |
| 149 | |
| 150 TEST_F(PaintPropertyTreeBuilderTest, Perspective) | |
| 151 { | |
| 152 loadTestData("perspective.html"); | |
| 153 | |
| 154 Element* perspective = document().getElementById("perspective"); | |
| 155 ObjectPaintProperties* perspectiveProperties = perspective->layoutObject()-> objectPaintProperties(); | |
| 156 EXPECT_EQ(TransformationMatrix().applyPerspective(100), perspectivePropertie s->perspective()->matrix()); | |
| 157 // The perspective origin is the center of the border box plus accumulated p aint offset. | |
| 158 EXPECT_EQ(FloatPoint3D(250, 250, 0), perspectiveProperties->perspective()->o rigin()); | |
| 159 EXPECT_EQ(document().view()->scrollTranslation(), perspectiveProperties->per spective()->parent()); | |
| 160 | |
| 161 // Adding perspective doesn't clear paint offset. The paint offset will be p assed down to children. | |
| 162 Element* inner = document().getElementById("inner"); | |
| 163 ObjectPaintProperties* innerProperties = inner->layoutObject()->objectPaintP roperties(); | |
| 164 EXPECT_EQ(TransformationMatrix().translate(50, 100), innerProperties->paintO ffsetTranslation()->matrix()); | |
| 165 EXPECT_EQ(perspectiveProperties->perspective(), innerProperties->paintOffset Translation()->parent()); | |
| 166 } | |
| 167 | |
| 168 TEST_F(PaintPropertyTreeBuilderTest, Transform) | |
| 169 { | |
| 170 loadTestData("transform.html"); | |
| 171 | |
| 172 Element* transform = document().getElementById("transform"); | |
| 173 ObjectPaintProperties* transformProperties = transform->layoutObject()->obje ctPaintProperties(); | |
| 174 EXPECT_EQ(TransformationMatrix().translate3d(123, 456, 789), transformProper ties->transform()->matrix()); | |
| 175 EXPECT_EQ(FloatPoint3D(200, 150, 0), transformProperties->transform()->origi n()); | |
| 176 EXPECT_EQ(transformProperties->paintOffsetTranslation(), transformProperties ->transform()->parent()); | |
| 177 EXPECT_EQ(TransformationMatrix().translate(50, 100), transformProperties->pa intOffsetTranslation()->matrix()); | |
| 178 EXPECT_EQ(document().view()->scrollTranslation(), transformProperties->paint OffsetTranslation()->parent()); | |
| 179 } | |
| 180 | |
| 181 TEST_F(PaintPropertyTreeBuilderTest, RelativePositionInline) | |
| 182 { | |
| 183 loadTestData("relative-position-inline.html"); | |
| 184 | |
| 185 Element* inlineBlock = document().getElementById("inline-block"); | |
| 186 ObjectPaintProperties* inlineBlockProperties = inlineBlock->layoutObject()-> objectPaintProperties(); | |
| 187 EXPECT_EQ(TransformationMatrix().translate(135, 490), inlineBlockProperties- >paintOffsetTranslation()->matrix()); | |
| 188 EXPECT_EQ(document().view()->scrollTranslation(), inlineBlockProperties->pai ntOffsetTranslation()->parent()); | |
| 189 } | |
| 190 | |
| 191 } // namespace blink | |
| OLD | NEW |