OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ScrollAnchor.h" | 5 #include "core/layout/ScrollAnchor.h" |
6 | 6 |
7 #include "core/layout/LayoutBox.h" | 7 #include "core/layout/LayoutBox.h" |
8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
9 #include "core/paint/PaintLayerScrollableArea.h" | 9 #include "core/paint/PaintLayerScrollableArea.h" |
10 #include "platform/testing/HistogramTester.h" | 10 #include "platform/testing/HistogramTester.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 "<div id=f>fixed</div>" | 218 "<div id=f>fixed</div>" |
219 "<div id=c>content</div>"); | 219 "<div id=c>content</div>"); |
220 | 220 |
221 scrollLayoutViewport(DoubleSize(0, 50)); | 221 scrollLayoutViewport(DoubleSize(0, 50)); |
222 | 222 |
223 setHeight(document().body(), 1100); | 223 setHeight(document().body(), 1100); |
224 EXPECT_EQ(document().getElementById("c")->layoutObject(), | 224 EXPECT_EQ(document().getElementById("c")->layoutObject(), |
225 scrollAnchor(layoutViewport()).anchorObject()); | 225 scrollAnchor(layoutViewport()).anchorObject()); |
226 } | 226 } |
227 | 227 |
228 TEST_F(ScrollAnchorTest, ExcludeAbsolutePosition) | 228 // This test verifies that position:absolute elements that stick to the viewport |
| 229 // are not selected as anchors. |
| 230 TEST_F(ScrollAnchorTest, ExcludeAbsolutePositionThatSticksToViewport) |
229 { | 231 { |
230 setBodyInnerHTML( | 232 setBodyInnerHTML( |
231 "<style>" | 233 "<style>" |
232 " body { margin: 0; }" | 234 " body { margin: 0; }" |
233 " #scroller { overflow: scroll; width: 500px; height: 400px; }" | 235 " #scroller { overflow: scroll; width: 500px; height: 400px; }" |
234 " #space { height: 1000px; }" | 236 " #space { height: 1000px; }" |
235 " #abs {" | 237 " #abs {" |
236 " position: absolute; background-color: red;" | 238 " position: absolute; background-color: red;" |
237 " left: 200px; top: 100px; width: 100px; height: 100px;" | 239 " width: 100px; height: 100px;" |
238 " }" | 240 " }" |
239 " #rel {" | 241 " #rel {" |
240 " position: relative; background-color: green;" | 242 " position: relative; background-color: green;" |
241 " left: 50px; top: 100px; width: 100px; height: 75px;" | 243 " left: 50px; top: 100px; width: 100px; height: 75px;" |
242 " }" | 244 " }" |
243 "</style>" | 245 "</style>" |
244 "<div id='scroller'><div id='space'>" | 246 "<div id='scroller'><div id='space'>" |
245 " <div id='abs'></div>" | 247 " <div id='abs'></div>" |
246 " <div id='rel'></div>" | 248 " <div id='rel'></div>" |
247 "</div></div>"); | 249 "</div></div>"); |
(...skipping 10 matching lines...) Expand all Loading... |
258 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 260 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
259 | 261 |
260 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); | 262 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); |
261 scroller->scrollBy(DoubleSize(0, 25), UserScroll); | 263 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
262 setHeight(relPos, 125); | 264 setHeight(relPos, 125); |
263 | 265 |
264 // When the scroller is position:relative, the anchor may be position:absolu
te. | 266 // When the scroller is position:relative, the anchor may be position:absolu
te. |
265 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 267 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
266 } | 268 } |
267 | 269 |
| 270 // This test verifies that position:absolute elements with top/right/bottom/left |
| 271 // set are not selected as anchors. |
| 272 TEST_F(ScrollAnchorTest, ExcludeOffsettedAbsolutePosition) |
| 273 { |
| 274 setBodyInnerHTML( |
| 275 "<style>" |
| 276 " body { margin: 0; }" |
| 277 " #scroller { overflow: scroll; width: 500px; height: 400px; position
:relative; }" |
| 278 " #space { height: 1000px; }" |
| 279 " #abs {" |
| 280 " position: absolute; background-color: red;" |
| 281 " width: 100px; height: 100px;" |
| 282 " }" |
| 283 " #rel {" |
| 284 " position: relative; background-color: green;" |
| 285 " left: 50px; top: 100px; width: 100px; height: 75px;" |
| 286 " }" |
| 287 " .top { top: 10px }" |
| 288 " .left { left: 10px }" |
| 289 " .right { right: 10px }" |
| 290 " .bottom { bottom: 10px }" |
| 291 "</style>" |
| 292 "<div id='scroller'><div id='space'>" |
| 293 " <div id='abs'></div>" |
| 294 " <div id='rel'></div>" |
| 295 "</div></div>"); |
| 296 |
| 297 Element* scrollerElement = document().getElementById("scroller"); |
| 298 ScrollableArea* scroller = scrollerForElement(scrollerElement); |
| 299 Element* relPos = document().getElementById("rel"); |
| 300 Element* absPos = document().getElementById("abs"); |
| 301 |
| 302 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 303 setHeight(relPos, 100); |
| 304 // Pick absolute anchor. |
| 305 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 306 |
| 307 absPos->setAttribute(HTMLNames::classAttr, "top"); |
| 308 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 309 setHeight(relPos, 125); |
| 310 // Don't pick absolute anchor since top is set. |
| 311 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 312 |
| 313 absPos->removeAttribute(HTMLNames::classAttr); |
| 314 absPos->setAttribute(HTMLNames::classAttr, "right"); |
| 315 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 316 setHeight(relPos, 150); |
| 317 // Don't pick absolute anchor since right is set. |
| 318 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 319 |
| 320 absPos->removeAttribute(HTMLNames::classAttr); |
| 321 absPos->setAttribute(HTMLNames::classAttr, "bottom"); |
| 322 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 323 setHeight(relPos, 175); |
| 324 // Don't pick absolute anchor since bottom is set. |
| 325 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 326 |
| 327 absPos->removeAttribute(HTMLNames::classAttr); |
| 328 absPos->setAttribute(HTMLNames::classAttr, "left"); |
| 329 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 330 setHeight(relPos, 200); |
| 331 // Don't pick absolute anchor since left is set. |
| 332 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 333 } |
| 334 |
268 // Test that we descend into zero-height containers that have overflowing conten
t. | 335 // Test that we descend into zero-height containers that have overflowing conten
t. |
269 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) | 336 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) |
270 { | 337 { |
271 setBodyInnerHTML( | 338 setBodyInnerHTML( |
272 "<style>" | 339 "<style>" |
273 " body { height: 1000; }" | 340 " body { height: 1000; }" |
274 " #outer { width: 300px; }" | 341 " #outer { width: 300px; }" |
275 " #zeroheight { height: 0px; }" | 342 " #zeroheight { height: 0px; }" |
276 " #changer { height: 100px; background-color: red; }" | 343 " #changer { height: 100px; background-color: red; }" |
277 " #bottom { margin-top: 600px; }" | 344 " #bottom { margin-top: 600px; }" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 "<div id=c></div>" | 536 "<div id=c></div>" |
470 "<div id=d></div>"); | 537 "<div id=d></div>"); |
471 | 538 |
472 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 539 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; |
473 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | 540 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); |
474 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | 541 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); |
475 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | 542 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); |
476 } | 543 } |
477 | 544 |
478 } | 545 } |
OLD | NEW |