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