| 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/frame/TopControls.h" |
| 11 #include "core/html/HTMLBodyElement.h" | 12 #include "core/html/HTMLBodyElement.h" |
| 12 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
| 13 #include "core/input/EventHandler.h" | 14 #include "core/input/EventHandler.h" |
| 14 #include "core/layout/LayoutObject.h" | 15 #include "core/layout/LayoutObject.h" |
| 15 #include "core/layout/api/LayoutViewItem.h" | 16 #include "core/layout/api/LayoutViewItem.h" |
| 16 #include "core/layout/compositing/PaintLayerCompositor.h" | 17 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 17 #include "core/page/Page.h" | 18 #include "core/page/Page.h" |
| 18 #include "platform/PlatformGestureEvent.h" | 19 #include "platform/PlatformGestureEvent.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" |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 | 1171 |
| 1171 EXPECT_POINT_EQ(DoublePoint(0, 900.5), layoutViewportScrollableArea->scrollP
ositionDouble()); | 1172 EXPECT_POINT_EQ(DoublePoint(0, 900.5), layoutViewportScrollableArea->scrollP
ositionDouble()); |
| 1172 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); | 1173 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); |
| 1173 } | 1174 } |
| 1174 | 1175 |
| 1175 // Top controls can make an unscrollable page temporarily scrollable, causing | 1176 // Top controls can make an unscrollable page temporarily scrollable, causing |
| 1176 // a scroll clamp when the page is resized. Make sure this bug is fixed. | 1177 // a scroll clamp when the page is resized. Make sure this bug is fixed. |
| 1177 // crbug.com/437620 | 1178 // crbug.com/437620 |
| 1178 TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) | 1179 TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) |
| 1179 { | 1180 { |
| 1181 RuntimeEnabledFeatures::setInertTopControlsEnabled(false); |
| 1180 initializeWithAndroidSettings(); | 1182 initializeWithAndroidSettings(); |
| 1181 webViewImpl()->resize(IntSize(980, 650)); | 1183 webViewImpl()->resizeWithTopControls(IntSize(980, 650), 20, false); |
| 1182 | 1184 |
| 1183 navigateTo("about:blank"); | 1185 navigateTo("about:blank"); |
| 1184 | 1186 |
| 1185 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 1187 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 1186 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1188 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1187 | 1189 |
| 1188 webViewImpl()->setTopControlsHeight(20, false); | |
| 1189 | |
| 1190 // Outer viewport isn't scrollable | 1190 // Outer viewport isn't scrollable |
| 1191 EXPECT_SIZE_EQ(IntSize(980, 650), frameView.visibleContentRect().size()); | 1191 EXPECT_SIZE_EQ(IntSize(980, 650), frameView.visibleContentRect().size()); |
| 1192 | 1192 |
| 1193 visualViewport.setScale(2); | 1193 visualViewport.setScale(2); |
| 1194 visualViewport.move(FloatPoint(0, 40)); | 1194 visualViewport.move(FloatPoint(0, 40)); |
| 1195 | 1195 |
| 1196 // Simulate bringing down the top controls by 20px but counterscrolling the
outer viewport. | 1196 // Simulate bringing down the top controls by 20px but counterscrolling the
outer viewport. |
| 1197 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(0, 20), WebF
loatSize(), 1, 1); | 1197 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(0, 20), WebF
loatSize(), 1, 1); |
| 1198 | 1198 |
| 1199 EXPECT_EQ(20, frameView.layoutViewportScrollableArea()->scrollPosition().y()
); | 1199 EXPECT_EQ(20, frameView.layoutViewportScrollableArea()->scrollPosition().y()
); |
| 1200 | 1200 |
| 1201 webViewImpl()->setTopControlsHeight(20, true); | 1201 webViewImpl()->resizeWithTopControls(WebSize(980, 630), 20, true); |
| 1202 webViewImpl()->resize(WebSize(980, 630)); | |
| 1203 | 1202 |
| 1204 EXPECT_EQ(0, frameView.layoutViewportScrollableArea()->scrollPosition().y())
; | 1203 EXPECT_EQ(0, frameView.layoutViewportScrollableArea()->scrollPosition().y())
; |
| 1205 EXPECT_EQ(60, visualViewport.location().y()); | 1204 EXPECT_EQ(60, visualViewport.location().y()); |
| 1206 } | 1205 } |
| 1207 | 1206 |
| 1208 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport,
FrameView& frameView) | 1207 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport,
FrameView& frameView) |
| 1209 { | 1208 { |
| 1210 float aspectRatio = visualViewport.visibleRect().width() / visualViewport.vi
sibleRect().height(); | 1209 float aspectRatio = visualViewport.visibleRect().width() / visualViewport.vi
sibleRect().height(); |
| 1211 float newHeight = frameView.frameRect().width() / aspectRatio; | 1210 float newHeight = frameView.frameRect().width() / aspectRatio; |
| 1212 return IntPoint( | 1211 return IntPoint( |
| 1213 frameView.contentsSize().width() - frameView.frameRect().width(), | 1212 frameView.contentsSize().width() - frameView.frameRect().width(), |
| 1214 frameView.contentsSize().height() - newHeight); | 1213 frameView.contentsSize().height() - newHeight); |
| 1215 } | 1214 } |
| 1216 | 1215 |
| 1217 TEST_F(VisualViewportTest, TestTopControlsAdjustment) | 1216 TEST_F(VisualViewportTest, TestTopControlsAdjustment) |
| 1218 { | 1217 { |
| 1219 initializeWithAndroidSettings(); | 1218 initializeWithAndroidSettings(); |
| 1220 webViewImpl()->resize(IntSize(500, 450)); | 1219 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); |
| 1221 | 1220 |
| 1222 registerMockedHttpURLLoad("content-width-1000.html"); | 1221 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1223 navigateTo(m_baseURL + "content-width-1000.html"); | 1222 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1224 | 1223 |
| 1225 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 1224 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 1226 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1225 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1227 | 1226 |
| 1228 webViewImpl()->setTopControlsHeight(20, false); | |
| 1229 | |
| 1230 visualViewport.setScale(1); | 1227 visualViewport.setScale(1); |
| 1231 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); | 1228 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); |
| 1232 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1229 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1233 | 1230 |
| 1234 // Simulate bringing down the top controls by 20px. | 1231 // Simulate bringing down the top controls by 20px. |
| 1235 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); | 1232 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); |
| 1236 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); | 1233 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); |
| 1237 | 1234 |
| 1238 // Test that the scroll bounds are adjusted appropriately: the visual viewpo
rt | 1235 // Test that the scroll bounds are adjusted appropriately: the visual viewpo
rt |
| 1239 // should be shrunk by 20px to 430px. The outer viewport was shrunk to maint
ain the | 1236 // should be shrunk by 20px to 430px. The outer viewport was shrunk to maint
ain the |
| 1240 // aspect ratio so it's height is 860px. | 1237 // aspect ratio so it's height is 860px. |
| 1241 visualViewport.move(FloatPoint(10000, 10000)); | 1238 visualViewport.move(FloatPoint(10000, 10000)); |
| 1242 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); | 1239 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); |
| 1243 | 1240 |
| 1244 // The outer viewport (FrameView) should be affected as well. | 1241 // The outer viewport (FrameView) should be affected as well. |
| 1245 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1242 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1246 EXPECT_POINT_EQ( | 1243 EXPECT_POINT_EQ( |
| 1247 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1244 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1248 frameView.scrollPosition()); | 1245 frameView.scrollPosition()); |
| 1249 | 1246 |
| 1250 // Simulate bringing up the top controls by 10.5px. | 1247 // Simulate bringing up the top controls by 10.5px. |
| 1251 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, -10.5f / 20); | 1248 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, -10.5f / 20); |
| 1252 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), visualViewport.visibleRect().si
ze()); | 1249 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), visualViewport.visibleRect().si
ze()); |
| 1253 | 1250 |
| 1254 // maximumScrollPosition floors the final values. | 1251 // maximumScrollPosition |ceil|s the top controls adjustment. |
| 1255 visualViewport.move(FloatPoint(10000, 10000)); | 1252 visualViewport.move(FloatPoint(10000, 10000)); |
| 1256 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 440.5f), visualViewport.location
()); | 1253 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location())
; |
| 1257 | 1254 |
| 1258 // The outer viewport (FrameView) should be affected as well. | 1255 // The outer viewport (FrameView) should be affected as well. |
| 1259 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1256 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1260 EXPECT_POINT_EQ( | 1257 EXPECT_POINT_EQ( |
| 1261 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1258 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1262 frameView.scrollPosition()); | 1259 frameView.scrollPosition()); |
| 1263 } | 1260 } |
| 1264 | 1261 |
| 1265 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) | 1262 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) |
| 1266 { | 1263 { |
| 1267 initializeWithAndroidSettings(); | 1264 initializeWithAndroidSettings(); |
| 1268 webViewImpl()->resize(IntSize(500, 450)); | 1265 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); |
| 1269 | 1266 |
| 1270 registerMockedHttpURLLoad("content-width-1000.html"); | 1267 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1271 navigateTo(m_baseURL + "content-width-1000.html"); | 1268 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1272 | 1269 |
| 1273 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 1270 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 1274 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1271 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1275 | 1272 |
| 1276 webViewImpl()->setTopControlsHeight(20, false); | |
| 1277 | |
| 1278 visualViewport.setScale(2); | 1273 visualViewport.setScale(2); |
| 1279 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1274 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
| 1280 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1275 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1281 | 1276 |
| 1282 // Simulate bringing down the top controls by 20px. Since we're zoomed in, | 1277 // Simulate bringing down the top controls by 20px. Since we're zoomed in, |
| 1283 // the top controls take up half as much space (in document-space) than | 1278 // the top controls take up half as much space (in document-space) than |
| 1284 // they do at an unzoomed level. | 1279 // they do at an unzoomed level. |
| 1285 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); | 1280 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); |
| 1286 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1281 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
| 1287 | 1282 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1318 visualViewport.move(FloatPoint(10000, 10000)); | 1313 visualViewport.move(FloatPoint(10000, 10000)); |
| 1319 EXPECT_FLOAT_POINT_EQ(FloatPoint(375, 877.5 - 548.75), visualViewport.locati
on()); | 1314 EXPECT_FLOAT_POINT_EQ(FloatPoint(375, 877.5 - 548.75), visualViewport.locati
on()); |
| 1320 | 1315 |
| 1321 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1316 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1322 EXPECT_POINT_EQ( | 1317 EXPECT_POINT_EQ( |
| 1323 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1318 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1324 frameView.scrollPosition()); | 1319 frameView.scrollPosition()); |
| 1325 | 1320 |
| 1326 } | 1321 } |
| 1327 | 1322 |
| 1323 // Tests that a scroll all the way to the bottom of the page, while hiding the |
| 1324 // top controls doesn't cause a clamp in the viewport scroll offset when the |
| 1325 // top controls initiated resize occurs. |
| 1328 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) | 1326 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) |
| 1329 { | 1327 { |
| 1328 int topControlsHeight = 20; |
| 1329 int visualViewportHeight = 450; |
| 1330 int layoutViewportHeight = 900; |
| 1331 float pageScale = 2; |
| 1332 float minPageScale = 0.5; |
| 1333 |
| 1330 initializeWithAndroidSettings(); | 1334 initializeWithAndroidSettings(); |
| 1331 webViewImpl()->resize(IntSize(500, 450)); | 1335 |
| 1336 // Initialize with top controls showing and shrinking the Blink size. |
| 1337 webViewImpl()->resizeWithTopControls( |
| 1338 WebSize(500, visualViewportHeight - topControlsHeight), |
| 1339 20, |
| 1340 true); |
| 1341 webViewImpl()->topControls().setShownRatio(1); |
| 1332 | 1342 |
| 1333 registerMockedHttpURLLoad("content-width-1000.html"); | 1343 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1334 navigateTo(m_baseURL + "content-width-1000.html"); | 1344 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1335 | 1345 |
| 1336 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | 1346 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 1337 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1347 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1338 | 1348 |
| 1339 visualViewport.setScale(2); | 1349 visualViewport.setScale(pageScale); |
| 1340 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1350 EXPECT_SIZE_EQ( |
| 1341 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1351 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| 1352 visualViewport.visibleRect().size()); |
| 1353 EXPECT_SIZE_EQ( |
| 1354 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
| 1355 frameView.frameRect().size()); |
| 1356 EXPECT_SIZE_EQ( |
| 1357 IntSize(500, visualViewportHeight - topControlsHeight), |
| 1358 visualViewport.size()); |
| 1342 | 1359 |
| 1343 webViewImpl()->setTopControlsHeight(20, false); | 1360 // Scroll all the way to the bottom, hiding the top controls in the process. |
| 1344 | |
| 1345 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); | |
| 1346 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.size()); | |
| 1347 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | |
| 1348 | |
| 1349 // Scroll all the way to the bottom. | |
| 1350 visualViewport.move(FloatPoint(10000, 10000)); | 1361 visualViewport.move(FloatPoint(10000, 10000)); |
| 1351 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1362 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1352 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(visualViewport
, frameView); | 1363 webViewImpl()->topControls().setShownRatio(0); |
| 1353 FloatPoint visualViewportExpected = FloatPoint(750, 860 - 215); | 1364 |
| 1365 EXPECT_SIZE_EQ( |
| 1366 IntSize(250, visualViewportHeight / pageScale), |
| 1367 visualViewport.visibleRect().size()); |
| 1368 |
| 1369 IntPoint frameViewExpected = |
| 1370 expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
| 1371 FloatPoint visualViewportExpected = |
| 1372 FloatPoint( |
| 1373 750, |
| 1374 layoutViewportHeight - visualViewportHeight / pageScale); |
| 1375 |
| 1354 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1376 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); |
| 1355 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1377 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1356 | 1378 |
| 1357 // Resize the widget to match the top controls adjustment. Ensure that scrol
l | 1379 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; |
| 1358 // offsets don't get clamped in the the process. | |
| 1359 webViewImpl()->setTopControlsHeight(20, true); | |
| 1360 webViewImpl()->resize(WebSize(500, 430)); | |
| 1361 | 1380 |
| 1362 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.size()); | 1381 // Resize the widget to match the top controls adjustment. Ensure that the |
| 1363 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1382 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1364 EXPECT_SIZE_EQ(IntSize(1000, 860), frameView.frameRect().size()); | 1383 // the offsets to valid values. |
| 1384 webViewImpl()->resizeWithTopControls( |
| 1385 WebSize(500, visualViewportHeight), |
| 1386 20, |
| 1387 false); |
| 1365 | 1388 |
| 1389 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
| 1390 EXPECT_SIZE_EQ( |
| 1391 IntSize(250, visualViewportHeight / pageScale), |
| 1392 visualViewport.visibleRect().size()); |
| 1393 EXPECT_SIZE_EQ( |
| 1394 IntSize(1000, layoutViewportHeight), |
| 1395 frameView.frameRect().size()); |
| 1396 EXPECT_POINT_EQ( |
| 1397 totalExpected, |
| 1398 frameView.scrollPosition() + visualViewport.location()); |
| 1399 } |
| 1400 |
| 1401 // Tests that a scroll all the way to the bottom while showing the top controls |
| 1402 // doesn't cause a clamp to the viewport scroll offset when the top controls |
| 1403 // initiated resize occurs. |
| 1404 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) |
| 1405 { |
| 1406 int topControlsHeight = 20; |
| 1407 int visualViewportHeight = 500; |
| 1408 int layoutViewportHeight = 1000; |
| 1409 int contentHeight = 2000; |
| 1410 float pageScale = 2; |
| 1411 float minPageScale = 0.5; |
| 1412 |
| 1413 initializeWithAndroidSettings(); |
| 1414 |
| 1415 // Initialize with top controls hidden and not shrinking the Blink size. |
| 1416 webViewImpl()->resizeWithTopControls( |
| 1417 IntSize(500, visualViewportHeight), |
| 1418 20, |
| 1419 false); |
| 1420 webViewImpl()->topControls().setShownRatio(0); |
| 1421 |
| 1422 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1423 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1424 |
| 1425 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); |
| 1426 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1427 |
| 1428 visualViewport.setScale(pageScale); |
| 1429 EXPECT_SIZE_EQ( |
| 1430 IntSize(250, visualViewportHeight / pageScale), |
| 1431 visualViewport.visibleRect().size()); |
| 1432 EXPECT_SIZE_EQ( |
| 1433 IntSize(1000, layoutViewportHeight), |
| 1434 frameView.frameRect().size()); |
| 1435 EXPECT_SIZE_EQ( |
| 1436 IntSize(500, visualViewportHeight), |
| 1437 visualViewport.size()); |
| 1438 |
| 1439 // Scroll all the way to the bottom, showing the the top controls in the |
| 1440 // process. (This could happen via window.scrollTo during a scroll, for |
| 1441 // example). |
| 1442 webViewImpl()->topControls().setShownRatio(1); |
| 1443 visualViewport.move(FloatPoint(10000, 10000)); |
| 1444 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1445 |
| 1446 EXPECT_SIZE_EQ( |
| 1447 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| 1448 visualViewport.visibleRect().size()); |
| 1449 |
| 1450 IntPoint frameViewExpected = IntPoint(0, |
| 1451 contentHeight |
| 1452 - (layoutViewportHeight - topControlsHeight / minPageScale)); |
| 1453 FloatPoint visualViewportExpected = |
| 1454 FloatPoint(750, |
| 1455 (layoutViewportHeight - topControlsHeight / minPageScale |
| 1456 - visualViewport.visibleRect().height())); |
| 1457 |
| 1458 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); |
| 1366 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1459 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1367 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1460 |
| 1461 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; |
| 1462 |
| 1463 // Resize the widget to match the top controls adjustment. Ensure that the |
| 1464 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1465 // the offsets to valid values. |
| 1466 webViewImpl()->resizeWithTopControls( |
| 1467 WebSize(500, visualViewportHeight - topControlsHeight), |
| 1468 20, |
| 1469 true); |
| 1470 |
| 1471 EXPECT_SIZE_EQ( |
| 1472 IntSize(500, visualViewportHeight - topControlsHeight), |
| 1473 visualViewport.size()); |
| 1474 EXPECT_SIZE_EQ( |
| 1475 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| 1476 visualViewport.visibleRect().size()); |
| 1477 EXPECT_SIZE_EQ( |
| 1478 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
| 1479 frameView.frameRect().size()); |
| 1480 EXPECT_POINT_EQ( |
| 1481 totalExpected, |
| 1482 frameView.scrollPosition() + visualViewport.location()); |
| 1368 } | 1483 } |
| 1369 | 1484 |
| 1370 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the | 1485 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the |
| 1371 // main frame's scroll offset. crbug.com/428193. | 1486 // main frame's scroll offset. crbug.com/428193. |
| 1372 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) | 1487 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) |
| 1373 { | 1488 { |
| 1374 initializeWithAndroidSettings(); | 1489 initializeWithAndroidSettings(); |
| 1375 webViewImpl()->setTopControlsHeight(500, false); | 1490 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false); |
| 1376 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); | 1491 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, 1); |
| 1377 webViewImpl()->setTopControlsHeight(500, true); | 1492 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true); |
| 1378 webViewImpl()->resize(IntSize(1000, 1000)); | |
| 1379 | 1493 |
| 1380 registerMockedHttpURLLoad("content-width-1000.html"); | 1494 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1381 navigateTo(m_baseURL + "content-width-1000.html"); | 1495 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1382 | 1496 |
| 1383 // Scroll the FrameView to the bottom of the page but "hide" the top | 1497 // Scroll the FrameView to the bottom of the page but "hide" the top |
| 1384 // controls on the compositor side so the max scroll position should account | 1498 // controls on the compositor side so the max scroll position should account |
| 1385 // for the full viewport height. | 1499 // for the full viewport height. |
| 1386 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, -1); | 1500 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS
ize(), 1, -1); |
| 1387 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1501 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1388 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); | 1502 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); |
| 1389 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1503 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| 1390 | 1504 |
| 1391 // Now send the resize, make sure the scroll offset doesn't change. | 1505 // Now send the resize, make sure the scroll offset doesn't change. |
| 1392 webViewImpl()->setTopControlsHeight(500, false); | 1506 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false); |
| 1393 webViewImpl()->resize(IntSize(1000, 1500)); | |
| 1394 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1507 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| 1395 } | 1508 } |
| 1396 | 1509 |
| 1397 // Tests that the layout viewport's scroll layer bounds are updated in a composi
ting | 1510 // Tests that the layout viewport's scroll layer bounds are updated in a composi
ting |
| 1398 // change update. crbug.com/423188. | 1511 // change update. crbug.com/423188. |
| 1399 TEST_P(ParameterizedVisualViewportTest, TestChangingContentSizeAffectsScrollBoun
ds) | 1512 TEST_P(ParameterizedVisualViewportTest, TestChangingContentSizeAffectsScrollBoun
ds) |
| 1400 { | 1513 { |
| 1401 initializeWithAndroidSettings(); | 1514 initializeWithAndroidSettings(); |
| 1402 webViewImpl()->resize(IntSize(100, 150)); | 1515 webViewImpl()->resize(IntSize(100, 150)); |
| 1403 | 1516 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 webViewImpl()->handleInputEvent(pinchUpdate); | 1856 webViewImpl()->handleInputEvent(pinchUpdate); |
| 1744 | 1857 |
| 1745 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); | 1858 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); |
| 1746 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1859 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1747 | 1860 |
| 1748 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1861 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); |
| 1749 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1862 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); |
| 1750 } | 1863 } |
| 1751 | 1864 |
| 1752 } // namespace | 1865 } // namespace |
| OLD | NEW |