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/BrowserControls.h" | 8 #include "core/frame/BrowserControls.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/loader/DocumentLoader.h" |
17 #include "core/page/Page.h" | 18 #include "core/page/Page.h" |
18 #include "core/paint/PaintLayer.h" | 19 #include "core/paint/PaintLayer.h" |
19 #include "platform/geometry/DoublePoint.h" | 20 #include "platform/geometry/DoublePoint.h" |
20 #include "platform/geometry/DoubleRect.h" | 21 #include "platform/geometry/DoubleRect.h" |
21 #include "platform/graphics/CompositorElementId.h" | 22 #include "platform/graphics/CompositorElementId.h" |
22 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 23 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
23 #include "platform/testing/URLTestHelpers.h" | 24 #include "platform/testing/URLTestHelpers.h" |
24 #include "platform/testing/UnitTestHelpers.h" | 25 #include "platform/testing/UnitTestHelpers.h" |
25 #include "public/platform/Platform.h" | 26 #include "public/platform/Platform.h" |
26 #include "public/platform/WebCachePolicy.h" | 27 #include "public/platform/WebCachePolicy.h" |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 initializeWithDesktopSettings(); | 870 initializeWithDesktopSettings(); |
870 webViewImpl()->resize(IntSize(200, 300)); | 871 webViewImpl()->resize(IntSize(200, 300)); |
871 webViewImpl()->updateAllLifecyclePhases(); | 872 webViewImpl()->updateAllLifecyclePhases(); |
872 | 873 |
873 registerMockedHttpURLLoad("200-by-300.html"); | 874 registerMockedHttpURLLoad("200-by-300.html"); |
874 navigateTo(m_baseURL + "200-by-300.html"); | 875 navigateTo(m_baseURL + "200-by-300.html"); |
875 | 876 |
876 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 877 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
877 toLocalFrame(webViewImpl()->page()->mainFrame()) | 878 toLocalFrame(webViewImpl()->page()->mainFrame()) |
878 ->loader() | 879 ->loader() |
879 .currentItem() | 880 .documentLoader() |
| 881 ->historyItem() |
880 ->visualViewportScrollOffset()); | 882 ->visualViewportScrollOffset()); |
881 | 883 |
882 VisualViewport& visualViewport = frame()->page()->visualViewport(); | 884 VisualViewport& visualViewport = frame()->page()->visualViewport(); |
883 visualViewport.setScale(2); | 885 visualViewport.setScale(2); |
884 | 886 |
885 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) | 887 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) |
886 ->loader() | 888 ->loader() |
887 .currentItem() | 889 .documentLoader() |
| 890 ->historyItem() |
888 ->pageScaleFactor()); | 891 ->pageScaleFactor()); |
889 | 892 |
890 visualViewport.setLocation(FloatPoint(10, 20)); | 893 visualViewport.setLocation(FloatPoint(10, 20)); |
891 | 894 |
892 EXPECT_SIZE_EQ(ScrollOffset(10, 20), | 895 EXPECT_SIZE_EQ(ScrollOffset(10, 20), |
893 toLocalFrame(webViewImpl()->page()->mainFrame()) | 896 toLocalFrame(webViewImpl()->page()->mainFrame()) |
894 ->loader() | 897 ->loader() |
895 .currentItem() | 898 .documentLoader() |
| 899 ->historyItem() |
896 ->visualViewportScrollOffset()); | 900 ->visualViewportScrollOffset()); |
897 } | 901 } |
898 | 902 |
899 // Test restoring a HistoryItem properly restores the visual viewport's state. | 903 // Test restoring a HistoryItem properly restores the visual viewport's state. |
900 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { | 904 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { |
901 initializeWithDesktopSettings(); | 905 initializeWithDesktopSettings(); |
902 webViewImpl()->resize(IntSize(200, 300)); | 906 webViewImpl()->resize(IntSize(200, 300)); |
903 | 907 |
904 registerMockedHttpURLLoad("200-by-300.html"); | 908 registerMockedHttpURLLoad("200-by-300.html"); |
905 | 909 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView(); | 972 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView(); |
969 frameView->layoutViewportScrollableArea()->setScrollOffset( | 973 frameView->layoutViewportScrollableArea()->setScrollOffset( |
970 ScrollOffset(0, 1000), ProgrammaticScroll); | 974 ScrollOffset(0, 1000), ProgrammaticScroll); |
971 | 975 |
972 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size()); | 976 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size()); |
973 | 977 |
974 VisualViewport& visualViewport = frame()->page()->visualViewport(); | 978 VisualViewport& visualViewport = frame()->page()->visualViewport(); |
975 visualViewport.setScale(2); | 979 visualViewport.setScale(2); |
976 visualViewport.setLocation(FloatPoint(350, 350)); | 980 visualViewport.setLocation(FloatPoint(350, 350)); |
977 | 981 |
978 Persistent<HistoryItem> firstItem = | 982 Persistent<HistoryItem> firstItem = webViewImpl() |
979 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem(); | 983 ->mainFrameImpl() |
| 984 ->frame() |
| 985 ->loader() |
| 986 .documentLoader() |
| 987 ->historyItem(); |
980 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->getScrollOffset()); | 988 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->getScrollOffset()); |
981 | 989 |
982 // Now navigate to a page which causes a smaller frameView. Make sure that | 990 // Now navigate to a page which causes a smaller frameView. Make sure that |
983 // navigating doesn't cause the history item to set a new scroll offset | 991 // navigating doesn't cause the history item to set a new scroll offset |
984 // before the item was replaced. | 992 // before the item was replaced. |
985 navigateTo("about:blank"); | 993 navigateTo("about:blank"); |
986 frameView = webViewImpl()->mainFrameImpl()->frameView(); | 994 frameView = webViewImpl()->mainFrameImpl()->frameView(); |
987 | 995 |
988 EXPECT_NE(firstItem, | 996 EXPECT_NE(firstItem, webViewImpl() |
989 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem()); | 997 ->mainFrameImpl() |
| 998 ->frame() |
| 999 ->loader() |
| 1000 .documentLoader() |
| 1001 ->historyItem()); |
990 EXPECT_LT(frameView->frameRect().size().width(), 1000); | 1002 EXPECT_LT(frameView->frameRect().size().width(), 1000); |
991 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->getScrollOffset()); | 1003 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->getScrollOffset()); |
992 } | 1004 } |
993 | 1005 |
994 // Test that the coordinates sent into moveRangeSelection are offset by the | 1006 // Test that the coordinates sent into moveRangeSelection are offset by the |
995 // visual viewport's location. | 1007 // visual viewport's location. |
996 TEST_P(VisualViewportTest, | 1008 TEST_P(VisualViewportTest, |
997 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { | 1009 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { |
998 initializeWithDesktopSettings(); | 1010 initializeWithDesktopSettings(); |
999 webViewImpl()->settings()->setDefaultFontSize(12); | 1011 webViewImpl()->settings()->setDefaultFontSize(12); |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 " body {" | 2442 " body {" |
2431 " margin: 0px;" | 2443 " margin: 0px;" |
2432 " }" | 2444 " }" |
2433 " div { height:110vh; width: 110vw; }" | 2445 " div { height:110vh; width: 110vw; }" |
2434 "</style>" | 2446 "</style>" |
2435 "<div></div>", | 2447 "<div></div>", |
2436 baseURL); | 2448 baseURL); |
2437 } | 2449 } |
2438 | 2450 |
2439 } // namespace | 2451 } // namespace |
OLD | NEW |