| 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/VisualViewport.h" | 5 #include "core/frame/VisualViewport.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/FrameHost.h" | 8 #include "core/frame/FrameHost.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/html/HTMLBodyElement.h" | 11 #include "core/html/HTMLBodyElement.h" |
| 12 #include "core/html/HTMLElement.h" | 12 #include "core/html/HTMLElement.h" |
| 13 #include "core/input/EventHandler.h" | 13 #include "core/input/EventHandler.h" |
| 14 #include "core/layout/LayoutObject.h" | 14 #include "core/layout/LayoutObject.h" |
| 15 #include "core/layout/LayoutView.h" | 15 #include "core/layout/LayoutView.h" |
| 16 #include "core/layout/compositing/PaintLayerCompositor.h" | 16 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 17 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 18 #include "platform/PlatformGestureEvent.h" | 18 #include "platform/PlatformGestureEvent.h" |
| 19 #include "platform/geometry/DoublePoint.h" | 19 #include "platform/geometry/DoublePoint.h" |
| 20 #include "platform/geometry/DoubleRect.h" | 20 #include "platform/geometry/DoubleRect.h" |
| 21 #include "platform/testing/URLTestHelpers.h" | 21 #include "platform/testing/URLTestHelpers.h" |
| 22 #include "public/platform/Platform.h" | 22 #include "public/platform/Platform.h" |
| 23 #include "public/platform/WebCachePolicy.h" |
| 23 #include "public/platform/WebLayerTreeView.h" | 24 #include "public/platform/WebLayerTreeView.h" |
| 24 #include "public/platform/WebUnitTestSupport.h" | 25 #include "public/platform/WebUnitTestSupport.h" |
| 25 #include "public/web/WebContextMenuData.h" | 26 #include "public/web/WebContextMenuData.h" |
| 26 #include "public/web/WebDocument.h" | 27 #include "public/web/WebDocument.h" |
| 27 #include "public/web/WebFrameClient.h" | 28 #include "public/web/WebFrameClient.h" |
| 28 #include "public/web/WebInputEvent.h" | 29 #include "public/web/WebInputEvent.h" |
| 29 #include "public/web/WebScriptSource.h" | 30 #include "public/web/WebScriptSource.h" |
| 30 #include "public/web/WebSettings.h" | 31 #include "public/web/WebSettings.h" |
| 31 #include "public/web/WebViewClient.h" | 32 #include "public/web/WebViewClient.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 837 |
| 837 registerMockedHttpURLLoad("200-by-300.html"); | 838 registerMockedHttpURLLoad("200-by-300.html"); |
| 838 | 839 |
| 839 WebHistoryItem item; | 840 WebHistoryItem item; |
| 840 item.initialize(); | 841 item.initialize(); |
| 841 WebURL destinationURL(URLTestHelpers::toKURL(m_baseURL + "200-by-300.html"))
; | 842 WebURL destinationURL(URLTestHelpers::toKURL(m_baseURL + "200-by-300.html"))
; |
| 842 item.setURLString(destinationURL.string()); | 843 item.setURLString(destinationURL.string()); |
| 843 item.setVisualViewportScrollOffset(WebFloatPoint(100, 120)); | 844 item.setVisualViewportScrollOffset(WebFloatPoint(100, 120)); |
| 844 item.setPageScaleFactor(2); | 845 item.setPageScaleFactor(2); |
| 845 | 846 |
| 846 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebURLRequest::UseProtocolCachePolicy); | 847 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebCachePolicy::UseProtocolCachePolicy); |
| 847 | 848 |
| 848 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 849 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 849 EXPECT_EQ(2, visualViewport.scale()); | 850 EXPECT_EQ(2, visualViewport.scale()); |
| 850 | 851 |
| 851 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), visualViewport.visibleRect().loc
ation()); | 852 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), visualViewport.visibleRect().loc
ation()); |
| 852 } | 853 } |
| 853 | 854 |
| 854 // Test restoring a HistoryItem without the visual viewport offset falls back to
distributing | 855 // Test restoring a HistoryItem without the visual viewport offset falls back to
distributing |
| 855 // the scroll offset between the main frame and the visual viewport. | 856 // the scroll offset between the main frame and the visual viewport. |
| 856 TEST_F(VisualViewportTest, TestRestoredFromLegacyHistoryItem) | 857 TEST_F(VisualViewportTest, TestRestoredFromLegacyHistoryItem) |
| 857 { | 858 { |
| 858 initializeWithDesktopSettings(); | 859 initializeWithDesktopSettings(); |
| 859 webViewImpl()->resize(IntSize(100, 150)); | 860 webViewImpl()->resize(IntSize(100, 150)); |
| 860 | 861 |
| 861 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 862 registerMockedHttpURLLoad("200-by-300-viewport.html"); |
| 862 | 863 |
| 863 WebHistoryItem item; | 864 WebHistoryItem item; |
| 864 item.initialize(); | 865 item.initialize(); |
| 865 WebURL destinationURL(URLTestHelpers::toKURL(m_baseURL + "200-by-300-viewpor
t.html")); | 866 WebURL destinationURL(URLTestHelpers::toKURL(m_baseURL + "200-by-300-viewpor
t.html")); |
| 866 item.setURLString(destinationURL.string()); | 867 item.setURLString(destinationURL.string()); |
| 867 // (-1, -1) will be used if the HistoryItem is an older version prior to hav
ing | 868 // (-1, -1) will be used if the HistoryItem is an older version prior to hav
ing |
| 868 // visual viewport scroll offset. | 869 // visual viewport scroll offset. |
| 869 item.setVisualViewportScrollOffset(WebFloatPoint(-1, -1)); | 870 item.setVisualViewportScrollOffset(WebFloatPoint(-1, -1)); |
| 870 item.setScrollOffset(WebPoint(120, 180)); | 871 item.setScrollOffset(WebPoint(120, 180)); |
| 871 item.setPageScaleFactor(2); | 872 item.setPageScaleFactor(2); |
| 872 | 873 |
| 873 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebURLRequest::UseProtocolCachePolicy); | 874 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebCachePolicy::UseProtocolCachePolicy); |
| 874 | 875 |
| 875 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 876 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 876 EXPECT_EQ(2, visualViewport.scale()); | 877 EXPECT_EQ(2, visualViewport.scale()); |
| 877 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 878 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
| 878 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), visualViewport.visibleRect().locat
ion()); | 879 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), visualViewport.visibleRect().locat
ion()); |
| 879 } | 880 } |
| 880 | 881 |
| 881 // Test that navigation to a new page with a different sized main frame doesn't | 882 // Test that navigation to a new page with a different sized main frame doesn't |
| 882 // clobber the history item's main frame scroll offset. crbug.com/371867 | 883 // clobber the history item's main frame scroll offset. crbug.com/371867 |
| 883 TEST_P(ParameterizedVisualViewportTest, TestNavigateToSmallerFrameViewHistoryIte
mClobberBug) | 884 TEST_P(ParameterizedVisualViewportTest, TestNavigateToSmallerFrameViewHistoryIte
mClobberBug) |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 webViewImpl()->handleInputEvent(pinchUpdate); | 1741 webViewImpl()->handleInputEvent(pinchUpdate); |
| 1741 | 1742 |
| 1742 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); | 1743 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); |
| 1743 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1744 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1744 | 1745 |
| 1745 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1746 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); |
| 1746 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1747 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); |
| 1747 } | 1748 } |
| 1748 | 1749 |
| 1749 } // namespace | 1750 } // namespace |
| OLD | NEW |