| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 234 |
| 235 document().getElementById("scroller")->setScrollTop(1600); | 235 document().getElementById("scroller")->setScrollTop(1600); |
| 236 | 236 |
| 237 setHeight(document().getElementById("changer"), 0); | 237 setHeight(document().getElementById("changer"), 0); |
| 238 | 238 |
| 239 EXPECT_EQ(100, scroller->scrollOffsetInt().height()); | 239 EXPECT_EQ(100, scroller->scrollOffsetInt().height()); |
| 240 EXPECT_EQ(document().getElementById("anchor")->layoutObject(), | 240 EXPECT_EQ(document().getElementById("anchor")->layoutObject(), |
| 241 scrollAnchor(scroller).anchorObject()); | 241 scrollAnchor(scroller).anchorObject()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // Test that a non-anchoring scroll on scroller clears scroll anchors for all |
| 245 // parent scrollers. |
| 246 TEST_F(ScrollAnchorTest, ClearScrollAnchorsOnAncestors) { |
| 247 setBodyInnerHTML( |
| 248 "<style>" |
| 249 " body { height: 1000px } div { height: 200px }" |
| 250 " #scroller { height: 100px; width: 200px; overflow: scroll; }" |
| 251 "</style>" |
| 252 "<div id='changer'>abc</div>" |
| 253 "<div id='anchor'>def</div>" |
| 254 "<div id='scroller'><div></div></div>"); |
| 255 |
| 256 ScrollableArea* viewport = layoutViewport(); |
| 257 |
| 258 scrollLayoutViewport(ScrollOffset(0, 250)); |
| 259 setHeight(document().getElementById("changer"), 300); |
| 260 |
| 261 EXPECT_EQ(350, viewport->scrollOffsetInt().height()); |
| 262 EXPECT_EQ(document().getElementById("anchor")->layoutObject(), |
| 263 scrollAnchor(viewport).anchorObject()); |
| 264 |
| 265 // Scrolling the nested scroller should clear the anchor on the main frame. |
| 266 ScrollableArea* scroller = |
| 267 scrollerForElement(document().getElementById("scroller")); |
| 268 scroller->scrollBy(ScrollOffset(0, 100), UserScroll); |
| 269 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); |
| 270 } |
| 271 |
| 244 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) { | 272 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) { |
| 245 setBodyInnerHTML( | 273 setBodyInnerHTML( |
| 246 "<style> body { height: 1000px } </style>" | 274 "<style> body { height: 1000px } </style>" |
| 247 "<div id='block1' style='height: 50.4px'>abc</div>" | 275 "<div id='block1' style='height: 50.4px'>abc</div>" |
| 248 "<div id='block2' style='height: 100px'>def</div>"); | 276 "<div id='block2' style='height: 100px'>def</div>"); |
| 249 | 277 |
| 250 ScrollableArea* viewport = layoutViewport(); | 278 ScrollableArea* viewport = layoutViewport(); |
| 251 scrollLayoutViewport(ScrollOffset(0, 100)); | 279 scrollLayoutViewport(ScrollOffset(0, 100)); |
| 252 | 280 |
| 253 document().getElementById("block1")->setAttribute(HTMLNames::styleAttr, | 281 document().getElementById("block1")->setAttribute(HTMLNames::styleAttr, |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 | 1007 |
| 980 scrollLayoutViewport(ScrollOffset(-50, 0)); | 1008 scrollLayoutViewport(ScrollOffset(-50, 0)); |
| 981 | 1009 |
| 982 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); | 1010 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); |
| 983 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); | 1011 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); |
| 984 update(); | 1012 update(); |
| 985 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); | 1013 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); |
| 986 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); | 1014 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); |
| 987 } | 1015 } |
| 988 } | 1016 } |
| OLD | NEW |