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 28 matching lines...) Expand all Loading... |
39 #include "web/tests/FrameTestHelpers.h" | 39 #include "web/tests/FrameTestHelpers.h" |
40 | 40 |
41 #include <string> | 41 #include <string> |
42 | 42 |
43 #define ASSERT_POINT_EQ(expected, actual) \ | 43 #define ASSERT_POINT_EQ(expected, actual) \ |
44 do { \ | 44 do { \ |
45 ASSERT_EQ((expected).x(), (actual).x()); \ | 45 ASSERT_EQ((expected).x(), (actual).x()); \ |
46 ASSERT_EQ((expected).y(), (actual).y()); \ | 46 ASSERT_EQ((expected).y(), (actual).y()); \ |
47 } while (false) | 47 } while (false) |
48 | 48 |
| 49 #define ASSERT_SIZE_EQ(expected, actual) \ |
| 50 do { \ |
| 51 ASSERT_EQ((expected).width(), (actual).width()); \ |
| 52 ASSERT_EQ((expected).height(), (actual).height()); \ |
| 53 } while (false) |
| 54 |
49 #define EXPECT_POINT_EQ(expected, actual) \ | 55 #define EXPECT_POINT_EQ(expected, actual) \ |
50 do { \ | 56 do { \ |
51 EXPECT_EQ((expected).x(), (actual).x()); \ | 57 EXPECT_EQ((expected).x(), (actual).x()); \ |
52 EXPECT_EQ((expected).y(), (actual).y()); \ | 58 EXPECT_EQ((expected).y(), (actual).y()); \ |
53 } while (false) | 59 } while (false) |
54 | 60 |
55 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ | 61 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ |
56 do { \ | 62 do { \ |
57 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ | 63 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ |
58 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ | 64 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 registerMockedHttpURLLoad("content-width-1000.html"); | 239 registerMockedHttpURLLoad("content-width-1000.html"); |
234 navigateTo(m_baseURL + "content-width-1000.html"); | 240 navigateTo(m_baseURL + "content-width-1000.html"); |
235 | 241 |
236 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 242 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
237 VisualViewport& visualViewport = | 243 VisualViewport& visualViewport = |
238 frame()->page()->frameHost().visualViewport(); | 244 frame()->page()->frameHost().visualViewport(); |
239 | 245 |
240 visualViewport.setScale(2); | 246 visualViewport.setScale(2); |
241 | 247 |
242 // Fully scroll both viewports. | 248 // Fully scroll both viewports. |
243 frameView.layoutViewportScrollableArea()->setScrollPosition( | 249 frameView.layoutViewportScrollableArea()->setScrollOffset( |
244 DoublePoint(10000, 10000), ProgrammaticScroll); | 250 ScrollOffset(10000, 10000), ProgrammaticScroll); |
245 visualViewport.move(FloatSize(10000, 10000)); | 251 visualViewport.move(FloatSize(10000, 10000)); |
246 | 252 |
247 // Sanity check. | 253 // Sanity check. |
248 ASSERT_POINT_EQ(FloatPoint(400, 300), visualViewport.location()); | 254 ASSERT_SIZE_EQ(FloatSize(400, 300), visualViewport.scrollOffset()); |
249 ASSERT_POINT_EQ( | 255 ASSERT_SIZE_EQ(ScrollOffset(200, 1400), |
250 DoublePoint(200, 1400), | 256 frameView.layoutViewportScrollableArea()->scrollOffset()); |
251 frameView.layoutViewportScrollableArea()->scrollPositionDouble()); | |
252 | 257 |
253 DoublePoint expectedLocation = | 258 IntPoint expectedLocation = |
254 frameView.getScrollableArea()->visibleContentRectDouble().location(); | 259 frameView.getScrollableArea()->visibleContentRect().location(); |
255 | 260 |
256 // Shrink the WebView, this should cause both viewports to shrink and | 261 // Shrink the WebView, this should cause both viewports to shrink and |
257 // WebView should do whatever it needs to do to preserve the visible | 262 // WebView should do whatever it needs to do to preserve the visible |
258 // location. | 263 // location. |
259 webViewImpl()->resize(IntSize(700, 550)); | 264 webViewImpl()->resize(IntSize(700, 550)); |
260 | 265 |
261 EXPECT_POINT_EQ( | 266 EXPECT_POINT_EQ( |
262 expectedLocation, | 267 expectedLocation, |
263 frameView.getScrollableArea()->visibleContentRectDouble().location()); | 268 frameView.getScrollableArea()->visibleContentRect().location()); |
264 | 269 |
265 webViewImpl()->resize(IntSize(800, 600)); | 270 webViewImpl()->resize(IntSize(800, 600)); |
266 | 271 |
267 EXPECT_POINT_EQ( | 272 EXPECT_POINT_EQ( |
268 expectedLocation, | 273 expectedLocation, |
269 frameView.getScrollableArea()->visibleContentRectDouble().location()); | 274 frameView.getScrollableArea()->visibleContentRect().location()); |
270 } | 275 } |
271 | 276 |
272 // Test that the VisualViewport works as expected in case of a scaled | 277 // Test that the VisualViewport works as expected in case of a scaled |
273 // and scrolled viewport - scroll down. | 278 // and scrolled viewport - scroll down. |
274 TEST_P(ParameterizedVisualViewportTest, TestResizeAfterVerticalScroll) { | 279 TEST_P(ParameterizedVisualViewportTest, TestResizeAfterVerticalScroll) { |
275 /* | 280 /* |
276 200 200 | 281 200 200 |
277 | | | | | 282 | | | | |
278 | | | | | 283 | | | | |
279 | | 800 | | 800 | 284 | | 800 | | 800 |
(...skipping 25 matching lines...) Expand all Loading... |
305 | 310 |
306 initializeWithAndroidSettings(); | 311 initializeWithAndroidSettings(); |
307 | 312 |
308 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 313 registerMockedHttpURLLoad("200-by-800-viewport.html"); |
309 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 314 navigateTo(m_baseURL + "200-by-800-viewport.html"); |
310 | 315 |
311 webViewImpl()->resize(IntSize(100, 200)); | 316 webViewImpl()->resize(IntSize(100, 200)); |
312 | 317 |
313 // Scroll main frame to the bottom of the document | 318 // Scroll main frame to the bottom of the document |
314 webViewImpl()->mainFrame()->setScrollOffset(WebSize(0, 400)); | 319 webViewImpl()->mainFrame()->setScrollOffset(WebSize(0, 400)); |
315 EXPECT_POINT_EQ( | 320 EXPECT_SIZE_EQ( |
316 IntPoint(0, 400), | 321 ScrollOffset(0, 400), |
317 frame()->view()->layoutViewportScrollableArea()->scrollPosition()); | 322 frame()->view()->layoutViewportScrollableArea()->scrollOffset()); |
318 | 323 |
319 webViewImpl()->setPageScaleFactor(2.0); | 324 webViewImpl()->setPageScaleFactor(2.0); |
320 | 325 |
321 // Scroll visual viewport to the bottom of the main frame | 326 // Scroll visual viewport to the bottom of the main frame |
322 VisualViewport& visualViewport = | 327 VisualViewport& visualViewport = |
323 frame()->page()->frameHost().visualViewport(); | 328 frame()->page()->frameHost().visualViewport(); |
324 visualViewport.setLocation(FloatPoint(0, 300)); | 329 visualViewport.setLocation(FloatPoint(0, 300)); |
325 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 300), visualViewport.location()); | 330 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 300), visualViewport.scrollOffset()); |
326 | 331 |
327 // Verify the initial size of the visual viewport in the CSS pixels | 332 // Verify the initial size of the visual viewport in the CSS pixels |
328 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.visibleRect().size()); | 333 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.visibleRect().size()); |
329 | 334 |
330 // Perform the resizing | 335 // Perform the resizing |
331 webViewImpl()->resize(IntSize(200, 100)); | 336 webViewImpl()->resize(IntSize(200, 100)); |
332 | 337 |
333 // After resizing the scale changes 2.0 -> 4.0 | 338 // After resizing the scale changes 2.0 -> 4.0 |
334 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.visibleRect().size()); | 339 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.visibleRect().size()); |
335 | 340 |
336 EXPECT_POINT_EQ( | 341 EXPECT_SIZE_EQ( |
337 IntPoint(0, 625), | 342 ScrollOffset(0, 625), |
338 frame()->view()->layoutViewportScrollableArea()->scrollPosition()); | 343 frame()->view()->layoutViewportScrollableArea()->scrollOffset()); |
339 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 75), visualViewport.location()); | 344 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 75), visualViewport.scrollOffset()); |
340 } | 345 } |
341 | 346 |
342 // Test that the VisualViewport works as expected in case if a scaled | 347 // Test that the VisualViewport works as expected in case if a scaled |
343 // and scrolled viewport - scroll right. | 348 // and scrolled viewport - scroll right. |
344 TEST_P(ParameterizedVisualViewportTest, TestResizeAfterHorizontalScroll) { | 349 TEST_P(ParameterizedVisualViewportTest, TestResizeAfterHorizontalScroll) { |
345 /* | 350 /* |
346 200 200 | 351 200 200 |
347 ---------------o----- ---------------o----- | 352 ---------------o----- ---------------o----- |
348 | | | | 25| | | 353 | | | | 25| | |
349 | | | | -----| | 354 | | | | -----| |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 webViewImpl()->resize(IntSize(100, 200)); | 388 webViewImpl()->resize(IntSize(100, 200)); |
384 | 389 |
385 // Outer viewport takes the whole width of the document. | 390 // Outer viewport takes the whole width of the document. |
386 | 391 |
387 webViewImpl()->setPageScaleFactor(2.0); | 392 webViewImpl()->setPageScaleFactor(2.0); |
388 | 393 |
389 // Scroll visual viewport to the right edge of the frame | 394 // Scroll visual viewport to the right edge of the frame |
390 VisualViewport& visualViewport = | 395 VisualViewport& visualViewport = |
391 frame()->page()->frameHost().visualViewport(); | 396 frame()->page()->frameHost().visualViewport(); |
392 visualViewport.setLocation(FloatPoint(150, 0)); | 397 visualViewport.setLocation(FloatPoint(150, 0)); |
393 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), visualViewport.location()); | 398 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visualViewport.scrollOffset()); |
394 | 399 |
395 // Verify the initial size of the visual viewport in the CSS pixels | 400 // Verify the initial size of the visual viewport in the CSS pixels |
396 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.visibleRect().size()); | 401 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.visibleRect().size()); |
397 | 402 |
398 webViewImpl()->resize(IntSize(200, 100)); | 403 webViewImpl()->resize(IntSize(200, 100)); |
399 | 404 |
400 // After resizing the scale changes 2.0 -> 4.0 | 405 // After resizing the scale changes 2.0 -> 4.0 |
401 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.visibleRect().size()); | 406 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.visibleRect().size()); |
402 | 407 |
403 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); | 408 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); |
404 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), visualViewport.location()); | 409 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visualViewport.scrollOffset()); |
405 } | 410 } |
406 | 411 |
407 // Test that the container layer gets sized properly if the WebView is resized | 412 // Test that the container layer gets sized properly if the WebView is resized |
408 // prior to the VisualViewport being attached to the layer tree. | 413 // prior to the VisualViewport being attached to the layer tree. |
409 TEST_P(ParameterizedVisualViewportTest, TestWebViewResizedBeforeAttachment) { | 414 TEST_P(ParameterizedVisualViewportTest, TestWebViewResizedBeforeAttachment) { |
410 initializeWithDesktopSettings(); | 415 initializeWithDesktopSettings(); |
411 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 416 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
412 GraphicsLayer* rootGraphicsLayer = | 417 GraphicsLayer* rootGraphicsLayer = |
413 frameView.layoutViewItem().compositor()->rootGraphicsLayer(); | 418 frameView.layoutViewItem().compositor()->rootGraphicsLayer(); |
414 | 419 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 499 |
495 // Scale the viewport to 2X and move it. | 500 // Scale the viewport to 2X and move it. |
496 visualViewport.setScale(2); | 501 visualViewport.setScale(2); |
497 visualViewport.setLocation(FloatPoint(10, 15)); | 502 visualViewport.setLocation(FloatPoint(10, 15)); |
498 EXPECT_FLOAT_RECT_EQ(FloatRect(10, 15, 50, 200), | 503 EXPECT_FLOAT_RECT_EQ(FloatRect(10, 15, 50, 200), |
499 visualViewport.visibleRectInDocument()); | 504 visualViewport.visibleRectInDocument()); |
500 | 505 |
501 // Scroll the layout viewport. Ensure its offset is reflected in | 506 // Scroll the layout viewport. Ensure its offset is reflected in |
502 // visibleRectInDocument(). | 507 // visibleRectInDocument(). |
503 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 508 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
504 frameView.layoutViewportScrollableArea()->setScrollPosition( | 509 frameView.layoutViewportScrollableArea()->setScrollOffset( |
505 DoublePoint(40, 100), ProgrammaticScroll); | 510 ScrollOffset(40, 100), ProgrammaticScroll); |
506 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200), | 511 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200), |
507 visualViewport.visibleRectInDocument()); | 512 visualViewport.visibleRectInDocument()); |
508 } | 513 } |
509 | 514 |
510 TEST_P(ParameterizedVisualViewportTest, | 515 TEST_P(ParameterizedVisualViewportTest, |
511 TestFractionalScrollOffsetIsNotOverwritten) { | 516 TestFractionalScrollOffsetIsNotOverwritten) { |
512 bool origFractionalOffsetsEnabled = | 517 bool origFractionalOffsetsEnabled = |
513 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); | 518 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); |
514 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); | 519 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); |
515 | 520 |
516 initializeWithAndroidSettings(); | 521 initializeWithAndroidSettings(); |
517 webViewImpl()->resize(IntSize(200, 250)); | 522 webViewImpl()->resize(IntSize(200, 250)); |
518 | 523 |
519 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 524 registerMockedHttpURLLoad("200-by-800-viewport.html"); |
520 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 525 navigateTo(m_baseURL + "200-by-800-viewport.html"); |
521 | 526 |
522 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 527 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
523 frameView.layoutViewportScrollableArea()->setScrollPosition( | 528 frameView.layoutViewportScrollableArea()->setScrollOffset( |
524 DoublePoint(0, 10.5), ProgrammaticScroll); | 529 ScrollOffset(0, 10.5), ProgrammaticScroll); |
525 frameView.layoutViewportScrollableArea()->ScrollableArea::setScrollPosition( | 530 frameView.layoutViewportScrollableArea()->ScrollableArea::setScrollOffset( |
526 DoublePoint(10, 30.5), CompositorScroll); | 531 ScrollOffset(10, 30.5), CompositorScroll); |
527 | 532 |
528 EXPECT_EQ( | 533 EXPECT_EQ(30.5, |
529 30.5, | 534 frameView.layoutViewportScrollableArea()->scrollOffset().height()); |
530 frameView.layoutViewportScrollableArea()->scrollPositionDouble().y()); | |
531 | 535 |
532 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled( | 536 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled( |
533 origFractionalOffsetsEnabled); | 537 origFractionalOffsetsEnabled); |
534 } | 538 } |
535 | 539 |
536 // Test that the viewport's scroll offset is always appropriately bounded such | 540 // Test that the viewport's scroll offset is always appropriately bounded such |
537 // that the visual viewport always stays within the bounds of the main frame. | 541 // that the visual viewport always stays within the bounds of the main frame. |
538 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) { | 542 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) { |
539 initializeWithDesktopSettings(); | 543 initializeWithDesktopSettings(); |
540 webViewImpl()->resize(IntSize(320, 240)); | 544 webViewImpl()->resize(IntSize(320, 240)); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 763 |
760 // Load a wider page first, the navigation should resize the scroll layer to | 764 // Load a wider page first, the navigation should resize the scroll layer to |
761 // the smaller size on the second navigation. | 765 // the smaller size on the second navigation. |
762 registerMockedHttpURLLoad("content-width-1000.html"); | 766 registerMockedHttpURLLoad("content-width-1000.html"); |
763 navigateTo(m_baseURL + "content-width-1000.html"); | 767 navigateTo(m_baseURL + "content-width-1000.html"); |
764 webViewImpl()->updateAllLifecyclePhases(); | 768 webViewImpl()->updateAllLifecyclePhases(); |
765 | 769 |
766 VisualViewport& visualViewport = | 770 VisualViewport& visualViewport = |
767 frame()->page()->frameHost().visualViewport(); | 771 frame()->page()->frameHost().visualViewport(); |
768 visualViewport.setScale(2); | 772 visualViewport.setScale(2); |
769 visualViewport.move(FloatPoint(50, 60)); | 773 visualViewport.move(ScrollOffset(50, 60)); |
770 | 774 |
771 // Move and scale the viewport to make sure it gets reset in the navigation. | 775 // Move and scale the viewport to make sure it gets reset in the navigation. |
772 EXPECT_POINT_EQ(FloatPoint(50, 60), visualViewport.location()); | 776 EXPECT_SIZE_EQ(FloatSize(50, 60), visualViewport.scrollOffset()); |
773 EXPECT_EQ(2, visualViewport.scale()); | 777 EXPECT_EQ(2, visualViewport.scale()); |
774 | 778 |
775 // Navigate again, this time the FrameView should be smaller. | 779 // Navigate again, this time the FrameView should be smaller. |
776 registerMockedHttpURLLoad("viewport-device-width.html"); | 780 registerMockedHttpURLLoad("viewport-device-width.html"); |
777 navigateTo(m_baseURL + "viewport-device-width.html"); | 781 navigateTo(m_baseURL + "viewport-device-width.html"); |
778 | 782 |
779 // Ensure the scroll layer matches the frame view's size. | 783 // Ensure the scroll layer matches the frame view's size. |
780 EXPECT_SIZE_EQ(FloatSize(320, 240), visualViewport.scrollLayer()->size()); | 784 EXPECT_SIZE_EQ(FloatSize(320, 240), visualViewport.scrollLayer()->size()); |
781 | 785 |
782 // Ensure the location and scale were reset. | 786 // Ensure the location and scale were reset. |
783 EXPECT_POINT_EQ(FloatPoint(), visualViewport.location()); | 787 EXPECT_SIZE_EQ(FloatSize(), visualViewport.scrollOffset()); |
784 EXPECT_EQ(1, visualViewport.scale()); | 788 EXPECT_EQ(1, visualViewport.scale()); |
785 } | 789 } |
786 | 790 |
787 // The main FrameView's size should be set such that its the size of the visual | 791 // The main FrameView's size should be set such that its the size of the visual |
788 // viewport at minimum scale. Test that the FrameView is appropriately sized in | 792 // viewport at minimum scale. Test that the FrameView is appropriately sized in |
789 // the presence of a viewport <meta> tag. | 793 // the presence of a viewport <meta> tag. |
790 TEST_P(ParameterizedVisualViewportTest, | 794 TEST_P(ParameterizedVisualViewportTest, |
791 TestFrameViewSizedToViewportMetaMinimumScale) { | 795 TestFrameViewSizedToViewportMetaMinimumScale) { |
792 initializeWithAndroidSettings(); | 796 initializeWithAndroidSettings(); |
793 webViewImpl()->resize(IntSize(320, 240)); | 797 webViewImpl()->resize(IntSize(320, 240)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // Test that the HistoryItem for the page stores the visual viewport's offset | 863 // Test that the HistoryItem for the page stores the visual viewport's offset |
860 // and scale. | 864 // and scale. |
861 TEST_P(ParameterizedVisualViewportTest, TestSavedToHistoryItem) { | 865 TEST_P(ParameterizedVisualViewportTest, TestSavedToHistoryItem) { |
862 initializeWithDesktopSettings(); | 866 initializeWithDesktopSettings(); |
863 webViewImpl()->resize(IntSize(200, 300)); | 867 webViewImpl()->resize(IntSize(200, 300)); |
864 webViewImpl()->updateAllLifecyclePhases(); | 868 webViewImpl()->updateAllLifecyclePhases(); |
865 | 869 |
866 registerMockedHttpURLLoad("200-by-300.html"); | 870 registerMockedHttpURLLoad("200-by-300.html"); |
867 navigateTo(m_baseURL + "200-by-300.html"); | 871 navigateTo(m_baseURL + "200-by-300.html"); |
868 | 872 |
869 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 873 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
870 toLocalFrame(webViewImpl()->page()->mainFrame()) | 874 toLocalFrame(webViewImpl()->page()->mainFrame()) |
871 ->loader() | 875 ->loader() |
872 .currentItem() | 876 .currentItem() |
873 ->visualViewportScrollPoint()); | 877 ->visualViewportScrollOffset()); |
874 | 878 |
875 VisualViewport& visualViewport = | 879 VisualViewport& visualViewport = |
876 frame()->page()->frameHost().visualViewport(); | 880 frame()->page()->frameHost().visualViewport(); |
877 visualViewport.setScale(2); | 881 visualViewport.setScale(2); |
878 | 882 |
879 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) | 883 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) |
880 ->loader() | 884 ->loader() |
881 .currentItem() | 885 .currentItem() |
882 ->pageScaleFactor()); | 886 ->pageScaleFactor()); |
883 | 887 |
884 visualViewport.setLocation(FloatPoint(10, 20)); | 888 visualViewport.setLocation(FloatPoint(10, 20)); |
885 | 889 |
886 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20), | 890 EXPECT_SIZE_EQ(ScrollOffset(10, 20), |
887 toLocalFrame(webViewImpl()->page()->mainFrame()) | 891 toLocalFrame(webViewImpl()->page()->mainFrame()) |
888 ->loader() | 892 ->loader() |
889 .currentItem() | 893 .currentItem() |
890 ->visualViewportScrollPoint()); | 894 ->visualViewportScrollOffset()); |
891 } | 895 } |
892 | 896 |
893 // Test restoring a HistoryItem properly restores the visual viewport's state. | 897 // Test restoring a HistoryItem properly restores the visual viewport's state. |
894 TEST_P(ParameterizedVisualViewportTest, TestRestoredFromHistoryItem) { | 898 TEST_P(ParameterizedVisualViewportTest, TestRestoredFromHistoryItem) { |
895 initializeWithDesktopSettings(); | 899 initializeWithDesktopSettings(); |
896 webViewImpl()->resize(IntSize(200, 300)); | 900 webViewImpl()->resize(IntSize(200, 300)); |
897 | 901 |
898 registerMockedHttpURLLoad("200-by-300.html"); | 902 registerMockedHttpURLLoad("200-by-300.html"); |
899 | 903 |
900 WebHistoryItem item; | 904 WebHistoryItem item; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 item.setScrollOffset(WebPoint(120, 180)); | 940 item.setScrollOffset(WebPoint(120, 180)); |
937 item.setPageScaleFactor(2); | 941 item.setPageScaleFactor(2); |
938 | 942 |
939 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, | 943 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, |
940 WebHistoryDifferentDocumentLoad, | 944 WebHistoryDifferentDocumentLoad, |
941 WebCachePolicy::UseProtocolCachePolicy); | 945 WebCachePolicy::UseProtocolCachePolicy); |
942 | 946 |
943 VisualViewport& visualViewport = | 947 VisualViewport& visualViewport = |
944 frame()->page()->frameHost().visualViewport(); | 948 frame()->page()->frameHost().visualViewport(); |
945 EXPECT_EQ(2, visualViewport.scale()); | 949 EXPECT_EQ(2, visualViewport.scale()); |
946 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 950 EXPECT_SIZE_EQ(ScrollOffset(100, 150), frame()->view()->scrollOffset()); |
947 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), | 951 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), |
948 visualViewport.visibleRect().location()); | 952 visualViewport.visibleRect().location()); |
949 } | 953 } |
950 | 954 |
951 // Test that navigation to a new page with a different sized main frame doesn't | 955 // Test that navigation to a new page with a different sized main frame doesn't |
952 // clobber the history item's main frame scroll offset. crbug.com/371867 | 956 // clobber the history item's main frame scroll offset. crbug.com/371867 |
953 TEST_P(ParameterizedVisualViewportTest, | 957 TEST_P(ParameterizedVisualViewportTest, |
954 TestNavigateToSmallerFrameViewHistoryItemClobberBug) { | 958 TestNavigateToSmallerFrameViewHistoryItemClobberBug) { |
955 initializeWithAndroidSettings(); | 959 initializeWithAndroidSettings(); |
956 webViewImpl()->resize(IntSize(400, 400)); | 960 webViewImpl()->resize(IntSize(400, 400)); |
957 webViewImpl()->updateAllLifecyclePhases(); | 961 webViewImpl()->updateAllLifecyclePhases(); |
958 | 962 |
959 registerMockedHttpURLLoad("content-width-1000.html"); | 963 registerMockedHttpURLLoad("content-width-1000.html"); |
960 navigateTo(m_baseURL + "content-width-1000.html"); | 964 navigateTo(m_baseURL + "content-width-1000.html"); |
961 | 965 |
962 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView(); | 966 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView(); |
963 frameView->layoutViewportScrollableArea()->setScrollPosition( | 967 frameView->layoutViewportScrollableArea()->setScrollOffset( |
964 IntPoint(0, 1000), ProgrammaticScroll); | 968 ScrollOffset(0, 1000), ProgrammaticScroll); |
965 | 969 |
966 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size()); | 970 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size()); |
967 | 971 |
968 VisualViewport& visualViewport = | 972 VisualViewport& visualViewport = |
969 frame()->page()->frameHost().visualViewport(); | 973 frame()->page()->frameHost().visualViewport(); |
970 visualViewport.setScale(2); | 974 visualViewport.setScale(2); |
971 visualViewport.setLocation(FloatPoint(350, 350)); | 975 visualViewport.setLocation(FloatPoint(350, 350)); |
972 | 976 |
973 Persistent<HistoryItem> firstItem = | 977 Persistent<HistoryItem> firstItem = |
974 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem(); | 978 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem(); |
975 EXPECT_POINT_EQ(IntPoint(0, 1000), firstItem->scrollPoint()); | 979 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->scrollOffset()); |
976 | 980 |
977 // Now navigate to a page which causes a smaller frameView. Make sure that | 981 // Now navigate to a page which causes a smaller frameView. Make sure that |
978 // navigating doesn't cause the history item to set a new scroll offset | 982 // navigating doesn't cause the history item to set a new scroll offset |
979 // before the item was replaced. | 983 // before the item was replaced. |
980 navigateTo("about:blank"); | 984 navigateTo("about:blank"); |
981 frameView = webViewImpl()->mainFrameImpl()->frameView(); | 985 frameView = webViewImpl()->mainFrameImpl()->frameView(); |
982 | 986 |
983 EXPECT_NE(firstItem, | 987 EXPECT_NE(firstItem, |
984 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem()); | 988 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem()); |
985 EXPECT_LT(frameView->frameRect().size().width(), 1000); | 989 EXPECT_LT(frameView->frameRect().size().width(), 1000); |
986 EXPECT_POINT_EQ(IntPoint(0, 1000), firstItem->scrollPoint()); | 990 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->scrollOffset()); |
987 } | 991 } |
988 | 992 |
989 // Test that the coordinates sent into moveRangeSelection are offset by the | 993 // Test that the coordinates sent into moveRangeSelection are offset by the |
990 // visual viewport's location. | 994 // visual viewport's location. |
991 TEST_P(ParameterizedVisualViewportTest, | 995 TEST_P(ParameterizedVisualViewportTest, |
992 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { | 996 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { |
993 initializeWithDesktopSettings(); | 997 initializeWithDesktopSettings(); |
994 webViewImpl()->settings()->setDefaultFontSize(12); | 998 webViewImpl()->settings()->setDefaultFontSize(12); |
995 webViewImpl()->resize(WebSize(640, 480)); | 999 webViewImpl()->resize(WebSize(640, 480)); |
996 registerMockedHttpURLLoad("move_range.html"); | 1000 registerMockedHttpURLLoad("move_range.html"); |
(...skipping 13 matching lines...) Expand all Loading... |
1010 | 1014 |
1011 webViewImpl()->selectionBounds(baseRect, extentRect); | 1015 webViewImpl()->selectionBounds(baseRect, extentRect); |
1012 WebPoint initialPoint(baseRect.x, baseRect.y); | 1016 WebPoint initialPoint(baseRect.x, baseRect.y); |
1013 WebPoint endPoint(extentRect.x, extentRect.y); | 1017 WebPoint endPoint(extentRect.x, extentRect.y); |
1014 | 1018 |
1015 // Move the visual viewport over and make the selection in the same | 1019 // Move the visual viewport over and make the selection in the same |
1016 // screen-space location. The selection should change to two characters to the | 1020 // screen-space location. The selection should change to two characters to the |
1017 // right and down one line. | 1021 // right and down one line. |
1018 VisualViewport& visualViewport = | 1022 VisualViewport& visualViewport = |
1019 frame()->page()->frameHost().visualViewport(); | 1023 frame()->page()->frameHost().visualViewport(); |
1020 visualViewport.move(FloatPoint(60, 25)); | 1024 visualViewport.move(ScrollOffset(60, 25)); |
1021 mainFrame->toWebLocalFrame()->moveRangeSelection(initialPoint, endPoint); | 1025 mainFrame->toWebLocalFrame()->moveRangeSelection(initialPoint, endPoint); |
1022 EXPECT_EQ("t ", mainFrame->toWebLocalFrame()->selectionAsText().utf8()); | 1026 EXPECT_EQ("t ", mainFrame->toWebLocalFrame()->selectionAsText().utf8()); |
1023 } | 1027 } |
1024 | 1028 |
1025 // Test that the scrollFocusedEditableElementIntoRect method works with the | 1029 // Test that the scrollFocusedEditableElementIntoRect method works with the |
1026 // visual viewport. | 1030 // visual viewport. |
1027 TEST_P(ParameterizedVisualViewportTest, | 1031 TEST_P(ParameterizedVisualViewportTest, |
1028 DISABLED_TestScrollFocusedEditableElementIntoRect) { | 1032 DISABLED_TestScrollFocusedEditableElementIntoRect) { |
1029 initializeWithDesktopSettings(); | 1033 initializeWithDesktopSettings(); |
1030 webViewImpl()->resize(IntSize(500, 300)); | 1034 webViewImpl()->resize(IntSize(500, 300)); |
1031 | 1035 |
1032 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); | 1036 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); |
1033 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); | 1037 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); |
1034 | 1038 |
1035 VisualViewport& visualViewport = | 1039 VisualViewport& visualViewport = |
1036 frame()->page()->frameHost().visualViewport(); | 1040 frame()->page()->frameHost().visualViewport(); |
1037 webViewImpl()->resizeVisualViewport(IntSize(200, 100)); | 1041 webViewImpl()->resizeVisualViewport(IntSize(200, 100)); |
1038 webViewImpl()->setInitialFocus(false); | 1042 webViewImpl()->setInitialFocus(false); |
1039 visualViewport.setLocation(FloatPoint()); | 1043 visualViewport.setLocation(FloatPoint()); |
1040 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1044 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
1041 | 1045 |
1042 EXPECT_POINT_EQ(IntPoint(0, frame()->view()->maximumScrollPosition().y()), | 1046 EXPECT_SIZE_EQ( |
1043 frame()->view()->scrollPosition()); | 1047 ScrollOffset(0, frame()->view()->maximumScrollOffset().height()), |
| 1048 frame()->view()->scrollOffset()); |
1044 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200), | 1049 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200), |
1045 visualViewport.visibleRect().location()); | 1050 visualViewport.visibleRect().location()); |
1046 | 1051 |
1047 // Try it again but with the page zoomed in | 1052 // Try it again but with the page zoomed in |
1048 frame()->view()->setScrollPosition(IntPoint(0, 0), ProgrammaticScroll); | 1053 frame()->view()->setScrollOffset(ScrollOffset(0, 0), ProgrammaticScroll); |
1049 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); | 1054 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); |
1050 visualViewport.setLocation(FloatPoint(0, 0)); | 1055 visualViewport.setLocation(FloatPoint(0, 0)); |
1051 | 1056 |
1052 webViewImpl()->setPageScaleFactor(2); | 1057 webViewImpl()->setPageScaleFactor(2); |
1053 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1058 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
1054 EXPECT_POINT_EQ(IntPoint(0, frame()->view()->maximumScrollPosition().y()), | 1059 EXPECT_SIZE_EQ( |
1055 frame()->view()->scrollPosition()); | 1060 ScrollOffset(0, frame()->view()->maximumScrollOffset().height()), |
| 1061 frame()->view()->scrollOffset()); |
1056 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150), | 1062 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150), |
1057 visualViewport.visibleRect().location()); | 1063 visualViewport.visibleRect().location()); |
1058 | 1064 |
1059 // Once more but make sure that we don't move the visual viewport unless | 1065 // Once more but make sure that we don't move the visual viewport unless |
1060 // necessary. | 1066 // necessary. |
1061 registerMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html"); | 1067 registerMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html"); |
1062 navigateTo(m_baseURL + "pinch-viewport-input-field-long-and-wide.html"); | 1068 navigateTo(m_baseURL + "pinch-viewport-input-field-long-and-wide.html"); |
1063 webViewImpl()->setInitialFocus(false); | 1069 webViewImpl()->setInitialFocus(false); |
1064 visualViewport.setLocation(FloatPoint()); | 1070 visualViewport.setLocation(FloatPoint()); |
1065 frame()->view()->setScrollPosition(IntPoint(0, 0), ProgrammaticScroll); | 1071 frame()->view()->setScrollOffset(ScrollOffset(0, 0), ProgrammaticScroll); |
1066 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); | 1072 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); |
1067 visualViewport.setLocation(FloatPoint(30, 50)); | 1073 visualViewport.setLocation(FloatPoint(30, 50)); |
1068 | 1074 |
1069 webViewImpl()->setPageScaleFactor(2); | 1075 webViewImpl()->setPageScaleFactor(2); |
1070 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1076 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
1071 EXPECT_POINT_EQ(IntPoint(200 - 30 - 75, 600 - 50 - 65), | 1077 EXPECT_SIZE_EQ(ScrollOffset(200 - 30 - 75, 600 - 50 - 65), |
1072 frame()->view()->scrollPosition()); | 1078 frame()->view()->scrollOffset()); |
1073 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50), | 1079 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50), |
1074 visualViewport.visibleRect().location()); | 1080 visualViewport.visibleRect().location()); |
1075 } | 1081 } |
1076 | 1082 |
1077 // Test that resizing the WebView causes ViewportConstrained objects to | 1083 // Test that resizing the WebView causes ViewportConstrained objects to |
1078 // relayout. | 1084 // relayout. |
1079 TEST_P(ParameterizedVisualViewportTest, | 1085 TEST_P(ParameterizedVisualViewportTest, |
1080 TestWebViewResizeCausesViewportConstrainedLayout) { | 1086 TestWebViewResizeCausesViewportConstrainedLayout) { |
1081 initializeWithDesktopSettings(); | 1087 initializeWithDesktopSettings(); |
1082 webViewImpl()->resize(IntSize(500, 300)); | 1088 webViewImpl()->resize(IntSize(500, 300)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 frameView.layoutViewportScrollableArea(); | 1220 frameView.layoutViewportScrollableArea(); |
1215 VisualViewport& visualViewport = | 1221 VisualViewport& visualViewport = |
1216 frame()->page()->frameHost().visualViewport(); | 1222 frame()->page()->frameHost().visualViewport(); |
1217 Element* inputBox = frame()->document()->getElementById("box"); | 1223 Element* inputBox = frame()->document()->getElementById("box"); |
1218 | 1224 |
1219 webViewImpl()->setPageScaleFactor(2); | 1225 webViewImpl()->setPageScaleFactor(2); |
1220 | 1226 |
1221 // The element is already in the view so the scrollIntoView shouldn't move | 1227 // The element is already in the view so the scrollIntoView shouldn't move |
1222 // the viewport at all. | 1228 // the viewport at all. |
1223 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); | 1229 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); |
1224 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), | 1230 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.75), |
1225 ProgrammaticScroll); | 1231 ProgrammaticScroll); |
1226 inputBox->scrollIntoViewIfNeeded(false); | 1232 inputBox->scrollIntoViewIfNeeded(false); |
1227 | 1233 |
1228 EXPECT_POINT_EQ(DoublePoint(0, 900), | 1234 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
1229 layoutViewportScrollableArea->scrollPositionDouble()); | 1235 layoutViewportScrollableArea->scrollOffset()); |
1230 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); | 1236 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), visualViewport.scrollOffset()); |
1231 | 1237 |
1232 // Change the fractional part of the frameview to one that would round down. | 1238 // Change the fractional part of the frameview to one that would round down. |
1233 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), | 1239 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.125), |
1234 ProgrammaticScroll); | 1240 ProgrammaticScroll); |
1235 inputBox->scrollIntoViewIfNeeded(false); | 1241 inputBox->scrollIntoViewIfNeeded(false); |
1236 | 1242 |
1237 EXPECT_POINT_EQ(DoublePoint(0, 900), | 1243 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
1238 layoutViewportScrollableArea->scrollPositionDouble()); | 1244 layoutViewportScrollableArea->scrollOffset()); |
1239 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); | 1245 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), visualViewport.scrollOffset()); |
1240 | 1246 |
1241 // Repeat both tests above with the visual viewport at a high fractional. | 1247 // Repeat both tests above with the visual viewport at a high fractional. |
1242 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); | 1248 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); |
1243 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), | 1249 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.75), |
1244 ProgrammaticScroll); | 1250 ProgrammaticScroll); |
1245 inputBox->scrollIntoViewIfNeeded(false); | 1251 inputBox->scrollIntoViewIfNeeded(false); |
1246 | 1252 |
1247 EXPECT_POINT_EQ(DoublePoint(0, 900), | 1253 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
1248 layoutViewportScrollableArea->scrollPositionDouble()); | 1254 layoutViewportScrollableArea->scrollOffset()); |
1249 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); | 1255 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), visualViewport.scrollOffset()); |
1250 | 1256 |
1251 // Change the fractional part of the frameview to one that would round down. | 1257 // Change the fractional part of the frameview to one that would round down. |
1252 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), | 1258 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.125), |
1253 ProgrammaticScroll); | 1259 ProgrammaticScroll); |
1254 inputBox->scrollIntoViewIfNeeded(false); | 1260 inputBox->scrollIntoViewIfNeeded(false); |
1255 | 1261 |
1256 EXPECT_POINT_EQ(DoublePoint(0, 900), | 1262 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
1257 layoutViewportScrollableArea->scrollPositionDouble()); | 1263 layoutViewportScrollableArea->scrollOffset()); |
1258 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); | 1264 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), visualViewport.scrollOffset()); |
1259 | 1265 |
1260 // Both viewports with a 0.5 fraction. | 1266 // Both viewports with a 0.5 fraction. |
1261 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); | 1267 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); |
1262 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), | 1268 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.5), |
1263 ProgrammaticScroll); | 1269 ProgrammaticScroll); |
1264 inputBox->scrollIntoViewIfNeeded(false); | 1270 inputBox->scrollIntoViewIfNeeded(false); |
1265 | 1271 |
1266 EXPECT_POINT_EQ(DoublePoint(0, 900), | 1272 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
1267 layoutViewportScrollableArea->scrollPositionDouble()); | 1273 layoutViewportScrollableArea->scrollOffset()); |
1268 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); | 1274 EXPECT_SIZE_EQ(FloatSize(250.5f, 100.5f), visualViewport.scrollOffset()); |
1269 } | 1275 } |
1270 | 1276 |
1271 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport, | 1277 static ScrollOffset expectedMaxFrameViewScrollOffset( |
1272 FrameView& frameView) { | 1278 VisualViewport& visualViewport, |
| 1279 FrameView& frameView) { |
1273 float aspectRatio = visualViewport.visibleRect().width() / | 1280 float aspectRatio = visualViewport.visibleRect().width() / |
1274 visualViewport.visibleRect().height(); | 1281 visualViewport.visibleRect().height(); |
1275 float newHeight = frameView.frameRect().width() / aspectRatio; | 1282 float newHeight = frameView.frameRect().width() / aspectRatio; |
1276 return IntPoint( | 1283 return ScrollOffset( |
1277 frameView.contentsSize().width() - frameView.frameRect().width(), | 1284 frameView.contentsSize().width() - frameView.frameRect().width(), |
1278 frameView.contentsSize().height() - newHeight); | 1285 frameView.contentsSize().height() - newHeight); |
1279 } | 1286 } |
1280 | 1287 |
1281 TEST_F(VisualViewportTest, TestTopControlsAdjustment) { | 1288 TEST_F(VisualViewportTest, TestTopControlsAdjustment) { |
1282 initializeWithAndroidSettings(); | 1289 initializeWithAndroidSettings(); |
1283 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); | 1290 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); |
1284 | 1291 |
1285 registerMockedHttpURLLoad("content-width-1000.html"); | 1292 registerMockedHttpURLLoad("content-width-1000.html"); |
1286 navigateTo(m_baseURL + "content-width-1000.html"); | 1293 navigateTo(m_baseURL + "content-width-1000.html"); |
1287 | 1294 |
1288 VisualViewport& visualViewport = | 1295 VisualViewport& visualViewport = |
1289 frame()->page()->frameHost().visualViewport(); | 1296 frame()->page()->frameHost().visualViewport(); |
1290 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1297 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1291 | 1298 |
1292 visualViewport.setScale(1); | 1299 visualViewport.setScale(1); |
1293 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); | 1300 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); |
1294 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1301 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
1295 | 1302 |
1296 // Simulate bringing down the top controls by 20px. | 1303 // Simulate bringing down the top controls by 20px. |
1297 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1304 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1298 WebFloatSize(), 1, 1); | 1305 WebFloatSize(), 1, 1); |
1299 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); | 1306 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); |
1300 | 1307 |
1301 // Test that the scroll bounds are adjusted appropriately: the visual viewport | 1308 // Test that the scroll bounds are adjusted appropriately: the visual viewport |
1302 // should be shrunk by 20px to 430px. The outer viewport was shrunk to | 1309 // should be shrunk by 20px to 430px. The outer viewport was shrunk to |
1303 // maintain the aspect ratio so it's height is 860px. | 1310 // maintain the |
1304 visualViewport.move(FloatPoint(10000, 10000)); | 1311 // aspect ratio so it's height is 860px. |
1305 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); | 1312 visualViewport.move(ScrollOffset(10000, 10000)); |
| 1313 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
1306 | 1314 |
1307 // The outer viewport (FrameView) should be affected as well. | 1315 // The outer viewport (FrameView) should be affected as well. |
1308 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1316 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1309 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1317 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
1310 frameView.scrollPosition()); | 1318 frameView.scrollOffset()); |
1311 | 1319 |
1312 // Simulate bringing up the top controls by 10.5px. | 1320 // Simulate bringing up the top controls by 10.5px. |
1313 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1321 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1314 WebFloatSize(), 1, -10.5f / 20); | 1322 WebFloatSize(), 1, -10.5f / 20); |
1315 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), | 1323 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), |
1316 visualViewport.visibleRect().size()); | 1324 visualViewport.visibleRect().size()); |
1317 | 1325 |
1318 // maximumScrollPosition |ceil|s the top controls adjustment. | 1326 // maximumScrollPosition |ceil|s the top controls adjustment. |
1319 visualViewport.move(FloatPoint(10000, 10000)); | 1327 visualViewport.move(ScrollOffset(10000, 10000)); |
1320 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location()); | 1328 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 881 - 441), |
| 1329 visualViewport.scrollOffset()); |
1321 | 1330 |
1322 // The outer viewport (FrameView) should be affected as well. | 1331 // The outer viewport (FrameView) should be affected as well. |
1323 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1332 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1324 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1333 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
1325 frameView.scrollPosition()); | 1334 frameView.scrollOffset()); |
1326 } | 1335 } |
1327 | 1336 |
1328 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) { | 1337 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) { |
1329 initializeWithAndroidSettings(); | 1338 initializeWithAndroidSettings(); |
1330 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); | 1339 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); |
1331 | 1340 |
1332 registerMockedHttpURLLoad("content-width-1000.html"); | 1341 registerMockedHttpURLLoad("content-width-1000.html"); |
1333 navigateTo(m_baseURL + "content-width-1000.html"); | 1342 navigateTo(m_baseURL + "content-width-1000.html"); |
1334 | 1343 |
1335 VisualViewport& visualViewport = | 1344 VisualViewport& visualViewport = |
1336 frame()->page()->frameHost().visualViewport(); | 1345 frame()->page()->frameHost().visualViewport(); |
1337 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1346 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1338 | 1347 |
1339 visualViewport.setScale(2); | 1348 visualViewport.setScale(2); |
1340 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); | 1349 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
1341 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); | 1350 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
1342 | 1351 |
1343 // Simulate bringing down the top controls by 20px. Since we're zoomed in, the | 1352 // Simulate bringing down the top controls by 20px. Since we're zoomed in, the |
1344 // top controls take up half as much space (in document-space) than they do at | 1353 // top controls take up half as much space (in document-space) than they do at |
1345 // an unzoomed level. | 1354 // an unzoomed level. |
1346 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1355 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1347 WebFloatSize(), 1, 1); | 1356 WebFloatSize(), 1, 1); |
1348 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); | 1357 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
1349 | 1358 |
1350 // Test that the scroll bounds are adjusted appropriately. | 1359 // Test that the scroll bounds are adjusted appropriately. |
1351 visualViewport.move(FloatPoint(10000, 10000)); | 1360 visualViewport.move(ScrollOffset(10000, 10000)); |
1352 EXPECT_POINT_EQ(FloatPoint(750, 860 - 215), visualViewport.location()); | 1361 EXPECT_SIZE_EQ(FloatSize(750, 860 - 215), visualViewport.scrollOffset()); |
1353 | 1362 |
1354 // The outer viewport (FrameView) should be affected as well. | 1363 // The outer viewport (FrameView) should be affected as well. |
1355 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1364 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1356 IntPoint expected = | 1365 ScrollOffset expected = |
1357 expectedMaxFrameViewScrollOffset(visualViewport, frameView); | 1366 expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
1358 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1367 EXPECT_SIZE_EQ(expected, frameView.scrollOffset()); |
1359 | 1368 |
1360 // Scale back out, FrameView max scroll shouldn't have changed. Visual | 1369 // Scale back out, FrameView max scroll shouldn't have changed. Visual |
1361 // viewport should be moved up to accomodate larger view. | 1370 // viewport should be moved up to accomodate larger view. |
1362 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1371 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1363 WebFloatSize(), 0.5f, 0); | 1372 WebFloatSize(), 0.5f, 0); |
1364 EXPECT_EQ(1, visualViewport.scale()); | 1373 EXPECT_EQ(1, visualViewport.scale()); |
1365 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1374 EXPECT_SIZE_EQ(expected, frameView.scrollOffset()); |
1366 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1375 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1367 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | 1376 EXPECT_SIZE_EQ(expected, frameView.scrollOffset()); |
1368 | 1377 |
1369 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); | 1378 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
1370 visualViewport.move(FloatPoint(10000, 10000)); | 1379 visualViewport.move(ScrollOffset(10000, 10000)); |
1371 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); | 1380 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.scrollOffset()); |
1372 | 1381 |
1373 // Scale out, use a scale that causes fractional rects. | 1382 // Scale out, use a scale that causes fractional rects. |
1374 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1383 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1375 WebFloatSize(), 0.8f, -1); | 1384 WebFloatSize(), 0.8f, -1); |
1376 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size()); | 1385 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size()); |
1377 | 1386 |
1378 // Bring out the top controls by 11 | 1387 // Bring out the top controls by 11 |
1379 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1388 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1380 WebFloatSize(), 1, 11 / 20.f); | 1389 WebFloatSize(), 1, 11 / 20.f); |
1381 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size()); | 1390 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size()); |
1382 | 1391 |
1383 // Ensure max scroll offsets are updated properly. | 1392 // Ensure max scroll offsets are updated properly. |
1384 visualViewport.move(FloatPoint(10000, 10000)); | 1393 visualViewport.move(ScrollOffset(10000, 10000)); |
1385 EXPECT_FLOAT_POINT_EQ(FloatPoint(375, 877.5 - 548.75), | 1394 EXPECT_FLOAT_SIZE_EQ(FloatSize(375, 877.5 - 548.75), |
1386 visualViewport.location()); | 1395 visualViewport.scrollOffset()); |
1387 | 1396 |
1388 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1397 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1389 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1398 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), |
1390 frameView.scrollPosition()); | 1399 frameView.scrollOffset()); |
1391 } | 1400 } |
1392 | 1401 |
1393 // Tests that a scroll all the way to the bottom of the page, while hiding the | 1402 // Tests that a scroll all the way to the bottom of the page, while hiding the |
1394 // top controls doesn't cause a clamp in the viewport scroll offset when the top | 1403 // top controls doesn't cause a clamp in the viewport scroll offset when the top |
1395 // controls initiated resize occurs. | 1404 // controls initiated resize occurs. |
1396 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) { | 1405 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) { |
1397 int topControlsHeight = 20; | 1406 int topControlsHeight = 20; |
1398 int visualViewportHeight = 450; | 1407 int visualViewportHeight = 450; |
1399 int layoutViewportHeight = 900; | 1408 int layoutViewportHeight = 900; |
1400 float pageScale = 2; | 1409 float pageScale = 2; |
(...skipping 17 matching lines...) Expand all Loading... |
1418 EXPECT_SIZE_EQ( | 1427 EXPECT_SIZE_EQ( |
1419 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1428 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
1420 visualViewport.visibleRect().size()); | 1429 visualViewport.visibleRect().size()); |
1421 EXPECT_SIZE_EQ( | 1430 EXPECT_SIZE_EQ( |
1422 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), | 1431 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
1423 frameView.frameRect().size()); | 1432 frameView.frameRect().size()); |
1424 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), | 1433 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), |
1425 visualViewport.size()); | 1434 visualViewport.size()); |
1426 | 1435 |
1427 // Scroll all the way to the bottom, hiding the top controls in the process. | 1436 // Scroll all the way to the bottom, hiding the top controls in the process. |
1428 visualViewport.move(FloatPoint(10000, 10000)); | 1437 visualViewport.move(ScrollOffset(10000, 10000)); |
1429 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1438 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1430 webViewImpl()->topControls().setShownRatio(0); | 1439 webViewImpl()->topControls().setShownRatio(0); |
1431 | 1440 |
1432 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1441 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
1433 visualViewport.visibleRect().size()); | 1442 visualViewport.visibleRect().size()); |
1434 | 1443 |
1435 IntPoint frameViewExpected = | 1444 ScrollOffset frameViewExpected = |
1436 expectedMaxFrameViewScrollOffset(visualViewport, frameView); | 1445 expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
1437 FloatPoint visualViewportExpected = | 1446 ScrollOffset visualViewportExpected = ScrollOffset( |
1438 FloatPoint(750, layoutViewportHeight - visualViewportHeight / pageScale); | 1447 750, layoutViewportHeight - visualViewportHeight / pageScale); |
1439 | 1448 |
1440 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1449 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); |
1441 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1450 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); |
1442 | 1451 |
1443 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; | 1452 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; |
1444 | 1453 |
1445 // Resize the widget to match the top controls adjustment. Ensure that the | 1454 // Resize the widget to match the top controls adjustment. Ensure that the |
1446 // total offset (i.e. what the user sees) doesn't change because of clamping | 1455 // total offset (i.e. what the user sees) doesn't change because of clamping |
1447 // the offsets to valid values. | 1456 // the offsets to valid values. |
1448 webViewImpl()->resizeWithTopControls(WebSize(500, visualViewportHeight), 20, | 1457 webViewImpl()->resizeWithTopControls(WebSize(500, visualViewportHeight), 20, |
1449 false); | 1458 false); |
1450 | 1459 |
1451 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); | 1460 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
1452 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1461 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
1453 visualViewport.visibleRect().size()); | 1462 visualViewport.visibleRect().size()); |
1454 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1463 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), |
1455 frameView.frameRect().size()); | 1464 frameView.frameRect().size()); |
1456 EXPECT_POINT_EQ(totalExpected, | 1465 EXPECT_SIZE_EQ(totalExpected, |
1457 frameView.scrollPosition() + visualViewport.location()); | 1466 visualViewport.scrollOffset() + frameView.scrollOffset()); |
1458 } | 1467 } |
1459 | 1468 |
1460 // Tests that a scroll all the way to the bottom while showing the top controls | 1469 // Tests that a scroll all the way to the bottom while showing the top controls |
1461 // doesn't cause a clamp to the viewport scroll offset when the top controls | 1470 // doesn't cause a clamp to the viewport scroll offset when the top controls |
1462 // initiated resize occurs. | 1471 // initiated resize occurs. |
1463 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) { | 1472 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) { |
1464 int topControlsHeight = 20; | 1473 int topControlsHeight = 20; |
1465 int visualViewportHeight = 500; | 1474 int visualViewportHeight = 500; |
1466 int layoutViewportHeight = 1000; | 1475 int layoutViewportHeight = 1000; |
1467 int contentHeight = 2000; | 1476 int contentHeight = 2000; |
(...skipping 18 matching lines...) Expand all Loading... |
1486 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1495 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), |
1487 visualViewport.visibleRect().size()); | 1496 visualViewport.visibleRect().size()); |
1488 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1497 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), |
1489 frameView.frameRect().size()); | 1498 frameView.frameRect().size()); |
1490 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); | 1499 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
1491 | 1500 |
1492 // Scroll all the way to the bottom, showing the the top controls in the | 1501 // Scroll all the way to the bottom, showing the the top controls in the |
1493 // process. (This could happen via window.scrollTo during a scroll, for | 1502 // process. (This could happen via window.scrollTo during a scroll, for |
1494 // example). | 1503 // example). |
1495 webViewImpl()->topControls().setShownRatio(1); | 1504 webViewImpl()->topControls().setShownRatio(1); |
1496 visualViewport.move(FloatPoint(10000, 10000)); | 1505 visualViewport.move(ScrollOffset(10000, 10000)); |
1497 frameView.scrollBy(IntSize(10000, 10000), UserScroll); | 1506 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll); |
1498 | 1507 |
1499 EXPECT_SIZE_EQ( | 1508 EXPECT_SIZE_EQ( |
1500 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1509 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
1501 visualViewport.visibleRect().size()); | 1510 visualViewport.visibleRect().size()); |
1502 | 1511 |
1503 IntPoint frameViewExpected = IntPoint( | 1512 ScrollOffset frameViewExpected( |
1504 0, contentHeight - | 1513 0, contentHeight - |
1505 (layoutViewportHeight - topControlsHeight / minPageScale)); | 1514 (layoutViewportHeight - topControlsHeight / minPageScale)); |
1506 FloatPoint visualViewportExpected = | 1515 ScrollOffset visualViewportExpected = ScrollOffset( |
1507 FloatPoint(750, (layoutViewportHeight - topControlsHeight / minPageScale - | 1516 750, (layoutViewportHeight - topControlsHeight / minPageScale - |
1508 visualViewport.visibleRect().height())); | 1517 visualViewport.visibleRect().height())); |
1509 | 1518 |
1510 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); | 1519 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.scrollOffset()); |
1511 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | 1520 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset()); |
1512 | 1521 |
1513 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; | 1522 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; |
1514 | 1523 |
1515 // Resize the widget to match the top controls adjustment. Ensure that the | 1524 // Resize the widget to match the top controls adjustment. Ensure that the |
1516 // total offset (i.e. what the user sees) doesn't change because of clamping | 1525 // total offset (i.e. what the user sees) doesn't change because of clamping |
1517 // the offsets to valid values. | 1526 // the offsets to valid values. |
1518 webViewImpl()->resizeWithTopControls( | 1527 webViewImpl()->resizeWithTopControls( |
1519 WebSize(500, visualViewportHeight - topControlsHeight), 20, true); | 1528 WebSize(500, visualViewportHeight - topControlsHeight), 20, true); |
1520 | 1529 |
1521 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), | 1530 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), |
1522 visualViewport.size()); | 1531 visualViewport.size()); |
1523 EXPECT_SIZE_EQ( | 1532 EXPECT_SIZE_EQ( |
1524 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), | 1533 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
1525 visualViewport.visibleRect().size()); | 1534 visualViewport.visibleRect().size()); |
1526 EXPECT_SIZE_EQ( | 1535 EXPECT_SIZE_EQ( |
1527 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), | 1536 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
1528 frameView.frameRect().size()); | 1537 frameView.frameRect().size()); |
1529 EXPECT_POINT_EQ(totalExpected, | 1538 EXPECT_SIZE_EQ(totalExpected, |
1530 frameView.scrollPosition() + visualViewport.location()); | 1539 visualViewport.scrollOffset() + frameView.scrollOffset()); |
1531 } | 1540 } |
1532 | 1541 |
1533 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the | 1542 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the |
1534 // main frame's scroll offset. crbug.com/428193. | 1543 // main frame's scroll offset. crbug.com/428193. |
1535 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { | 1544 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { |
1536 initializeWithAndroidSettings(); | 1545 initializeWithAndroidSettings(); |
1537 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false); | 1546 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false); |
1538 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1547 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1539 WebFloatSize(), 1, 1); | 1548 WebFloatSize(), 1, 1); |
1540 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true); | 1549 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true); |
1541 | 1550 |
1542 registerMockedHttpURLLoad("content-width-1000.html"); | 1551 registerMockedHttpURLLoad("content-width-1000.html"); |
1543 navigateTo(m_baseURL + "content-width-1000.html"); | 1552 navigateTo(m_baseURL + "content-width-1000.html"); |
1544 | 1553 |
1545 // Scroll the FrameView to the bottom of the page but "hide" the top controls | 1554 // Scroll the FrameView to the bottom of the page but "hide" the top controls |
1546 // on the compositor side so the max scroll position should account for the | 1555 // on the compositor side so the max scroll position should account for the |
1547 // full viewport height. | 1556 // full viewport height. |
1548 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1557 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
1549 WebFloatSize(), 1, -1); | 1558 WebFloatSize(), 1, -1); |
1550 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1559 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1551 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); | 1560 frameView.setScrollOffset(ScrollOffset(0, 10000), ProgrammaticScroll); |
1552 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1561 EXPECT_EQ(500, frameView.scrollOffset().height()); |
1553 | 1562 |
1554 // Now send the resize, make sure the scroll offset doesn't change. | 1563 // Now send the resize, make sure the scroll offset doesn't change. |
1555 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false); | 1564 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false); |
1556 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); | 1565 EXPECT_EQ(500, frameView.scrollOffset().height()); |
1557 } | 1566 } |
1558 | 1567 |
1559 static void configureHiddenScrollbarsSettings(WebSettings* settings) { | 1568 static void configureHiddenScrollbarsSettings(WebSettings* settings) { |
1560 VisualViewportTest::configureAndroidSettings(settings); | 1569 VisualViewportTest::configureAndroidSettings(settings); |
1561 settings->setHideScrollbars(true); | 1570 settings->setHideScrollbars(true); |
1562 } | 1571 } |
1563 | 1572 |
1564 // Tests that scrollbar layers are not attached to the inner viewport container | 1573 // Tests that scrollbar layers are not attached to the inner viewport container |
1565 // layer when hideScrollbars WebSetting is true. | 1574 // layer when hideScrollbars WebSetting is true. |
1566 TEST_F(VisualViewportTest, | 1575 TEST_F(VisualViewportTest, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 initializeWithDesktopSettings(); | 1627 initializeWithDesktopSettings(); |
1619 webViewImpl()->resize(IntSize(100, 200)); | 1628 webViewImpl()->resize(IntSize(100, 200)); |
1620 | 1629 |
1621 navigateTo("about:blank"); | 1630 navigateTo("about:blank"); |
1622 webViewImpl()->updateAllLifecyclePhases(); | 1631 webViewImpl()->updateAllLifecyclePhases(); |
1623 | 1632 |
1624 webViewImpl()->resizeVisualViewport(IntSize(100, 100)); | 1633 webViewImpl()->resizeVisualViewport(IntSize(100, 100)); |
1625 | 1634 |
1626 VisualViewport& visualViewport = | 1635 VisualViewport& visualViewport = |
1627 frame()->page()->frameHost().visualViewport(); | 1636 frame()->page()->frameHost().visualViewport(); |
1628 visualViewport.move(FloatPoint(0, 100)); | 1637 visualViewport.move(ScrollOffset(0, 100)); |
1629 | 1638 |
1630 EXPECT_EQ(100, visualViewport.location().y()); | 1639 EXPECT_EQ(100, visualViewport.scrollOffset().height()); |
1631 | 1640 |
1632 webViewImpl()->resizeVisualViewport(IntSize(100, 200)); | 1641 webViewImpl()->resizeVisualViewport(IntSize(100, 200)); |
1633 | 1642 |
1634 EXPECT_EQ(0, visualViewport.location().y()); | 1643 EXPECT_EQ(0, visualViewport.scrollOffset().height()); |
1635 } | 1644 } |
1636 | 1645 |
1637 TEST_P(ParameterizedVisualViewportTest, | 1646 TEST_P(ParameterizedVisualViewportTest, |
1638 ElementBoundsInViewportSpaceAccountsForViewport) { | 1647 ElementBoundsInViewportSpaceAccountsForViewport) { |
1639 initializeWithAndroidSettings(); | 1648 initializeWithAndroidSettings(); |
1640 | 1649 |
1641 webViewImpl()->resize(IntSize(500, 800)); | 1650 webViewImpl()->resize(IntSize(500, 800)); |
1642 | 1651 |
1643 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); | 1652 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); |
1644 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); | 1653 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 | 1707 |
1699 // Chrome's quirky behavior regarding viewport scrolling means we treat the | 1708 // Chrome's quirky behavior regarding viewport scrolling means we treat the |
1700 // body element as the viewport and don't apply scrolling to the HTML element. | 1709 // body element as the viewport and don't apply scrolling to the HTML element. |
1701 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); | 1710 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); |
1702 | 1711 |
1703 LocalDOMWindow* window = | 1712 LocalDOMWindow* window = |
1704 webViewImpl()->mainFrameImpl()->frame()->localDOMWindow(); | 1713 webViewImpl()->mainFrameImpl()->frame()->localDOMWindow(); |
1705 window->scrollTo(100, 150); | 1714 window->scrollTo(100, 150); |
1706 EXPECT_EQ(100, window->scrollX()); | 1715 EXPECT_EQ(100, window->scrollX()); |
1707 EXPECT_EQ(150, window->scrollY()); | 1716 EXPECT_EQ(150, window->scrollY()); |
1708 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | 1717 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.scrollOffset()); |
1709 | 1718 |
1710 HTMLElement* body = toHTMLBodyElement(window->document()->body()); | 1719 HTMLElement* body = toHTMLBodyElement(window->document()->body()); |
1711 body->setScrollLeft(50); | 1720 body->setScrollLeft(50); |
1712 body->setScrollTop(130); | 1721 body->setScrollTop(130); |
1713 EXPECT_EQ(50, body->scrollLeft()); | 1722 EXPECT_EQ(50, body->scrollLeft()); |
1714 EXPECT_EQ(130, body->scrollTop()); | 1723 EXPECT_EQ(130, body->scrollTop()); |
1715 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); | 1724 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visualViewport.scrollOffset()); |
1716 | 1725 |
1717 HTMLElement* documentElement = | 1726 HTMLElement* documentElement = |
1718 toHTMLElement(window->document()->documentElement()); | 1727 toHTMLElement(window->document()->documentElement()); |
1719 documentElement->setScrollLeft(40); | 1728 documentElement->setScrollLeft(40); |
1720 documentElement->setScrollTop(50); | 1729 documentElement->setScrollTop(50); |
1721 EXPECT_EQ(0, documentElement->scrollLeft()); | 1730 EXPECT_EQ(0, documentElement->scrollLeft()); |
1722 EXPECT_EQ(0, documentElement->scrollTop()); | 1731 EXPECT_EQ(0, documentElement->scrollTop()); |
1723 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); | 1732 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visualViewport.scrollOffset()); |
1724 | 1733 |
1725 visualViewport.setLocation(FloatPoint(10, 20)); | 1734 visualViewport.setLocation(FloatPoint(10, 20)); |
1726 EXPECT_EQ(10, body->scrollLeft()); | 1735 EXPECT_EQ(10, body->scrollLeft()); |
1727 EXPECT_EQ(20, body->scrollTop()); | 1736 EXPECT_EQ(20, body->scrollTop()); |
1728 EXPECT_EQ(0, documentElement->scrollLeft()); | 1737 EXPECT_EQ(0, documentElement->scrollLeft()); |
1729 EXPECT_EQ(0, documentElement->scrollTop()); | 1738 EXPECT_EQ(0, documentElement->scrollTop()); |
1730 EXPECT_EQ(10, window->scrollX()); | 1739 EXPECT_EQ(10, window->scrollX()); |
1731 EXPECT_EQ(20, window->scrollY()); | 1740 EXPECT_EQ(20, window->scrollY()); |
1732 | 1741 |
1733 // Turning on the standards-compliant viewport scrolling impl should make the | 1742 // Turning on the standards-compliant viewport scrolling impl should make the |
1734 // document element the viewport and not body. | 1743 // document element the viewport and not body. |
1735 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); | 1744 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); |
1736 | 1745 |
1737 window->scrollTo(100, 150); | 1746 window->scrollTo(100, 150); |
1738 EXPECT_EQ(100, window->scrollX()); | 1747 EXPECT_EQ(100, window->scrollX()); |
1739 EXPECT_EQ(150, window->scrollY()); | 1748 EXPECT_EQ(150, window->scrollY()); |
1740 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | 1749 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.scrollOffset()); |
1741 | 1750 |
1742 body->setScrollLeft(50); | 1751 body->setScrollLeft(50); |
1743 body->setScrollTop(130); | 1752 body->setScrollTop(130); |
1744 EXPECT_EQ(0, body->scrollLeft()); | 1753 EXPECT_EQ(0, body->scrollLeft()); |
1745 EXPECT_EQ(0, body->scrollTop()); | 1754 EXPECT_EQ(0, body->scrollTop()); |
1746 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | 1755 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.scrollOffset()); |
1747 | 1756 |
1748 documentElement->setScrollLeft(40); | 1757 documentElement->setScrollLeft(40); |
1749 documentElement->setScrollTop(50); | 1758 documentElement->setScrollTop(50); |
1750 EXPECT_EQ(40, documentElement->scrollLeft()); | 1759 EXPECT_EQ(40, documentElement->scrollLeft()); |
1751 EXPECT_EQ(50, documentElement->scrollTop()); | 1760 EXPECT_EQ(50, documentElement->scrollTop()); |
1752 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 50), visualViewport.location()); | 1761 EXPECT_FLOAT_SIZE_EQ(FloatSize(40, 50), visualViewport.scrollOffset()); |
1753 | 1762 |
1754 visualViewport.setLocation(FloatPoint(10, 20)); | 1763 visualViewport.setLocation(FloatPoint(10, 20)); |
1755 EXPECT_EQ(0, body->scrollLeft()); | 1764 EXPECT_EQ(0, body->scrollLeft()); |
1756 EXPECT_EQ(0, body->scrollTop()); | 1765 EXPECT_EQ(0, body->scrollTop()); |
1757 EXPECT_EQ(10, documentElement->scrollLeft()); | 1766 EXPECT_EQ(10, documentElement->scrollLeft()); |
1758 EXPECT_EQ(20, documentElement->scrollTop()); | 1767 EXPECT_EQ(20, documentElement->scrollTop()); |
1759 EXPECT_EQ(10, window->scrollX()); | 1768 EXPECT_EQ(10, window->scrollX()); |
1760 EXPECT_EQ(20, window->scrollY()); | 1769 EXPECT_EQ(20, window->scrollY()); |
1761 } | 1770 } |
1762 | 1771 |
(...skipping 22 matching lines...) Expand all Loading... |
1785 TEST_P(ParameterizedVisualViewportTest, FractionalMaxScrollOffset) { | 1794 TEST_P(ParameterizedVisualViewportTest, FractionalMaxScrollOffset) { |
1786 initializeWithDesktopSettings(); | 1795 initializeWithDesktopSettings(); |
1787 webViewImpl()->resize(IntSize(101, 201)); | 1796 webViewImpl()->resize(IntSize(101, 201)); |
1788 navigateTo("about:blank"); | 1797 navigateTo("about:blank"); |
1789 | 1798 |
1790 VisualViewport& visualViewport = | 1799 VisualViewport& visualViewport = |
1791 frame()->page()->frameHost().visualViewport(); | 1800 frame()->page()->frameHost().visualViewport(); |
1792 ScrollableArea* scrollableArea = &visualViewport; | 1801 ScrollableArea* scrollableArea = &visualViewport; |
1793 | 1802 |
1794 webViewImpl()->setPageScaleFactor(1.0); | 1803 webViewImpl()->setPageScaleFactor(1.0); |
1795 EXPECT_FLOAT_POINT_EQ(DoublePoint(), | 1804 EXPECT_SIZE_EQ(ScrollOffset(), scrollableArea->maximumScrollOffset()); |
1796 scrollableArea->maximumScrollPositionDouble()); | |
1797 | 1805 |
1798 webViewImpl()->setPageScaleFactor(2); | 1806 webViewImpl()->setPageScaleFactor(2); |
1799 EXPECT_FLOAT_POINT_EQ(DoublePoint(101. / 2., 201. / 2.), | 1807 EXPECT_SIZE_EQ(ScrollOffset(101. / 2., 201. / 2.), |
1800 scrollableArea->maximumScrollPositionDouble()); | 1808 scrollableArea->maximumScrollOffset()); |
1801 } | 1809 } |
1802 | 1810 |
1803 // Tests that the slow scrolling after an impl scroll on the visual viewport is | 1811 // Tests that the slow scrolling after an impl scroll on the visual viewport is |
1804 // continuous. crbug.com/453460 was caused by the impl-path not updating the | 1812 // continuous. crbug.com/453460 was caused by the impl-path not updating the |
1805 // ScrollAnimatorBase class. | 1813 // ScrollAnimatorBase class. |
1806 TEST_P(ParameterizedVisualViewportTest, SlowScrollAfterImplScroll) { | 1814 TEST_P(ParameterizedVisualViewportTest, SlowScrollAfterImplScroll) { |
1807 initializeWithDesktopSettings(); | 1815 initializeWithDesktopSettings(); |
1808 webViewImpl()->resize(IntSize(800, 600)); | 1816 webViewImpl()->resize(IntSize(800, 600)); |
1809 navigateTo("about:blank"); | 1817 navigateTo("about:blank"); |
1810 | 1818 |
1811 VisualViewport& visualViewport = | 1819 VisualViewport& visualViewport = |
1812 frame()->page()->frameHost().visualViewport(); | 1820 frame()->page()->frameHost().visualViewport(); |
1813 | 1821 |
1814 // Apply some scroll and scale from the impl-side. | 1822 // Apply some scroll and scale from the impl-side. |
1815 webViewImpl()->applyViewportDeltas(WebFloatSize(300, 200), WebFloatSize(0, 0), | 1823 webViewImpl()->applyViewportDeltas(WebFloatSize(300, 200), WebFloatSize(0, 0), |
1816 WebFloatSize(0, 0), 2, 0); | 1824 WebFloatSize(0, 0), 2, 0); |
1817 | 1825 |
1818 EXPECT_POINT_EQ(FloatPoint(300, 200), visualViewport.location()); | 1826 EXPECT_SIZE_EQ(FloatSize(300, 200), visualViewport.scrollOffset()); |
1819 | 1827 |
1820 // Send a scroll event on the main thread path. | 1828 // Send a scroll event on the main thread path. |
1821 PlatformGestureEvent gsu(PlatformEvent::GestureScrollUpdate, IntPoint(0, 0), | 1829 PlatformGestureEvent gsu(PlatformEvent::GestureScrollUpdate, IntPoint(0, 0), |
1822 IntPoint(0, 0), IntSize(5, 5), 0, | 1830 IntPoint(0, 0), IntSize(5, 5), 0, |
1823 PlatformEvent::NoModifiers, | 1831 PlatformEvent::NoModifiers, |
1824 PlatformGestureSourceTouchpad); | 1832 PlatformGestureSourceTouchpad); |
1825 gsu.setScrollGestureData(-50, -60, ScrollByPrecisePixel, 1, 1, | 1833 gsu.setScrollGestureData(-50, -60, ScrollByPrecisePixel, 1, 1, |
1826 ScrollInertialPhaseUnknown, false, | 1834 ScrollInertialPhaseUnknown, false, |
1827 -1 /* null plugin id */); | 1835 -1 /* null plugin id */); |
1828 | 1836 |
1829 frame()->eventHandler().handleGestureEvent(gsu); | 1837 frame()->eventHandler().handleGestureEvent(gsu); |
1830 | 1838 |
1831 // The scroll sent from the impl-side must not be overwritten. | 1839 // The scroll sent from the impl-side must not be overwritten. |
1832 EXPECT_POINT_EQ(FloatPoint(350, 260), visualViewport.location()); | 1840 EXPECT_SIZE_EQ(FloatSize(350, 260), visualViewport.scrollOffset()); |
1833 } | 1841 } |
1834 | 1842 |
1835 static void accessibilitySettings(WebSettings* settings) { | 1843 static void accessibilitySettings(WebSettings* settings) { |
1836 VisualViewportTest::configureSettings(settings); | 1844 VisualViewportTest::configureSettings(settings); |
1837 settings->setAccessibilityEnabled(true); | 1845 settings->setAccessibilityEnabled(true); |
1838 } | 1846 } |
1839 | 1847 |
1840 TEST_P(ParameterizedVisualViewportTest, AccessibilityHitTestWhileZoomedIn) { | 1848 TEST_P(ParameterizedVisualViewportTest, AccessibilityHitTestWhileZoomedIn) { |
1841 initializeWithDesktopSettings(accessibilitySettings); | 1849 initializeWithDesktopSettings(accessibilitySettings); |
1842 | 1850 |
1843 registerMockedHttpURLLoad("hit-test.html"); | 1851 registerMockedHttpURLLoad("hit-test.html"); |
1844 navigateTo(m_baseURL + "hit-test.html"); | 1852 navigateTo(m_baseURL + "hit-test.html"); |
1845 | 1853 |
1846 webViewImpl()->resize(IntSize(500, 500)); | 1854 webViewImpl()->resize(IntSize(500, 500)); |
1847 webViewImpl()->updateAllLifecyclePhases(); | 1855 webViewImpl()->updateAllLifecyclePhases(); |
1848 | 1856 |
1849 WebDocument webDoc = webViewImpl()->mainFrame()->document(); | 1857 WebDocument webDoc = webViewImpl()->mainFrame()->document(); |
1850 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1858 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1851 | 1859 |
1852 webViewImpl()->setPageScaleFactor(2); | 1860 webViewImpl()->setPageScaleFactor(2); |
1853 webViewImpl()->setVisualViewportOffset(WebFloatPoint(200, 230)); | 1861 webViewImpl()->setVisualViewportOffset(WebFloatPoint(200, 230)); |
1854 frameView.layoutViewportScrollableArea()->setScrollPosition( | 1862 frameView.layoutViewportScrollableArea()->setScrollOffset( |
1855 DoublePoint(400, 1100), ProgrammaticScroll); | 1863 ScrollOffset(400, 1100), ProgrammaticScroll); |
1856 | 1864 |
1857 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state. | 1865 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state. |
1858 forceFullCompositingUpdate(); | 1866 forceFullCompositingUpdate(); |
1859 | 1867 |
1860 // Because of where the visual viewport is located, this should hit the bottom | 1868 // Because of where the visual viewport is located, this should hit the bottom |
1861 // right target (target 4). | 1869 // right target (target 4). |
1862 WebAXObject hitNode = | 1870 WebAXObject hitNode = |
1863 webDoc.accessibilityObject().hitTest(WebPoint(154, 165)); | 1871 webDoc.accessibilityObject().hitTest(WebPoint(154, 165)); |
1864 WebAXNameFrom nameFrom; | 1872 WebAXNameFrom nameFrom; |
1865 WebVector<WebAXObject> nameObjects; | 1873 WebVector<WebAXObject> nameObjects; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 | 1910 |
1903 // Test points that will cause non-integer values. | 1911 // Test points that will cause non-integer values. |
1904 EXPECT_FLOAT_POINT_EQ( | 1912 EXPECT_FLOAT_POINT_EQ( |
1905 FloatPoint(50.5, 62.4), | 1913 FloatPoint(50.5, 62.4), |
1906 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8))); | 1914 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8))); |
1907 EXPECT_FLOAT_POINT_EQ( | 1915 EXPECT_FLOAT_POINT_EQ( |
1908 FloatPoint(81, 100.8), | 1916 FloatPoint(81, 100.8), |
1909 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4))); | 1917 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4))); |
1910 | 1918 |
1911 // Scrolling the main frame should have no effect. | 1919 // Scrolling the main frame should have no effect. |
1912 frameView.layoutViewportScrollableArea()->setScrollPosition( | 1920 frameView.layoutViewportScrollableArea()->setScrollOffset( |
1913 DoublePoint(100, 120), ProgrammaticScroll); | 1921 ScrollOffset(100, 120), ProgrammaticScroll); |
1914 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame( | 1922 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame( |
1915 FloatPoint(80, 100))); | 1923 FloatPoint(80, 100))); |
1916 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), | 1924 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), |
1917 visualViewport.rootFrameToViewport(FloatPoint(50, 62))); | 1925 visualViewport.rootFrameToViewport(FloatPoint(50, 62))); |
1918 } | 1926 } |
1919 | 1927 |
1920 // Tests that the window dimensions are available before a full layout occurs. | 1928 // Tests that the window dimensions are available before a full layout occurs. |
1921 // More specifically, it checks that the innerWidth and innerHeight window | 1929 // More specifically, it checks that the innerWidth and innerHeight window |
1922 // properties will trigger a layout which will cause an update to viewport | 1930 // properties will trigger a layout which will cause an update to viewport |
1923 // constraints and a refreshed initial scale. crbug.com/466718 | 1931 // constraints and a refreshed initial scale. crbug.com/466718 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 pinchUpdate.y = 100; | 1972 pinchUpdate.y = 100; |
1965 pinchUpdate.data.pinchUpdate.scale = 2; | 1973 pinchUpdate.data.pinchUpdate.scale = 2; |
1966 pinchUpdate.data.pinchUpdate.zoomDisabled = false; | 1974 pinchUpdate.data.pinchUpdate.zoomDisabled = false; |
1967 | 1975 |
1968 webViewImpl()->handleInputEvent(pinchUpdate); | 1976 webViewImpl()->handleInputEvent(pinchUpdate); |
1969 | 1977 |
1970 VisualViewport& visualViewport = | 1978 VisualViewport& visualViewport = |
1971 webViewImpl()->page()->frameHost().visualViewport(); | 1979 webViewImpl()->page()->frameHost().visualViewport(); |
1972 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1980 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1973 | 1981 |
1974 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1982 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 50), visualViewport.scrollOffset()); |
1975 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1983 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frameView.scrollOffset()); |
1976 } | 1984 } |
1977 | 1985 |
1978 TEST_P(ParameterizedVisualViewportTest, ResizeWithScrollAnchoring) { | 1986 TEST_P(ParameterizedVisualViewportTest, ResizeWithScrollAnchoring) { |
1979 bool wasScrollAnchoringEnabled = | 1987 bool wasScrollAnchoringEnabled = |
1980 RuntimeEnabledFeatures::scrollAnchoringEnabled(); | 1988 RuntimeEnabledFeatures::scrollAnchoringEnabled(); |
1981 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); | 1989 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); |
1982 | 1990 |
1983 initializeWithDesktopSettings(); | 1991 initializeWithDesktopSettings(); |
1984 webViewImpl()->resize(IntSize(800, 600)); | 1992 webViewImpl()->resize(IntSize(800, 600)); |
1985 | 1993 |
1986 registerMockedHttpURLLoad("icb-relative-content.html"); | 1994 registerMockedHttpURLLoad("icb-relative-content.html"); |
1987 navigateTo(m_baseURL + "icb-relative-content.html"); | 1995 navigateTo(m_baseURL + "icb-relative-content.html"); |
1988 | 1996 |
1989 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1997 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1990 frameView.layoutViewportScrollableArea()->setScrollPosition( | 1998 frameView.layoutViewportScrollableArea()->setScrollOffset( |
1991 DoublePoint(700, 500), ProgrammaticScroll); | 1999 ScrollOffset(700, 500), ProgrammaticScroll); |
1992 | 2000 |
1993 webViewImpl()->resize(IntSize(800, 300)); | 2001 webViewImpl()->resize(IntSize(800, 300)); |
1994 EXPECT_POINT_EQ( | 2002 EXPECT_SIZE_EQ(ScrollOffset(700, 200), |
1995 DoublePoint(700, 200), | 2003 frameView.layoutViewportScrollableArea()->scrollOffset()); |
1996 frameView.layoutViewportScrollableArea()->scrollPositionDouble()); | |
1997 | 2004 |
1998 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); | 2005 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); |
1999 } | 2006 } |
2000 | 2007 |
2001 // Ensure that resize anchoring as happens when top controls hide/show affects | 2008 // Ensure that resize anchoring as happens when top controls hide/show affects |
2002 // the scrollable area that's currently set as the root scroller. | 2009 // the scrollable area that's currently set as the root scroller. |
2003 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) { | 2010 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) { |
2004 bool wasRootScrollerEnabled = | 2011 bool wasRootScrollerEnabled = |
2005 RuntimeEnabledFeatures::setRootScrollerEnabled(); | 2012 RuntimeEnabledFeatures::setRootScrollerEnabled(); |
2006 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 2013 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
2007 | 2014 |
2008 initializeWithAndroidSettings(); | 2015 initializeWithAndroidSettings(); |
2009 webViewImpl()->resize(IntSize(800, 600)); | 2016 webViewImpl()->resize(IntSize(800, 600)); |
2010 | 2017 |
2011 registerMockedHttpURLLoad("root-scroller-div.html"); | 2018 registerMockedHttpURLLoad("root-scroller-div.html"); |
2012 navigateTo(m_baseURL + "root-scroller-div.html"); | 2019 navigateTo(m_baseURL + "root-scroller-div.html"); |
2013 | 2020 |
2014 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 2021 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
2015 | 2022 |
2016 Element* scroller = frame()->document()->getElementById("rootScroller"); | 2023 Element* scroller = frame()->document()->getElementById("rootScroller"); |
2017 NonThrowableExceptionState nonThrow; | 2024 NonThrowableExceptionState nonThrow; |
2018 frame()->document()->setRootScroller(scroller, nonThrow); | 2025 frame()->document()->setRootScroller(scroller, nonThrow); |
2019 | 2026 |
2020 webViewImpl()->setPageScaleFactor(3.f); | 2027 webViewImpl()->setPageScaleFactor(3.f); |
2021 frameView.getScrollableArea()->setScrollPosition(DoublePoint(0, 400), | 2028 frameView.getScrollableArea()->setScrollOffset(ScrollOffset(0, 400), |
2022 ProgrammaticScroll); | 2029 ProgrammaticScroll); |
2023 | 2030 |
2024 VisualViewport& visualViewport = | 2031 VisualViewport& visualViewport = |
2025 webViewImpl()->page()->frameHost().visualViewport(); | 2032 webViewImpl()->page()->frameHost().visualViewport(); |
2026 visualViewport.setScrollPosition(DoublePoint(0, 400), ProgrammaticScroll); | 2033 visualViewport.setScrollOffset(ScrollOffset(0, 400), ProgrammaticScroll); |
2027 | 2034 |
2028 webViewImpl()->resize(IntSize(800, 500)); | 2035 webViewImpl()->resize(IntSize(800, 500)); |
2029 | 2036 |
2030 EXPECT_POINT_EQ( | 2037 EXPECT_SIZE_EQ(ScrollOffset(), |
2031 DoublePoint(), | 2038 frameView.layoutViewportScrollableArea()->scrollOffset()); |
2032 frameView.layoutViewportScrollableArea()->scrollPositionDouble()); | |
2033 | 2039 |
2034 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); | 2040 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); |
2035 } | 2041 } |
2036 | 2042 |
2037 // Ensure that resize anchoring as happens when the device is rotated affects | 2043 // Ensure that resize anchoring as happens when the device is rotated affects |
2038 // the scrollable area that's currently set as the root scroller. | 2044 // the scrollable area that's currently set as the root scroller. |
2039 TEST_P(ParameterizedVisualViewportTest, RotationAnchoringWithRootScroller) { | 2045 TEST_P(ParameterizedVisualViewportTest, RotationAnchoringWithRootScroller) { |
2040 bool wasRootScrollerEnabled = | 2046 bool wasRootScrollerEnabled = |
2041 RuntimeEnabledFeatures::setRootScrollerEnabled(); | 2047 RuntimeEnabledFeatures::setRootScrollerEnabled(); |
2042 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 2048 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
2043 | 2049 |
2044 initializeWithAndroidSettings(); | 2050 initializeWithAndroidSettings(); |
2045 webViewImpl()->resize(IntSize(800, 600)); | 2051 webViewImpl()->resize(IntSize(800, 600)); |
2046 | 2052 |
2047 registerMockedHttpURLLoad("root-scroller-div.html"); | 2053 registerMockedHttpURLLoad("root-scroller-div.html"); |
2048 navigateTo(m_baseURL + "root-scroller-div.html"); | 2054 navigateTo(m_baseURL + "root-scroller-div.html"); |
2049 | 2055 |
2050 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 2056 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
2051 | 2057 |
2052 Element* scroller = frame()->document()->getElementById("rootScroller"); | 2058 Element* scroller = frame()->document()->getElementById("rootScroller"); |
2053 NonThrowableExceptionState nonThrow; | 2059 NonThrowableExceptionState nonThrow; |
2054 frame()->document()->setRootScroller(scroller, nonThrow); | 2060 frame()->document()->setRootScroller(scroller, nonThrow); |
2055 webViewImpl()->updateAllLifecyclePhases(); | 2061 webViewImpl()->updateAllLifecyclePhases(); |
2056 | 2062 |
2057 scroller->setScrollTop(800); | 2063 scroller->setScrollTop(800); |
2058 | 2064 |
2059 webViewImpl()->resize(IntSize(600, 800)); | 2065 webViewImpl()->resize(IntSize(600, 800)); |
2060 | 2066 |
2061 EXPECT_POINT_EQ( | 2067 EXPECT_SIZE_EQ(ScrollOffset(), |
2062 DoublePoint(), | 2068 frameView.layoutViewportScrollableArea()->scrollOffset()); |
2063 frameView.layoutViewportScrollableArea()->scrollPositionDouble()); | |
2064 EXPECT_EQ(600, scroller->scrollTop()); | 2069 EXPECT_EQ(600, scroller->scrollTop()); |
2065 | 2070 |
2066 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); | 2071 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); |
2067 } | 2072 } |
2068 | 2073 |
2069 } // namespace | 2074 } // namespace |
OLD | NEW |