| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 { | 52 { |
| 53 element->setAttribute(HTMLNames::styleAttr, | 53 element->setAttribute(HTMLNames::styleAttr, |
| 54 AtomicString(String::format("height: %dpx", height))); | 54 AtomicString(String::format("height: %dpx", height))); |
| 55 update(); | 55 update(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void scrollLayoutViewport(DoubleSize delta) | 58 void scrollLayoutViewport(DoubleSize delta) |
| 59 { | 59 { |
| 60 Element* scrollingElement = document().scrollingElement(); | 60 Element* scrollingElement = document().scrollingElement(); |
| 61 if (delta.width()) | 61 if (delta.width()) |
| 62 scrollingElement->setScrollTop(scrollingElement->scrollLeft() + delt
a.width()); | 62 scrollingElement->setScrollLeft(scrollingElement->scrollLeft() + del
ta.width()); |
| 63 if (delta.height()) | 63 if (delta.height()) |
| 64 scrollingElement->setScrollTop(scrollingElement->scrollTop() + delta
.height()); | 64 scrollingElement->setScrollTop(scrollingElement->scrollTop() + delta
.height()); |
| 65 } | 65 } |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // TODO(ymalik): Currently, this should be the first test in the file to avoid | 68 // TODO(ymalik): Currently, this should be the first test in the file to avoid |
| 69 // failure when running with other tests. Dig into this more and fix. | 69 // failure when running with other tests. Dig into this more and fix. |
| 70 TEST_F(ScrollAnchorTest, UMAMetricUpdated) | 70 TEST_F(ScrollAnchorTest, UMAMetricUpdated) |
| 71 { | 71 { |
| 72 HistogramTester histogramTester; | 72 HistogramTester histogramTester; |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 " body { position: relative; width: 1220px; height: 920px; }" | 934 " body { position: relative; width: 1220px; height: 920px; }" |
| 935 " #a { width: 400px; height: 300px; }" | 935 " #a { width: 400px; height: 300px; }" |
| 936 " .change { width: 100px; }" | 936 " .change { width: 100px; }" |
| 937 "</style>" | 937 "</style>" |
| 938 "<div id='changer'></div>" | 938 "<div id='changer'></div>" |
| 939 "<div id='a'></div>"); | 939 "<div id='a'></div>"); |
| 940 | 940 |
| 941 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(-100, 0)); | 941 checkCorner(Corner::TopRight, DoublePoint(-20, 20), DoubleSize(-100, 0)); |
| 942 } | 942 } |
| 943 | 943 |
| 944 TEST_F(ScrollAnchorTest, IgnoreNonBlockLayoutAxis) |
| 945 { |
| 946 setBodyInnerHTML( |
| 947 "<style>" |
| 948 " body {" |
| 949 " margin: 0; line-height: 0;" |
| 950 " width: 1200px; height: 1200px;" |
| 951 " }" |
| 952 " div {" |
| 953 " width: 100px; height: 100px;" |
| 954 " border: 5px solid gray;" |
| 955 " display: inline-block;" |
| 956 " box-sizing: border-box;" |
| 957 " }" |
| 958 "</style>" |
| 959 "<div id='a'></div><br>" |
| 960 "<div id='b'></div><div id='c'></div>"); |
| 961 |
| 962 ScrollableArea* viewport = layoutViewport(); |
| 963 scrollLayoutViewport(DoubleSize(150, 0)); |
| 964 |
| 965 Element* a = document().getElementById("a"); |
| 966 Element* b = document().getElementById("b"); |
| 967 Element* c = document().getElementById("c"); |
| 968 |
| 969 a->setAttribute(HTMLNames::styleAttr, "height: 150px"); |
| 970 update(); |
| 971 EXPECT_EQ(DoublePoint(150, 0), viewport->scrollPositionDouble()); |
| 972 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); |
| 973 |
| 974 scrollLayoutViewport(DoubleSize(0, 50)); |
| 975 |
| 976 a->setAttribute(HTMLNames::styleAttr, "height: 200px"); |
| 977 b->setAttribute(HTMLNames::styleAttr, "width: 150px"); |
| 978 update(); |
| 979 EXPECT_EQ(DoublePoint(150, 100), viewport->scrollPositionDouble()); |
| 980 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); |
| 981 |
| 982 a->setAttribute(HTMLNames::styleAttr, "height: 100px"); |
| 983 b->setAttribute(HTMLNames::styleAttr, "width: 100px"); |
| 984 document().documentElement()->setAttribute(HTMLNames::styleAttr, "writing-mo
de: vertical-rl"); |
| 985 document().scrollingElement()->setScrollLeft(0); |
| 986 document().scrollingElement()->setScrollTop(0); |
| 987 scrollLayoutViewport(DoubleSize(0, 150)); |
| 988 |
| 989 a->setAttribute(HTMLNames::styleAttr, "width: 150px"); |
| 990 update(); |
| 991 EXPECT_EQ(DoublePoint(0, 150), viewport->scrollPositionDouble()); |
| 992 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); |
| 993 |
| 994 scrollLayoutViewport(DoubleSize(-50, 0)); |
| 995 |
| 996 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); |
| 997 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); |
| 998 update(); |
| 999 EXPECT_EQ(DoublePoint(-100, 150), viewport->scrollPositionDouble()); |
| 1000 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); |
| 944 } | 1001 } |
| 1002 |
| 1003 } |
| OLD | NEW |