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