| 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" | 7 #include "core/dom/DOMTokenList.h" |
| 8 #include "core/dom/DocumentLifecycle.h" | 8 #include "core/dom/DocumentLifecycle.h" |
| 9 #include "core/html/HTMLElement.h" | 9 #include "core/html/HTMLElement.h" |
| 10 #include "core/layout/ImageQualityController.h" | 10 #include "core/layout/ImageQualityController.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 46 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 47 scrollableArea->scrollToAbsolutePosition( | 47 scrollableArea->scrollToAbsolutePosition( |
| 48 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); | 48 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); |
| 49 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 49 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 50 LayoutBoxModelObject* sticky = | 50 LayoutBoxModelObject* sticky = |
| 51 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 51 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 52 sticky->updateStickyPositionConstraints(); | 52 sticky->updateStickyPositionConstraints(); |
| 53 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 53 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 54 | 54 |
| 55 const StickyPositionScrollingConstraints& constraints = | 55 const StickyPositionScrollingConstraints& constraints = |
| 56 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 56 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 57 ASSERT_EQ(0.f, constraints.topOffset()); | 57 ASSERT_EQ(0.f, constraints.topOffset()); |
| 58 | 58 |
| 59 // The coordinates of the constraint rects should all be with respect to the | 59 // The coordinates of the constraint rects should all be with respect to the |
| 60 // unscrolled scroller. | 60 // unscrolled scroller. |
| 61 ASSERT_EQ(IntRect(15, 115, 170, 370), | 61 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 62 enclosingIntRect( | 62 enclosingIntRect( |
| 63 getScrollContainerRelativeContainingBlockRect(constraints))); | 63 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 64 ASSERT_EQ( | 64 ASSERT_EQ( |
| 65 IntRect(15, 115, 100, 100), | 65 IntRect(15, 115, 100, 100), |
| 66 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 66 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 88 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 89 scrollableArea->scrollToAbsolutePosition( | 89 scrollableArea->scrollToAbsolutePosition( |
| 90 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); | 90 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); |
| 91 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 91 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 92 LayoutBoxModelObject* sticky = | 92 LayoutBoxModelObject* sticky = |
| 93 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 93 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 94 sticky->updateStickyPositionConstraints(); | 94 sticky->updateStickyPositionConstraints(); |
| 95 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 95 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 96 | 96 |
| 97 const StickyPositionScrollingConstraints& constraints = | 97 const StickyPositionScrollingConstraints& constraints = |
| 98 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 98 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 99 ASSERT_EQ(0.f, constraints.topOffset()); | 99 ASSERT_EQ(0.f, constraints.topOffset()); |
| 100 | 100 |
| 101 // The coordinates of the constraint rects should all be with respect to the | 101 // The coordinates of the constraint rects should all be with respect to the |
| 102 // unscrolled scroller. | 102 // unscrolled scroller. |
| 103 ASSERT_EQ(IntRect(215, 115, 170, 370), | 103 ASSERT_EQ(IntRect(215, 115, 170, 370), |
| 104 enclosingIntRect( | 104 enclosingIntRect( |
| 105 getScrollContainerRelativeContainingBlockRect(constraints))); | 105 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 106 ASSERT_EQ( | 106 ASSERT_EQ( |
| 107 IntRect(285, 115, 100, 100), | 107 IntRect(285, 115, 100, 100), |
| 108 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 108 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 130 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 130 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 131 scrollableArea->scrollToAbsolutePosition( | 131 scrollableArea->scrollToAbsolutePosition( |
| 132 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); | 132 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); |
| 133 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 133 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 134 LayoutBoxModelObject* sticky = | 134 LayoutBoxModelObject* sticky = |
| 135 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 135 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 136 sticky->updateStickyPositionConstraints(); | 136 sticky->updateStickyPositionConstraints(); |
| 137 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 137 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 138 | 138 |
| 139 const StickyPositionScrollingConstraints& constraints = | 139 const StickyPositionScrollingConstraints& constraints = |
| 140 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 140 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 141 ASSERT_EQ(0.f, constraints.topOffset()); | 141 ASSERT_EQ(0.f, constraints.topOffset()); |
| 142 | 142 |
| 143 // The coordinates of the constraint rects should all be with respect to the | 143 // The coordinates of the constraint rects should all be with respect to the |
| 144 // unscrolled scroller. | 144 // unscrolled scroller. |
| 145 ASSERT_EQ(IntRect(15, 115, 170, 370), | 145 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 146 enclosingIntRect( | 146 enclosingIntRect( |
| 147 getScrollContainerRelativeContainingBlockRect(constraints))); | 147 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 148 ASSERT_EQ( | 148 ASSERT_EQ( |
| 149 IntRect(15, 115, 100, 100), | 149 IntRect(15, 115, 100, 100), |
| 150 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 150 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 167 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 168 scrollableArea->scrollToAbsolutePosition( | 168 scrollableArea->scrollToAbsolutePosition( |
| 169 FloatPoint(scrollableArea->scrollPosition().x(), 50)); | 169 FloatPoint(scrollableArea->scrollPosition().x(), 50)); |
| 170 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 170 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 171 LayoutBoxModelObject* sticky = | 171 LayoutBoxModelObject* sticky = |
| 172 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 172 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 173 sticky->updateStickyPositionConstraints(); | 173 sticky->updateStickyPositionConstraints(); |
| 174 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 174 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 175 | 175 |
| 176 const StickyPositionScrollingConstraints& constraints = | 176 const StickyPositionScrollingConstraints& constraints = |
| 177 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 177 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 178 ASSERT_EQ(0.f, constraints.topOffset()); | 178 ASSERT_EQ(0.f, constraints.topOffset()); |
| 179 | 179 |
| 180 ASSERT_EQ(IntRect(25, 145, 200, 330), | 180 ASSERT_EQ(IntRect(25, 145, 200, 330), |
| 181 enclosingIntRect( | 181 enclosingIntRect( |
| 182 getScrollContainerRelativeContainingBlockRect(constraints))); | 182 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 183 ASSERT_EQ( | 183 ASSERT_EQ( |
| 184 IntRect(25, 145, 100, 100), | 184 IntRect(25, 145, 100, 100), |
| 185 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 185 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 186 } | 186 } |
| 187 | 187 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 201 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 201 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 202 scrollableArea->scrollToAbsolutePosition( | 202 scrollableArea->scrollToAbsolutePosition( |
| 203 FloatPoint(scrollableArea->scrollPosition().x(), 50)); | 203 FloatPoint(scrollableArea->scrollPosition().x(), 50)); |
| 204 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 204 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 205 LayoutBoxModelObject* sticky = | 205 LayoutBoxModelObject* sticky = |
| 206 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 206 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 207 sticky->updateStickyPositionConstraints(); | 207 sticky->updateStickyPositionConstraints(); |
| 208 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 208 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 209 | 209 |
| 210 const StickyPositionScrollingConstraints& constraints = | 210 const StickyPositionScrollingConstraints& constraints = |
| 211 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 211 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 212 ASSERT_EQ(IntRect(0, 0, 400, 1100), | 212 ASSERT_EQ(IntRect(0, 0, 400, 1100), |
| 213 enclosingIntRect( | 213 enclosingIntRect( |
| 214 getScrollContainerRelativeContainingBlockRect(constraints))); | 214 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 215 ASSERT_EQ( | 215 ASSERT_EQ( |
| 216 IntRect(0, 0, 100, 100), | 216 IntRect(0, 0, 100, 100), |
| 217 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 217 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Verifies that the sticky constraints are correct when the sticky position | 220 // Verifies that the sticky constraints are correct when the sticky position |
| 221 // object has an anonymous containing block. | 221 // object has an anonymous containing block. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 236 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 237 scrollableArea->scrollToAbsolutePosition( | 237 scrollableArea->scrollToAbsolutePosition( |
| 238 FloatPoint(scrollableArea->scrollPosition().x(), 50)); | 238 FloatPoint(scrollableArea->scrollPosition().x(), 50)); |
| 239 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); | 239 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); |
| 240 LayoutBoxModelObject* sticky = | 240 LayoutBoxModelObject* sticky = |
| 241 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 241 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 242 sticky->updateStickyPositionConstraints(); | 242 sticky->updateStickyPositionConstraints(); |
| 243 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); | 243 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 244 | 244 |
| 245 const StickyPositionScrollingConstraints& constraints = | 245 const StickyPositionScrollingConstraints& constraints = |
| 246 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 246 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 247 ASSERT_EQ(IntRect(15, 115, 170, 370), | 247 ASSERT_EQ(IntRect(15, 115, 170, 370), |
| 248 enclosingIntRect( | 248 enclosingIntRect( |
| 249 getScrollContainerRelativeContainingBlockRect(constraints))); | 249 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 250 ASSERT_EQ( | 250 ASSERT_EQ( |
| 251 IntRect(15, 165, 100, 100), | 251 IntRect(15, 165, 100, 100), |
| 252 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 252 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 253 } | 253 } |
| 254 | 254 |
| 255 TEST_F(LayoutBoxModelObjectTest, StickyPositionTableContainers) { | 255 TEST_F(LayoutBoxModelObjectTest, StickyPositionTableContainers) { |
| 256 setBodyInnerHTML( | 256 setBodyInnerHTML( |
| 257 "<style> td, th { height: 50px; width: 50px; } " | 257 "<style> td, th { height: 50px; width: 50px; } " |
| 258 "#sticky { position: sticky; left: 0; will-change: transform; }" | 258 "#sticky { position: sticky; left: 0; will-change: transform; }" |
| 259 "table {border: none; }" | 259 "table {border: none; }" |
| 260 "#scroller { overflow: auto; }" | 260 "#scroller { overflow: auto; }" |
| 261 "</style>" | 261 "</style>" |
| 262 "<div id='scroller'>" | 262 "<div id='scroller'>" |
| 263 "<table cellspacing='0' cellpadding='0'>" | 263 "<table cellspacing='0' cellpadding='0'>" |
| 264 " <thead><tr><td></td></tr></thead>" | 264 " <thead><tr><td></td></tr></thead>" |
| 265 " <tr><td id='sticky'></td></tr>" | 265 " <tr><td id='sticky'></td></tr>" |
| 266 "</table></div>"); | 266 "</table></div>"); |
| 267 LayoutBoxModelObject* scroller = | 267 LayoutBoxModelObject* scroller = |
| 268 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 268 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 269 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 269 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 270 LayoutBoxModelObject* sticky = | 270 LayoutBoxModelObject* sticky = |
| 271 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 271 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 272 sticky->updateStickyPositionConstraints(); | 272 sticky->updateStickyPositionConstraints(); |
| 273 const StickyPositionScrollingConstraints& constraints = | 273 const StickyPositionScrollingConstraints& constraints = |
| 274 scrollableArea->stickyConstraintsMap().get(sticky->layer()); | 274 scrollableArea->stickyConstraintsMap().at(sticky->layer()); |
| 275 EXPECT_EQ(IntRect(0, 0, 50, 100), | 275 EXPECT_EQ(IntRect(0, 0, 50, 100), |
| 276 enclosingIntRect( | 276 enclosingIntRect( |
| 277 getScrollContainerRelativeContainingBlockRect(constraints))); | 277 getScrollContainerRelativeContainingBlockRect(constraints))); |
| 278 EXPECT_EQ( | 278 EXPECT_EQ( |
| 279 IntRect(0, 50, 50, 50), | 279 IntRect(0, 50, 50, 50), |
| 280 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); | 280 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Tests that when a non-layer changes size it invalidates the constraints for | 283 // Tests that when a non-layer changes size it invalidates the constraints for |
| 284 // sticky position elements within the same scroller. | 284 // sticky position elements within the same scroller. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 301 LayoutBoxModelObject* scroller = | 301 LayoutBoxModelObject* scroller = |
| 302 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); | 302 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); |
| 303 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); | 303 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); |
| 304 LayoutBoxModelObject* sticky = | 304 LayoutBoxModelObject* sticky = |
| 305 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); | 305 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); |
| 306 LayoutBoxModelObject* target = | 306 LayoutBoxModelObject* target = |
| 307 toLayoutBoxModelObject(getLayoutObjectByElementId("target")); | 307 toLayoutBoxModelObject(getLayoutObjectByElementId("target")); |
| 308 EXPECT_TRUE(scrollableArea->stickyConstraintsMap().contains(sticky->layer())); | 308 EXPECT_TRUE(scrollableArea->stickyConstraintsMap().contains(sticky->layer())); |
| 309 EXPECT_EQ(25.f, | 309 EXPECT_EQ(25.f, |
| 310 getScrollContainerRelativeStickyBoxRect( | 310 getScrollContainerRelativeStickyBoxRect( |
| 311 scrollableArea->stickyConstraintsMap().get(sticky->layer())) | 311 scrollableArea->stickyConstraintsMap().at(sticky->layer())) |
| 312 .location() | 312 .location() |
| 313 .x()); | 313 .x()); |
| 314 toHTMLElement(target->node())->classList().add("hide", ASSERT_NO_EXCEPTION); | 314 toHTMLElement(target->node())->classList().add("hide", ASSERT_NO_EXCEPTION); |
| 315 document().view()->updateLifecycleToLayoutClean(); | 315 document().view()->updateLifecycleToLayoutClean(); |
| 316 // Layout should invalidate the sticky constraints of the sticky element and | 316 // Layout should invalidate the sticky constraints of the sticky element and |
| 317 // mark it as needing a compositing inputs update. | 317 // mark it as needing a compositing inputs update. |
| 318 EXPECT_FALSE( | 318 EXPECT_FALSE( |
| 319 scrollableArea->stickyConstraintsMap().contains(sticky->layer())); | 319 scrollableArea->stickyConstraintsMap().contains(sticky->layer())); |
| 320 EXPECT_TRUE(sticky->layer()->needsCompositingInputsUpdate()); | 320 EXPECT_TRUE(sticky->layer()->needsCompositingInputsUpdate()); |
| 321 | 321 |
| 322 // After updating compositing inputs we should have the updated position. | 322 // After updating compositing inputs we should have the updated position. |
| 323 document().view()->updateAllLifecyclePhases(); | 323 document().view()->updateAllLifecyclePhases(); |
| 324 EXPECT_EQ(50.f, | 324 EXPECT_EQ(50.f, |
| 325 getScrollContainerRelativeStickyBoxRect( | 325 getScrollContainerRelativeStickyBoxRect( |
| 326 scrollableArea->stickyConstraintsMap().get(sticky->layer())) | 326 scrollableArea->stickyConstraintsMap().at(sticky->layer())) |
| 327 .location() | 327 .location() |
| 328 .x()); | 328 .x()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 } // namespace blink | 331 } // namespace blink |
| OLD | NEW |