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

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

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