| 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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 EXPECT_EQ(100, scroller->scrollPosition().y()); | 635 EXPECT_EQ(100, scroller->scrollPosition().y()); |
| 636 EXPECT_EQ(nullptr, scrollAnchor(scroller).anchorObject()); | 636 EXPECT_EQ(nullptr, scrollAnchor(scroller).anchorObject()); |
| 637 // Scroll anchoring should apply within main frame. | 637 // Scroll anchoring should apply within main frame. |
| 638 EXPECT_EQ(250, viewport->scrollPosition().y()); | 638 EXPECT_EQ(250, viewport->scrollPosition().y()); |
| 639 EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(), | 639 EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(), |
| 640 scrollAnchor(viewport).anchorObject()); | 640 scrollAnchor(viewport).anchorObject()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 class ScrollAnchorCornerTest : public ScrollAnchorTest { | 643 class ScrollAnchorCornerTest : public ScrollAnchorTest { |
| 644 protected: | 644 protected: |
| 645 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos
, DoubleSize expectedAdjustment) | 645 void checkCorner(Corner corner, DoublePoint startPos, DoubleSize expectedAdj
ustment) |
| 646 { | 646 { |
| 647 ScrollableArea* viewport = layoutViewport(); | 647 ScrollableArea* viewport = layoutViewport(); |
| 648 Element* element = document().getElementById(id); | 648 Element* element = document().getElementById("changer"); |
| 649 | 649 |
| 650 viewport->setScrollPosition(startPos, UserScroll); | 650 viewport->setScrollPosition(startPos, UserScroll); |
| 651 element->setAttribute(HTMLNames::classAttr, "big"); | 651 element->setAttribute(HTMLNames::classAttr, "change"); |
| 652 update(); | 652 update(); |
| 653 | 653 |
| 654 DoublePoint endPos = startPos; | 654 DoublePoint endPos = startPos; |
| 655 endPos.move(expectedAdjustment); | 655 endPos.move(expectedAdjustment); |
| 656 | 656 |
| 657 EXPECT_EQ(endPos, viewport->scrollPositionDouble()); | 657 EXPECT_EQ(endPos, viewport->scrollPositionDouble()); |
| 658 EXPECT_EQ(element->layoutObject(), scrollAnchor(viewport).anchorObject()
); | 658 EXPECT_EQ(document().getElementById("a")->layoutObject(), |
| 659 scrollAnchor(viewport).anchorObject()); |
| 659 EXPECT_EQ(corner, scrollAnchor(viewport).corner()); | 660 EXPECT_EQ(corner, scrollAnchor(viewport).corner()); |
| 660 | 661 |
| 661 element->removeAttribute(HTMLNames::classAttr); | 662 element->removeAttribute(HTMLNames::classAttr); |
| 662 update(); | 663 update(); |
| 663 } | 664 } |
| 664 }; | 665 }; |
| 665 | 666 |
| 666 TEST_F(ScrollAnchorCornerTest, Corners) | 667 // Verify that we anchor to the top left corner of an element for LTR. |
| 668 TEST_F(ScrollAnchorCornerTest, CornersLTR) |
| 667 { | 669 { |
| 668 setBodyInnerHTML( | 670 setBodyInnerHTML( |
| 669 "<style>" | 671 "<style>" |
| 670 " body {" | 672 " body { position: relative; width: 1220px; height: 920px; }" |
| 671 " position: absolute; border: 10px solid #ccc;" | 673 " #a { width: 400px; height: 300px; }" |
| 672 " width: 1220px; height: 920px;" | 674 " .change { height: 100px; }" |
| 673 " }" | |
| 674 " #a, #b, #c, #d {" | |
| 675 " position: absolute; background-color: #ace;" | |
| 676 " width: 400px; height: 300px;" | |
| 677 " }" | |
| 678 " #a, #b { top: 0; }" | |
| 679 " #a, #c { left: 0; }" | |
| 680 " #b, #d { right: 0; }" | |
| 681 " #c, #d { bottom: 0; }" | |
| 682 " .big { width: 800px !important; height: 600px !important }" | |
| 683 "</style>" | 675 "</style>" |
| 684 "<div id=a></div>" | 676 "<div id='changer'></div>" |
| 685 "<div id=b></div>" | 677 "<div id='a'></div>"); |
| 686 "<div id=c></div>" | |
| 687 "<div id=d></div>"); | |
| 688 | 678 |
| 689 checkCorner("a", Corner::TopLeft, DoublePoint(20, 20), DoubleSize(0, 0)); | 679 checkCorner(Corner::TopLeft, DoublePoint(20, 20), DoubleSize(0, 100)); |
| 690 checkCorner("b", Corner::TopLeft, DoublePoint(420, 20), DoubleSize(-400, 0)
); | |
| 691 checkCorner("c", Corner::TopLeft, DoublePoint(20, 320), DoubleSize(0, -300)
); | |
| 692 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400, -3
00)); | |
| 693 } | 680 } |
| 694 | 681 |
| 682 // Verify that we anchor to the top left corner of an anchor element for |
| 683 // vertical-lr writing mode. |
| 695 TEST_F(ScrollAnchorCornerTest, CornersVerticalLR) | 684 TEST_F(ScrollAnchorCornerTest, CornersVerticalLR) |
| 696 { | 685 { |
| 697 setBodyInnerHTML( | 686 setBodyInnerHTML( |
| 698 "<style>" | 687 "<style>" |
| 699 " html {" | 688 " html { writing-mode: vertical-lr; }" |
| 700 " writing-mode: vertical-lr;" | 689 " body { position: relative; width: 1220px; height: 920px; }" |
| 701 " }" | 690 " #a { width: 400px; height: 300px; }" |
| 702 " body {" | 691 " .change { width: 100px; }" |
| 703 " position: absolute; border: 10px solid #ccc;" | |
| 704 " width: 1220px; height: 920px;" | |
| 705 " }" | |
| 706 " #a, #b, #c, #d {" | |
| 707 " position: absolute; background-color: #ace;" | |
| 708 " width: 400px; height: 300px;" | |
| 709 " }" | |
| 710 " #a, #b { top: 0; }" | |
| 711 " #a, #c { left: 0; }" | |
| 712 " #b, #d { right: 0; }" | |
| 713 " #c, #d { bottom: 0; }" | |
| 714 " .big { width: 800px !important; height: 600px !important }" | |
| 715 "</style>" | 692 "</style>" |
| 716 "<div id=a></div>" | 693 "<div id='changer'></div>" |
| 717 "<div id=b></div>" | 694 "<div id='a'></div>"); |
| 718 "<div id=c></div>" | |
| 719 "<div id=d></div>"); | |
| 720 | 695 |
| 721 checkCorner("a", Corner::TopLeft, DoublePoint(20, 20), DoubleSize(0, 0)); | 696 checkCorner(Corner::TopLeft, DoublePoint(20, 20), DoubleSize(100, 0)); |
| 722 checkCorner("b", Corner::TopLeft, DoublePoint(420, 20), DoubleSize(-400, 0)
); | |
| 723 checkCorner("c", Corner::TopLeft, DoublePoint(20, 320), DoubleSize(0, -300)
); | |
| 724 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400, -3
00)); | |
| 725 } | 697 } |
| 726 | 698 |
| 699 // Verify that we anchor to the top right corner of an anchor element for RTL. |
| 727 TEST_F(ScrollAnchorCornerTest, CornersRTL) | 700 TEST_F(ScrollAnchorCornerTest, CornersRTL) |
| 728 { | 701 { |
| 729 setBodyInnerHTML( | 702 setBodyInnerHTML( |
| 730 "<style>" | 703 "<style>" |
| 731 " html {" | 704 " html { direction: rtl; }" |
| 732 " direction: rtl;" | 705 " body { position: relative; width: 1220px; height: 920px; }" |
| 733 " }" | 706 " #a { width: 400px; height: 300px; }" |
| 734 " body {" | 707 " .change { height: 100px; }" |
| 735 " position: absolute; border: 10px solid #ccc;" | |
| 736 " width: 1220px; height: 920px;" | |
| 737 " }" | |
| 738 " #a, #b, #c, #d {" | |
| 739 " position: absolute; background-color: #ace;" | |
| 740 " width: 400px; height: 300px;" | |
| 741 " }" | |
| 742 " #a, #b { top: 0; }" | |
| 743 " #a, #c { left: 0; }" | |
| 744 " #b, #d { right: 0; }" | |
| 745 " #c, #d { bottom: 0; }" | |
| 746 " .big { width: 800px !important; height: 600px !important }" | |
| 747 "</style>" | 708 "</style>" |
| 748 "<div id=a></div>" | 709 "<div id='changer'></div>" |
| 749 "<div id=b></div>" | 710 "<div id='a'></div>"); |
| 750 "<div id=c></div>" | |
| 751 "<div id=d></div>"); | |
| 752 | 711 |
| 753 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 712 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 100)); |
| 754 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | |
| 755 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | |
| 756 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | |
| 757 } | 713 } |
| 758 | 714 |
| 715 // Verify that we anchor to the top right corner of an anchor element for |
| 716 // vertical-lr writing mode. |
| 759 TEST_F(ScrollAnchorCornerTest, CornersVerticalRL) | 717 TEST_F(ScrollAnchorCornerTest, CornersVerticalRL) |
| 760 { | 718 { |
| 761 setBodyInnerHTML( | 719 setBodyInnerHTML( |
| 762 "<style>" | 720 "<style>" |
| 763 " html {" | 721 " html { writing-mode: vertical-rl; }" |
| 764 " writing-mode: vertical-rl;" | 722 " body { position: relative; width: 1220px; height: 920px; }" |
| 765 " }" | 723 " #a { width: 400px; height: 300px; }" |
| 766 " body {" | 724 " .change { width: 100px; }" |
| 767 " position: absolute; border: 10px solid #ccc;" | |
| 768 " width: 1220px; height: 920px;" | |
| 769 " }" | |
| 770 " #a, #b, #c, #d {" | |
| 771 " position: absolute; background-color: #ace;" | |
| 772 " width: 400px; height: 300px;" | |
| 773 " }" | |
| 774 " #a, #b { top: 0; }" | |
| 775 " #a, #c { left: 0; }" | |
| 776 " #b, #d { right: 0; }" | |
| 777 " #c, #d { bottom: 0; }" | |
| 778 " .big { width: 800px !important; height: 600px !important }" | |
| 779 "</style>" | 725 "</style>" |
| 780 "<div id=a></div>" | 726 "<div id='changer'></div>" |
| 781 "<div id=b></div>" | 727 "<div id='a'></div>"); |
| 782 "<div id=c></div>" | |
| 783 "<div id=d></div>"); | |
| 784 | 728 |
| 785 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 729 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(-100, 0)); |
| 786 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | |
| 787 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | |
| 788 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | |
| 789 } | 730 } |
| 790 | 731 |
| 791 } | 732 } |
| OLD | NEW |