Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp

Issue 2020103002: Fix sticky constraints and update sticky layer positions recursively after scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bugs with overflow scrollers in sticky position constraints, add unit tests, and test clipped b… Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 };
19
20 // Verifies that the sticky constraints are correctly computed.
21 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints)
22 {
23 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h eight: 100px; }"
24 "#container { box-sizing: border-box; position: relative; top: 100px; he ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
25 "#scroller { height: 100px; overflow: auto; position: relative; top: 200 px; }"
26 ".spacer { height: 1000px; }</style>"
27 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di v class='spacer'></div></div>");
28 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle mentId("scroller"));
29 scroller->getScrollableArea()->scrollToYOffset(50);
30 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
31 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme ntId("sticky"));
32 sticky->updateStickyPositionConstraints();
33 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
34
35 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla bleArea()->stickyConstraintsMap().get(sticky->layer());
36 ASSERT_EQ(0.f, constraints.topOffset());
37
38 // The coordinates of the constraint rects should all be with respect to the unscrolled scroller.
39 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollCon tainerRelativeContainingBlockRect()));
chrishtr 2016/06/06 22:18:40 Why 115 and not 15?
flackr 2016/06/09 17:13:33 Because it's 115 from the top of the scrollable ar
40 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(constraints.scrollCon tainerRelativeStickyBoxRect()));
41 }
42
43 // Verifies that the sticky constraints are correct when the sticky position con tainer is also
44 // the ancestor scroller.
45 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller)
46 {
47 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h eight: 100px; }"
48 "#scroller { height: 100px; width: 400px; overflow: auto; position: rela tive; top: 200px; }"
49 ".spacer { height: 1000px; }</style>"
50 "<div id='scroller'><div id='sticky'></div><div class='spacer'></div></d iv>");
51 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle mentId("scroller"));
52 scroller->getScrollableArea()->scrollToYOffset(50);
53 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
54 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme ntId("sticky"));
55 sticky->updateStickyPositionConstraints();
56 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
57
58 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla bleArea()->stickyConstraintsMap().get(sticky->layer());
59 ASSERT_EQ(IntRect(0, 0, 400, 1100), enclosingIntRect(constraints.scrollConta inerRelativeContainingBlockRect()));
chrishtr 2016/06/06 22:18:39 Why should it include the overflow (and hence heig
flackr 2016/06/09 17:13:33 Because the #sticky element is constrained to the
60 ASSERT_EQ(IntRect(0, 0, 100, 100), enclosingIntRect(constraints.scrollContai nerRelativeStickyBoxRect()));
61 }
62
63 // Verifies that the sticky constraints are correct when the sticky position obj ect has an
64 // anonymous containing block.
65 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer)
66 {
67 setBodyInnerHTML("<style>#sticky { display: inline-block; position: sticky; top: 0; width: 100px; height: 100px; }"
68 "#container { box-sizing: border-box; position: relative; top: 100px; he ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
chrishtr 2016/06/06 22:18:40 Where is the anonymous containing block in this ex
flackr 2016/06/09 17:13:33 Inside .container, .header is a block and #sticky
69 "#scroller { height: 100px; overflow: auto; position: relative; top: 200 px; }"
70 ".header { height: 50px; }"
71 ".spacer { height: 1000px; }</style>"
72 "<div id='scroller'><div id='container'><div class='header'></div><div i d='sticky'></div></div><div class='spacer'></div></div>");
73 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle mentId("scroller"));
74 scroller->getScrollableArea()->scrollToYOffset(50);
75 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
76 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme ntId("sticky"));
77 sticky->updateStickyPositionConstraints();
78 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
79
80 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla bleArea()->stickyConstraintsMap().get(sticky->layer());
81 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollCon tainerRelativeContainingBlockRect()));
82 ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(constraints.scrollCon tainerRelativeStickyBoxRect()));
83 }
84 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698