| 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 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Verifies that the sticky constraints are correctly computed. | 30 // Verifies that the sticky constraints are correctly computed. |
| 31 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) { | 31 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) { |
| 32 setBodyInnerHTML( | 32 setBodyInnerHTML( |
| 33 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " | 33 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 34 "}" | 34 "}" |
| 35 "#container { box-sizing: border-box; position: relative; top: 100px; " | 35 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 36 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" | 36 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 37 "#scroller { height: 100px; overflow: auto; position: relative; top: " | 37 "#scroller { width: 400px; height: 100px; overflow: auto; " |
| 38 "200px; }" | 38 "position: relative; top: 200px; border: 2px solid black; }" |
| 39 ".spacer { height: 1000px; }</style>" | 39 ".spacer { height: 1000px; }</style>" |
| 40 "<div id='scroller'><div id='container'><div " | 40 "<div id='scroller'><div id='container'><div " |
| 41 "id='sticky'></div></div><div class='spacer'></div></div>"); | 41 "id='sticky'></div></div><div class='spacer'></div></div>"); |
| 42 LayoutBoxModelObject* scroller = | 42 LayoutBoxModelObject* scroller = |
| 43 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 43 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 44 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 44 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 45 scrollableArea->scrollToAbsolutePosition( | 45 scrollableArea->scrollToAbsolutePosition( |
| 46 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); | 46 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); |
| 47 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 47 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 48 LayoutBoxModelObject* sticky = | 48 LayoutBoxModelObject* sticky = |
| 49 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 49 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 50 sticky->updateStickyPositionConstraints(); | 50 sticky->updateStickyPositionConstraints(); |
| 51 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 51 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 52 | 52 |
| 53 const StickyPositionScrollingConstraints& constraints = | 53 const StickyPositionScrollingConstraints& constraints = |
| 54 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 54 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 55 ASSERT_EQ(0.f, constraints.topOffset()); | 55 ASSERT_EQ(0.f, constraints.topOffset()); |
| 56 | 56 |
| 57 // The coordinates of the constraint rects should all be with respect to the | 57 // The coordinates of the constraint rects should all be with respect to the |
| 58 // unscrolled scroller. | 58 // unscrolled scroller. |
| 59 ASSERT_EQ(IntRect(15, 115, 170, 370), | 59 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 60 enclosingIntRect( | 60 enclosingIntRect( |
| 61 getScrollContainerRelativeContainingBlockRect(constraints))); | 61 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 62 ASSERT_EQ( | 62 ASSERT_EQ( |
| 63 IntRect(15, 115, 100, 100), | 63 IntRect(15, 115, 100, 100), |
| 64 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 64 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 65 |
| 66 // The sticky constraining rect also doesn't include the border offset. |
| 67 ASSERT_EQ(IntRect(0, 50, 400, 100), |
| 68 enclosingIntRect(sticky->computeStickyConstrainingRect())); |
| 69 } |
| 70 |
| 71 // Verifies that the sticky constraints are correctly computed in right to left. |
| 72 TEST_F(LayoutBoxModelObjectTest, StickyPositionVerticalRLConstraints) { |
| 73 setBodyInnerHTML( |
| 74 "<style> html { -webkit-writing-mode: vertical-rl; } " |
| 75 "#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 76 "}" |
| 77 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 78 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 79 "#scroller { width: 400px; height: 100px; overflow: auto; " |
| 80 "position: relative; top: 200px; border: 2px solid black; }" |
| 81 ".spacer { height: 1000px; }</style>" |
| 82 "<div id='scroller'><div id='container'><div " |
| 83 "id='sticky'></div></div><div class='spacer'></div></div>"); |
| 84 LayoutBoxModelObject* scroller = |
| 85 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 86 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 87 scrollableArea->scrollToAbsolutePosition( |
| 88 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); |
| 89 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 90 LayoutBoxModelObject* sticky = |
| 91 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 92 sticky->updateStickyPositionConstraints(); |
| 93 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 94 |
| 95 const StickyPositionScrollingConstraints& constraints = |
| 96 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 97 ASSERT_EQ(0.f, constraints.topOffset()); |
| 98 |
| 99 // The coordinates of the constraint rects should all be with respect to the |
| 100 // unscrolled scroller. |
| 101 ASSERT_EQ(IntRect(215, 115, 170, 370), |
| 102 enclosingIntRect( |
| 103 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 104 ASSERT_EQ( |
| 105 IntRect(285, 115, 100, 100), |
| 106 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 107 |
| 108 // The sticky constraining rect also doesn't include the border offset. |
| 109 ASSERT_EQ(IntRect(0, 50, 400, 100), |
| 110 enclosingIntRect(sticky->computeStickyConstrainingRect())); |
| 65 } | 111 } |
| 66 | 112 |
| 67 // Verifies that the sticky constraints are not affected by transforms | 113 // Verifies that the sticky constraints are not affected by transforms |
| 68 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) { | 114 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) { |
| 69 setBodyInnerHTML( | 115 setBodyInnerHTML( |
| 70 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " | 116 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 71 "transform: scale(2); transform-origin: top left; }" | 117 "transform: scale(2); transform-origin: top left; }" |
| 72 "#container { box-sizing: border-box; position: relative; top: 100px; " | 118 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 73 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; " | 119 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; " |
| 74 "transform: scale(2); transform-origin: top left; }" | 120 "transform: scale(2); transform-origin: top left; }" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 183 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 138 } | 184 } |
| 139 | 185 |
| 140 // Verifies that the sticky constraints are correct when the sticky position | 186 // Verifies that the sticky constraints are correct when the sticky position |
| 141 // container is also the ancestor scroller. | 187 // container is also the ancestor scroller. |
| 142 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { | 188 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { |
| 143 setBodyInnerHTML( | 189 setBodyInnerHTML( |
| 144 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " | 190 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 145 "}" | 191 "}" |
| 146 "#scroller { height: 100px; width: 400px; overflow: auto; position: " | 192 "#scroller { height: 100px; width: 400px; overflow: auto; position: " |
| 147 "relative; top: 200px; }" | 193 "relative; top: 200px; border: 2px solid black; }" |
| 148 ".spacer { height: 1000px; }</style>" | 194 ".spacer { height: 1000px; }</style>" |
| 149 "<div id='scroller'><div id='sticky'></div><div " | 195 "<div id='scroller'><div id='sticky'></div><div " |
| 150 "class='spacer'></div></div>"); | 196 "class='spacer'></div></div>"); |
| 151 LayoutBoxModelObject* scroller = | 197 LayoutBoxModelObject* scroller = |
| 152 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 198 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 153 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 199 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 154 scrollableArea->scrollToAbsolutePosition( | 200 scrollableArea->scrollToAbsolutePosition( |
| 155 FloatPoint(scrollableArea->scrollPosition().x(), 50)); | 201 FloatPoint(scrollableArea->scrollPosition().x(), 50)); |
| 156 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 202 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 157 LayoutBoxModelObject* sticky = | 203 LayoutBoxModelObject* sticky = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 const StickyPositionScrollingConstraints& constraints = | 243 const StickyPositionScrollingConstraints& constraints = |
| 198 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 244 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 199 ASSERT_EQ(IntRect(15, 115, 170, 370), | 245 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 200 enclosingIntRect( | 246 enclosingIntRect( |
| 201 getScrollContainerRelativeContainingBlockRect(constraints))); | 247 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 202 ASSERT_EQ( | 248 ASSERT_EQ( |
| 203 IntRect(15, 165, 100, 100), | 249 IntRect(15, 165, 100, 100), |
| 204 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 250 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 205 } | 251 } |
| 206 } // namespace blink | 252 } // namespace blink |
| OLD | NEW |