| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame/RootFrameViewport.h" | 5 #include "core/frame/RootFrameViewport.h" |
| 6 | 6 |
| 7 #include "core/layout/ScrollAlignment.h" | 7 #include "core/layout/ScrollAlignment.h" |
| 8 #include "platform/geometry/DoubleRect.h" | 8 #include "platform/geometry/DoubleRect.h" |
| 9 #include "platform/geometry/LayoutRect.h" | 9 #include "platform/geometry/LayoutRect.h" |
| 10 #include "platform/scroll/ScrollableArea.h" | 10 #include "platform/scroll/ScrollableArea.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 LayoutRect(100, 250, 50, 50), | 352 LayoutRect(100, 250, 50, 50), |
| 353 ScrollAlignment::alignToEdgeIfNeeded, | 353 ScrollAlignment::alignToEdgeIfNeeded, |
| 354 ScrollAlignment::alignToEdgeIfNeeded); | 354 ScrollAlignment::alignToEdgeIfNeeded); |
| 355 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport->scrollPositionDouble()
); | 355 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport->scrollPositionDouble()
); |
| 356 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport->scrollPositionDouble()); | 356 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport->scrollPositionDouble()); |
| 357 | 357 |
| 358 rootFrameViewport->scrollIntoView( | 358 rootFrameViewport->scrollIntoView( |
| 359 LayoutRect(25, 75, 50, 50), | 359 LayoutRect(25, 75, 50, 50), |
| 360 ScrollAlignment::alignToEdgeIfNeeded, | 360 ScrollAlignment::alignToEdgeIfNeeded, |
| 361 ScrollAlignment::alignToEdgeIfNeeded); | 361 ScrollAlignment::alignToEdgeIfNeeded); |
| 362 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport->scrollPositionDouble())
; | 362 EXPECT_POINT_EQ(DoublePoint(25, 75), layoutViewport->scrollPositionDouble())
; |
| 363 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport->scrollPositionDouble()); | 363 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 364 | 364 |
| 365 // Reset the visual viewport's size, scale the page and repeat the test | 365 // Reset the visual viewport's size, scale the page, and repeat the test |
| 366 visualViewport->setViewportSize(IntSize(100, 150)); | 366 visualViewport->setViewportSize(IntSize(100, 150)); |
| 367 visualViewport->setScale(2); | 367 visualViewport->setScale(2); |
| 368 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 368 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 369 | 369 |
| 370 rootFrameViewport->scrollIntoView( | 370 rootFrameViewport->scrollIntoView( |
| 371 LayoutRect(50, 75, 50, 75), | 371 LayoutRect(50, 75, 50, 75), |
| 372 ScrollAlignment::alignToEdgeIfNeeded, | 372 ScrollAlignment::alignToEdgeIfNeeded, |
| 373 ScrollAlignment::alignToEdgeIfNeeded); | 373 ScrollAlignment::alignToEdgeIfNeeded); |
| 374 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport->scrollPositionDouble())
; | 374 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 375 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); | 375 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble())
; |
| 376 | 376 |
| 377 rootFrameViewport->scrollIntoView( | 377 rootFrameViewport->scrollIntoView( |
| 378 LayoutRect(190, 290, 10, 10), | 378 LayoutRect(190, 290, 10, 10), |
| 379 ScrollAlignment::alignToEdgeIfNeeded, | 379 ScrollAlignment::alignToEdgeIfNeeded, |
| 380 ScrollAlignment::alignToEdgeIfNeeded); | 380 ScrollAlignment::alignToEdgeIfNeeded); |
| 381 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport->scrollPositionDouble(
)); | 381 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport->scrollPositionDouble(
)); |
| 382 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble())
; | 382 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble())
; |
| 383 | 383 |
| 384 // Scrolling into view the viewport rect itself should be a no-op. | 384 // Scrolling into view the viewport rect itself should be a no-op. |
| 385 visualViewport->setViewportSize(IntSize(100, 100)); | 385 visualViewport->setViewportSize(IntSize(100, 100)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 414 TEST_F(RootFrameViewportTest, SetScrollPosition) | 414 TEST_F(RootFrameViewportTest, SetScrollPosition) |
| 415 { | 415 { |
| 416 IntSize viewportSize(500, 500); | 416 IntSize viewportSize(500, 500); |
| 417 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(1000, 2000)); | 417 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(1000, 2000)); |
| 418 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); | 418 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 419 | 419 |
| 420 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); | 420 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 421 | 421 |
| 422 visualViewport->setScale(2); | 422 visualViewport->setScale(2); |
| 423 | 423 |
| 424 // Ensure that the layout viewport scrolls first. | 424 // Ensure that the visual viewport scrolls first. |
| 425 rootFrameViewport->setScrollPosition(DoublePoint(100, 100), ProgrammaticScro
ll); | 425 rootFrameViewport->setScrollPosition(DoublePoint(100, 100), ProgrammaticScro
ll); |
| 426 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); | 426 EXPECT_POINT_EQ(DoublePoint(100, 100), visualViewport->scrollPositionDouble(
)); |
| 427 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport->scrollPositionDouble(
)); | 427 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 428 | 428 |
| 429 // Scroll to the layout viewport's extent, the visual viewport should scroll
the | 429 // Scroll to the visual viewport's extent, the layout viewport should scroll
the |
| 430 // remainder. | 430 // remainder. |
| 431 rootFrameViewport->setScrollPosition(DoublePoint(700, 1700), ProgrammaticScr
oll); | 431 rootFrameViewport->setScrollPosition(DoublePoint(300, 400), ProgrammaticScro
ll); |
| 432 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport->scrollPositionDouble(
)); | 432 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport->scrollPositionDouble(
)); |
| 433 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport->scrollPositionDouble
()); | 433 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport->scrollPositionDouble()
); |
| 434 | 434 |
| 435 // Only the visual viewport should scroll further. Make sure it doesn't scro
ll | 435 // Only the layout viewport should scroll further. Make sure it doesn't scro
ll |
| 436 // out of bounds. | 436 // out of bounds. |
| 437 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScr
oll); | 437 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScr
oll); |
| 438 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport->scrollPositionDouble(
)); | 438 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport->scrollPositionDouble(
)); |
| 439 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport->scrollPositionDouble
()); | 439 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport->scrollPositionDouble
()); |
| 440 | 440 |
| 441 // Scroll all the way back. | 441 // Scroll all the way back. |
| 442 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); | 442 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); |
| 443 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); | 443 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 444 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); | 444 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 445 } | 445 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); | 462 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); |
| 463 | 463 |
| 464 visualViewport->setScale(2); | 464 visualViewport->setScale(2); |
| 465 | 465 |
| 466 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); | 466 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); |
| 467 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); | 467 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); |
| 468 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect()
.size()); | 468 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect()
.size()); |
| 469 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect
Double().size()); | 469 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect
Double().size()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 // Tests that the invert scroll order experiment scrolls the visual viewport | 472 // Tests that scrolls on the root frame scroll the visual viewport before |
| 473 // before trying to scroll the layout viewport. | 473 // trying to scroll the layout viewport. |
| 474 TEST_F(RootFrameViewportTest, ViewportScrollOrder) | 474 TEST_F(RootFrameViewportTest, ViewportScrollOrder) |
| 475 { | 475 { |
| 476 IntSize viewportSize(100, 100); | 476 IntSize viewportSize(100, 100); |
| 477 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); | 477 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); |
| 478 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); | 478 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 479 | 479 |
| 480 bool invertScrollOrder = true; | |
| 481 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = | 480 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = |
| 482 RootFrameViewport::create(*visualViewport.get(), *layoutViewport.get(),
invertScrollOrder); | 481 RootFrameViewport::create(*visualViewport.get(), *layoutViewport.get()); |
| 483 | 482 |
| 484 visualViewport->setScale(2); | 483 visualViewport->setScale(2); |
| 485 | 484 |
| 486 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll); | 485 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll); |
| 487 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble())
; | 486 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble())
; |
| 488 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); | 487 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 489 | 488 |
| 490 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll
); | 489 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll
); |
| 491 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble())
; | 490 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble())
; |
| 492 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble())
; | 491 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble())
; |
| 493 } | 492 } |
| 494 | 493 |
| 495 } // namespace blink | 494 } // namespace blink |
| OLD | NEW |