| 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" |
| 11 #include "core/page/PrintContext.h" |
| 11 #include "core/paint/PaintLayerScrollableArea.h" | 12 #include "core/paint/PaintLayerScrollableArea.h" |
| 12 #include "platform/testing/HistogramTester.h" | 13 #include "platform/testing/HistogramTester.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 using Corner = ScrollAnchor::Corner; | 17 using Corner = ScrollAnchor::Corner; |
| 17 | 18 |
| 18 class ScrollAnchorTest : public RenderingTest { | 19 class ScrollAnchorTest : public RenderingTest { |
| 19 public: | 20 public: |
| 20 ScrollAnchorTest() { | 21 ScrollAnchorTest() { |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 | 835 |
| 835 // Scroll anchoring should be applied to #rootScroller. | 836 // Scroll anchoring should be applied to #rootScroller. |
| 836 EXPECT_EQ(1000, scroller->scrollOffset().height()); | 837 EXPECT_EQ(1000, scroller->scrollOffset().height()); |
| 837 EXPECT_EQ(document().getElementById("target")->layoutObject(), | 838 EXPECT_EQ(document().getElementById("target")->layoutObject(), |
| 838 scrollAnchor(scroller).anchorObject()); | 839 scrollAnchor(scroller).anchorObject()); |
| 839 // Scroll anchoring should not apply within main frame. | 840 // Scroll anchoring should not apply within main frame. |
| 840 EXPECT_EQ(0, layoutViewport()->scrollOffset().height()); | 841 EXPECT_EQ(0, layoutViewport()->scrollOffset().height()); |
| 841 EXPECT_EQ(nullptr, scrollAnchor(layoutViewport()).anchorObject()); | 842 EXPECT_EQ(nullptr, scrollAnchor(layoutViewport()).anchorObject()); |
| 842 } | 843 } |
| 843 | 844 |
| 845 // This test verifies that scroll anchoring is disabled when the document is in |
| 846 // printing mode. |
| 847 TEST_F(ScrollAnchorTest, AnchoringDisabledForPrinting) { |
| 848 setBodyInnerHTML( |
| 849 "<style> body { height: 1000px } div { height: 100px } </style>" |
| 850 "<div id='block1'>abc</div>" |
| 851 "<div id='block2'>def</div>"); |
| 852 |
| 853 ScrollableArea* viewport = layoutViewport(); |
| 854 scrollLayoutViewport(ScrollOffset(0, 150)); |
| 855 |
| 856 // This will trigger printing and layout. |
| 857 PrintContext::numberOfPages(document().frame(), FloatSize(500, 500)); |
| 858 |
| 859 EXPECT_EQ(150, viewport->scrollOffsetInt().height()); |
| 860 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); |
| 861 } |
| 862 |
| 844 class ScrollAnchorCornerTest : public ScrollAnchorTest { | 863 class ScrollAnchorCornerTest : public ScrollAnchorTest { |
| 845 protected: | 864 protected: |
| 846 void checkCorner(Corner corner, | 865 void checkCorner(Corner corner, |
| 847 ScrollOffset startOffset, | 866 ScrollOffset startOffset, |
| 848 ScrollOffset expectedAdjustment) { | 867 ScrollOffset expectedAdjustment) { |
| 849 ScrollableArea* viewport = layoutViewport(); | 868 ScrollableArea* viewport = layoutViewport(); |
| 850 Element* element = document().getElementById("changer"); | 869 Element* element = document().getElementById("changer"); |
| 851 | 870 |
| 852 viewport->setScrollOffset(startOffset, UserScroll); | 871 viewport->setScrollOffset(startOffset, UserScroll); |
| 853 element->setAttribute(HTMLNames::classAttr, "change"); | 872 element->setAttribute(HTMLNames::classAttr, "change"); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 | 998 |
| 980 scrollLayoutViewport(ScrollOffset(-50, 0)); | 999 scrollLayoutViewport(ScrollOffset(-50, 0)); |
| 981 | 1000 |
| 982 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); | 1001 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); |
| 983 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); | 1002 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); |
| 984 update(); | 1003 update(); |
| 985 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); | 1004 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); |
| 986 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); | 1005 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); |
| 987 } | 1006 } |
| 988 } | 1007 } |
| OLD | NEW |