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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/frame/PinchViewport.h" | 7 #include "core/frame/PinchViewport.h" |
8 | 8 |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 navigateTo(m_baseURL + "content-width-1000.html"); | 1061 navigateTo(m_baseURL + "content-width-1000.html"); |
1062 | 1062 |
1063 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | 1063 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
1064 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1064 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1065 | 1065 |
1066 pinchViewport.setScale(1); | 1066 pinchViewport.setScale(1); |
1067 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.visibleRect().size()); | 1067 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.visibleRect().size()); |
1068 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | 1068 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
1069 | 1069 |
1070 // Simulate bringing down the top controls by 20px. | 1070 // Simulate bringing down the top controls by 20px. |
1071 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | 1071 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
20); |
1072 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.visibleRect().size()); | 1072 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.visibleRect().size()); |
1073 | 1073 |
1074 // Test that the scroll bounds are adjusted appropriately: the pinch viewpor
t | 1074 // Test that the scroll bounds are adjusted appropriately: the pinch viewpor
t |
1075 // should be shrunk by 20px to 130px. The outer viewport was shrunk to maint
ain the | 1075 // should be shrunk by 20px to 130px. The outer viewport was shrunk to maint
ain the |
1076 // aspect ratio so it's height is 1300px. | 1076 // aspect ratio so it's height is 1300px. |
1077 pinchViewport.move(FloatPoint(10000, 10000)); | 1077 pinchViewport.move(FloatPoint(10000, 10000)); |
1078 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | 1078 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
1079 | 1079 |
1080 // The outer viewport (FrameView) should be affected as well. | 1080 // The outer viewport (FrameView) should be affected as well. |
1081 frameView.scrollBy(IntSize(10000, 10000)); | 1081 frameView.scrollBy(IntSize(10000, 10000)); |
1082 EXPECT_POINT_EQ( | 1082 EXPECT_POINT_EQ( |
1083 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | 1083 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
1084 frameView.scrollPosition()); | 1084 frameView.scrollPosition()); |
1085 | 1085 |
1086 // Simulate bringing up the top controls by 10.5px. | 1086 // Simulate bringing up the top controls by 10.5px. |
1087 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, -10.5f); | 1087 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
-10.5f); |
1088 EXPECT_SIZE_EQ(FloatSize(100, 140.5f), pinchViewport.visibleRect().size()); | 1088 EXPECT_SIZE_EQ(FloatSize(100, 140.5f), pinchViewport.visibleRect().size()); |
1089 | 1089 |
1090 // maximumScrollPosition floors the final values. | 1090 // maximumScrollPosition floors the final values. |
1091 pinchViewport.move(FloatPoint(10000, 10000)); | 1091 pinchViewport.move(FloatPoint(10000, 10000)); |
1092 EXPECT_POINT_EQ(FloatPoint(900, floor(1405 - 140.5f)), pinchViewport.locatio
n()); | 1092 EXPECT_POINT_EQ(FloatPoint(900, floor(1405 - 140.5f)), pinchViewport.locatio
n()); |
1093 | 1093 |
1094 // The outer viewport (FrameView) should be affected as well. | 1094 // The outer viewport (FrameView) should be affected as well. |
1095 frameView.scrollBy(IntSize(10000, 10000)); | 1095 frameView.scrollBy(IntSize(10000, 10000)); |
1096 EXPECT_POINT_EQ( | 1096 EXPECT_POINT_EQ( |
1097 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | 1097 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
(...skipping 11 matching lines...) Expand all Loading... |
1109 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | 1109 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
1110 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1110 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1111 | 1111 |
1112 pinchViewport.setScale(2); | 1112 pinchViewport.setScale(2); |
1113 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); | 1113 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); |
1114 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | 1114 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
1115 | 1115 |
1116 // Simulate bringing down the top controls by 20px. Since we're zoomed in, | 1116 // Simulate bringing down the top controls by 20px. Since we're zoomed in, |
1117 // the top controls take up half as much space (in document-space) than | 1117 // the top controls take up half as much space (in document-space) than |
1118 // they do at an unzoomed level. | 1118 // they do at an unzoomed level. |
1119 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | 1119 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
20); |
1120 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); | 1120 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); |
1121 | 1121 |
1122 // Test that the scroll bounds are adjusted appropriately. | 1122 // Test that the scroll bounds are adjusted appropriately. |
1123 pinchViewport.move(FloatPoint(10000, 10000)); | 1123 pinchViewport.move(FloatPoint(10000, 10000)); |
1124 EXPECT_POINT_EQ(FloatPoint(950, 1300 - 65), pinchViewport.location()); | 1124 EXPECT_POINT_EQ(FloatPoint(950, 1300 - 65), pinchViewport.location()); |
1125 | 1125 |
1126 // The outer viewport (FrameView) should be affected as well. | 1126 // The outer viewport (FrameView) should be affected as well. |
1127 frameView.scrollBy(IntSize(10000, 10000)); | 1127 frameView.scrollBy(IntSize(10000, 10000)); |
1128 IntPoint expected = expectedMaxFrameViewScrollOffset(pinchViewport, frameVie
w); | 1128 IntPoint expected = expectedMaxFrameViewScrollOffset(pinchViewport, frameVie
w); |
1129 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1129 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
1130 | 1130 |
1131 // Scale back out, FrameView max scroll shouldn't have changed. Pinch | 1131 // Scale back out, FrameView max scroll shouldn't have changed. Pinch |
1132 // viewport should be moved up to accomodate larger view. | 1132 // viewport should be moved up to accomodate larger view. |
1133 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.5f, 0); | 1133 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 0.5
f, 0); |
1134 EXPECT_EQ(1, pinchViewport.scale()); | 1134 EXPECT_EQ(1, pinchViewport.scale()); |
1135 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1135 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
1136 frameView.scrollBy(IntSize(10000, 10000)); | 1136 frameView.scrollBy(IntSize(10000, 10000)); |
1137 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1137 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
1138 | 1138 |
1139 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | 1139 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
1140 pinchViewport.move(FloatPoint(10000, 10000)); | 1140 pinchViewport.move(FloatPoint(10000, 10000)); |
1141 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | 1141 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
1142 | 1142 |
1143 // Scale out, use a scale that causes fractional rects. | 1143 // Scale out, use a scale that causes fractional rects. |
1144 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.8f, -20); | 1144 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 0.8
f, -20); |
1145 EXPECT_SIZE_EQ(FloatSize(125, 187.5), pinchViewport.visibleRect().size()); | 1145 EXPECT_SIZE_EQ(FloatSize(125, 187.5), pinchViewport.visibleRect().size()); |
1146 | 1146 |
1147 // Bring out the top controls by 11px. | 1147 // Bring out the top controls by 11px. |
1148 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 11); | 1148 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
11); |
1149 EXPECT_SIZE_EQ(FloatSize(125, 173.75), pinchViewport.visibleRect().size()); | 1149 EXPECT_SIZE_EQ(FloatSize(125, 173.75), pinchViewport.visibleRect().size()); |
1150 | 1150 |
1151 // Ensure max scroll offsets are updated properly. | 1151 // Ensure max scroll offsets are updated properly. |
1152 pinchViewport.move(FloatPoint(10000, 10000)); | 1152 pinchViewport.move(FloatPoint(10000, 10000)); |
1153 EXPECT_POINT_EQ(FloatPoint(875, floor(1390 - 173.75)), pinchViewport.locatio
n()); | 1153 EXPECT_POINT_EQ(FloatPoint(875, floor(1390 - 173.75)), pinchViewport.locatio
n()); |
1154 | 1154 |
1155 frameView.scrollBy(IntSize(10000, 10000)); | 1155 frameView.scrollBy(IntSize(10000, 10000)); |
1156 EXPECT_POINT_EQ( | 1156 EXPECT_POINT_EQ( |
1157 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | 1157 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
1158 frameView.scrollPosition()); | 1158 frameView.scrollPosition()); |
1159 | 1159 |
1160 } | 1160 } |
1161 | 1161 |
1162 TEST_F(PinchViewportTest, TestTopControlsAdjustmentAndResize) | 1162 TEST_F(PinchViewportTest, TestTopControlsAdjustmentAndResize) |
1163 { | 1163 { |
1164 initializeWithAndroidSettings(); | 1164 initializeWithAndroidSettings(); |
1165 webViewImpl()->resize(IntSize(100, 150)); | 1165 webViewImpl()->resize(IntSize(100, 150)); |
1166 | 1166 |
1167 registerMockedHttpURLLoad("content-width-1000.html"); | 1167 registerMockedHttpURLLoad("content-width-1000.html"); |
1168 navigateTo(m_baseURL + "content-width-1000.html"); | 1168 navigateTo(m_baseURL + "content-width-1000.html"); |
1169 | 1169 |
1170 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | 1170 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
1171 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1171 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1172 | 1172 |
1173 pinchViewport.setScale(2); | 1173 pinchViewport.setScale(2); |
1174 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); | 1174 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); |
1175 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | 1175 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
1176 | 1176 |
1177 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | 1177 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
20); |
1178 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.size()); | 1178 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.size()); |
1179 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); | 1179 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); |
1180 | 1180 |
1181 // Scroll all the way to the bottom. | 1181 // Scroll all the way to the bottom. |
1182 pinchViewport.move(FloatPoint(10000, 10000)); | 1182 pinchViewport.move(FloatPoint(10000, 10000)); |
1183 frameView.scrollBy(IntSize(10000, 10000)); | 1183 frameView.scrollBy(IntSize(10000, 10000)); |
1184 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(pinchViewport,
frameView); | 1184 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(pinchViewport,
frameView); |
1185 FloatPoint pinchViewportExpected = FloatPoint(950, 1300 - 65); | 1185 FloatPoint pinchViewportExpected = FloatPoint(950, 1300 - 65); |
1186 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); | 1186 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); |
1187 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1187 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
(...skipping 28 matching lines...) Expand all Loading... |
1216 frameView.updateLayoutAndStyleForPainting(); | 1216 frameView.updateLayoutAndStyleForPainting(); |
1217 | 1217 |
1218 EXPECT_SIZE_EQ(IntSize(1500, 2400), IntSize(scrollLayer->bounds())); | 1218 EXPECT_SIZE_EQ(IntSize(1500, 2400), IntSize(scrollLayer->bounds())); |
1219 } | 1219 } |
1220 | 1220 |
1221 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the | 1221 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the |
1222 // main frame's scroll offset. crbug.com/428193. | 1222 // main frame's scroll offset. crbug.com/428193. |
1223 TEST_F(PinchViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) | 1223 TEST_F(PinchViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) |
1224 { | 1224 { |
1225 initializeWithAndroidSettings(); | 1225 initializeWithAndroidSettings(); |
1226 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 500); | 1226 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
500); |
1227 webViewImpl()->setTopControlsLayoutHeight(500); | 1227 webViewImpl()->setTopControlsLayoutHeight(500); |
1228 webViewImpl()->resize(IntSize(1000, 1000)); | 1228 webViewImpl()->resize(IntSize(1000, 1000)); |
1229 | 1229 |
1230 registerMockedHttpURLLoad("content-width-1000.html"); | 1230 registerMockedHttpURLLoad("content-width-1000.html"); |
1231 navigateTo(m_baseURL + "content-width-1000.html"); | 1231 navigateTo(m_baseURL + "content-width-1000.html"); |
1232 | 1232 |
1233 // Scroll the FrameView to the bottom of the page but "hide" the top | 1233 // Scroll the FrameView to the bottom of the page but "hide" the top |
1234 // controls on the compositor side so the max scroll position should account | 1234 // controls on the compositor side so the max scroll position should account |
1235 // for the full viewport height. | 1235 // for the full viewport height. |
1236 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, -500); | 1236 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), WebFloatSize(), 1,
-500); |
1237 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1237 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1238 frameView.setScrollPosition(IntPoint(0, 10000)); | 1238 frameView.setScrollPosition(IntPoint(0, 10000)); |
1239 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1239 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
1240 | 1240 |
1241 // Now send the resize, make sure the scroll offset doesn't change. | 1241 // Now send the resize, make sure the scroll offset doesn't change. |
1242 webViewImpl()->setTopControlsLayoutHeight(0); | 1242 webViewImpl()->setTopControlsLayoutHeight(0); |
1243 webViewImpl()->resize(IntSize(1000, 1500)); | 1243 webViewImpl()->resize(IntSize(1000, 1500)); |
1244 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1244 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
1245 } | 1245 } |
1246 | 1246 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 navigateTo(m_baseURL + "content-width-1000.html"); | 1305 navigateTo(m_baseURL + "content-width-1000.html"); |
1306 | 1306 |
1307 WebLocalFrameImpl* localFrame = webViewImpl()->mainFrameImpl(); | 1307 WebLocalFrameImpl* localFrame = webViewImpl()->mainFrameImpl(); |
1308 FrameView& frameView = *localFrame->frameView(); | 1308 FrameView& frameView = *localFrame->frameView(); |
1309 localFrame->createFrameView(); | 1309 localFrame->createFrameView(); |
1310 | 1310 |
1311 EXPECT_SIZE_EQ(IntSize(200, 400), frameView.frameRect().size()); | 1311 EXPECT_SIZE_EQ(IntSize(200, 400), frameView.frameRect().size()); |
1312 } | 1312 } |
1313 | 1313 |
1314 } // namespace | 1314 } // namespace |
OLD | NEW |