| 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/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 9 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
| 11 #include "core/frame/TopControls.h" | |
| 12 #include "core/html/HTMLBodyElement.h" | 12 #include "core/html/HTMLBodyElement.h" |
| 13 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
| 14 #include "core/input/EventHandler.h" | 14 #include "core/input/EventHandler.h" |
| 15 #include "core/layout/LayoutObject.h" | 15 #include "core/layout/LayoutObject.h" |
| 16 #include "core/layout/api/LayoutViewItem.h" | 16 #include "core/layout/api/LayoutViewItem.h" |
| 17 #include "core/layout/compositing/PaintLayerCompositor.h" | 17 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 18 #include "core/page/Page.h" | 18 #include "core/page/Page.h" |
| 19 #include "platform/PlatformGestureEvent.h" | 19 #include "platform/PlatformGestureEvent.h" |
| 20 #include "platform/geometry/DoublePoint.h" | 20 #include "platform/geometry/DoublePoint.h" |
| 21 #include "platform/geometry/DoubleRect.h" | 21 #include "platform/geometry/DoubleRect.h" |
| (...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 VisualViewport& visualViewport, | 1282 VisualViewport& visualViewport, |
| 1283 FrameView& frameView) { | 1283 FrameView& frameView) { |
| 1284 float aspectRatio = visualViewport.visibleRect().width() / | 1284 float aspectRatio = visualViewport.visibleRect().width() / |
| 1285 visualViewport.visibleRect().height(); | 1285 visualViewport.visibleRect().height(); |
| 1286 float newHeight = frameView.frameRect().width() / aspectRatio; | 1286 float newHeight = frameView.frameRect().width() / aspectRatio; |
| 1287 return ScrollOffset( | 1287 return ScrollOffset( |
| 1288 frameView.contentsSize().width() - frameView.frameRect().width(), | 1288 frameView.contentsSize().width() - frameView.frameRect().width(), |
| 1289 frameView.contentsSize().height() - newHeight); | 1289 frameView.contentsSize().height() - newHeight); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 TEST_F(VisualViewportTest, TestTopControlsAdjustment) { | 1292 TEST_F(VisualViewportTest, TestBrowserControlsAdjustment) { |
| 1293 initializeWithAndroidSettings(); | 1293 initializeWithAndroidSettings(); |
| 1294 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); | 1294 webViewImpl()->resizeWithBrowserControls(IntSize(500, 450), 20, false); |
| 1295 | 1295 |
| 1296 registerMockedHttpURLLoad("content-width-1000.html"); | 1296 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1297 navigateTo(m_baseURL + "content-width-1000.html"); | 1297 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1298 | 1298 |
| 1299 VisualViewport& visualViewport = | 1299 VisualViewport& visualViewport = |
| 1300 frame()->page()->frameHost().visualViewport(); | 1300 frame()->page()->frameHost().visualViewport(); |
| 1301 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1301 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1302 | 1302 |
| 1303 visualViewport.setScale(1); | 1303 visualViewport.setScale(1); |
| 1304 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); | 1304 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); |
| 1305 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1305 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1306 | 1306 |
| 1307 // Simulate bringing down the top controls by 20px. | 1307 // Simulate bringing down the browser controls by 20px. |
| 1308 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1308 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1309 WebFloatSize(), 1, 1); | 1309 WebFloatSize(), 1, 1); |
| 1310 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); | 1310 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); |
| 1311 | 1311 |
| 1312 // Test that the scroll bounds are adjusted appropriately: the visual viewport | 1312 // Test that the scroll bounds are adjusted appropriately: the visual viewport |
| 1313 // should be shrunk by 20px to 430px. The outer viewport was shrunk to | 1313 // should be shrunk by 20px to 430px. The outer viewport was shrunk to |
| 1314 // maintain the | 1314 // maintain the |
| 1315 // aspect ratio so it's height is 860px. | 1315 // aspect ratio so it's height is 860px. |
| 1316 visualViewport.move(ScrollOffset(10000, 10000)); | 1316 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1317 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); | 1317 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
| 1318 | 1318 |
| 1319 // The outer viewport (FrameView) should be affected as well. | 1319 // The outer viewport (FrameView) should be affected as well. |
| 1320 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1320 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| 1321 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1321 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1322 frameView.scrollOffset()); | 1322 frameView.scrollOffset()); |
| 1323 | 1323 |
| 1324 // Simulate bringing up the top controls by 10.5px. | 1324 // Simulate bringing up the browser controls by 10.5px. |
| 1325 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1325 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1326 WebFloatSize(), 1, -10.5f / 20); | 1326 WebFloatSize(), 1, -10.5f / 20); |
| 1327 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), | 1327 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), |
| 1328 visualViewport.visibleRect().size()); | 1328 visualViewport.visibleRect().size()); |
| 1329 | 1329 |
| 1330 // maximumScrollPosition |ceil|s the top controls adjustment. | 1330 // maximumScrollPosition |ceil|s the browser controls adjustment. |
| 1331 visualViewport.move(ScrollOffset(10000, 10000)); | 1331 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1332 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 881 - 441), | 1332 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 881 - 441), |
| 1333 visualViewport.scrollOffset()); | 1333 visualViewport.scrollOffset()); |
| 1334 | 1334 |
| 1335 // The outer viewport (FrameView) should be affected as well. | 1335 // The outer viewport (FrameView) should be affected as well. |
| 1336 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1336 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| 1337 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1337 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1338 frameView.scrollOffset()); | 1338 frameView.scrollOffset()); |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) { | 1341 TEST_F(VisualViewportTest, TestBrowserControlsAdjustmentWithScale) { |
| 1342 initializeWithAndroidSettings(); | 1342 initializeWithAndroidSettings(); |
| 1343 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); | 1343 webViewImpl()->resizeWithBrowserControls(IntSize(500, 450), 20, false); |
| 1344 | 1344 |
| 1345 registerMockedHttpURLLoad("content-width-1000.html"); | 1345 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1346 navigateTo(m_baseURL + "content-width-1000.html"); | 1346 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1347 | 1347 |
| 1348 VisualViewport& visualViewport = | 1348 VisualViewport& visualViewport = |
| 1349 frame()->page()->frameHost().visualViewport(); | 1349 frame()->page()->frameHost().visualViewport(); |
| 1350 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1350 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1351 | 1351 |
| 1352 visualViewport.setScale(2); | 1352 visualViewport.setScale(2); |
| 1353 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1353 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
| 1354 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1354 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1355 | 1355 |
| 1356 // Simulate bringing down the top controls by 20px. Since we're zoomed in, the | 1356 // Simulate bringing down the browser controls by 20px. Since we're zoomed in, |
| 1357 // top controls take up half as much space (in document-space) than they do at | 1357 // the browser controls take up half as much space (in document-space) than |
| 1358 // an unzoomed level. | 1358 // they do at an unzoomed level. |
| 1359 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1359 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1360 WebFloatSize(), 1, 1); | 1360 WebFloatSize(), 1, 1); |
| 1361 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1361 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
| 1362 | 1362 |
| 1363 // Test that the scroll bounds are adjusted appropriately. | 1363 // Test that the scroll bounds are adjusted appropriately. |
| 1364 visualViewport.move(ScrollOffset(10000, 10000)); | 1364 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1365 EXPECT_SIZE_EQ(FloatSize(750, 860 - 215), visualViewport.scrollOffset()); | 1365 EXPECT_SIZE_EQ(FloatSize(750, 860 - 215), visualViewport.scrollOffset()); |
| 1366 | 1366 |
| 1367 // The outer viewport (FrameView) should be affected as well. | 1367 // The outer viewport (FrameView) should be affected as well. |
| 1368 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1368 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1381 | 1381 |
| 1382 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); | 1382 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
| 1383 visualViewport.move(ScrollOffset(10000, 10000)); | 1383 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1384 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); | 1384 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
| 1385 | 1385 |
| 1386 // Scale out, use a scale that causes fractional rects. | 1386 // Scale out, use a scale that causes fractional rects. |
| 1387 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1387 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1388 WebFloatSize(), 0.8f, -1); | 1388 WebFloatSize(), 0.8f, -1); |
| 1389 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size()); | 1389 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size()); |
| 1390 | 1390 |
| 1391 // Bring out the top controls by 11 | 1391 // Bring out the browser controls by 11 |
| 1392 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1392 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1393 WebFloatSize(), 1, 11 / 20.f); | 1393 WebFloatSize(), 1, 11 / 20.f); |
| 1394 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size()); | 1394 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size()); |
| 1395 | 1395 |
| 1396 // Ensure max scroll offsets are updated properly. | 1396 // Ensure max scroll offsets are updated properly. |
| 1397 visualViewport.move(ScrollOffset(10000, 10000)); | 1397 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1398 EXPECT_FLOAT_SIZE_EQ(FloatSize(375, 877.5 - 548.75), | 1398 EXPECT_FLOAT_SIZE_EQ(FloatSize(375, 877.5 - 548.75), |
| 1399 visualViewport.scrollOffset()); | 1399 visualViewport.scrollOffset()); |
| 1400 | 1400 |
| 1401 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1401 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| 1402 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1402 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1403 frameView.scrollOffset()); | 1403 frameView.scrollOffset()); |
| 1404 } | 1404 } |
| 1405 | 1405 |
| 1406 // Tests that a scroll all the way to the bottom of the page, while hiding the | 1406 // Tests that a scroll all the way to the bottom of the page, while hiding the |
| 1407 // top controls doesn't cause a clamp in the viewport scroll offset when the top | 1407 // browser controls doesn't cause a clamp in the viewport scroll offset when the |
| 1408 // controls initiated resize occurs. | 1408 // top controls initiated resize occurs. |
| 1409 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) { | 1409 TEST_F(VisualViewportTest, TestBrowserControlsAdjustmentAndResize) { |
| 1410 int topControlsHeight = 20; | 1410 int browserControlsHeight = 20; |
| 1411 int visualViewportHeight = 450; | 1411 int visualViewportHeight = 450; |
| 1412 int layoutViewportHeight = 900; | 1412 int layoutViewportHeight = 900; |
| 1413 float pageScale = 2; | 1413 float pageScale = 2; |
| 1414 float minPageScale = 0.5; | 1414 float minPageScale = 0.5; |
| 1415 | 1415 |
| 1416 initializeWithAndroidSettings(); | 1416 initializeWithAndroidSettings(); |
| 1417 | 1417 |
| 1418 // Initialize with top controls showing and shrinking the Blink size. | 1418 // Initialize with browser controls showing and shrinking the Blink size. |
| 1419 webViewImpl()->resizeWithTopControls( | 1419 webViewImpl()->resizeWithBrowserControls( |
| 1420 WebSize(500, visualViewportHeight - topControlsHeight), 20, true); | 1420 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true); |
| 1421 webViewImpl()->topControls().setShownRatio(1); | 1421 webViewImpl()->browserControls().setShownRatio(1); |
| 1422 | 1422 |
| 1423 registerMockedHttpURLLoad("content-width-1000.html"); | 1423 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1424 navigateTo(m_baseURL + "content-width-1000.html"); | 1424 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1425 | 1425 |
| 1426 VisualViewport& visualViewport = | 1426 VisualViewport& visualViewport = |
| 1427 frame()->page()->frameHost().visualViewport(); | 1427 frame()->page()->frameHost().visualViewport(); |
| 1428 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1428 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1429 | 1429 |
| 1430 visualViewport.setScale(pageScale); | 1430 visualViewport.setScale(pageScale); |
| 1431 EXPECT_SIZE_EQ( | 1431 EXPECT_SIZE_EQ( |
| 1432 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1432 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), |
| 1433 visualViewport.visibleRect().size()); | 1433 visualViewport.visibleRect().size()); |
| 1434 EXPECT_SIZE_EQ( | 1434 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - |
| 1435 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), | 1435 browserControlsHeight / minPageScale), |
| 1436 frameView.frameRect().size()); | 1436 frameView.frameRect().size()); |
| 1437 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), | 1437 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), |
| 1438 visualViewport.size()); | 1438 visualViewport.size()); |
| 1439 | 1439 |
| 1440 // Scroll all the way to the bottom, hiding the top controls in the process. | 1440 // Scroll all the way to the bottom, hiding the browser controls in the |
| 1441 // process. |
| 1441 visualViewport.move(ScrollOffset(10000, 10000)); | 1442 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1442 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1443 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| 1443 webViewImpl()->topControls().setShownRatio(0); | 1444 webViewImpl()->browserControls().setShownRatio(0); |
| 1444 | 1445 |
| 1445 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1446 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
| 1446 visualViewport.visibleRect().size()); | 1447 visualViewport.visibleRect().size()); |
| 1447 | 1448 |
| 1448 ScrollOffset frameViewExpected = | 1449 ScrollOffset frameViewExpected = |
| 1449 expectedMaxFrameViewScrollOffset(visualViewport, frameView); | 1450 expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
| 1450 ScrollOffset visualViewportExpected = ScrollOffset( | 1451 ScrollOffset visualViewportExpected = ScrollOffset( |
| 1451 750, layoutViewportHeight - visualViewportHeight / pageScale); | 1452 750, layoutViewportHeight - visualViewportHeight / pageScale); |
| 1452 | 1453 |
| 1453 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); | 1454 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); |
| 1454 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); | 1455 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); |
| 1455 | 1456 |
| 1456 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; | 1457 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; |
| 1457 | 1458 |
| 1458 // Resize the widget to match the top controls adjustment. Ensure that the | 1459 // Resize the widget to match the browser controls adjustment. Ensure that the |
| 1459 // total offset (i.e. what the user sees) doesn't change because of clamping | 1460 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1460 // the offsets to valid values. | 1461 // the offsets to valid values. |
| 1461 webViewImpl()->resizeWithTopControls(WebSize(500, visualViewportHeight), 20, | 1462 webViewImpl()->resizeWithBrowserControls(WebSize(500, visualViewportHeight), |
| 1462 false); | 1463 20, false); |
| 1463 | 1464 |
| 1464 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); | 1465 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
| 1465 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1466 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
| 1466 visualViewport.visibleRect().size()); | 1467 visualViewport.visibleRect().size()); |
| 1467 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1468 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), |
| 1468 frameView.frameRect().size()); | 1469 frameView.frameRect().size()); |
| 1469 EXPECT_SIZE_EQ(totalExpected, | 1470 EXPECT_SIZE_EQ(totalExpected, |
| 1470 visualViewport.scrollOffset() + frameView.scrollOffset()); | 1471 visualViewport.scrollOffset() + frameView.scrollOffset()); |
| 1471 } | 1472 } |
| 1472 | 1473 |
| 1473 // Tests that a scroll all the way to the bottom while showing the top controls | 1474 // Tests that a scroll all the way to the bottom while showing the browser |
| 1474 // doesn't cause a clamp to the viewport scroll offset when the top controls | 1475 // controls doesn't cause a clamp to the viewport scroll offset when the browser |
| 1475 // initiated resize occurs. | 1476 // controls initiated resize occurs. |
| 1476 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) { | 1477 TEST_F(VisualViewportTest, TestBrowserControlsShrinkAdjustmentAndResize) { |
| 1477 int topControlsHeight = 20; | 1478 int browserControlsHeight = 20; |
| 1478 int visualViewportHeight = 500; | 1479 int visualViewportHeight = 500; |
| 1479 int layoutViewportHeight = 1000; | 1480 int layoutViewportHeight = 1000; |
| 1480 int contentHeight = 2000; | 1481 int contentHeight = 2000; |
| 1481 float pageScale = 2; | 1482 float pageScale = 2; |
| 1482 float minPageScale = 0.5; | 1483 float minPageScale = 0.5; |
| 1483 | 1484 |
| 1484 initializeWithAndroidSettings(); | 1485 initializeWithAndroidSettings(); |
| 1485 | 1486 |
| 1486 // Initialize with top controls hidden and not shrinking the Blink size. | 1487 // Initialize with browser controls hidden and not shrinking the Blink size. |
| 1487 webViewImpl()->resizeWithTopControls(IntSize(500, visualViewportHeight), 20, | 1488 webViewImpl()->resizeWithBrowserControls(IntSize(500, visualViewportHeight), |
| 1488 false); | 1489 20, false); |
| 1489 webViewImpl()->topControls().setShownRatio(0); | 1490 webViewImpl()->browserControls().setShownRatio(0); |
| 1490 | 1491 |
| 1491 registerMockedHttpURLLoad("content-width-1000.html"); | 1492 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1492 navigateTo(m_baseURL + "content-width-1000.html"); | 1493 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1493 | 1494 |
| 1494 VisualViewport& visualViewport = | 1495 VisualViewport& visualViewport = |
| 1495 frame()->page()->frameHost().visualViewport(); | 1496 frame()->page()->frameHost().visualViewport(); |
| 1496 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1497 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1497 | 1498 |
| 1498 visualViewport.setScale(pageScale); | 1499 visualViewport.setScale(pageScale); |
| 1499 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1500 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
| 1500 visualViewport.visibleRect().size()); | 1501 visualViewport.visibleRect().size()); |
| 1501 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1502 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), |
| 1502 frameView.frameRect().size()); | 1503 frameView.frameRect().size()); |
| 1503 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); | 1504 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
| 1504 | 1505 |
| 1505 // Scroll all the way to the bottom, showing the the top controls in the | 1506 // Scroll all the way to the bottom, showing the the browser controls in the |
| 1506 // process. (This could happen via window.scrollTo during a scroll, for | 1507 // process. (This could happen via window.scrollTo during a scroll, for |
| 1507 // example). | 1508 // example). |
| 1508 webViewImpl()->topControls().setShownRatio(1); | 1509 webViewImpl()->browserControls().setShownRatio(1); |
| 1509 visualViewport.move(ScrollOffset(10000, 10000)); | 1510 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1510 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); | 1511 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
| 1511 | 1512 |
| 1512 EXPECT_SIZE_EQ( | 1513 EXPECT_SIZE_EQ( |
| 1513 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1514 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), |
| 1514 visualViewport.visibleRect().size()); | 1515 visualViewport.visibleRect().size()); |
| 1515 | 1516 |
| 1516 ScrollOffset frameViewExpected( | 1517 ScrollOffset frameViewExpected( |
| 1517 0, contentHeight - | 1518 0, contentHeight - |
| 1518 (layoutViewportHeight - topControlsHeight / minPageScale)); | 1519 (layoutViewportHeight - browserControlsHeight / minPageScale)); |
| 1519 ScrollOffset visualViewportExpected = ScrollOffset( | 1520 ScrollOffset visualViewportExpected = ScrollOffset( |
| 1520 750, (layoutViewportHeight - topControlsHeight / minPageScale - | 1521 750, (layoutViewportHeight - browserControlsHeight / minPageScale - |
| 1521 visualViewport.visibleRect().height())); | 1522 visualViewport.visibleRect().height())); |
| 1522 | 1523 |
| 1523 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); | 1524 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); |
| 1524 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); | 1525 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); |
| 1525 | 1526 |
| 1526 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; | 1527 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; |
| 1527 | 1528 |
| 1528 // Resize the widget to match the top controls adjustment. Ensure that the | 1529 // Resize the widget to match the browser controls adjustment. Ensure that the |
| 1529 // total offset (i.e. what the user sees) doesn't change because of clamping | 1530 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1530 // the offsets to valid values. | 1531 // the offsets to valid values. |
| 1531 webViewImpl()->resizeWithTopControls( | 1532 webViewImpl()->resizeWithBrowserControls( |
| 1532 WebSize(500, visualViewportHeight - topControlsHeight), 20, true); | 1533 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true); |
| 1533 | 1534 |
| 1534 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), | 1535 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), |
| 1535 visualViewport.size()); | 1536 visualViewport.size()); |
| 1536 EXPECT_SIZE_EQ( | 1537 EXPECT_SIZE_EQ( |
| 1537 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1538 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), |
| 1538 visualViewport.visibleRect().size()); | 1539 visualViewport.visibleRect().size()); |
| 1539 EXPECT_SIZE_EQ( | 1540 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - |
| 1540 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), | 1541 browserControlsHeight / minPageScale), |
| 1541 frameView.frameRect().size()); | 1542 frameView.frameRect().size()); |
| 1542 EXPECT_SIZE_EQ(totalExpected, | 1543 EXPECT_SIZE_EQ(totalExpected, |
| 1543 visualViewport.scrollOffset() + frameView.scrollOffset()); | 1544 visualViewport.scrollOffset() + frameView.scrollOffset()); |
| 1544 } | 1545 } |
| 1545 | 1546 |
| 1546 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the | 1547 // Tests that a resize due to browser controls hiding doesn't incorrectly clamp |
| 1547 // main frame's scroll offset. crbug.com/428193. | 1548 // the main frame's scroll offset. crbug.com/428193. |
| 1548 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { | 1549 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { |
| 1549 initializeWithAndroidSettings(); | 1550 initializeWithAndroidSettings(); |
| 1550 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false); | 1551 webViewImpl()->resizeWithBrowserControls(webViewImpl()->size(), 500, false); |
| 1551 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1552 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1552 WebFloatSize(), 1, 1); | 1553 WebFloatSize(), 1, 1); |
| 1553 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true); | 1554 webViewImpl()->resizeWithBrowserControls(WebSize(1000, 1000), 500, true); |
| 1554 | 1555 |
| 1555 registerMockedHttpURLLoad("content-width-1000.html"); | 1556 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1556 navigateTo(m_baseURL + "content-width-1000.html"); | 1557 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1557 | 1558 |
| 1558 // Scroll the FrameView to the bottom of the page but "hide" the top controls | 1559 // Scroll the FrameView to the bottom of the page but "hide" the browser |
| 1559 // on the compositor side so the max scroll position should account for the | 1560 // controls on the compositor side so the max scroll position should account |
| 1560 // full viewport height. | 1561 // for the full viewport height. |
| 1561 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1562 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1562 WebFloatSize(), 1, -1); | 1563 WebFloatSize(), 1, -1); |
| 1563 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1564 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1564 frameView.setScrollOffset(ScrollOffset(0, 10000), ProgrammaticScroll); | 1565 frameView.setScrollOffset(ScrollOffset(0, 10000), ProgrammaticScroll); |
| 1565 EXPECT_EQ(500, frameView.scrollOffset().height()); | 1566 EXPECT_EQ(500, frameView.scrollOffset().height()); |
| 1566 | 1567 |
| 1567 // Now send the resize, make sure the scroll offset doesn't change. | 1568 // Now send the resize, make sure the scroll offset doesn't change. |
| 1568 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false); | 1569 webViewImpl()->resizeWithBrowserControls(WebSize(1000, 1500), 500, false); |
| 1569 EXPECT_EQ(500, frameView.scrollOffset().height()); | 1570 EXPECT_EQ(500, frameView.scrollOffset().height()); |
| 1570 } | 1571 } |
| 1571 | 1572 |
| 1572 static void configureHiddenScrollbarsSettings(WebSettings* settings) { | 1573 static void configureHiddenScrollbarsSettings(WebSettings* settings) { |
| 1573 VisualViewportTest::configureAndroidSettings(settings); | 1574 VisualViewportTest::configureAndroidSettings(settings); |
| 1574 settings->setHideScrollbars(true); | 1575 settings->setHideScrollbars(true); |
| 1575 } | 1576 } |
| 1576 | 1577 |
| 1577 // Tests that scrollbar layers are not attached to the inner viewport container | 1578 // Tests that scrollbar layers are not attached to the inner viewport container |
| 1578 // layer when hideScrollbars WebSetting is true. | 1579 // layer when hideScrollbars WebSetting is true. |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 frameView.layoutViewportScrollableArea()->setScrollOffset( | 2003 frameView.layoutViewportScrollableArea()->setScrollOffset( |
| 2003 ScrollOffset(700, 500), ProgrammaticScroll); | 2004 ScrollOffset(700, 500), ProgrammaticScroll); |
| 2004 | 2005 |
| 2005 webViewImpl()->resize(IntSize(800, 300)); | 2006 webViewImpl()->resize(IntSize(800, 300)); |
| 2006 EXPECT_SIZE_EQ(ScrollOffset(700, 200), | 2007 EXPECT_SIZE_EQ(ScrollOffset(700, 200), |
| 2007 frameView.layoutViewportScrollableArea()->scrollOffset()); | 2008 frameView.layoutViewportScrollableArea()->scrollOffset()); |
| 2008 | 2009 |
| 2009 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); | 2010 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); |
| 2010 } | 2011 } |
| 2011 | 2012 |
| 2012 // Ensure that resize anchoring as happens when top controls hide/show affects | 2013 // Ensure that resize anchoring as happens when browser controls hide/show |
| 2013 // the scrollable area that's currently set as the root scroller. | 2014 // affects the scrollable area that's currently set as the root scroller. |
| 2014 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) { | 2015 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) { |
| 2015 bool wasRootScrollerEnabled = | 2016 bool wasRootScrollerEnabled = |
| 2016 RuntimeEnabledFeatures::setRootScrollerEnabled(); | 2017 RuntimeEnabledFeatures::setRootScrollerEnabled(); |
| 2017 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 2018 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
| 2018 | 2019 |
| 2019 initializeWithAndroidSettings(); | 2020 initializeWithAndroidSettings(); |
| 2020 webViewImpl()->resize(IntSize(800, 600)); | 2021 webViewImpl()->resize(IntSize(800, 600)); |
| 2021 | 2022 |
| 2022 registerMockedHttpURLLoad("root-scroller-div.html"); | 2023 registerMockedHttpURLLoad("root-scroller-div.html"); |
| 2023 navigateTo(m_baseURL + "root-scroller-div.html"); | 2024 navigateTo(m_baseURL + "root-scroller-div.html"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2069 webViewImpl()->resize(IntSize(600, 800)); | 2070 webViewImpl()->resize(IntSize(600, 800)); |
| 2070 | 2071 |
| 2071 EXPECT_SIZE_EQ(ScrollOffset(), | 2072 EXPECT_SIZE_EQ(ScrollOffset(), |
| 2072 frameView.layoutViewportScrollableArea()->scrollOffset()); | 2073 frameView.layoutViewportScrollableArea()->scrollOffset()); |
| 2073 EXPECT_EQ(600, scroller->scrollTop()); | 2074 EXPECT_EQ(600, scroller->scrollTop()); |
| 2074 | 2075 |
| 2075 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); | 2076 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); |
| 2076 } | 2077 } |
| 2077 | 2078 |
| 2078 } // namespace | 2079 } // namespace |
| OLD | NEW |