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