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" |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 EXPECT_FALSE(navbar->NeedsLayout()); | 1106 EXPECT_FALSE(navbar->NeedsLayout()); |
1107 | 1107 |
1108 frame()->View()->Resize(IntSize(500, 200)); | 1108 frame()->View()->Resize(IntSize(500, 200)); |
1109 | 1109 |
1110 EXPECT_TRUE(navbar->NeedsLayout()); | 1110 EXPECT_TRUE(navbar->NeedsLayout()); |
1111 } | 1111 } |
1112 | 1112 |
1113 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 1113 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
1114 public: | 1114 public: |
1115 MOCK_METHOD1(ShowContextMenu, void(const WebContextMenuData&)); | 1115 MOCK_METHOD1(ShowContextMenu, void(const WebContextMenuData&)); |
1116 MOCK_METHOD1(DidChangeScrollOffset, void(WebLocalFrame*)); | 1116 MOCK_METHOD0(DidChangeScrollOffset, void()); |
1117 }; | 1117 }; |
1118 | 1118 |
1119 MATCHER_P2(ContextMenuAtLocation, | 1119 MATCHER_P2(ContextMenuAtLocation, |
1120 x, | 1120 x, |
1121 y, | 1121 y, |
1122 std::string(negation ? "is" : "isn't") + " at expected location [" + | 1122 std::string(negation ? "is" : "isn't") + " at expected location [" + |
1123 PrintToString(x) + | 1123 PrintToString(x) + |
1124 ", " + | 1124 ", " + |
1125 PrintToString(y) + | 1125 PrintToString(y) + |
1126 "]") { | 1126 "]") { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); | 1160 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); |
1161 | 1161 |
1162 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1162 Mock::VerifyAndClearExpectations(&mockWebFrameClient); |
1163 mouseDownEvent.button = WebMouseEvent::Button::kLeft; | 1163 mouseDownEvent.button = WebMouseEvent::Button::kLeft; |
1164 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); | 1164 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); |
1165 | 1165 |
1166 // Now pinch zoom into the page and move the visual viewport. The context menu | 1166 // Now pinch zoom into the page and move the visual viewport. The context menu |
1167 // should still appear at the location of the event, relative to the WebView. | 1167 // should still appear at the location of the event, relative to the WebView. |
1168 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1168 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); |
1169 webViewImpl()->SetPageScaleFactor(2); | 1169 webViewImpl()->SetPageScaleFactor(2); |
1170 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset(_)); | 1170 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); |
1171 visualViewport.SetLocation(FloatPoint(60, 80)); | 1171 visualViewport.SetLocation(FloatPoint(60, 80)); |
1172 EXPECT_CALL(mockWebFrameClient, ShowContextMenu(ContextMenuAtLocation( | 1172 EXPECT_CALL(mockWebFrameClient, ShowContextMenu(ContextMenuAtLocation( |
1173 mouseDownEvent.PositionInWidget().x, | 1173 mouseDownEvent.PositionInWidget().x, |
1174 mouseDownEvent.PositionInWidget().y))); | 1174 mouseDownEvent.PositionInWidget().y))); |
1175 | 1175 |
1176 mouseDownEvent.button = WebMouseEvent::Button::kRight; | 1176 mouseDownEvent.button = WebMouseEvent::Button::kRight; |
1177 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); | 1177 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); |
1178 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); | 1178 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); |
1179 | 1179 |
1180 // Reset the old client so destruction can occur naturally. | 1180 // Reset the old client so destruction can occur naturally. |
1181 webViewImpl()->MainFrameImpl()->SetClient(oldClient); | 1181 webViewImpl()->MainFrameImpl()->SetClient(oldClient); |
1182 } | 1182 } |
1183 | 1183 |
1184 // Test that the client is notified if page scroll events. | 1184 // Test that the client is notified if page scroll events. |
1185 TEST_P(VisualViewportTest, TestClientNotifiedOfScrollEvents) { | 1185 TEST_P(VisualViewportTest, TestClientNotifiedOfScrollEvents) { |
1186 initializeWithAndroidSettings(); | 1186 initializeWithAndroidSettings(); |
1187 webViewImpl()->Resize(IntSize(200, 300)); | 1187 webViewImpl()->Resize(IntSize(200, 300)); |
1188 | 1188 |
1189 registerMockedHttpURLLoad("200-by-300.html"); | 1189 registerMockedHttpURLLoad("200-by-300.html"); |
1190 navigateTo(m_baseURL + "200-by-300.html"); | 1190 navigateTo(m_baseURL + "200-by-300.html"); |
1191 | 1191 |
1192 WebFrameClient* oldClient = webViewImpl()->MainFrameImpl()->Client(); | 1192 WebFrameClient* oldClient = webViewImpl()->MainFrameImpl()->Client(); |
1193 MockWebFrameClient mockWebFrameClient; | 1193 MockWebFrameClient mockWebFrameClient; |
1194 webViewImpl()->MainFrameImpl()->SetClient(&mockWebFrameClient); | 1194 webViewImpl()->MainFrameImpl()->SetClient(&mockWebFrameClient); |
1195 | 1195 |
1196 webViewImpl()->SetPageScaleFactor(2); | 1196 webViewImpl()->SetPageScaleFactor(2); |
1197 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1197 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); |
1198 | 1198 |
1199 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset(_)); | 1199 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); |
1200 visualViewport.SetLocation(FloatPoint(60, 80)); | 1200 visualViewport.SetLocation(FloatPoint(60, 80)); |
1201 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1201 Mock::VerifyAndClearExpectations(&mockWebFrameClient); |
1202 | 1202 |
1203 // Scroll vertically. | 1203 // Scroll vertically. |
1204 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset(_)); | 1204 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); |
1205 visualViewport.SetLocation(FloatPoint(60, 90)); | 1205 visualViewport.SetLocation(FloatPoint(60, 90)); |
1206 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1206 Mock::VerifyAndClearExpectations(&mockWebFrameClient); |
1207 | 1207 |
1208 // Scroll horizontally. | 1208 // Scroll horizontally. |
1209 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset(_)); | 1209 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); |
1210 visualViewport.SetLocation(FloatPoint(70, 90)); | 1210 visualViewport.SetLocation(FloatPoint(70, 90)); |
1211 | 1211 |
1212 // Reset the old client so destruction can occur naturally. | 1212 // Reset the old client so destruction can occur naturally. |
1213 webViewImpl()->MainFrameImpl()->SetClient(oldClient); | 1213 webViewImpl()->MainFrameImpl()->SetClient(oldClient); |
1214 } | 1214 } |
1215 | 1215 |
1216 // Tests that calling scroll into view on a visible element doesn't cause | 1216 // Tests that calling scroll into view on a visible element doesn't cause |
1217 // a scroll due to a fractional offset. Bug crbug.com/463356. | 1217 // a scroll due to a fractional offset. Bug crbug.com/463356. |
1218 TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { | 1218 TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { |
1219 initializeWithAndroidSettings(); | 1219 initializeWithAndroidSettings(); |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2448 " body {" | 2448 " body {" |
2449 " margin: 0px;" | 2449 " margin: 0px;" |
2450 " }" | 2450 " }" |
2451 " div { height:110vh; width: 110vw; }" | 2451 " div { height:110vh; width: 110vw; }" |
2452 "</style>" | 2452 "</style>" |
2453 "<div></div>", | 2453 "<div></div>", |
2454 baseURL); | 2454 baseURL); |
2455 } | 2455 } |
2456 | 2456 |
2457 } // namespace | 2457 } // namespace |
OLD | NEW |