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/dom/ClientRect.h" | 7 #include "core/dom/ClientRect.h" |
8 #include "core/frame/VisualViewport.h" | 8 #include "core/frame/VisualViewport.h" |
9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/LayoutTestHelper.h" | 10 #include "core/layout/LayoutTestHelper.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 ScrollableArea* viewport = layoutViewport(); | 495 ScrollableArea* viewport = layoutViewport(); |
496 | 496 |
497 scrollLayoutViewport(DoubleSize(0, 200)); | 497 scrollLayoutViewport(DoubleSize(0, 200)); |
498 setHeight(document().getElementById("a"), 100); | 498 setHeight(document().getElementById("a"), 100); |
499 | 499 |
500 EXPECT_EQ(200, viewport->scrollPosition().y()); | 500 EXPECT_EQ(200, viewport->scrollPosition().y()); |
501 EXPECT_EQ(document().getElementById("float")->layoutObject(), | 501 EXPECT_EQ(document().getElementById("float")->layoutObject(), |
502 scrollAnchor(viewport).anchorObject()); | 502 scrollAnchor(viewport).anchorObject()); |
503 } | 503 } |
504 | 504 |
| 505 // This test verifies that scroll anchoring is disabled when any element within |
| 506 // the main scroller changes its in-flow state. |
| 507 TEST_F(ScrollAnchorTest, ChangeInFlowStateDisablesAnchoringForMainScroller) |
| 508 { |
| 509 setBodyInnerHTML( |
| 510 "<style>" |
| 511 " body { height: 1000px; }" |
| 512 " #header { background-color: #F5B335; height: 50px; width: 100%; }" |
| 513 " #content { background-color: #D3D3D3; height: 200px; }" |
| 514 "</style>" |
| 515 "<div id='header'></div>" |
| 516 "<div id='content'></div>"); |
| 517 |
| 518 ScrollableArea* viewport = layoutViewport(); |
| 519 scrollLayoutViewport(DoubleSize(0, 200)); |
| 520 |
| 521 document().getElementById("header")->setAttribute( |
| 522 HTMLNames::styleAttr, "position: fixed;"); |
| 523 update(); |
| 524 |
| 525 EXPECT_EQ(200, viewport->scrollPosition().y()); |
| 526 } |
| 527 |
| 528 // This test verifies that scroll anchoring is disabled when any element within |
| 529 // a scrolling div changes its in-flow state. |
| 530 TEST_F(ScrollAnchorTest, ChangeInFlowStateDisablesAnchoringForScrollingDiv) |
| 531 { |
| 532 setBodyInnerHTML( |
| 533 "<style>" |
| 534 " #container { position: relative; width: 500px; }" |
| 535 " #scroller { height: 200px; overflow: scroll; }" |
| 536 " #changer { background-color: #F5B335; height: 50px; width: 100%; }" |
| 537 " #anchor { background-color: #D3D3D3; height: 300px; }" |
| 538 "</style>" |
| 539 "<div id='container'>" |
| 540 " <div id='scroller'>" |
| 541 " <div id='changer'></div>" |
| 542 " <div id='anchor'></div>" |
| 543 " </div>" |
| 544 "</div>"); |
| 545 |
| 546 ScrollableArea* scroller = scrollerForElement(document().getElementById("scr
oller")); |
| 547 document().getElementById("scroller")->setScrollTop(100); |
| 548 |
| 549 document().getElementById("changer")->setAttribute( |
| 550 HTMLNames::styleAttr, "position: absolute;"); |
| 551 update(); |
| 552 |
| 553 EXPECT_EQ(100, scroller->scrollPosition().y()); |
| 554 } |
| 555 |
505 TEST_F(ScrollAnchorTest, FlexboxDelayedClampingAlsoDelaysAdjustment) | 556 TEST_F(ScrollAnchorTest, FlexboxDelayedClampingAlsoDelaysAdjustment) |
506 { | 557 { |
507 setBodyInnerHTML( | 558 setBodyInnerHTML( |
508 "<style>" | 559 "<style>" |
509 " html { overflow: hidden; }" | 560 " html { overflow: hidden; }" |
510 " body {" | 561 " body {" |
511 " position: absolute; display: flex;" | 562 " position: absolute; display: flex;" |
512 " top: 0; bottom: 0; margin: 0;" | 563 " top: 0; bottom: 0; margin: 0;" |
513 " }" | 564 " }" |
514 " #scroller { overflow: auto; }" | 565 " #scroller { overflow: auto; }" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 " #a { width: 400px; height: 300px; }" | 880 " #a { width: 400px; height: 300px; }" |
830 " .change { width: 100px; }" | 881 " .change { width: 100px; }" |
831 "</style>" | 882 "</style>" |
832 "<div id='changer'></div>" | 883 "<div id='changer'></div>" |
833 "<div id='a'></div>"); | 884 "<div id='a'></div>"); |
834 | 885 |
835 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(-100, 0)); | 886 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(-100, 0)); |
836 } | 887 } |
837 | 888 |
838 } | 889 } |
OLD | NEW |