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/paint/PaintLayerScrollableArea.h" | 11 #include "core/paint/PaintLayerScrollableArea.h" |
12 #include "platform/testing/HistogramTester.h" | 12 #include "platform/testing/HistogramTester.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 using Corner = ScrollAnchor::Corner; | 16 using Corner = ScrollAnchor::Corner; |
17 | 17 |
18 class ScrollAnchorTest : public RenderingTest { | 18 class ScrollAnchorTest : public RenderingTest { |
19 public: | 19 public: |
20 ScrollAnchorTest() { | 20 ScrollAnchorTest() { |
21 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); | 21 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); |
22 } | 22 } |
23 ~ScrollAnchorTest() { | 23 ~ScrollAnchorTest() { |
24 RuntimeEnabledFeatures::setScrollAnchoringEnabled(false); | 24 RuntimeEnabledFeatures::setScrollAnchoringEnabled(false); |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 void update() { | 28 void update() { |
29 // TODO(skobes): Use SimTest instead of RenderingTest and move into Source/w
eb? | 29 // TODO(skobes): Use SimTest instead of RenderingTest and move into |
| 30 // Source/web? |
30 document().view()->updateAllLifecyclePhases(); | 31 document().view()->updateAllLifecyclePhases(); |
31 } | 32 } |
32 | 33 |
33 ScrollableArea* layoutViewport() { | 34 ScrollableArea* layoutViewport() { |
34 return document().view()->layoutViewportScrollableArea(); | 35 return document().view()->layoutViewportScrollableArea(); |
35 } | 36 } |
36 | 37 |
37 VisualViewport& visualViewport() { | 38 VisualViewport& visualViewport() { |
38 return document().view()->page()->frameHost().visualViewport(); | 39 return document().view()->page()->frameHost().visualViewport(); |
39 } | 40 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 Element* block1 = document().getElementById("block1"); | 275 Element* block1 = document().getElementById("block1"); |
275 Element* block2 = document().getElementById("block2"); | 276 Element* block2 = document().getElementById("block2"); |
276 | 277 |
277 scroller->scrollBy(ScrollOffset(0, 150), UserScroll); | 278 scroller->scrollBy(ScrollOffset(0, 150), UserScroll); |
278 | 279 |
279 // In this layout pass we will anchor to #block2 which has its own PaintLayer. | 280 // In this layout pass we will anchor to #block2 which has its own PaintLayer. |
280 setHeight(block1, 200); | 281 setHeight(block1, 200); |
281 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); | 282 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); |
282 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject()); | 283 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject()); |
283 | 284 |
284 // Test that the anchor object can be destroyed without affecting the scroll p
osition. | 285 // Test that the anchor object can be destroyed without affecting the scroll |
| 286 // position. |
285 block2->remove(); | 287 block2->remove(); |
286 update(); | 288 update(); |
287 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); | 289 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); |
288 } | 290 } |
289 | 291 |
290 TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates) { | 292 TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates) { |
291 setBodyInnerHTML( | 293 setBodyInnerHTML( |
292 "<style>" | 294 "<style>" |
293 " body { height: 3500px }" | 295 " body { height: 3500px }" |
294 " #div {" | 296 " #div {" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 "</div></div>"); | 409 "</div></div>"); |
408 | 410 |
409 Element* scrollerElement = document().getElementById("scroller"); | 411 Element* scrollerElement = document().getElementById("scroller"); |
410 ScrollableArea* scroller = scrollerForElement(scrollerElement); | 412 ScrollableArea* scroller = scrollerForElement(scrollerElement); |
411 Element* absPos = document().getElementById("abs"); | 413 Element* absPos = document().getElementById("abs"); |
412 Element* relPos = document().getElementById("rel"); | 414 Element* relPos = document().getElementById("rel"); |
413 | 415 |
414 scroller->scrollBy(ScrollOffset(0, 25), UserScroll); | 416 scroller->scrollBy(ScrollOffset(0, 25), UserScroll); |
415 setHeight(document().getElementById("a"), 100); | 417 setHeight(document().getElementById("a"), 100); |
416 | 418 |
417 // When the scroller is position:static, the anchor cannot be position:absolut
e. | 419 // When the scroller is position:static, the anchor cannot be |
| 420 // position:absolute. |
418 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 421 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
419 | 422 |
420 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); | 423 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); |
421 update(); | 424 update(); |
422 scroller->scrollBy(ScrollOffset(0, 25), UserScroll); | 425 scroller->scrollBy(ScrollOffset(0, 25), UserScroll); |
423 setHeight(document().getElementById("a"), 125); | 426 setHeight(document().getElementById("a"), 125); |
424 | 427 |
425 // When the scroller is position:relative, the anchor may be position:absolute
. | 428 // When the scroller is position:relative, the anchor may be |
| 429 // position:absolute. |
426 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); | 430 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); |
427 } | 431 } |
428 | 432 |
429 // Test that we descend into zero-height containers that have overflowing conten
t. | 433 // Test that we descend into zero-height containers that have overflowing |
| 434 // content. |
430 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) { | 435 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) { |
431 setBodyInnerHTML( | 436 setBodyInnerHTML( |
432 "<style>" | 437 "<style>" |
433 " body { height: 1000; }" | 438 " body { height: 1000; }" |
434 " #outer { width: 300px; }" | 439 " #outer { width: 300px; }" |
435 " #zeroheight { height: 0px; }" | 440 " #zeroheight { height: 0px; }" |
436 " #changer { height: 100px; background-color: red; }" | 441 " #changer { height: 100px; background-color: red; }" |
437 " #bottom { margin-top: 600px; }" | 442 " #bottom { margin-top: 600px; }" |
438 "</style>" | 443 "</style>" |
439 "<div id='outer'>" | 444 "<div id='outer'>" |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 | 979 |
975 scrollLayoutViewport(ScrollOffset(-50, 0)); | 980 scrollLayoutViewport(ScrollOffset(-50, 0)); |
976 | 981 |
977 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); | 982 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); |
978 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); | 983 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); |
979 update(); | 984 update(); |
980 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); | 985 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); |
981 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); | 986 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); |
982 } | 987 } |
983 } | 988 } |
OLD | NEW |