| 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 23 matching lines...) Expand all Loading... |
| 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 { height: 100px; overflow: auto; position: relative; top: " |
| 38 "200px; }" | 38 "200px; }" |
| 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 scroller->getScrollableArea()->scrollToYOffset(50); | 44 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 45 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 45 scrollableArea->scrollToOffsetFromOrigin( |
| 46 DoubleSize(scrollableArea->offsetFromOrigin().width(), 50)); |
| 47 ASSERT_EQ(50.0, scrollableArea->offsetFromOrigin().height()); |
| 46 LayoutBoxModelObject* sticky = | 48 LayoutBoxModelObject* sticky = |
| 47 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 49 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 48 sticky->updateStickyPositionConstraints(); | 50 sticky->updateStickyPositionConstraints(); |
| 49 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 51 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 50 | 52 |
| 51 const StickyPositionScrollingConstraints& constraints = | 53 const StickyPositionScrollingConstraints& constraints = |
| 52 scroller->getScrollableArea()->stickyConstraintsMap().get( | 54 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 53 sticky->layer()); | |
| 54 ASSERT_EQ(0.f, constraints.topOffset()); | 55 ASSERT_EQ(0.f, constraints.topOffset()); |
| 55 | 56 |
| 56 // The coordinates of the constraint rects should all be with respect to the u
nscrolled scroller. | 57 // The coordinates of the constraint rects should all be with respect to the u
nscrolled scroller. |
| 57 ASSERT_EQ(IntRect(15, 115, 170, 370), | 58 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 58 enclosingIntRect( | 59 enclosingIntRect( |
| 59 getScrollContainerRelativeContainingBlockRect(constraints))); | 60 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 60 ASSERT_EQ( | 61 ASSERT_EQ( |
| 61 IntRect(15, 115, 100, 100), | 62 IntRect(15, 115, 100, 100), |
| 62 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 63 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Verifies that the sticky constraints are not affected by transforms | 66 // Verifies that the sticky constraints are not affected by transforms |
| 66 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) { | 67 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) { |
| 67 setBodyInnerHTML( | 68 setBodyInnerHTML( |
| 68 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " | 69 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 69 "transform: scale(2); transform-origin: top left; }" | 70 "transform: scale(2); transform-origin: top left; }" |
| 70 "#container { box-sizing: border-box; position: relative; top: 100px; " | 71 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 71 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; " | 72 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; " |
| 72 "transform: scale(2); transform-origin: top left; }" | 73 "transform: scale(2); transform-origin: top left; }" |
| 73 "#scroller { height: 100px; overflow: auto; position: relative; top: " | 74 "#scroller { height: 100px; overflow: auto; position: relative; top: " |
| 74 "200px; }" | 75 "200px; }" |
| 75 ".spacer { height: 1000px; }</style>" | 76 ".spacer { height: 1000px; }</style>" |
| 76 "<div id='scroller'><div id='container'><div " | 77 "<div id='scroller'><div id='container'><div " |
| 77 "id='sticky'></div></div><div class='spacer'></div></div>"); | 78 "id='sticky'></div></div><div class='spacer'></div></div>"); |
| 78 LayoutBoxModelObject* scroller = | 79 LayoutBoxModelObject* scroller = |
| 79 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 80 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 80 scroller->getScrollableArea()->scrollToYOffset(50); | 81 DoubleSize newOffset( |
| 81 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 82 scroller->getScrollableArea()->offsetFromOrigin().width(), 50); |
| 83 scroller->getScrollableArea()->scrollToOffsetFromOrigin(newOffset); |
| 84 ASSERT_EQ(50.0, scroller->getScrollableArea()->offsetFromOrigin().height()); |
| 82 LayoutBoxModelObject* sticky = | 85 LayoutBoxModelObject* sticky = |
| 83 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 86 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 84 sticky->updateStickyPositionConstraints(); | 87 sticky->updateStickyPositionConstraints(); |
| 85 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 88 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 86 | 89 |
| 87 const StickyPositionScrollingConstraints& constraints = | 90 const StickyPositionScrollingConstraints& constraints = |
| 88 scroller->getScrollableArea()->stickyConstraintsMap().get( | 91 scroller->getScrollableArea()->stickyConstraintsMap().get( |
| 89 sticky->layer()); | 92 sticky->layer()); |
| 90 ASSERT_EQ(0.f, constraints.topOffset()); | 93 ASSERT_EQ(0.f, constraints.topOffset()); |
| 91 | 94 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 105 "100px; height: 100px; }" | 108 "100px; height: 100px; }" |
| 106 "#container { box-sizing: border-box; position: relative; top: 100px; " | 109 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 107 "height: 400px; width: 250px; padding: 5%; border: 5px solid black; }" | 110 "height: 400px; width: 250px; padding: 5%; border: 5px solid black; }" |
| 108 "#scroller { width: 400px; height: 100px; overflow: auto; position: " | 111 "#scroller { width: 400px; height: 100px; overflow: auto; position: " |
| 109 "relative; top: 200px; }" | 112 "relative; top: 200px; }" |
| 110 ".spacer { height: 1000px; }</style>" | 113 ".spacer { height: 1000px; }</style>" |
| 111 "<div id='scroller'><div id='container'><div " | 114 "<div id='scroller'><div id='container'><div " |
| 112 "id='sticky'></div></div><div class='spacer'></div></div>"); | 115 "id='sticky'></div></div><div class='spacer'></div></div>"); |
| 113 LayoutBoxModelObject* scroller = | 116 LayoutBoxModelObject* scroller = |
| 114 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 117 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 115 scroller->getScrollableArea()->scrollToYOffset(50); | 118 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 116 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 119 scrollableArea->scrollToOffsetFromOrigin( |
| 120 DoubleSize(scrollableArea->offsetFromOrigin().width(), 50)); |
| 121 ASSERT_EQ(50.0, scrollableArea->offsetFromOrigin().height()); |
| 117 LayoutBoxModelObject* sticky = | 122 LayoutBoxModelObject* sticky = |
| 118 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 123 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 119 sticky->updateStickyPositionConstraints(); | 124 sticky->updateStickyPositionConstraints(); |
| 120 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 125 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 121 | 126 |
| 122 const StickyPositionScrollingConstraints& constraints = | 127 const StickyPositionScrollingConstraints& constraints = |
| 123 scroller->getScrollableArea()->stickyConstraintsMap().get( | 128 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 124 sticky->layer()); | |
| 125 ASSERT_EQ(0.f, constraints.topOffset()); | 129 ASSERT_EQ(0.f, constraints.topOffset()); |
| 126 | 130 |
| 127 ASSERT_EQ(IntRect(25, 145, 200, 330), | 131 ASSERT_EQ(IntRect(25, 145, 200, 330), |
| 128 enclosingIntRect( | 132 enclosingIntRect( |
| 129 getScrollContainerRelativeContainingBlockRect(constraints))); | 133 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 130 ASSERT_EQ( | 134 ASSERT_EQ( |
| 131 IntRect(25, 145, 100, 100), | 135 IntRect(25, 145, 100, 100), |
| 132 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 136 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 133 } | 137 } |
| 134 | 138 |
| 135 // Verifies that the sticky constraints are correct when the sticky position con
tainer is also | 139 // Verifies that the sticky constraints are correct when the sticky position con
tainer is also |
| 136 // the ancestor scroller. | 140 // the ancestor scroller. |
| 137 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { | 141 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { |
| 138 setBodyInnerHTML( | 142 setBodyInnerHTML( |
| 139 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " | 143 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " |
| 140 "}" | 144 "}" |
| 141 "#scroller { height: 100px; width: 400px; overflow: auto; position: " | 145 "#scroller { height: 100px; width: 400px; overflow: auto; position: " |
| 142 "relative; top: 200px; }" | 146 "relative; top: 200px; }" |
| 143 ".spacer { height: 1000px; }</style>" | 147 ".spacer { height: 1000px; }</style>" |
| 144 "<div id='scroller'><div id='sticky'></div><div " | 148 "<div id='scroller'><div id='sticky'></div><div " |
| 145 "class='spacer'></div></div>"); | 149 "class='spacer'></div></div>"); |
| 146 LayoutBoxModelObject* scroller = | 150 LayoutBoxModelObject* scroller = |
| 147 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 151 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 148 scroller->getScrollableArea()->scrollToYOffset(50); | 152 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 149 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 153 scrollableArea->scrollToOffsetFromOrigin( |
| 154 DoubleSize(scrollableArea->offsetFromOrigin().width(), 50)); |
| 155 ASSERT_EQ(50.0, scrollableArea->offsetFromOrigin().height()); |
| 150 LayoutBoxModelObject* sticky = | 156 LayoutBoxModelObject* sticky = |
| 151 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 157 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 152 sticky->updateStickyPositionConstraints(); | 158 sticky->updateStickyPositionConstraints(); |
| 153 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 159 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 154 | 160 |
| 155 const StickyPositionScrollingConstraints& constraints = | 161 const StickyPositionScrollingConstraints& constraints = |
| 156 scroller->getScrollableArea()->stickyConstraintsMap().get( | 162 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 157 sticky->layer()); | |
| 158 ASSERT_EQ(IntRect(0, 0, 400, 1100), | 163 ASSERT_EQ(IntRect(0, 0, 400, 1100), |
| 159 enclosingIntRect( | 164 enclosingIntRect( |
| 160 getScrollContainerRelativeContainingBlockRect(constraints))); | 165 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 161 ASSERT_EQ( | 166 ASSERT_EQ( |
| 162 IntRect(0, 0, 100, 100), | 167 IntRect(0, 0, 100, 100), |
| 163 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 168 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 164 } | 169 } |
| 165 | 170 |
| 166 // Verifies that the sticky constraints are correct when the sticky position obj
ect has an | 171 // Verifies that the sticky constraints are correct when the sticky position obj
ect has an |
| 167 // anonymous containing block. | 172 // anonymous containing block. |
| 168 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) { | 173 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) { |
| 169 setBodyInnerHTML( | 174 setBodyInnerHTML( |
| 170 "<style>#sticky { display: inline-block; position: sticky; top: 0; " | 175 "<style>#sticky { display: inline-block; position: sticky; top: 0; " |
| 171 "width: 100px; height: 100px; }" | 176 "width: 100px; height: 100px; }" |
| 172 "#container { box-sizing: border-box; position: relative; top: 100px; " | 177 "#container { box-sizing: border-box; position: relative; top: 100px; " |
| 173 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" | 178 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 174 "#scroller { height: 100px; overflow: auto; position: relative; top: " | 179 "#scroller { height: 100px; overflow: auto; position: relative; top: " |
| 175 "200px; }" | 180 "200px; }" |
| 176 ".header { height: 50px; }" | 181 ".header { height: 50px; }" |
| 177 ".spacer { height: 1000px; }</style>" | 182 ".spacer { height: 1000px; }</style>" |
| 178 "<div id='scroller'><div id='container'><div class='header'></div><div " | 183 "<div id='scroller'><div id='container'><div class='header'></div><div " |
| 179 "id='sticky'></div></div><div class='spacer'></div></div>"); | 184 "id='sticky'></div></div><div class='spacer'></div></div>"); |
| 180 LayoutBoxModelObject* scroller = | 185 LayoutBoxModelObject* scroller = |
| 181 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 186 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 182 scroller->getScrollableArea()->scrollToYOffset(50); | 187 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 183 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); | 188 scrollableArea->scrollToOffsetFromOrigin( |
| 189 DoubleSize(scrollableArea->offsetFromOrigin().width(), 50)); |
| 190 ASSERT_EQ(50.0, scrollableArea->offsetFromOrigin().height()); |
| 184 LayoutBoxModelObject* sticky = | 191 LayoutBoxModelObject* sticky = |
| 185 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 192 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 186 sticky->updateStickyPositionConstraints(); | 193 sticky->updateStickyPositionConstraints(); |
| 187 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 194 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 188 | 195 |
| 189 const StickyPositionScrollingConstraints& constraints = | 196 const StickyPositionScrollingConstraints& constraints = |
| 190 scroller->getScrollableArea()->stickyConstraintsMap().get( | 197 scrollableArea->stickyConstraintsMap().get(sticky->layer()); |
| 191 sticky->layer()); | |
| 192 ASSERT_EQ(IntRect(15, 115, 170, 370), | 198 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 193 enclosingIntRect( | 199 enclosingIntRect( |
| 194 getScrollContainerRelativeContainingBlockRect(constraints))); | 200 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 195 ASSERT_EQ( | 201 ASSERT_EQ( |
| 196 IntRect(15, 165, 100, 100), | 202 IntRect(15, 165, 100, 100), |
| 197 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 203 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 198 } | 204 } |
| 199 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |