OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 | 1463 |
1464 // Make the page scale and scroll with the given paremeters. | 1464 // Make the page scale and scroll with the given paremeters. |
1465 webViewImpl->setPageScaleFactor(2.0f); | 1465 webViewImpl->setPageScaleFactor(2.0f); |
1466 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); | 1466 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); |
1467 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1467 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
1468 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1468 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
1469 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1469 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
1470 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame()); | 1470 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame()); |
1471 mainFrameLocal->loader().saveScrollState(); | 1471 mainFrameLocal->loader().saveScrollState(); |
1472 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); | 1472 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); |
1473 EXPECT_EQ(94, mainFrameLocal->loader().currentItem()->scrollPoint().x()); | 1473 EXPECT_EQ(94, mainFrameLocal->loader().currentItem()->scrollOffset().width()); |
1474 EXPECT_EQ(111, mainFrameLocal->loader().currentItem()->scrollPoint().y()); | 1474 EXPECT_EQ(111, |
| 1475 mainFrameLocal->loader().currentItem()->scrollOffset().height()); |
1475 | 1476 |
1476 // Confirm that resetting the page state resets the saved scroll position. | 1477 // Confirm that resetting the page state resets the saved scroll position. |
1477 webViewImpl->resetScrollAndScaleState(); | 1478 webViewImpl->resetScrollAndScaleState(); |
1478 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 1479 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
1479 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 1480 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
1480 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1481 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
1481 EXPECT_EQ(1.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); | 1482 EXPECT_EQ(1.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); |
1482 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().x()); | 1483 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollOffset().width()); |
1483 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().y()); | 1484 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollOffset().height()); |
1484 } | 1485 } |
1485 | 1486 |
1486 TEST_F(WebViewTest, BackForwardRestoreScroll) { | 1487 TEST_F(WebViewTest, BackForwardRestoreScroll) { |
1487 URLTestHelpers::registerMockedURLFromBaseURL( | 1488 URLTestHelpers::registerMockedURLFromBaseURL( |
1488 WebString::fromUTF8(m_baseURL.c_str()), | 1489 WebString::fromUTF8(m_baseURL.c_str()), |
1489 WebString::fromUTF8("back_forward_restore_scroll.html")); | 1490 WebString::fromUTF8("back_forward_restore_scroll.html")); |
1490 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad( | 1491 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad( |
1491 m_baseURL + "back_forward_restore_scroll.html"); | 1492 m_baseURL + "back_forward_restore_scroll.html"); |
1492 webViewImpl->resize(WebSize(640, 480)); | 1493 webViewImpl->resize(WebSize(640, 480)); |
1493 webViewImpl->updateAllLifecyclePhases(); | 1494 webViewImpl->updateAllLifecyclePhases(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 | 1559 |
1559 // Enter fullscreen. | 1560 // Enter fullscreen. |
1560 Element* element = static_cast<Element*>( | 1561 Element* element = static_cast<Element*>( |
1561 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); | 1562 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); |
1562 webViewImpl->enterFullscreenForElement(element); | 1563 webViewImpl->enterFullscreenForElement(element); |
1563 webViewImpl->didEnterFullscreen(); | 1564 webViewImpl->didEnterFullscreen(); |
1564 webViewImpl->updateAllLifecyclePhases(); | 1565 webViewImpl->updateAllLifecyclePhases(); |
1565 | 1566 |
1566 // Sanity-check. There should be no scrolling possible. | 1567 // Sanity-check. There should be no scrolling possible. |
1567 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1568 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
1568 ASSERT_EQ( | 1569 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
1569 0, | 1570 ->frameView() |
1570 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); | 1571 ->maximumScrollOffset() |
| 1572 .height()); |
1571 | 1573 |
1572 // Confirm that after exiting and doing a layout, the scroll and scale | 1574 // Confirm that after exiting and doing a layout, the scroll and scale |
1573 // parameters are reset. The page sets display: none on overflowing elements | 1575 // parameters are reset. The page sets display: none on overflowing elements |
1574 // while in fullscreen so if we try to restore before the style and layout | 1576 // while in fullscreen so if we try to restore before the style and layout |
1575 // is applied the offsets will be clamped. | 1577 // is applied the offsets will be clamped. |
1576 webViewImpl->didExitFullscreen(); | 1578 webViewImpl->didExitFullscreen(); |
1577 EXPECT_TRUE(webViewImpl->mainFrameImpl()->frameView()->needsLayout()); | 1579 EXPECT_TRUE(webViewImpl->mainFrameImpl()->frameView()->needsLayout()); |
1578 webViewImpl->updateAllLifecyclePhases(); | 1580 webViewImpl->updateAllLifecyclePhases(); |
1579 | 1581 |
1580 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); | 1582 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
(...skipping 16 matching lines...) Expand all Loading... |
1597 | 1599 |
1598 // Enter fullscreen. | 1600 // Enter fullscreen. |
1599 Element* element = static_cast<Element*>( | 1601 Element* element = static_cast<Element*>( |
1600 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); | 1602 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); |
1601 webViewImpl->enterFullscreenForElement(element); | 1603 webViewImpl->enterFullscreenForElement(element); |
1602 webViewImpl->didEnterFullscreen(); | 1604 webViewImpl->didEnterFullscreen(); |
1603 webViewImpl->updateAllLifecyclePhases(); | 1605 webViewImpl->updateAllLifecyclePhases(); |
1604 | 1606 |
1605 // Sanity-check. There should be no scrolling possible. | 1607 // Sanity-check. There should be no scrolling possible. |
1606 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1608 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
1607 ASSERT_EQ( | 1609 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
1608 0, | 1610 ->frameView() |
1609 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); | 1611 ->maximumScrollOffset() |
| 1612 .height()); |
1610 | 1613 |
1611 // Exit and, without performing a layout, reenter fullscreen again. We | 1614 // Exit and, without performing a layout, reenter fullscreen again. We |
1612 // shouldn't try to restore the scroll and scale values when we layout to | 1615 // shouldn't try to restore the scroll and scale values when we layout to |
1613 // enter fullscreen. | 1616 // enter fullscreen. |
1614 webViewImpl->exitFullscreenForElement(element); | 1617 webViewImpl->exitFullscreenForElement(element); |
1615 webViewImpl->didExitFullscreen(); | 1618 webViewImpl->didExitFullscreen(); |
1616 webViewImpl->enterFullscreenForElement(element); | 1619 webViewImpl->enterFullscreenForElement(element); |
1617 webViewImpl->didEnterFullscreen(); | 1620 webViewImpl->didEnterFullscreen(); |
1618 webViewImpl->updateAllLifecyclePhases(); | 1621 webViewImpl->updateAllLifecyclePhases(); |
1619 | 1622 |
1620 // Sanity-check. There should be no scrolling possible. | 1623 // Sanity-check. There should be no scrolling possible. |
1621 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1624 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
1622 ASSERT_EQ( | 1625 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
1623 0, | 1626 ->frameView() |
1624 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); | 1627 ->maximumScrollOffset() |
| 1628 .height()); |
1625 | 1629 |
1626 // When we exit now, we should restore the original scroll value. | 1630 // When we exit now, we should restore the original scroll value. |
1627 webViewImpl->exitFullscreenForElement(element); | 1631 webViewImpl->exitFullscreenForElement(element); |
1628 webViewImpl->didExitFullscreen(); | 1632 webViewImpl->didExitFullscreen(); |
1629 webViewImpl->updateAllLifecyclePhases(); | 1633 webViewImpl->updateAllLifecyclePhases(); |
1630 | 1634 |
1631 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); | 1635 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
1632 } | 1636 } |
1633 | 1637 |
1634 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) { | 1638 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) { |
(...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4020 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); | 4024 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
4021 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); | 4025 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); |
4022 | 4026 |
4023 TransformationMatrix expectedMatrix; | 4027 TransformationMatrix expectedMatrix; |
4024 expectedMatrix.makeIdentity(); | 4028 expectedMatrix.makeIdentity(); |
4025 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | 4029 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
4026 | 4030 |
4027 // Initial transform takes current page scale and scroll position into | 4031 // Initial transform takes current page scale and scroll position into |
4028 // account. | 4032 // account. |
4029 webViewImpl->setPageScaleFactor(1.5f); | 4033 webViewImpl->setPageScaleFactor(1.5f); |
4030 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, | 4034 frameView->setScrollOffset(ScrollOffset(100, 150), ProgrammaticScroll, |
4031 ScrollBehaviorInstant); | 4035 ScrollBehaviorInstant); |
4032 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); | 4036 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); |
4033 expectedMatrix.makeIdentity() | 4037 expectedMatrix.makeIdentity() |
4034 .scale(2.f) | 4038 .scale(2.f) |
4035 .translate(-50, -55) | 4039 .translate(-50, -55) |
4036 .translate(100, 150) | 4040 .translate(100, 150) |
4037 .scale(1. / 1.5f); | 4041 .scale(1. / 1.5f); |
4038 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | 4042 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
4039 // Page scroll and scale are irrelevant for visibleContentRect. | 4043 // Page scroll and scale are irrelevant for visibleContentRect. |
4040 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4044 EXPECT_EQ(IntRect(50, 55, 50, 75), |
4041 *devToolsEmulator->visibleContentRectForPainting()); | 4045 *devToolsEmulator->visibleContentRectForPainting()); |
4042 | 4046 |
4043 // Transform adapts to scroll changes. | 4047 // Transform adapts to scroll changes. |
4044 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, | 4048 frameView->setScrollOffset(ScrollOffset(50, 55), ProgrammaticScroll, |
4045 ScrollBehaviorInstant); | 4049 ScrollBehaviorInstant); |
4046 expectedMatrix.makeIdentity() | 4050 expectedMatrix.makeIdentity() |
4047 .scale(2.f) | 4051 .scale(2.f) |
4048 .translate(-50, -55) | 4052 .translate(-50, -55) |
4049 .translate(50, 55) | 4053 .translate(50, 55) |
4050 .scale(1. / 1.5f); | 4054 .scale(1. / 1.5f); |
4051 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | 4055 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
4052 // visibleContentRect doesn't change. | 4056 // visibleContentRect doesn't change. |
4053 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4057 EXPECT_EQ(IntRect(50, 55, 50, 75), |
4054 *devToolsEmulator->visibleContentRectForPainting()); | 4058 *devToolsEmulator->visibleContentRectForPainting()); |
4055 | 4059 |
4056 // Transform adapts to page scale changes. | 4060 // Transform adapts to page scale changes. |
4057 webViewImpl->setPageScaleFactor(2.f); | 4061 webViewImpl->setPageScaleFactor(2.f); |
4058 expectedMatrix.makeIdentity() | 4062 expectedMatrix.makeIdentity() |
4059 .scale(2.f) | 4063 .scale(2.f) |
4060 .translate(-50, -55) | 4064 .translate(-50, -55) |
4061 .translate(50, 55) | 4065 .translate(50, 55) |
4062 .scale(1. / 2.f); | 4066 .scale(1. / 2.f); |
4063 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | 4067 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
4064 // visibleContentRect doesn't change. | 4068 // visibleContentRect doesn't change. |
4065 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4069 EXPECT_EQ(IntRect(50, 55, 50, 75), |
4066 *devToolsEmulator->visibleContentRectForPainting()); | 4070 *devToolsEmulator->visibleContentRectForPainting()); |
4067 } | 4071 } |
4068 | 4072 |
4069 } // namespace blink | 4073 } // namespace blink |
OLD | NEW |