| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "public/web/WebView.h" | 31 #include "public/web/WebView.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/V8Document.h" | 33 #include "bindings/core/v8/V8Document.h" |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/DocumentUserGestureToken.h" |
| 35 #include "core/dom/Element.h" | 36 #include "core/dom/Element.h" |
| 37 #include "core/dom/Fullscreen.h" |
| 36 #include "core/editing/FrameSelection.h" | 38 #include "core/editing/FrameSelection.h" |
| 37 #include "core/editing/InputMethodController.h" | 39 #include "core/editing/InputMethodController.h" |
| 38 #include "core/editing/markers/DocumentMarkerController.h" | 40 #include "core/editing/markers/DocumentMarkerController.h" |
| 39 #include "core/frame/EventHandlerRegistry.h" | 41 #include "core/frame/EventHandlerRegistry.h" |
| 40 #include "core/frame/FrameHost.h" | 42 #include "core/frame/FrameHost.h" |
| 41 #include "core/frame/FrameView.h" | 43 #include "core/frame/FrameView.h" |
| 42 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
| 43 #include "core/frame/Settings.h" | 45 #include "core/frame/Settings.h" |
| 44 #include "core/frame/VisualViewport.h" | 46 #include "core/frame/VisualViewport.h" |
| 45 #include "core/html/HTMLIFrameElement.h" | 47 #include "core/html/HTMLIFrameElement.h" |
| (...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 WebViewImpl* webViewImpl = | 1710 WebViewImpl* webViewImpl = |
| 1709 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); | 1711 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); |
| 1710 webViewImpl->resize(WebSize(800, 600)); | 1712 webViewImpl->resize(WebSize(800, 600)); |
| 1711 webViewImpl->updateAllLifecyclePhases(); | 1713 webViewImpl->updateAllLifecyclePhases(); |
| 1712 | 1714 |
| 1713 // Scroll the page down. | 1715 // Scroll the page down. |
| 1714 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); | 1716 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
| 1715 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); | 1717 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1716 | 1718 |
| 1717 // Enter fullscreen. | 1719 // Enter fullscreen. |
| 1718 Element* element = static_cast<Element*>( | 1720 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 1719 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); | 1721 Element* element = document->getElementById("fullscreenElement"); |
| 1720 webViewImpl->enterFullscreenForElement(element); | 1722 UserGestureIndicator gesture(DocumentUserGestureToken::create(document)); |
| 1723 Fullscreen::requestFullscreen(*element, Fullscreen::PrefixedRequest); |
| 1721 webViewImpl->didEnterFullscreen(); | 1724 webViewImpl->didEnterFullscreen(); |
| 1722 webViewImpl->updateAllLifecyclePhases(); | 1725 webViewImpl->updateAllLifecyclePhases(); |
| 1723 | 1726 |
| 1724 // Sanity-check. There should be no scrolling possible. | 1727 // Sanity-check. There should be no scrolling possible. |
| 1725 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1728 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1726 ASSERT_EQ(0, webViewImpl->mainFrameImpl() | 1729 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
| 1727 ->frameView() | 1730 ->frameView() |
| 1728 ->maximumScrollOffset() | 1731 ->maximumScrollOffset() |
| 1729 .height()); | 1732 .height()); |
| 1730 | 1733 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1748 WebViewImpl* webViewImpl = | 1751 WebViewImpl* webViewImpl = |
| 1749 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); | 1752 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); |
| 1750 webViewImpl->resize(WebSize(800, 600)); | 1753 webViewImpl->resize(WebSize(800, 600)); |
| 1751 webViewImpl->updateAllLifecyclePhases(); | 1754 webViewImpl->updateAllLifecyclePhases(); |
| 1752 | 1755 |
| 1753 // Scroll the page down. | 1756 // Scroll the page down. |
| 1754 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); | 1757 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
| 1755 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); | 1758 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1756 | 1759 |
| 1757 // Enter fullscreen. | 1760 // Enter fullscreen. |
| 1758 Element* element = static_cast<Element*>( | 1761 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 1759 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); | 1762 Element* element = document->getElementById("fullscreenElement"); |
| 1760 webViewImpl->enterFullscreenForElement(element); | 1763 UserGestureIndicator gesture(DocumentUserGestureToken::create(document)); |
| 1764 Fullscreen::requestFullscreen(*element, Fullscreen::PrefixedRequest); |
| 1761 webViewImpl->didEnterFullscreen(); | 1765 webViewImpl->didEnterFullscreen(); |
| 1762 webViewImpl->updateAllLifecyclePhases(); | 1766 webViewImpl->updateAllLifecyclePhases(); |
| 1763 | 1767 |
| 1764 // Sanity-check. There should be no scrolling possible. | 1768 // Sanity-check. There should be no scrolling possible. |
| 1765 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1769 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1766 ASSERT_EQ(0, webViewImpl->mainFrameImpl() | 1770 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
| 1767 ->frameView() | 1771 ->frameView() |
| 1768 ->maximumScrollOffset() | 1772 ->maximumScrollOffset() |
| 1769 .height()); | 1773 .height()); |
| 1770 | 1774 |
| 1771 // Exit and, without performing a layout, reenter fullscreen again. We | 1775 // Exit and, without performing a layout, reenter fullscreen again. We |
| 1772 // shouldn't try to restore the scroll and scale values when we layout to | 1776 // shouldn't try to restore the scroll and scale values when we layout to |
| 1773 // enter fullscreen. | 1777 // enter fullscreen. |
| 1774 webViewImpl->exitFullscreen(element->document().frame()); | |
| 1775 webViewImpl->didExitFullscreen(); | 1778 webViewImpl->didExitFullscreen(); |
| 1776 webViewImpl->enterFullscreenForElement(element); | 1779 Fullscreen::requestFullscreen(*element, Fullscreen::PrefixedRequest); |
| 1777 webViewImpl->didEnterFullscreen(); | 1780 webViewImpl->didEnterFullscreen(); |
| 1778 webViewImpl->updateAllLifecyclePhases(); | 1781 webViewImpl->updateAllLifecyclePhases(); |
| 1779 | 1782 |
| 1780 // Sanity-check. There should be no scrolling possible. | 1783 // Sanity-check. There should be no scrolling possible. |
| 1781 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1784 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1782 ASSERT_EQ(0, webViewImpl->mainFrameImpl() | 1785 ASSERT_EQ(0, webViewImpl->mainFrameImpl() |
| 1783 ->frameView() | 1786 ->frameView() |
| 1784 ->maximumScrollOffset() | 1787 ->maximumScrollOffset() |
| 1785 .height()); | 1788 .height()); |
| 1786 | 1789 |
| 1787 // When we exit now, we should restore the original scroll value. | 1790 // When we exit now, we should restore the original scroll value. |
| 1788 webViewImpl->exitFullscreen(element->document().frame()); | |
| 1789 webViewImpl->didExitFullscreen(); | 1791 webViewImpl->didExitFullscreen(); |
| 1790 webViewImpl->updateAllLifecyclePhases(); | 1792 webViewImpl->updateAllLifecyclePhases(); |
| 1791 | 1793 |
| 1792 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); | 1794 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1793 } | 1795 } |
| 1794 | 1796 |
| 1795 TEST_P(WebViewTest, EnterFullscreenResetScrollAndScaleState) { | 1797 TEST_P(WebViewTest, EnterFullscreenResetScrollAndScaleState) { |
| 1796 URLTestHelpers::registerMockedURLFromBaseURL( | 1798 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1797 WebString::fromUTF8(m_baseURL.c_str()), | 1799 WebString::fromUTF8(m_baseURL.c_str()), |
| 1798 WebString::fromUTF8("200-by-300.html")); | 1800 WebString::fromUTF8("200-by-300.html")); |
| 1799 WebViewImpl* webViewImpl = | 1801 WebViewImpl* webViewImpl = |
| 1800 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); | 1802 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| 1801 webViewImpl->resize(WebSize(100, 150)); | 1803 webViewImpl->resize(WebSize(100, 150)); |
| 1802 webViewImpl->updateAllLifecyclePhases(); | 1804 webViewImpl->updateAllLifecyclePhases(); |
| 1803 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 1805 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 1804 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1806 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1805 | 1807 |
| 1806 // Make the page scale and scroll with the given paremeters. | 1808 // Make the page scale and scroll with the given paremeters. |
| 1807 webViewImpl->setPageScaleFactor(2.0f); | 1809 webViewImpl->setPageScaleFactor(2.0f); |
| 1808 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); | 1810 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); |
| 1809 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); | 1811 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); |
| 1810 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1812 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1811 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1813 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1812 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1814 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1813 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1815 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1814 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1816 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1815 | 1817 |
| 1816 Element* element = | 1818 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 1817 static_cast<Element*>(webViewImpl->mainFrame()->document().body()); | 1819 Element* element = document->body(); |
| 1818 webViewImpl->enterFullscreenForElement(element); | 1820 UserGestureIndicator gesture(DocumentUserGestureToken::create(document)); |
| 1821 Fullscreen::requestFullscreen(*element, Fullscreen::PrefixedRequest); |
| 1819 webViewImpl->didEnterFullscreen(); | 1822 webViewImpl->didEnterFullscreen(); |
| 1820 | 1823 |
| 1821 // Page scale factor must be 1.0 during fullscreen for elements to be sized | 1824 // Page scale factor must be 1.0 during fullscreen for elements to be sized |
| 1822 // properly. | 1825 // properly. |
| 1823 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 1826 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
| 1824 | 1827 |
| 1825 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. | 1828 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. |
| 1826 Element* otherElement = | 1829 Element* otherElement = document->getElementById("content"); |
| 1827 static_cast<Element*>(webViewImpl->mainFrame()->document().head()); | 1830 Fullscreen::requestFullscreen(*otherElement, Fullscreen::PrefixedRequest); |
| 1828 webViewImpl->enterFullscreenForElement(otherElement); | |
| 1829 | 1831 |
| 1830 // Confirm that exiting fullscreen restores the parameters. | 1832 // Confirm that exiting fullscreen restores the parameters. |
| 1831 webViewImpl->exitFullscreen(element->document().frame()); | |
| 1832 webViewImpl->didExitFullscreen(); | 1833 webViewImpl->didExitFullscreen(); |
| 1833 webViewImpl->updateAllLifecyclePhases(); | 1834 webViewImpl->updateAllLifecyclePhases(); |
| 1834 | 1835 |
| 1835 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1836 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1836 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1837 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1837 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1838 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1838 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1839 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1839 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1840 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1840 } | 1841 } |
| 1841 | 1842 |
| (...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4355 .translate(50, 55) | 4356 .translate(50, 55) |
| 4356 .scale(1. / 2.f); | 4357 .scale(1. / 2.f); |
| 4357 EXPECT_EQ(expectedMatrix, | 4358 EXPECT_EQ(expectedMatrix, |
| 4358 webViewImpl->getDeviceEmulationTransformForTesting()); | 4359 webViewImpl->getDeviceEmulationTransformForTesting()); |
| 4359 // visibleContentRect doesn't change. | 4360 // visibleContentRect doesn't change. |
| 4360 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4361 EXPECT_EQ(IntRect(50, 55, 50, 75), |
| 4361 *devToolsEmulator->visibleContentRectForPainting()); | 4362 *devToolsEmulator->visibleContentRectForPainting()); |
| 4362 } | 4363 } |
| 4363 | 4364 |
| 4364 } // namespace blink | 4365 } // namespace blink |
| OLD | NEW |