| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 256 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 257 | 257 |
| 258 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); | 258 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); |
| 259 scroller->scrollBy(DoubleSize(0, 25), UserScroll); | 259 scroller->scrollBy(DoubleSize(0, 25), UserScroll); |
| 260 setHeight(relPos, 125); | 260 setHeight(relPos, 125); |
| 261 | 261 |
| 262 // When the scroller is position:relative, the anchor may be position:absolu
te. | 262 // When the scroller is position:relative, the anchor may be position:absolu
te. |
| 263 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 263 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Test that we descend into zero-height containers that have overflowing conten
t. |
| 267 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) |
| 268 { |
| 269 setBodyInnerHTML( |
| 270 "<style>" |
| 271 " body { height: 1000; }" |
| 272 " #outer { width: 300px; }" |
| 273 " #zeroheight { height: 0px; }" |
| 274 " #changer { height: 100px; background-color: red; }" |
| 275 " #bottom { margin-top: 600px; }" |
| 276 "</style>" |
| 277 "<div id='outer'>" |
| 278 " <div id='zeroheight'>" |
| 279 " <div id='changer'></div>" |
| 280 " <div id='bottom'>bottom</div>" |
| 281 " </div>" |
| 282 "</div>"); |
| 283 |
| 284 ScrollableArea* viewport = layoutViewport(); |
| 285 |
| 286 scrollLayoutViewport(DoubleSize(0, 200)); |
| 287 setHeight(document().getElementById("changer"), 200); |
| 288 |
| 289 EXPECT_EQ(300, viewport->scrollPosition().y()); |
| 290 EXPECT_EQ(document().getElementById("bottom")->layoutObject(), |
| 291 scrollAnchor(viewport).anchorObject()); |
| 292 } |
| 293 |
| 294 // Test that we descend into zero-height containers that have floating content. |
| 295 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithFloat) |
| 296 { |
| 297 setBodyInnerHTML( |
| 298 "<style>" |
| 299 " body { height: 1000; }" |
| 300 " #outer { width: 300px; }" |
| 301 " #outer:after { content: ' '; clear:both; display: table; }" |
| 302 " #float {" |
| 303 " float: left; background-color: #ccc;" |
| 304 " height: 500px; width: 100%;" |
| 305 " }" |
| 306 " #inner { height: 21px; background-color:#7f0; }" |
| 307 "</style>" |
| 308 "<div id='outer'>" |
| 309 " <div id='zeroheight'>" |
| 310 " <div id='float'>" |
| 311 " <div id='inner'></div>" |
| 312 " </div>" |
| 313 " </div>" |
| 314 "</div>"); |
| 315 |
| 316 EXPECT_EQ(0, toLayoutBox(document().getElementById("zeroheight")->layoutObje
ct())->size().height()); |
| 317 |
| 318 ScrollableArea* viewport = layoutViewport(); |
| 319 |
| 320 scrollLayoutViewport(DoubleSize(0, 200)); |
| 321 setHeight(document().getElementById("float"), 600); |
| 322 |
| 323 EXPECT_EQ(200, viewport->scrollPosition().y()); |
| 324 EXPECT_EQ(document().getElementById("float")->layoutObject(), |
| 325 scrollAnchor(viewport).anchorObject()); |
| 326 } |
| 327 |
| 266 class ScrollAnchorCornerTest : public ScrollAnchorTest { | 328 class ScrollAnchorCornerTest : public ScrollAnchorTest { |
| 267 protected: | 329 protected: |
| 268 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos
, DoubleSize expectedAdjustment) | 330 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos
, DoubleSize expectedAdjustment) |
| 269 { | 331 { |
| 270 ScrollableArea* viewport = layoutViewport(); | 332 ScrollableArea* viewport = layoutViewport(); |
| 271 Element* element = document().getElementById(id); | 333 Element* element = document().getElementById(id); |
| 272 | 334 |
| 273 viewport->setScrollPosition(startPos, UserScroll); | 335 viewport->setScrollPosition(startPos, UserScroll); |
| 274 element->setAttribute(HTMLNames::classAttr, "big"); | 336 element->setAttribute(HTMLNames::classAttr, "big"); |
| 275 update(); | 337 update(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 "<div id=c></div>" | 467 "<div id=c></div>" |
| 406 "<div id=d></div>"); | 468 "<div id=d></div>"); |
| 407 | 469 |
| 408 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 470 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; |
| 409 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | 471 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); |
| 410 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | 472 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); |
| 411 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | 473 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); |
| 412 } | 474 } |
| 413 | 475 |
| 414 } | 476 } |
| OLD | NEW |