Chromium Code Reviews| 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()->resize(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()->resize(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()->resize(IntSize(500, 450)); |
| 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); | 1223 webViewImpl()->resize(webViewImpl()->size(), 20, false); |
| 1226 | 1224 |
| 1227 visualViewport.setScale(1); | 1225 visualViewport.setScale(1); |
| 1228 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); | 1226 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); |
| 1229 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1227 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1230 | 1228 |
| 1231 // Simulate bringing down the top controls by 20px. | 1229 // Simulate bringing down the top controls by 20px. |
| 1232 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); | 1230 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); |
| 1233 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); | 1231 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); |
| 1234 | 1232 |
| 1235 // Test that the scroll bounds are adjusted appropriately: the visual viewpo rt | 1233 // 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 | 1234 // 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. | 1235 // aspect ratio so it's height is 860px. |
| 1238 visualViewport.move(FloatPoint(10000, 10000)); | 1236 visualViewport.move(FloatPoint(10000, 10000)); |
| 1239 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); | 1237 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); |
| 1240 | 1238 |
| 1241 // The outer viewport (FrameView) should be affected as well. | 1239 // The outer viewport (FrameView) should be affected as well. |
| 1242 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1240 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1243 EXPECT_POINT_EQ( | 1241 EXPECT_POINT_EQ( |
| 1244 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1242 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1245 frameView.scrollPosition()); | 1243 frameView.scrollPosition()); |
| 1246 | 1244 |
| 1247 // Simulate bringing up the top controls by 10.5px. | 1245 // Simulate bringing up the top controls by 10.5px. |
| 1248 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, -10.5f / 20); | 1246 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, -10.5f / 20); |
| 1249 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), visualViewport.visibleRect().si ze()); | 1247 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), visualViewport.visibleRect().si ze()); |
| 1250 | 1248 |
| 1251 // maximumScrollPosition floors the final values. | 1249 // maximumScrollPosition |ceil|s the top controls adjustment. |
| 1252 visualViewport.move(FloatPoint(10000, 10000)); | 1250 visualViewport.move(FloatPoint(10000, 10000)); |
| 1253 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 440.5f), visualViewport.location ()); | 1251 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location()) ; |
| 1254 | 1252 |
| 1255 // The outer viewport (FrameView) should be affected as well. | 1253 // The outer viewport (FrameView) should be affected as well. |
| 1256 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1254 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1257 EXPECT_POINT_EQ( | 1255 EXPECT_POINT_EQ( |
| 1258 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1256 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1259 frameView.scrollPosition()); | 1257 frameView.scrollPosition()); |
| 1260 } | 1258 } |
| 1261 | 1259 |
| 1262 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) | 1260 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) |
| 1263 { | 1261 { |
| 1264 initializeWithAndroidSettings(); | 1262 initializeWithAndroidSettings(); |
| 1265 webViewImpl()->resize(IntSize(500, 450)); | 1263 webViewImpl()->resize(IntSize(500, 450)); |
| 1266 | 1264 |
| 1267 registerMockedHttpURLLoad("content-width-1000.html"); | 1265 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1268 navigateTo(m_baseURL + "content-width-1000.html"); | 1266 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1269 | 1267 |
| 1270 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport (); | 1268 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport (); |
| 1271 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1269 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1272 | 1270 |
| 1273 webViewImpl()->setTopControlsHeight(20, false); | 1271 webViewImpl()->resize(webViewImpl()->size(), 20, false); |
| 1274 | 1272 |
| 1275 visualViewport.setScale(2); | 1273 visualViewport.setScale(2); |
| 1276 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1274 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
| 1277 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1275 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| 1278 | 1276 |
| 1279 // 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, |
| 1280 // 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 |
| 1281 // they do at an unzoomed level. | 1279 // they do at an unzoomed level. |
| 1282 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); | 1280 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); |
| 1283 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1281 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1315 visualViewport.move(FloatPoint(10000, 10000)); | 1313 visualViewport.move(FloatPoint(10000, 10000)); |
| 1316 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()); |
| 1317 | 1315 |
| 1318 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1316 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1319 EXPECT_POINT_EQ( | 1317 EXPECT_POINT_EQ( |
| 1320 expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1318 expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
| 1321 frameView.scrollPosition()); | 1319 frameView.scrollPosition()); |
| 1322 | 1320 |
| 1323 } | 1321 } |
| 1324 | 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. | |
| 1325 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) | 1326 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) |
|
bokan
2016/04/05 17:11:41
I think this test was accidentally testing somethi
| |
| 1326 { | 1327 { |
| 1328 int topControlsHeight = 20; | |
| 1329 int visualViewportHeight = 450; | |
| 1330 int layoutViewportHeight = 900; | |
| 1331 float pageScale = 2; | |
| 1332 float minPageScale = 0.5; | |
| 1333 | |
| 1327 initializeWithAndroidSettings(); | 1334 initializeWithAndroidSettings(); |
| 1328 webViewImpl()->resize(IntSize(500, 450)); | 1335 |
| 1336 // Initialize with top controls showing and shrinking the Blink size. | |
| 1337 webViewImpl()->resize( | |
| 1338 IntSize(500, visualViewportHeight - topControlsHeight), | |
| 1339 20, | |
| 1340 true); | |
| 1341 webViewImpl()->topControls().setShownRatio(1); | |
| 1329 | 1342 |
| 1330 registerMockedHttpURLLoad("content-width-1000.html"); | 1343 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1331 navigateTo(m_baseURL + "content-width-1000.html"); | 1344 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1332 | 1345 |
| 1333 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport (); | 1346 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport (); |
| 1334 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1347 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1335 | 1348 |
| 1336 visualViewport.setScale(2); | 1349 visualViewport.setScale(pageScale); |
| 1337 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1350 EXPECT_SIZE_EQ( |
| 1338 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()); | |
| 1339 | 1359 |
| 1340 webViewImpl()->setTopControlsHeight(20, false); | 1360 // 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)); | 1361 visualViewport.move(FloatPoint(10000, 10000)); |
| 1348 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1362 frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| 1349 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(visualViewport , frameView); | 1363 webViewImpl()->topControls().setShownRatio(0); |
| 1350 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 | |
| 1351 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1376 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); |
| 1352 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1377 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1353 | 1378 |
| 1354 // Resize the widget to match the top controls adjustment. Ensure that scrol l | 1379 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 | 1380 |
| 1359 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.size()); | 1381 // Resize the widget to match the top controls adjustment. Ensure that the |
| 1360 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1382 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1361 EXPECT_SIZE_EQ(IntSize(1000, 860), frameView.frameRect().size()); | 1383 // the offsets to valid values. |
| 1384 webViewImpl()->resize(WebSize(500, visualViewportHeight), 20, false); | |
| 1362 | 1385 |
| 1386 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); | |
| 1387 EXPECT_SIZE_EQ( | |
| 1388 IntSize(250, visualViewportHeight / pageScale), | |
| 1389 visualViewport.visibleRect().size()); | |
| 1390 EXPECT_SIZE_EQ( | |
| 1391 IntSize(1000, layoutViewportHeight), | |
| 1392 frameView.frameRect().size()); | |
| 1393 EXPECT_POINT_EQ( | |
| 1394 totalExpected, | |
| 1395 frameView.scrollPosition() + visualViewport.location()); | |
| 1396 } | |
| 1397 | |
| 1398 // Tests that a scroll all the way to the bottom while showing the top controls | |
| 1399 // doesn't cause a clamp to the viewport scroll offset when the top controls | |
| 1400 // initiated resize occurs. | |
| 1401 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) | |
| 1402 { | |
| 1403 int topControlsHeight = 20; | |
| 1404 int visualViewportHeight = 500; | |
| 1405 int layoutViewportHeight = 1000; | |
| 1406 int contentHeight = 2000; | |
| 1407 float pageScale = 2; | |
| 1408 float minPageScale = 0.5; | |
| 1409 | |
| 1410 initializeWithAndroidSettings(); | |
| 1411 | |
| 1412 // Initialize with top controls hidden and not shrinking the Blink size. | |
| 1413 webViewImpl()->resize( | |
| 1414 IntSize(500, visualViewportHeight), | |
| 1415 20, | |
| 1416 false); | |
| 1417 webViewImpl()->topControls().setShownRatio(0); | |
| 1418 | |
| 1419 registerMockedHttpURLLoad("content-width-1000.html"); | |
| 1420 navigateTo(m_baseURL + "content-width-1000.html"); | |
| 1421 | |
| 1422 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport (); | |
| 1423 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
| 1424 | |
| 1425 visualViewport.setScale(pageScale); | |
| 1426 EXPECT_SIZE_EQ( | |
| 1427 IntSize(250, visualViewportHeight / pageScale), | |
| 1428 visualViewport.visibleRect().size()); | |
| 1429 EXPECT_SIZE_EQ( | |
| 1430 IntSize(1000, layoutViewportHeight), | |
| 1431 frameView.frameRect().size()); | |
| 1432 EXPECT_SIZE_EQ( | |
| 1433 IntSize(500, visualViewportHeight), | |
| 1434 visualViewport.size()); | |
| 1435 | |
| 1436 // Scroll all the way to the bottom, showing the the top controls in the | |
| 1437 // process. (This could happen via window.scrollTo during a scroll, for | |
| 1438 // example). | |
| 1439 webViewImpl()->topControls().setShownRatio(1); | |
| 1440 visualViewport.move(FloatPoint(10000, 10000)); | |
| 1441 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | |
| 1442 | |
| 1443 EXPECT_SIZE_EQ( | |
| 1444 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | |
| 1445 visualViewport.visibleRect().size()); | |
| 1446 | |
| 1447 IntPoint frameViewExpected = IntPoint(0, | |
| 1448 contentHeight | |
| 1449 - (layoutViewportHeight - topControlsHeight / minPageScale)); | |
| 1450 FloatPoint visualViewportExpected = | |
| 1451 FloatPoint(750, | |
| 1452 (layoutViewportHeight - topControlsHeight / minPageScale | |
| 1453 - visualViewport.visibleRect().height())); | |
| 1454 | |
| 1455 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | |
| 1363 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1456 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1364 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1457 |
| 1458 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; | |
| 1459 | |
| 1460 // Resize the widget to match the top controls adjustment. Ensure that the | |
| 1461 // total offset (i.e. what the user sees) doesn't change because of clamping | |
| 1462 // the offsets to valid values. | |
| 1463 webViewImpl()->resize( | |
| 1464 WebSize(500, visualViewportHeight - topControlsHeight), | |
| 1465 20, | |
| 1466 true); | |
| 1467 | |
| 1468 EXPECT_SIZE_EQ( | |
| 1469 IntSize(500, visualViewportHeight - topControlsHeight), | |
| 1470 visualViewport.size()); | |
| 1471 EXPECT_SIZE_EQ( | |
| 1472 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | |
| 1473 visualViewport.visibleRect().size()); | |
| 1474 EXPECT_SIZE_EQ( | |
| 1475 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), | |
| 1476 frameView.frameRect().size()); | |
| 1477 EXPECT_POINT_EQ( | |
| 1478 totalExpected, | |
| 1479 frameView.scrollPosition() + visualViewport.location()); | |
| 1365 } | 1480 } |
| 1366 | 1481 |
| 1367 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the | 1482 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the |
| 1368 // main frame's scroll offset. crbug.com/428193. | 1483 // main frame's scroll offset. crbug.com/428193. |
| 1369 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) | 1484 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) |
| 1370 { | 1485 { |
| 1371 initializeWithAndroidSettings(); | 1486 initializeWithAndroidSettings(); |
| 1372 webViewImpl()->setTopControlsHeight(500, false); | 1487 webViewImpl()->resize(webViewImpl()->size(), 500, false); |
| 1373 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); | 1488 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, 1); |
| 1374 webViewImpl()->setTopControlsHeight(500, true); | 1489 webViewImpl()->resize(IntSize(1000, 1000), 500, true); |
| 1375 webViewImpl()->resize(IntSize(1000, 1000)); | |
| 1376 | 1490 |
| 1377 registerMockedHttpURLLoad("content-width-1000.html"); | 1491 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1378 navigateTo(m_baseURL + "content-width-1000.html"); | 1492 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1379 | 1493 |
| 1380 // Scroll the FrameView to the bottom of the page but "hide" the top | 1494 // 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 | 1495 // controls on the compositor side so the max scroll position should account |
| 1382 // for the full viewport height. | 1496 // for the full viewport height. |
| 1383 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, -1); | 1497 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatS ize(), 1, -1); |
| 1384 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1498 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1385 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); | 1499 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); |
| 1386 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1500 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| 1387 | 1501 |
| 1388 // Now send the resize, make sure the scroll offset doesn't change. | 1502 // Now send the resize, make sure the scroll offset doesn't change. |
| 1389 webViewImpl()->setTopControlsHeight(500, false); | 1503 webViewImpl()->resize(IntSize(1000, 1500), 500, false); |
| 1390 webViewImpl()->resize(IntSize(1000, 1500)); | |
| 1391 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1504 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| 1392 } | 1505 } |
| 1393 | 1506 |
| 1394 // Tests that the layout viewport's scroll layer bounds are updated in a composi ting | 1507 // Tests that the layout viewport's scroll layer bounds are updated in a composi ting |
| 1395 // change update. crbug.com/423188. | 1508 // change update. crbug.com/423188. |
| 1396 TEST_P(ParameterizedVisualViewportTest, TestChangingContentSizeAffectsScrollBoun ds) | 1509 TEST_P(ParameterizedVisualViewportTest, TestChangingContentSizeAffectsScrollBoun ds) |
| 1397 { | 1510 { |
| 1398 initializeWithAndroidSettings(); | 1511 initializeWithAndroidSettings(); |
| 1399 webViewImpl()->resize(IntSize(100, 150)); | 1512 webViewImpl()->resize(IntSize(100, 150)); |
| 1400 | 1513 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1740 webViewImpl()->handleInputEvent(pinchUpdate); | 1853 webViewImpl()->handleInputEvent(pinchUpdate); |
| 1741 | 1854 |
| 1742 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi ewport(); | 1855 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi ewport(); |
| 1743 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1856 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1744 | 1857 |
| 1745 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1858 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); |
| 1746 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1859 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); |
| 1747 } | 1860 } |
| 1748 | 1861 |
| 1749 } // namespace | 1862 } // namespace |
| OLD | NEW |