| 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/html/HTMLElement.h" | 7 #include "core/html/HTMLElement.h" |
| 8 #include "core/layout/ImageQualityController.h" | 8 #include "core/layout/ImageQualityController.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" | 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 43 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 44 | 44 |
| 45 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); | 45 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 46 ASSERT_EQ(0.f, constraints.topOffset()); | 46 ASSERT_EQ(0.f, constraints.topOffset()); |
| 47 | 47 |
| 48 // The coordinates of the constraint rects should all be with respect to the
unscrolled scroller. | 48 // The coordinates of the constraint rects should all be with respect to the
unscrolled scroller. |
| 49 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); | 49 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); |
| 50 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); | 50 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Verifies that the sticky constraints are not affected by transforms |
| 54 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) |
| 55 { |
| 56 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h
eight: 100px; transform: scale(2); transform-origin: top left; }" |
| 57 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 200px; padding: 10px; border: 5px solid black; transform: sc
ale(2); transform-origin: top left; }" |
| 58 "#scroller { height: 100px; overflow: auto; position: relative; top: 200
px; }" |
| 59 ".spacer { height: 1000px; }</style>" |
| 60 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); |
| 61 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 62 scroller->getScrollableArea()->scrollToYOffset(50); |
| 63 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 64 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 65 sticky->updateStickyPositionConstraints(); |
| 66 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 67 |
| 68 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 69 ASSERT_EQ(0.f, constraints.topOffset()); |
| 70 |
| 71 // The coordinates of the constraint rects should all be with respect to the
unscrolled scroller. |
| 72 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); |
| 73 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 74 } |
| 75 |
| 53 // Verifies that the sticky constraints are correctly computed. | 76 // Verifies that the sticky constraints are correctly computed. |
| 54 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) | 77 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) |
| 55 { | 78 { |
| 56 setBodyInnerHTML("<style>#sticky { position: sticky; margin-top: 10%; top: 0
; width: 100px; height: 100px; }" | 79 setBodyInnerHTML("<style>#sticky { position: sticky; margin-top: 10%; top: 0
; width: 100px; height: 100px; }" |
| 57 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 250px; padding: 5%; border: 5px solid black; }" | 80 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 250px; padding: 5%; border: 5px solid black; }" |
| 58 "#scroller { width: 400px; height: 100px; overflow: auto; position: rela
tive; top: 200px; }" | 81 "#scroller { width: 400px; height: 100px; overflow: auto; position: rela
tive; top: 200px; }" |
| 59 ".spacer { height: 1000px; }</style>" | 82 ".spacer { height: 1000px; }</style>" |
| 60 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); | 83 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); |
| 61 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); | 84 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 62 scroller->getScrollableArea()->scrollToYOffset(50); | 85 scroller->getScrollableArea()->scrollToYOffset(50); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 130 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 108 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); | 131 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 109 sticky->updateStickyPositionConstraints(); | 132 sticky->updateStickyPositionConstraints(); |
| 110 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 133 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 111 | 134 |
| 112 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); | 135 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 113 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); | 136 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); |
| 114 ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); | 137 ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 115 } | 138 } |
| 116 } // namespace blink | 139 } // namespace blink |
| OLD | NEW |