Chromium Code Reviews| 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'>" | |
|
chrishtr
2017/02/10 23:14:33
nit: indent 2
flackr
2017/02/13 15:53:54
Done.
| |
| 296 " <div class='container'><div id='sticky'></div></div>" | |
| 297 "</div>" | |
| 298 "<div class='spacer' id='target'></div>" | |
| 299 "</div>"); | |
| 300 LayoutBoxModelObject* scroller = | |
| 301 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | |
| 302 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | |
| 303 LayoutBoxModelObject* sticky = | |
| 304 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | |
| 305 LayoutBoxModelObject* target = | |
| 306 toLayoutBoxModelObject(getLayoutObjectByElementId("target")); | |
| 307 EXPECT_TRUE(scrollableArea->stickyConstraintsMap().contains(sticky->layer())); | |
| 308 EXPECT_EQ(25.f, | |
| 309 getScrollContainerRelativeStickyBoxRect( | |
| 310 scrollableArea->stickyConstraintsMap().get(sticky->layer())) | |
| 311 .location() | |
| 312 .x()); | |
| 313 toHTMLElement(target->node())->classList().add("hide", ASSERT_NO_EXCEPTION); | |
| 314 document().view()->updateLifecycleToLayoutClean(); | |
| 315 // Layout should invalidate the sticky constraints of the sticky element and | |
| 316 // mark it as needing a compositing inputs update. | |
| 317 EXPECT_FALSE( | |
| 318 scrollableArea->stickyConstraintsMap().contains(sticky->layer())); | |
| 319 EXPECT_TRUE(sticky->layer()->needsCompositingInputsUpdate()); | |
| 320 | |
| 321 // After updating compositing inputs we should have the updated position. | |
| 322 document().view()->updateAllLifecyclePhases(); | |
| 323 EXPECT_EQ(50.f, | |
| 324 getScrollContainerRelativeStickyBoxRect( | |
| 325 scrollableArea->stickyConstraintsMap().get(sticky->layer())) | |
| 326 .location() | |
| 327 .x()); | |
| 328 } | |
| 329 | |
| 281 } // namespace blink | 330 } // namespace blink |
| OLD | NEW |