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

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

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: nits and rebase Created 4 years, 2 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
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
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->scrollToOffset(
46 DoubleSize(scrollableArea->adjustedScrollOffset().width(), 50));
47 ASSERT_EQ(50.0, scrollableArea->adjustedScrollOffset().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 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
81 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); 82 scrollableArea->scrollToOffset(
83 DoubleSize(scrollableArea->adjustedScrollOffset().width(), 50));
84 ASSERT_EQ(50.0, scrollableArea->adjustedScrollOffset().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 scrollableArea->stickyConstraintsMap().get(sticky->layer());
89 sticky->layer());
90 ASSERT_EQ(0.f, constraints.topOffset()); 92 ASSERT_EQ(0.f, constraints.topOffset());
91 93
92 // The coordinates of the constraint rects should all be with respect to the u nscrolled scroller. 94 // The coordinates of the constraint rects should all be with respect to the u nscrolled scroller.
93 ASSERT_EQ(IntRect(15, 115, 170, 370), 95 ASSERT_EQ(IntRect(15, 115, 170, 370),
94 enclosingIntRect( 96 enclosingIntRect(
95 getScrollContainerRelativeContainingBlockRect(constraints))); 97 getScrollContainerRelativeContainingBlockRect(constraints)));
96 ASSERT_EQ( 98 ASSERT_EQ(
97 IntRect(15, 115, 100, 100), 99 IntRect(15, 115, 100, 100),
98 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 100 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
99 } 101 }
100 102
101 // Verifies that the sticky constraints are correctly computed. 103 // Verifies that the sticky constraints are correctly computed.
102 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) { 104 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) {
103 setBodyInnerHTML( 105 setBodyInnerHTML(
104 "<style>#sticky { position: sticky; margin-top: 10%; top: 0; width: " 106 "<style>#sticky { position: sticky; margin-top: 10%; top: 0; width: "
105 "100px; height: 100px; }" 107 "100px; height: 100px; }"
106 "#container { box-sizing: border-box; position: relative; top: 100px; " 108 "#container { box-sizing: border-box; position: relative; top: 100px; "
107 "height: 400px; width: 250px; padding: 5%; border: 5px solid black; }" 109 "height: 400px; width: 250px; padding: 5%; border: 5px solid black; }"
108 "#scroller { width: 400px; height: 100px; overflow: auto; position: " 110 "#scroller { width: 400px; height: 100px; overflow: auto; position: "
109 "relative; top: 200px; }" 111 "relative; top: 200px; }"
110 ".spacer { height: 1000px; }</style>" 112 ".spacer { height: 1000px; }</style>"
111 "<div id='scroller'><div id='container'><div " 113 "<div id='scroller'><div id='container'><div "
112 "id='sticky'></div></div><div class='spacer'></div></div>"); 114 "id='sticky'></div></div><div class='spacer'></div></div>");
113 LayoutBoxModelObject* scroller = 115 LayoutBoxModelObject* scroller =
114 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 116 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
115 scroller->getScrollableArea()->scrollToYOffset(50); 117 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
116 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); 118 scrollableArea->scrollToOffset(
119 DoubleSize(scrollableArea->adjustedScrollOffset().width(), 50));
120 ASSERT_EQ(50.0, scrollableArea->adjustedScrollOffset().height());
117 LayoutBoxModelObject* sticky = 121 LayoutBoxModelObject* sticky =
118 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); 122 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
119 sticky->updateStickyPositionConstraints(); 123 sticky->updateStickyPositionConstraints();
120 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); 124 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
121 125
122 const StickyPositionScrollingConstraints& constraints = 126 const StickyPositionScrollingConstraints& constraints =
123 scroller->getScrollableArea()->stickyConstraintsMap().get( 127 scrollableArea->stickyConstraintsMap().get(sticky->layer());
124 sticky->layer());
125 ASSERT_EQ(0.f, constraints.topOffset()); 128 ASSERT_EQ(0.f, constraints.topOffset());
126 129
127 ASSERT_EQ(IntRect(25, 145, 200, 330), 130 ASSERT_EQ(IntRect(25, 145, 200, 330),
128 enclosingIntRect( 131 enclosingIntRect(
129 getScrollContainerRelativeContainingBlockRect(constraints))); 132 getScrollContainerRelativeContainingBlockRect(constraints)));
130 ASSERT_EQ( 133 ASSERT_EQ(
131 IntRect(25, 145, 100, 100), 134 IntRect(25, 145, 100, 100),
132 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 135 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
133 } 136 }
134 137
135 // Verifies that the sticky constraints are correct when the sticky position con tainer is also 138 // Verifies that the sticky constraints are correct when the sticky position con tainer is also
136 // the ancestor scroller. 139 // the ancestor scroller.
137 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { 140 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) {
138 setBodyInnerHTML( 141 setBodyInnerHTML(
139 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " 142 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; "
140 "}" 143 "}"
141 "#scroller { height: 100px; width: 400px; overflow: auto; position: " 144 "#scroller { height: 100px; width: 400px; overflow: auto; position: "
142 "relative; top: 200px; }" 145 "relative; top: 200px; }"
143 ".spacer { height: 1000px; }</style>" 146 ".spacer { height: 1000px; }</style>"
144 "<div id='scroller'><div id='sticky'></div><div " 147 "<div id='scroller'><div id='sticky'></div><div "
145 "class='spacer'></div></div>"); 148 "class='spacer'></div></div>");
146 LayoutBoxModelObject* scroller = 149 LayoutBoxModelObject* scroller =
147 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 150 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
148 scroller->getScrollableArea()->scrollToYOffset(50); 151 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
149 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); 152 scrollableArea->scrollToOffset(
153 DoubleSize(scrollableArea->adjustedScrollOffset().width(), 50));
154 ASSERT_EQ(50.0, scrollableArea->adjustedScrollOffset().height());
150 LayoutBoxModelObject* sticky = 155 LayoutBoxModelObject* sticky =
151 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); 156 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
152 sticky->updateStickyPositionConstraints(); 157 sticky->updateStickyPositionConstraints();
153 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); 158 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
154 159
155 const StickyPositionScrollingConstraints& constraints = 160 const StickyPositionScrollingConstraints& constraints =
156 scroller->getScrollableArea()->stickyConstraintsMap().get( 161 scrollableArea->stickyConstraintsMap().get(sticky->layer());
157 sticky->layer());
158 ASSERT_EQ(IntRect(0, 0, 400, 1100), 162 ASSERT_EQ(IntRect(0, 0, 400, 1100),
159 enclosingIntRect( 163 enclosingIntRect(
160 getScrollContainerRelativeContainingBlockRect(constraints))); 164 getScrollContainerRelativeContainingBlockRect(constraints)));
161 ASSERT_EQ( 165 ASSERT_EQ(
162 IntRect(0, 0, 100, 100), 166 IntRect(0, 0, 100, 100),
163 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 167 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
164 } 168 }
165 169
166 // Verifies that the sticky constraints are correct when the sticky position obj ect has an 170 // Verifies that the sticky constraints are correct when the sticky position obj ect has an
167 // anonymous containing block. 171 // anonymous containing block.
168 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) { 172 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) {
169 setBodyInnerHTML( 173 setBodyInnerHTML(
170 "<style>#sticky { display: inline-block; position: sticky; top: 0; " 174 "<style>#sticky { display: inline-block; position: sticky; top: 0; "
171 "width: 100px; height: 100px; }" 175 "width: 100px; height: 100px; }"
172 "#container { box-sizing: border-box; position: relative; top: 100px; " 176 "#container { box-sizing: border-box; position: relative; top: 100px; "
173 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" 177 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
174 "#scroller { height: 100px; overflow: auto; position: relative; top: " 178 "#scroller { height: 100px; overflow: auto; position: relative; top: "
175 "200px; }" 179 "200px; }"
176 ".header { height: 50px; }" 180 ".header { height: 50px; }"
177 ".spacer { height: 1000px; }</style>" 181 ".spacer { height: 1000px; }</style>"
178 "<div id='scroller'><div id='container'><div class='header'></div><div " 182 "<div id='scroller'><div id='container'><div class='header'></div><div "
179 "id='sticky'></div></div><div class='spacer'></div></div>"); 183 "id='sticky'></div></div><div class='spacer'></div></div>");
180 LayoutBoxModelObject* scroller = 184 LayoutBoxModelObject* scroller =
181 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 185 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
182 scroller->getScrollableArea()->scrollToYOffset(50); 186 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
183 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); 187 scrollableArea->scrollToOffset(
188 DoubleSize(scrollableArea->adjustedScrollOffset().width(), 50));
189 ASSERT_EQ(50.0, scrollableArea->adjustedScrollOffset().height());
184 LayoutBoxModelObject* sticky = 190 LayoutBoxModelObject* sticky =
185 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); 191 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
186 sticky->updateStickyPositionConstraints(); 192 sticky->updateStickyPositionConstraints();
187 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); 193 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
188 194
189 const StickyPositionScrollingConstraints& constraints = 195 const StickyPositionScrollingConstraints& constraints =
190 scroller->getScrollableArea()->stickyConstraintsMap().get( 196 scrollableArea->stickyConstraintsMap().get(sticky->layer());
191 sticky->layer());
192 ASSERT_EQ(IntRect(15, 115, 170, 370), 197 ASSERT_EQ(IntRect(15, 115, 170, 370),
193 enclosingIntRect( 198 enclosingIntRect(
194 getScrollContainerRelativeContainingBlockRect(constraints))); 199 getScrollContainerRelativeContainingBlockRect(constraints)));
195 ASSERT_EQ( 200 ASSERT_EQ(
196 IntRect(15, 165, 100, 100), 201 IntRect(15, 165, 100, 100),
197 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 202 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
198 } 203 }
199 } // namespace blink 204 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.cpp ('k') | third_party/WebKit/Source/core/layout/ScrollEnums.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698