| 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/compositing/CompositedLayerMapping.h" | 5 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/layout/LayoutBoxModelObject.h" | 8 #include "core/layout/LayoutBoxModelObject.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/layout/api/LayoutViewItem.h" | 10 #include "core/layout/api/LayoutViewItem.h" |
| 11 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | 11 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
| 12 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
| 13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 14 #include "public/platform/WebContentLayer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 typedef bool TestParamRootLayerScrolling; | 19 typedef bool TestParamRootLayerScrolling; |
| 19 class CompositedLayerMappingTest | 20 class CompositedLayerMappingTest |
| 20 : public testing::WithParamInterface<TestParamRootLayerScrolling>, | 21 : public testing::WithParamInterface<TestParamRootLayerScrolling>, |
| 21 private ScopedRootLayerScrollingForTest, | 22 private ScopedRootLayerScrollingForTest, |
| 22 public RenderingTest { | 23 public RenderingTest { |
| 23 public: | 24 public: |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 document().view()->updateAllLifecyclePhases(); | 1240 document().view()->updateAllLifecyclePhases(); |
| 1240 | 1241 |
| 1241 childPaintLayer = toLayoutBoxModelObject(child->layoutObject())->layer(); | 1242 childPaintLayer = toLayoutBoxModelObject(child->layoutObject())->layer(); |
| 1242 ASSERT_TRUE(childPaintLayer); | 1243 ASSERT_TRUE(childPaintLayer); |
| 1243 childMapping = childPaintLayer->compositedLayerMapping(); | 1244 childMapping = childPaintLayer->compositedLayerMapping(); |
| 1244 ASSERT_TRUE(childMapping); | 1245 ASSERT_TRUE(childMapping); |
| 1245 EXPECT_FALSE(childMapping->ancestorClippingLayer()); | 1246 EXPECT_FALSE(childMapping->ancestorClippingLayer()); |
| 1246 EXPECT_FALSE(childMapping->ancestorClippingMaskLayer()); | 1247 EXPECT_FALSE(childMapping->ancestorClippingMaskLayer()); |
| 1247 } | 1248 } |
| 1248 | 1249 |
| 1250 TEST_P(CompositedLayerMappingTest, StickyPositionContentOffset) { |
| 1251 setBodyInnerHTML( |
| 1252 "<div style='width: 400px; height: 400px; overflow: auto; " |
| 1253 "will-change: transform;' >" |
| 1254 " <div id='sticky1' style='position: sticky; top: 0px; width: 100px; " |
| 1255 "height: 100px; box-shadow: -5px -5px 5px 0 black; " |
| 1256 "will-change: transform;'></div>" |
| 1257 " <div style='height: 2000px;'></div>" |
| 1258 "</div>" |
| 1259 |
| 1260 "<div style='width: 400px; height: 400px; overflow: auto; " |
| 1261 "will-change: transform;' >" |
| 1262 " <div id='sticky2' style='position: sticky; top: 0px; width: 100px; " |
| 1263 "height: 100px; will-change: transform;'>" |
| 1264 " <div style='position: absolute; top: -50px; left: -50px; " |
| 1265 "width: 5px; height: 5px; background: red;'></div></div>" |
| 1266 " <div style='height: 2000px;'></div>" |
| 1267 "</div>"); |
| 1268 document().view()->updateLifecycleToCompositingCleanPlusScrolling(); |
| 1269 |
| 1270 CompositedLayerMapping* sticky1 = |
| 1271 toLayoutBlock(getLayoutObjectByElementId("sticky1")) |
| 1272 ->layer() |
| 1273 ->compositedLayerMapping(); |
| 1274 CompositedLayerMapping* sticky2 = |
| 1275 toLayoutBlock(getLayoutObjectByElementId("sticky2")) |
| 1276 ->layer() |
| 1277 ->compositedLayerMapping(); |
| 1278 |
| 1279 // Box offsets the content by the combination of the shadow offset and blur |
| 1280 // radius plus an additional pixel of anti-aliasing. |
| 1281 ASSERT_TRUE(sticky1); |
| 1282 WebLayerStickyPositionConstraint constraint1 = |
| 1283 sticky1->mainGraphicsLayer() |
| 1284 ->contentLayer() |
| 1285 ->layer() |
| 1286 ->stickyPositionConstraint(); |
| 1287 EXPECT_EQ(IntPoint(-11, -11), |
| 1288 IntPoint(constraint1.parentRelativeStickyBoxOffset)); |
| 1289 |
| 1290 // Since the nested div will be squashed into the same composited layer the |
| 1291 // sticky element is offset by the nested element's offset. |
| 1292 ASSERT_TRUE(sticky2); |
| 1293 WebLayerStickyPositionConstraint constraint2 = |
| 1294 sticky2->mainGraphicsLayer() |
| 1295 ->contentLayer() |
| 1296 ->layer() |
| 1297 ->stickyPositionConstraint(); |
| 1298 EXPECT_EQ(IntPoint(-50, -50), |
| 1299 IntPoint(constraint2.parentRelativeStickyBoxOffset)); |
| 1300 } |
| 1301 |
| 1249 } // namespace blink | 1302 } // namespace blink |
| OLD | NEW |