| 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 ScrollableArea* viewport = layoutViewport(); | 554 ScrollableArea* viewport = layoutViewport(); |
| 555 | 555 |
| 556 scrollLayoutViewport(DoubleSize(0, 200)); | 556 scrollLayoutViewport(DoubleSize(0, 200)); |
| 557 setHeight(document().getElementById("float"), 600); | 557 setHeight(document().getElementById("float"), 600); |
| 558 | 558 |
| 559 EXPECT_EQ(200, viewport->scrollPosition().y()); | 559 EXPECT_EQ(200, viewport->scrollPosition().y()); |
| 560 EXPECT_EQ(document().getElementById("float")->layoutObject(), | 560 EXPECT_EQ(document().getElementById("float")->layoutObject(), |
| 561 scrollAnchor(viewport).anchorObject()); | 561 scrollAnchor(viewport).anchorObject()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 // Test then an element and its children are not selected as the anchor when |
| 565 // it has the overflow-anchor property set to none. |
| 566 TEST_F(ScrollAnchorTest, OptOutElement) |
| 567 { |
| 568 setBodyInnerHTML( |
| 569 "<style>" |
| 570 " body { height: 1000px }" |
| 571 " .div {" |
| 572 " height: 100px; width: 100px;" |
| 573 " border: 1px solid gray; background-color: #afa;" |
| 574 " }" |
| 575 " #innerDiv {" |
| 576 " height: 50px; width: 50px;" |
| 577 " border: 1px solid gray; background-color: pink;" |
| 578 " }" |
| 579 "</style>" |
| 580 "<div id='changer'></div>" |
| 581 "<div class='div' id='firstDiv'><div id='innerDiv'></div></div>" |
| 582 "<div class='div' id='secondDiv'></div>"); |
| 583 |
| 584 ScrollableArea* viewport = layoutViewport(); |
| 585 scrollLayoutViewport(DoubleSize(0, 50)); |
| 586 |
| 587 // No opt-out. |
| 588 setHeight(document().getElementById("changer"), 100); |
| 589 EXPECT_EQ(150, viewport->scrollPosition().y()); |
| 590 EXPECT_EQ(document().getElementById("innerDiv")->layoutObject(), |
| 591 scrollAnchor(viewport).anchorObject()); |
| 592 |
| 593 // Clear anchor and opt-out element. |
| 594 scrollLayoutViewport(DoubleSize(0, 10)); |
| 595 document().getElementById("firstDiv")->setAttribute(HTMLNames::styleAttr, |
| 596 AtomicString("overflow-anchor: none")); |
| 597 update(); |
| 598 |
| 599 // Opted out element and it's children skipped. |
| 600 setHeight(document().getElementById("changer"), 200); |
| 601 EXPECT_EQ(260, viewport->scrollPosition().y()); |
| 602 EXPECT_EQ(document().getElementById("secondDiv")->layoutObject(), |
| 603 scrollAnchor(viewport).anchorObject()); |
| 604 } |
| 605 |
| 564 TEST_F(ScrollAnchorTest, OptOutBody) | 606 TEST_F(ScrollAnchorTest, OptOutBody) |
| 565 { | 607 { |
| 566 setBodyInnerHTML( | 608 setBodyInnerHTML( |
| 567 "<style>" | 609 "<style>" |
| 568 " body { height: 2000px; overflow-anchor: none; }" | 610 " body { height: 2000px; overflow-anchor: none; }" |
| 569 " #scroller { overflow: scroll; width: 500px; height: 300px; }" | 611 " #scroller { overflow: scroll; width: 500px; height: 300px; }" |
| 570 " .anchor {" | 612 " .anchor {" |
| 571 " position:relative; height: 100px; width: 150px;" | 613 " position:relative; height: 100px; width: 150px;" |
| 572 " background-color: #afa; border: 1px solid gray;" | 614 " background-color: #afa; border: 1px solid gray;" |
| 573 " }" | 615 " }" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 "<div id=c></div>" | 824 "<div id=c></div>" |
| 783 "<div id=d></div>"); | 825 "<div id=d></div>"); |
| 784 | 826 |
| 785 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 827 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; |
| 786 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | 828 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); |
| 787 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | 829 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); |
| 788 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | 830 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); |
| 789 } | 831 } |
| 790 | 832 |
| 791 } | 833 } |
| OLD | NEW |