| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/LayoutBoxModelObject.h" |
| 6 |
| 7 #include "core/html/HTMLElement.h" |
| 8 #include "core/layout/ImageQualityController.h" |
| 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" |
| 11 #include "core/paint/PaintLayer.h" |
| 12 #include "core/paint/PaintLayerScrollableArea.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class LayoutBoxModelObjectTest : public RenderingTest { |
| 18 protected: |
| 19 const FloatRect& getScrollContainerRelativeContainingBlockRect(const StickyP
ositionScrollingConstraints& constraints) const |
| 20 { |
| 21 return constraints.scrollContainerRelativeContainingBlockRect(); |
| 22 } |
| 23 |
| 24 const FloatRect& getScrollContainerRelativeStickyBoxRect(const StickyPositio
nScrollingConstraints& constraints) const |
| 25 { |
| 26 return constraints.scrollContainerRelativeStickyBoxRect(); |
| 27 } |
| 28 }; |
| 29 |
| 30 // Verifies that the sticky constraints are correctly computed. |
| 31 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) |
| 32 { |
| 33 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h
eight: 100px; }" |
| 34 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 35 "#scroller { height: 100px; overflow: auto; position: relative; top: 200
px; }" |
| 36 ".spacer { height: 1000px; }</style>" |
| 37 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); |
| 38 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 39 scroller->getScrollableArea()->scrollToYOffset(50); |
| 40 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 41 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 42 sticky->updateStickyPositionConstraints(); |
| 43 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 44 |
| 45 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 46 ASSERT_EQ(0.f, constraints.topOffset()); |
| 47 |
| 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))); |
| 50 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 51 } |
| 52 |
| 53 // Verifies that the sticky constraints are correctly computed. |
| 54 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) |
| 55 { |
| 56 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; }" |
| 58 "#scroller { width: 400px; height: 100px; overflow: auto; position: rela
tive; top: 200px; }" |
| 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 ASSERT_EQ(IntRect(25, 145, 200, 330), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); |
| 72 ASSERT_EQ(IntRect(25, 145, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 73 } |
| 74 |
| 75 // Verifies that the sticky constraints are correct when the sticky position con
tainer is also |
| 76 // the ancestor scroller. |
| 77 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) |
| 78 { |
| 79 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h
eight: 100px; }" |
| 80 "#scroller { height: 100px; width: 400px; overflow: auto; position: rela
tive; top: 200px; }" |
| 81 ".spacer { height: 1000px; }</style>" |
| 82 "<div id='scroller'><div id='sticky'></div><div class='spacer'></div></d
iv>"); |
| 83 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 84 scroller->getScrollableArea()->scrollToYOffset(50); |
| 85 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 86 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 87 sticky->updateStickyPositionConstraints(); |
| 88 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 89 |
| 90 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 91 ASSERT_EQ(IntRect(0, 0, 400, 1100), enclosingIntRect(getScrollContainerRelat
iveContainingBlockRect(constraints))); |
| 92 ASSERT_EQ(IntRect(0, 0, 100, 100), enclosingIntRect(getScrollContainerRelati
veStickyBoxRect(constraints))); |
| 93 } |
| 94 |
| 95 // Verifies that the sticky constraints are correct when the sticky position obj
ect has an |
| 96 // anonymous containing block. |
| 97 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) |
| 98 { |
| 99 setBodyInnerHTML("<style>#sticky { display: inline-block; position: sticky;
top: 0; width: 100px; height: 100px; }" |
| 100 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 101 "#scroller { height: 100px; overflow: auto; position: relative; top: 200
px; }" |
| 102 ".header { height: 50px; }" |
| 103 ".spacer { height: 1000px; }</style>" |
| 104 "<div id='scroller'><div id='container'><div class='header'></div><div i
d='sticky'></div></div><div class='spacer'></div></div>"); |
| 105 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 106 scroller->getScrollableArea()->scrollToYOffset(50); |
| 107 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 108 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 109 sticky->updateStickyPositionConstraints(); |
| 110 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 111 |
| 112 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 113 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(getScrollContainerRel
ativeContainingBlockRect(constraints))); |
| 114 ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(getScrollContainerRel
ativeStickyBoxRect(constraints))); |
| 115 } |
| 116 } // namespace blink |
| OLD | NEW |