| 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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 633 |
| 634 // Scroll anchoring should not apply within #scroller. | 634 // Scroll anchoring should not apply within #scroller. |
| 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 TEST_F(ScrollAnchorTest, ExcludeAnchoringIfAncestorChangesPaddingOrMargin) |
| 644 { |
| 645 setBodyInnerHTML( |
| 646 "<style> body { height: 1000px; margin: 0px; } div { height: 100px } </s
tyle>" |
| 647 "<div id='block1'>abc</div>" |
| 648 "<div id='block2'>def</div>"); |
| 649 |
| 650 ScrollableArea* viewport = layoutViewport(); |
| 651 scrollLayoutViewport(DoubleSize(0, 150)); |
| 652 |
| 653 // Padding change on anchor's ancestor shouldn't trigger anchoring. |
| 654 document().body()->setAttribute(HTMLNames::styleAttr, |
| 655 AtomicString(String::format("padding: %dpx", 10))); |
| 656 update(); |
| 657 EXPECT_EQ(150, viewport->scrollPosition().y()); |
| 658 |
| 659 // Margin change on anchor's ancestor shouldn't trigger anchoring. |
| 660 document().body()->setAttribute(HTMLNames::styleAttr, |
| 661 AtomicString(String::format("margin: %dpx", 10))); |
| 662 update(); |
| 663 EXPECT_EQ(150, viewport->scrollPosition().y()); |
| 664 |
| 665 // Padding change on other elements should trigger anchoring. |
| 666 document().getElementById("block1")->setAttribute(HTMLNames::styleAttr, |
| 667 AtomicString(String::format("padding: %dpx", 10))); |
| 668 update(); |
| 669 EXPECT_EQ(170, viewport->scrollPosition().y()); |
| 670 } |
| 671 |
| 643 class ScrollAnchorCornerTest : public ScrollAnchorTest { | 672 class ScrollAnchorCornerTest : public ScrollAnchorTest { |
| 644 protected: | 673 protected: |
| 645 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos
, DoubleSize expectedAdjustment) | 674 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos
, DoubleSize expectedAdjustment) |
| 646 { | 675 { |
| 647 ScrollableArea* viewport = layoutViewport(); | 676 ScrollableArea* viewport = layoutViewport(); |
| 648 Element* element = document().getElementById(id); | 677 Element* element = document().getElementById(id); |
| 649 | 678 |
| 650 viewport->setScrollPosition(startPos, UserScroll); | 679 viewport->setScrollPosition(startPos, UserScroll); |
| 651 element->setAttribute(HTMLNames::classAttr, "big"); | 680 element->setAttribute(HTMLNames::classAttr, "big"); |
| 652 update(); | 681 update(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 "<div id=c></div>" | 811 "<div id=c></div>" |
| 783 "<div id=d></div>"); | 812 "<div id=d></div>"); |
| 784 | 813 |
| 785 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; | 814 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0))
; |
| 786 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); | 815 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0
)); |
| 787 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); | 816 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30
0)); |
| 788 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); | 817 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, -
300)); |
| 789 } | 818 } |
| 790 | 819 |
| 791 } | 820 } |
| OLD | NEW |