| 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/layout/LayoutBoxModelObject.h" | 5 #include "core/layout/LayoutBoxModelObject.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMTokenList.h" |
| 8 #include "core/dom/DocumentLifecycle.h" |
| 7 #include "core/html/HTMLElement.h" | 9 #include "core/html/HTMLElement.h" |
| 8 #include "core/layout/ImageQualityController.h" | 10 #include "core/layout/ImageQualityController.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 11 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" | 12 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" |
| 11 #include "core/paint/PaintLayer.h" | 13 #include "core/paint/PaintLayer.h" |
| 12 #include "core/paint/PaintLayerScrollableArea.h" | 14 #include "core/paint/PaintLayerScrollableArea.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 const StickyPositionScrollingConstraints& constraints = | 273 const StickyPositionScrollingConstraints& constraints = |
| 272 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 274 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 273 EXPECT_EQ(IntRect(0, 0, 50, 100), | 275 EXPECT_EQ(IntRect(0, 0, 50, 100), |
| 274 enclosingIntRect( | 276 enclosingIntRect( |
| 275 getScrollContainerRelativeContainingBlockRect(constraints))); | 277 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 276 EXPECT_EQ( | 278 EXPECT_EQ( |
| 277 IntRect(0, 50, 50, 50), | 279 IntRect(0, 50, 50, 50), |
| 278 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 280 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 279 } | 281 } |
| 280 | 282 |
| 283 // Tests that when a non-layer changes size it invalidates the constraints for |
| 284 // sticky position elements within the same scroller. |
| 285 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraintInvalidation) { |
| 286 setBodyInnerHTML( |
| 287 "<style>" |
| 288 "#scroller { overflow: auto; display: flex; width: 200px; }" |
| 289 "#target { width: 50px; }" |
| 290 "#sticky { position: sticky; top: 0; }" |
| 291 ".container { width: 100px; margin-left: auto; margin-right: auto; }" |
| 292 ".hide { display: none; }" |
| 293 "</style>" |
| 294 "<div id='scroller'>" |
| 295 " <div style='flex: 1'>" |
| 296 " <div class='container'><div id='sticky'></div>" |
| 297 " </div>" |
| 298 "</div>" |
| 299 "<div class='spacer' id='target'></div>" |
| 300 "</div>"); |
| 301 LayoutBoxModelObject* scroller = |
| 302 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 303 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 304 LayoutBoxModelObject* sticky = |
| 305 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 306 LayoutBoxModelObject* target = |
| 307 toLayoutBoxModelObject(getLayoutObjectByElementId("target")); |
| 308 EXPECT_TRUE(scrollableArea->stickyConstraintsMap().contains(sticky->layer())); |
| 309 EXPECT_EQ(25.f, |
| 310 getScrollContainerRelativeStickyBoxRect( |
| 311 scrollableArea->stickyConstraintsMap().get(sticky->layer())) |
| 312 .location() |
| 313 .x()); |
| 314 toHTMLElement(target->node())->classList().add("hide", ASSERT_NO_EXCEPTION); |
| 315 document().view()->updateLifecycleToLayoutClean(); |
| 316 // Layout should invalidate the sticky constraints of the sticky element and |
| 317 // mark it as needing a compositing inputs update. |
| 318 EXPECT_FALSE( |
| 319 scrollableArea->stickyConstraintsMap().contains(sticky->layer())); |
| 320 EXPECT_TRUE(sticky->layer()->needsCompositingInputsUpdate()); |
| 321 |
| 322 // After updating compositing inputs we should have the updated position. |
| 323 document().view()->updateAllLifecyclePhases(); |
| 324 EXPECT_EQ(50.f, |
| 325 getScrollContainerRelativeStickyBoxRect( |
| 326 scrollableArea->stickyConstraintsMap().get(sticky->layer())) |
| 327 .location() |
| 328 .x()); |
| 329 } |
| 330 |
| 281 } // namespace blink | 331 } // namespace blink |
| OLD | NEW |