Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: third_party/WebKit/Source/web/tests/VisualViewportTest.cpp

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_POINT_EQ(FloatPoint(400, 300), visualViewport.location());
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
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_POINT_EQ(FloatPoint(0, 300), visualViewport.location());
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_POINT_EQ(FloatPoint(0, 75), visualViewport.location());
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| |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), visualViewport.location()); 398 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), visualViewport.location());
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_POINT_EQ(FloatPoint(150, 0), visualViewport.location());
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();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 frame()->page()->frameHost().visualViewport(); 498 frame()->page()->frameHost().visualViewport();
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 visibleRectIn Document(). 506 // Scroll the layout viewport. Ensure its offset is reflected in visibleRectIn Document().
502 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 507 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
503 frameView.layoutViewportScrollableArea()->setScrollPosition( 508 frameView.layoutViewportScrollableArea()->setScrollOffset(
504 DoublePoint(40, 100), ProgrammaticScroll); 509 ScrollOffset(40, 100), ProgrammaticScroll);
505 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200), 510 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200),
506 visualViewport.visibleRectInDocument()); 511 visualViewport.visibleRectInDocument());
507 } 512 }
508 513
509 TEST_P(ParameterizedVisualViewportTest, 514 TEST_P(ParameterizedVisualViewportTest,
510 TestFractionalScrollOffsetIsNotOverwritten) { 515 TestFractionalScrollOffsetIsNotOverwritten) {
511 bool origFractionalOffsetsEnabled = 516 bool origFractionalOffsetsEnabled =
512 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); 517 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled();
513 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); 518 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true);
514 519
515 initializeWithAndroidSettings(); 520 initializeWithAndroidSettings();
516 webViewImpl()->resize(IntSize(200, 250)); 521 webViewImpl()->resize(IntSize(200, 250));
517 522
518 registerMockedHttpURLLoad("200-by-800-viewport.html"); 523 registerMockedHttpURLLoad("200-by-800-viewport.html");
519 navigateTo(m_baseURL + "200-by-800-viewport.html"); 524 navigateTo(m_baseURL + "200-by-800-viewport.html");
520 525
521 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 526 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
522 frameView.layoutViewportScrollableArea()->setScrollPosition( 527 frameView.layoutViewportScrollableArea()->setScrollOffset(
523 DoublePoint(0, 10.5), ProgrammaticScroll); 528 ScrollOffset(0, 10.5), ProgrammaticScroll);
524 frameView.layoutViewportScrollableArea()->ScrollableArea::setScrollPosition( 529 frameView.layoutViewportScrollableArea()->ScrollableArea::setScrollOffset(
525 DoublePoint(10, 30.5), CompositorScroll); 530 ScrollOffset(10, 30.5), CompositorScroll);
526 531
527 EXPECT_EQ( 532 EXPECT_EQ(30.5,
528 30.5, 533 frameView.layoutViewportScrollableArea()->scrollOffset().height());
529 frameView.layoutViewportScrollableArea()->scrollPositionDouble().y());
530 534
531 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled( 535 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(
532 origFractionalOffsetsEnabled); 536 origFractionalOffsetsEnabled);
533 } 537 }
534 538
535 // Test that the viewport's scroll offset is always appropriately bounded such t hat the 539 // Test that the viewport's scroll offset is always appropriately bounded such t hat the
536 // visual viewport always stays within the bounds of the main frame. 540 // visual viewport always stays within the bounds of the main frame.
537 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) { 541 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) {
538 initializeWithDesktopSettings(); 542 initializeWithDesktopSettings();
539 webViewImpl()->resize(IntSize(320, 240)); 543 webViewImpl()->resize(IntSize(320, 240));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 754
751 // Load a wider page first, the navigation should resize the scroll layer to 755 // Load a wider page first, the navigation should resize the scroll layer to
752 // the smaller size on the second navigation. 756 // the smaller size on the second navigation.
753 registerMockedHttpURLLoad("content-width-1000.html"); 757 registerMockedHttpURLLoad("content-width-1000.html");
754 navigateTo(m_baseURL + "content-width-1000.html"); 758 navigateTo(m_baseURL + "content-width-1000.html");
755 webViewImpl()->updateAllLifecyclePhases(); 759 webViewImpl()->updateAllLifecyclePhases();
756 760
757 VisualViewport& visualViewport = 761 VisualViewport& visualViewport =
758 frame()->page()->frameHost().visualViewport(); 762 frame()->page()->frameHost().visualViewport();
759 visualViewport.setScale(2); 763 visualViewport.setScale(2);
760 visualViewport.move(FloatPoint(50, 60)); 764 visualViewport.move(ScrollOffset(50, 60));
761 765
762 // Move and scale the viewport to make sure it gets reset in the navigation. 766 // Move and scale the viewport to make sure it gets reset in the navigation.
763 EXPECT_POINT_EQ(FloatPoint(50, 60), visualViewport.location()); 767 EXPECT_POINT_EQ(FloatPoint(50, 60), visualViewport.location());
764 EXPECT_EQ(2, visualViewport.scale()); 768 EXPECT_EQ(2, visualViewport.scale());
765 769
766 // Navigate again, this time the FrameView should be smaller. 770 // Navigate again, this time the FrameView should be smaller.
767 registerMockedHttpURLLoad("viewport-device-width.html"); 771 registerMockedHttpURLLoad("viewport-device-width.html");
768 navigateTo(m_baseURL + "viewport-device-width.html"); 772 navigateTo(m_baseURL + "viewport-device-width.html");
769 773
770 // Ensure the scroll layer matches the frame view's size. 774 // Ensure the scroll layer matches the frame view's size.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 852
849 // Test that the HistoryItem for the page stores the visual viewport's offset an d scale. 853 // Test that the HistoryItem for the page stores the visual viewport's offset an d scale.
850 TEST_P(ParameterizedVisualViewportTest, TestSavedToHistoryItem) { 854 TEST_P(ParameterizedVisualViewportTest, TestSavedToHistoryItem) {
851 initializeWithDesktopSettings(); 855 initializeWithDesktopSettings();
852 webViewImpl()->resize(IntSize(200, 300)); 856 webViewImpl()->resize(IntSize(200, 300));
853 webViewImpl()->updateAllLifecyclePhases(); 857 webViewImpl()->updateAllLifecyclePhases();
854 858
855 registerMockedHttpURLLoad("200-by-300.html"); 859 registerMockedHttpURLLoad("200-by-300.html");
856 navigateTo(m_baseURL + "200-by-300.html"); 860 navigateTo(m_baseURL + "200-by-300.html");
857 861
858 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), 862 EXPECT_SIZE_EQ(ScrollOffset(0, 0),
859 toLocalFrame(webViewImpl()->page()->mainFrame()) 863 toLocalFrame(webViewImpl()->page()->mainFrame())
860 ->loader() 864 ->loader()
861 .currentItem() 865 .currentItem()
862 ->visualViewportScrollPoint()); 866 ->visualViewportScrollOffset());
863 867
864 VisualViewport& visualViewport = 868 VisualViewport& visualViewport =
865 frame()->page()->frameHost().visualViewport(); 869 frame()->page()->frameHost().visualViewport();
866 visualViewport.setScale(2); 870 visualViewport.setScale(2);
867 871
868 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) 872 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame())
869 ->loader() 873 ->loader()
870 .currentItem() 874 .currentItem()
871 ->pageScaleFactor()); 875 ->pageScaleFactor());
872 876
873 visualViewport.setLocation(FloatPoint(10, 20)); 877 visualViewport.setLocation(FloatPoint(10, 20));
874 878
875 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20), 879 EXPECT_SIZE_EQ(ScrollOffset(10, 20),
876 toLocalFrame(webViewImpl()->page()->mainFrame()) 880 toLocalFrame(webViewImpl()->page()->mainFrame())
877 ->loader() 881 ->loader()
878 .currentItem() 882 .currentItem()
879 ->visualViewportScrollPoint()); 883 ->visualViewportScrollOffset());
880 } 884 }
881 885
882 // Test restoring a HistoryItem properly restores the visual viewport's state. 886 // Test restoring a HistoryItem properly restores the visual viewport's state.
883 TEST_P(ParameterizedVisualViewportTest, TestRestoredFromHistoryItem) { 887 TEST_P(ParameterizedVisualViewportTest, TestRestoredFromHistoryItem) {
884 initializeWithDesktopSettings(); 888 initializeWithDesktopSettings();
885 webViewImpl()->resize(IntSize(200, 300)); 889 webViewImpl()->resize(IntSize(200, 300));
886 890
887 registerMockedHttpURLLoad("200-by-300.html"); 891 registerMockedHttpURLLoad("200-by-300.html");
888 892
889 WebHistoryItem item; 893 WebHistoryItem item;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 item.setScrollOffset(WebPoint(120, 180)); 928 item.setScrollOffset(WebPoint(120, 180));
925 item.setPageScaleFactor(2); 929 item.setPageScaleFactor(2);
926 930
927 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, 931 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item,
928 WebHistoryDifferentDocumentLoad, 932 WebHistoryDifferentDocumentLoad,
929 WebCachePolicy::UseProtocolCachePolicy); 933 WebCachePolicy::UseProtocolCachePolicy);
930 934
931 VisualViewport& visualViewport = 935 VisualViewport& visualViewport =
932 frame()->page()->frameHost().visualViewport(); 936 frame()->page()->frameHost().visualViewport();
933 EXPECT_EQ(2, visualViewport.scale()); 937 EXPECT_EQ(2, visualViewport.scale());
934 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); 938 EXPECT_SIZE_EQ(ScrollOffset(100, 150), frame()->view()->scrollOffset());
935 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), 939 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30),
936 visualViewport.visibleRect().location()); 940 visualViewport.visibleRect().location());
937 } 941 }
938 942
939 // Test that navigation to a new page with a different sized main frame doesn't 943 // Test that navigation to a new page with a different sized main frame doesn't
940 // clobber the history item's main frame scroll offset. crbug.com/371867 944 // clobber the history item's main frame scroll offset. crbug.com/371867
941 TEST_P(ParameterizedVisualViewportTest, 945 TEST_P(ParameterizedVisualViewportTest,
942 TestNavigateToSmallerFrameViewHistoryItemClobberBug) { 946 TestNavigateToSmallerFrameViewHistoryItemClobberBug) {
943 initializeWithAndroidSettings(); 947 initializeWithAndroidSettings();
944 webViewImpl()->resize(IntSize(400, 400)); 948 webViewImpl()->resize(IntSize(400, 400));
945 webViewImpl()->updateAllLifecyclePhases(); 949 webViewImpl()->updateAllLifecyclePhases();
946 950
947 registerMockedHttpURLLoad("content-width-1000.html"); 951 registerMockedHttpURLLoad("content-width-1000.html");
948 navigateTo(m_baseURL + "content-width-1000.html"); 952 navigateTo(m_baseURL + "content-width-1000.html");
949 953
950 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView(); 954 FrameView* frameView = webViewImpl()->mainFrameImpl()->frameView();
951 frameView->layoutViewportScrollableArea()->setScrollPosition( 955 frameView->layoutViewportScrollableArea()->setScrollOffset(
952 IntPoint(0, 1000), ProgrammaticScroll); 956 ScrollOffset(0, 1000), ProgrammaticScroll);
953 957
954 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size()); 958 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->frameRect().size());
955 959
956 VisualViewport& visualViewport = 960 VisualViewport& visualViewport =
957 frame()->page()->frameHost().visualViewport(); 961 frame()->page()->frameHost().visualViewport();
958 visualViewport.setScale(2); 962 visualViewport.setScale(2);
959 visualViewport.setLocation(FloatPoint(350, 350)); 963 visualViewport.setLocation(FloatPoint(350, 350));
960 964
961 Persistent<HistoryItem> firstItem = 965 Persistent<HistoryItem> firstItem =
962 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem(); 966 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem();
963 EXPECT_POINT_EQ(IntPoint(0, 1000), firstItem->scrollPoint()); 967 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->scrollOffset());
964 968
965 // Now navigate to a page which causes a smaller frameView. Make sure that 969 // Now navigate to a page which causes a smaller frameView. Make sure that
966 // navigating doesn't cause the history item to set a new scroll offset 970 // navigating doesn't cause the history item to set a new scroll offset
967 // before the item was replaced. 971 // before the item was replaced.
968 navigateTo("about:blank"); 972 navigateTo("about:blank");
969 frameView = webViewImpl()->mainFrameImpl()->frameView(); 973 frameView = webViewImpl()->mainFrameImpl()->frameView();
970 974
971 EXPECT_NE(firstItem, 975 EXPECT_NE(firstItem,
972 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem()); 976 webViewImpl()->mainFrameImpl()->frame()->loader().currentItem());
973 EXPECT_LT(frameView->frameRect().size().width(), 1000); 977 EXPECT_LT(frameView->frameRect().size().width(), 1000);
974 EXPECT_POINT_EQ(IntPoint(0, 1000), firstItem->scrollPoint()); 978 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->scrollOffset());
975 } 979 }
976 980
977 // Test that the coordinates sent into moveRangeSelection are offset by the 981 // Test that the coordinates sent into moveRangeSelection are offset by the
978 // visual viewport's location. 982 // visual viewport's location.
979 TEST_P(ParameterizedVisualViewportTest, 983 TEST_P(ParameterizedVisualViewportTest,
980 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { 984 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) {
981 initializeWithDesktopSettings(); 985 initializeWithDesktopSettings();
982 webViewImpl()->settings()->setDefaultFontSize(12); 986 webViewImpl()->settings()->setDefaultFontSize(12);
983 webViewImpl()->resize(WebSize(640, 480)); 987 webViewImpl()->resize(WebSize(640, 480));
984 registerMockedHttpURLLoad("move_range.html"); 988 registerMockedHttpURLLoad("move_range.html");
(...skipping 13 matching lines...) Expand all
998 1002
999 webViewImpl()->selectionBounds(baseRect, extentRect); 1003 webViewImpl()->selectionBounds(baseRect, extentRect);
1000 WebPoint initialPoint(baseRect.x, baseRect.y); 1004 WebPoint initialPoint(baseRect.x, baseRect.y);
1001 WebPoint endPoint(extentRect.x, extentRect.y); 1005 WebPoint endPoint(extentRect.x, extentRect.y);
1002 1006
1003 // Move the visual viewport over and make the selection in the same 1007 // Move the visual viewport over and make the selection in the same
1004 // screen-space location. The selection should change to two characters to 1008 // screen-space location. The selection should change to two characters to
1005 // the right and down one line. 1009 // the right and down one line.
1006 VisualViewport& visualViewport = 1010 VisualViewport& visualViewport =
1007 frame()->page()->frameHost().visualViewport(); 1011 frame()->page()->frameHost().visualViewport();
1008 visualViewport.move(FloatPoint(60, 25)); 1012 visualViewport.move(ScrollOffset(60, 25));
1009 mainFrame->toWebLocalFrame()->moveRangeSelection(initialPoint, endPoint); 1013 mainFrame->toWebLocalFrame()->moveRangeSelection(initialPoint, endPoint);
1010 EXPECT_EQ("t ", mainFrame->toWebLocalFrame()->selectionAsText().utf8()); 1014 EXPECT_EQ("t ", mainFrame->toWebLocalFrame()->selectionAsText().utf8());
1011 } 1015 }
1012 1016
1013 // Test that the scrollFocusedEditableElementIntoRect method works with the visu al viewport. 1017 // Test that the scrollFocusedEditableElementIntoRect method works with the visu al viewport.
1014 TEST_P(ParameterizedVisualViewportTest, 1018 TEST_P(ParameterizedVisualViewportTest,
1015 DISABLED_TestScrollFocusedEditableElementIntoRect) { 1019 DISABLED_TestScrollFocusedEditableElementIntoRect) {
1016 initializeWithDesktopSettings(); 1020 initializeWithDesktopSettings();
1017 webViewImpl()->resize(IntSize(500, 300)); 1021 webViewImpl()->resize(IntSize(500, 300));
1018 1022
1019 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); 1023 registerMockedHttpURLLoad("pinch-viewport-input-field.html");
1020 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); 1024 navigateTo(m_baseURL + "pinch-viewport-input-field.html");
1021 1025
1022 VisualViewport& visualViewport = 1026 VisualViewport& visualViewport =
1023 frame()->page()->frameHost().visualViewport(); 1027 frame()->page()->frameHost().visualViewport();
1024 webViewImpl()->resizeVisualViewport(IntSize(200, 100)); 1028 webViewImpl()->resizeVisualViewport(IntSize(200, 100));
1025 webViewImpl()->setInitialFocus(false); 1029 webViewImpl()->setInitialFocus(false);
1026 visualViewport.setLocation(FloatPoint()); 1030 visualViewport.setLocation(FloatPoint());
1027 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); 1031 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200));
1028 1032
1029 EXPECT_POINT_EQ(IntPoint(0, frame()->view()->maximumScrollPosition().y()), 1033 EXPECT_SIZE_EQ(
1030 frame()->view()->scrollPosition()); 1034 ScrollOffset(0, frame()->view()->maximumScrollOffset().height()),
1035 frame()->view()->scrollOffset());
1031 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200), 1036 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200),
1032 visualViewport.visibleRect().location()); 1037 visualViewport.visibleRect().location());
1033 1038
1034 // Try it again but with the page zoomed in 1039 // Try it again but with the page zoomed in
1035 frame()->view()->setScrollPosition(IntPoint(0, 0), ProgrammaticScroll); 1040 frame()->view()->setScrollOffset(ScrollOffset(0, 0), ProgrammaticScroll);
1036 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); 1041 webViewImpl()->resizeVisualViewport(IntSize(500, 300));
1037 visualViewport.setLocation(FloatPoint(0, 0)); 1042 visualViewport.setLocation(FloatPoint(0, 0));
1038 1043
1039 webViewImpl()->setPageScaleFactor(2); 1044 webViewImpl()->setPageScaleFactor(2);
1040 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); 1045 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200));
1041 EXPECT_POINT_EQ(IntPoint(0, frame()->view()->maximumScrollPosition().y()), 1046 EXPECT_SIZE_EQ(
1042 frame()->view()->scrollPosition()); 1047 ScrollOffset(0, frame()->view()->maximumScrollOffset().height()),
1048 frame()->view()->scrollOffset());
1043 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150), 1049 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150),
1044 visualViewport.visibleRect().location()); 1050 visualViewport.visibleRect().location());
1045 1051
1046 // Once more but make sure that we don't move the visual viewport unless neces sary. 1052 // Once more but make sure that we don't move the visual viewport unless neces sary.
1047 registerMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html"); 1053 registerMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html");
1048 navigateTo(m_baseURL + "pinch-viewport-input-field-long-and-wide.html"); 1054 navigateTo(m_baseURL + "pinch-viewport-input-field-long-and-wide.html");
1049 webViewImpl()->setInitialFocus(false); 1055 webViewImpl()->setInitialFocus(false);
1050 visualViewport.setLocation(FloatPoint()); 1056 visualViewport.setLocation(FloatPoint());
1051 frame()->view()->setScrollPosition(IntPoint(0, 0), ProgrammaticScroll); 1057 frame()->view()->setScrollOffset(ScrollOffset(0, 0), ProgrammaticScroll);
1052 webViewImpl()->resizeVisualViewport(IntSize(500, 300)); 1058 webViewImpl()->resizeVisualViewport(IntSize(500, 300));
1053 visualViewport.setLocation(FloatPoint(30, 50)); 1059 visualViewport.setLocation(FloatPoint(30, 50));
1054 1060
1055 webViewImpl()->setPageScaleFactor(2); 1061 webViewImpl()->setPageScaleFactor(2);
1056 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); 1062 webViewImpl()->scrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200));
1057 EXPECT_POINT_EQ(IntPoint(200 - 30 - 75, 600 - 50 - 65), 1063 EXPECT_SIZE_EQ(ScrollOffset(200 - 30 - 75, 600 - 50 - 65),
1058 frame()->view()->scrollPosition()); 1064 frame()->view()->scrollOffset());
1059 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50), 1065 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50),
1060 visualViewport.visibleRect().location()); 1066 visualViewport.visibleRect().location());
1061 } 1067 }
1062 1068
1063 // Test that resizing the WebView causes ViewportConstrained objects to relayout . 1069 // Test that resizing the WebView causes ViewportConstrained objects to relayout .
1064 TEST_P(ParameterizedVisualViewportTest, 1070 TEST_P(ParameterizedVisualViewportTest,
1065 TestWebViewResizeCausesViewportConstrainedLayout) { 1071 TestWebViewResizeCausesViewportConstrainedLayout) {
1066 initializeWithDesktopSettings(); 1072 initializeWithDesktopSettings();
1067 webViewImpl()->resize(IntSize(500, 300)); 1073 webViewImpl()->resize(IntSize(500, 300));
1068 1074
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 frameView.layoutViewportScrollableArea(); 1206 frameView.layoutViewportScrollableArea();
1201 VisualViewport& visualViewport = 1207 VisualViewport& visualViewport =
1202 frame()->page()->frameHost().visualViewport(); 1208 frame()->page()->frameHost().visualViewport();
1203 Element* inputBox = frame()->document()->getElementById("box"); 1209 Element* inputBox = frame()->document()->getElementById("box");
1204 1210
1205 webViewImpl()->setPageScaleFactor(2); 1211 webViewImpl()->setPageScaleFactor(2);
1206 1212
1207 // The element is already in the view so the scrollIntoView shouldn't move 1213 // The element is already in the view so the scrollIntoView shouldn't move
1208 // the viewport at all. 1214 // the viewport at all.
1209 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); 1215 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f));
1210 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), 1216 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.75),
1211 ProgrammaticScroll); 1217 ProgrammaticScroll);
1212 inputBox->scrollIntoViewIfNeeded(false); 1218 inputBox->scrollIntoViewIfNeeded(false);
1213 1219
1214 EXPECT_POINT_EQ(DoublePoint(0, 900), 1220 EXPECT_SIZE_EQ(ScrollOffset(0, 900),
1215 layoutViewportScrollableArea->scrollPositionDouble()); 1221 layoutViewportScrollableArea->scrollOffset());
1216 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); 1222 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location());
1217 1223
1218 // Change the fractional part of the frameview to one that would round down. 1224 // Change the fractional part of the frameview to one that would round down.
1219 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), 1225 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.125),
1220 ProgrammaticScroll); 1226 ProgrammaticScroll);
1221 inputBox->scrollIntoViewIfNeeded(false); 1227 inputBox->scrollIntoViewIfNeeded(false);
1222 1228
1223 EXPECT_POINT_EQ(DoublePoint(0, 900), 1229 EXPECT_SIZE_EQ(ScrollOffset(0, 900),
1224 layoutViewportScrollableArea->scrollPositionDouble()); 1230 layoutViewportScrollableArea->scrollOffset());
1225 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); 1231 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location());
1226 1232
1227 // Repeat both tests above with the visual viewport at a high fractional. 1233 // Repeat both tests above with the visual viewport at a high fractional.
1228 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); 1234 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f));
1229 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), 1235 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.75),
1230 ProgrammaticScroll); 1236 ProgrammaticScroll);
1231 inputBox->scrollIntoViewIfNeeded(false); 1237 inputBox->scrollIntoViewIfNeeded(false);
1232 1238
1233 EXPECT_POINT_EQ(DoublePoint(0, 900), 1239 EXPECT_SIZE_EQ(ScrollOffset(0, 900),
1234 layoutViewportScrollableArea->scrollPositionDouble()); 1240 layoutViewportScrollableArea->scrollOffset());
1235 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); 1241 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location());
1236 1242
1237 // Change the fractional part of the frameview to one that would round down. 1243 // Change the fractional part of the frameview to one that would round down.
1238 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), 1244 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.125),
1239 ProgrammaticScroll); 1245 ProgrammaticScroll);
1240 inputBox->scrollIntoViewIfNeeded(false); 1246 inputBox->scrollIntoViewIfNeeded(false);
1241 1247
1242 EXPECT_POINT_EQ(DoublePoint(0, 900), 1248 EXPECT_SIZE_EQ(ScrollOffset(0, 900),
1243 layoutViewportScrollableArea->scrollPositionDouble()); 1249 layoutViewportScrollableArea->scrollOffset());
1244 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); 1250 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location());
1245 1251
1246 // Both viewports with a 0.5 fraction. 1252 // Both viewports with a 0.5 fraction.
1247 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); 1253 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f));
1248 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), 1254 layoutViewportScrollableArea->setScrollOffset(ScrollOffset(0, 900.5),
1249 ProgrammaticScroll); 1255 ProgrammaticScroll);
1250 inputBox->scrollIntoViewIfNeeded(false); 1256 inputBox->scrollIntoViewIfNeeded(false);
1251 1257
1252 EXPECT_POINT_EQ(DoublePoint(0, 900), 1258 EXPECT_SIZE_EQ(ScrollOffset(0, 900),
1253 layoutViewportScrollableArea->scrollPositionDouble()); 1259 layoutViewportScrollableArea->scrollOffset());
1254 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); 1260 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location());
1255 } 1261 }
1256 1262
1257 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport, 1263 static ScrollOffset expectedMaxFrameViewScrollOffset(
1258 FrameView& frameView) { 1264 VisualViewport& visualViewport,
1265 FrameView& frameView) {
1259 float aspectRatio = visualViewport.visibleRect().width() / 1266 float aspectRatio = visualViewport.visibleRect().width() /
1260 visualViewport.visibleRect().height(); 1267 visualViewport.visibleRect().height();
1261 float newHeight = frameView.frameRect().width() / aspectRatio; 1268 float newHeight = frameView.frameRect().width() / aspectRatio;
1262 return IntPoint( 1269 return ScrollOffset(
1263 frameView.contentsSize().width() - frameView.frameRect().width(), 1270 frameView.contentsSize().width() - frameView.frameRect().width(),
1264 frameView.contentsSize().height() - newHeight); 1271 frameView.contentsSize().height() - newHeight);
1265 } 1272 }
1266 1273
1267 TEST_F(VisualViewportTest, TestTopControlsAdjustment) { 1274 TEST_F(VisualViewportTest, TestTopControlsAdjustment) {
1268 initializeWithAndroidSettings(); 1275 initializeWithAndroidSettings();
1269 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); 1276 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false);
1270 1277
1271 registerMockedHttpURLLoad("content-width-1000.html"); 1278 registerMockedHttpURLLoad("content-width-1000.html");
1272 navigateTo(m_baseURL + "content-width-1000.html"); 1279 navigateTo(m_baseURL + "content-width-1000.html");
1273 1280
1274 VisualViewport& visualViewport = 1281 VisualViewport& visualViewport =
1275 frame()->page()->frameHost().visualViewport(); 1282 frame()->page()->frameHost().visualViewport();
1276 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1283 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1277 1284
1278 visualViewport.setScale(1); 1285 visualViewport.setScale(1);
1279 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); 1286 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size());
1280 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); 1287 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size());
1281 1288
1282 // Simulate bringing down the top controls by 20px. 1289 // Simulate bringing down the top controls by 20px.
1283 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1290 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1284 WebFloatSize(), 1, 1); 1291 WebFloatSize(), 1, 1);
1285 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size()); 1292 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.visibleRect().size());
1286 1293
1287 // Test that the scroll bounds are adjusted appropriately: the visual viewport 1294 // Test that the scroll bounds are adjusted appropriately: the visual viewport
1288 // should be shrunk by 20px to 430px. The outer viewport was shrunk to maintai n the 1295 // should be shrunk by 20px to 430px. The outer viewport was shrunk to maintai n the
1289 // aspect ratio so it's height is 860px. 1296 // aspect ratio so it's height is 860px.
1290 visualViewport.move(FloatPoint(10000, 10000)); 1297 visualViewport.move(ScrollOffset(10000, 10000));
1291 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); 1298 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location());
1292 1299
1293 // The outer viewport (FrameView) should be affected as well. 1300 // The outer viewport (FrameView) should be affected as well.
1294 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1301 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1295 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), 1302 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView),
1296 frameView.scrollPosition()); 1303 frameView.scrollOffset());
1297 1304
1298 // Simulate bringing up the top controls by 10.5px. 1305 // Simulate bringing up the top controls by 10.5px.
1299 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1306 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1300 WebFloatSize(), 1, -10.5f / 20); 1307 WebFloatSize(), 1, -10.5f / 20);
1301 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), 1308 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f),
1302 visualViewport.visibleRect().size()); 1309 visualViewport.visibleRect().size());
1303 1310
1304 // maximumScrollPosition |ceil|s the top controls adjustment. 1311 // maximumScrollPosition |ceil|s the top controls adjustment.
1305 visualViewport.move(FloatPoint(10000, 10000)); 1312 visualViewport.move(ScrollOffset(10000, 10000));
1306 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location()); 1313 EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location());
1307 1314
1308 // The outer viewport (FrameView) should be affected as well. 1315 // The outer viewport (FrameView) should be affected as well.
1309 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1316 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1310 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), 1317 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView),
1311 frameView.scrollPosition()); 1318 frameView.scrollOffset());
1312 } 1319 }
1313 1320
1314 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) { 1321 TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) {
1315 initializeWithAndroidSettings(); 1322 initializeWithAndroidSettings();
1316 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false); 1323 webViewImpl()->resizeWithTopControls(IntSize(500, 450), 20, false);
1317 1324
1318 registerMockedHttpURLLoad("content-width-1000.html"); 1325 registerMockedHttpURLLoad("content-width-1000.html");
1319 navigateTo(m_baseURL + "content-width-1000.html"); 1326 navigateTo(m_baseURL + "content-width-1000.html");
1320 1327
1321 VisualViewport& visualViewport = 1328 VisualViewport& visualViewport =
1322 frame()->page()->frameHost().visualViewport(); 1329 frame()->page()->frameHost().visualViewport();
1323 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1330 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1324 1331
1325 visualViewport.setScale(2); 1332 visualViewport.setScale(2);
1326 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); 1333 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size());
1327 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); 1334 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size());
1328 1335
1329 // Simulate bringing down the top controls by 20px. Since we're zoomed in, 1336 // Simulate bringing down the top controls by 20px. Since we're zoomed in,
1330 // the top controls take up half as much space (in document-space) than 1337 // the top controls take up half as much space (in document-space) than
1331 // they do at an unzoomed level. 1338 // they do at an unzoomed level.
1332 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1339 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1333 WebFloatSize(), 1, 1); 1340 WebFloatSize(), 1, 1);
1334 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); 1341 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size());
1335 1342
1336 // Test that the scroll bounds are adjusted appropriately. 1343 // Test that the scroll bounds are adjusted appropriately.
1337 visualViewport.move(FloatPoint(10000, 10000)); 1344 visualViewport.move(ScrollOffset(10000, 10000));
1338 EXPECT_POINT_EQ(FloatPoint(750, 860 - 215), visualViewport.location()); 1345 EXPECT_POINT_EQ(FloatPoint(750, 860 - 215), visualViewport.location());
1339 1346
1340 // The outer viewport (FrameView) should be affected as well. 1347 // The outer viewport (FrameView) should be affected as well.
1341 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1348 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1342 IntPoint expected = 1349 ScrollOffset expected =
1343 expectedMaxFrameViewScrollOffset(visualViewport, frameView); 1350 expectedMaxFrameViewScrollOffset(visualViewport, frameView);
1344 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); 1351 EXPECT_SIZE_EQ(expected, frameView.scrollOffset());
1345 1352
1346 // Scale back out, FrameView max scroll shouldn't have changed. Visual 1353 // Scale back out, FrameView max scroll shouldn't have changed. Visual
1347 // viewport should be moved up to accomodate larger view. 1354 // viewport should be moved up to accomodate larger view.
1348 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1355 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1349 WebFloatSize(), 0.5f, 0); 1356 WebFloatSize(), 0.5f, 0);
1350 EXPECT_EQ(1, visualViewport.scale()); 1357 EXPECT_EQ(1, visualViewport.scale());
1351 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); 1358 EXPECT_SIZE_EQ(expected, frameView.scrollOffset());
1352 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1359 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1353 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); 1360 EXPECT_SIZE_EQ(expected, frameView.scrollOffset());
1354 1361
1355 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); 1362 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location());
1356 visualViewport.move(FloatPoint(10000, 10000)); 1363 visualViewport.move(ScrollOffset(10000, 10000));
1357 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location()); 1364 EXPECT_POINT_EQ(FloatPoint(500, 860 - 430), visualViewport.location());
1358 1365
1359 // Scale out, use a scale that causes fractional rects. 1366 // Scale out, use a scale that causes fractional rects.
1360 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1367 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1361 WebFloatSize(), 0.8f, -1); 1368 WebFloatSize(), 0.8f, -1);
1362 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size()); 1369 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.visibleRect().size());
1363 1370
1364 // Bring out the top controls by 11 1371 // Bring out the top controls by 11
1365 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1372 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1366 WebFloatSize(), 1, 11 / 20.f); 1373 WebFloatSize(), 1, 11 / 20.f);
1367 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size()); 1374 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.visibleRect().size());
1368 1375
1369 // Ensure max scroll offsets are updated properly. 1376 // Ensure max scroll offsets are updated properly.
1370 visualViewport.move(FloatPoint(10000, 10000)); 1377 visualViewport.move(ScrollOffset(10000, 10000));
1371 EXPECT_FLOAT_POINT_EQ(FloatPoint(375, 877.5 - 548.75), 1378 EXPECT_FLOAT_POINT_EQ(FloatPoint(375, 877.5 - 548.75),
1372 visualViewport.location()); 1379 visualViewport.location());
1373 1380
1374 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1381 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1375 EXPECT_POINT_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), 1382 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView),
1376 frameView.scrollPosition()); 1383 frameView.scrollOffset());
1377 } 1384 }
1378 1385
1379 // Tests that a scroll all the way to the bottom of the page, while hiding the 1386 // Tests that a scroll all the way to the bottom of the page, while hiding the
1380 // top controls doesn't cause a clamp in the viewport scroll offset when the 1387 // top controls doesn't cause a clamp in the viewport scroll offset when the
1381 // top controls initiated resize occurs. 1388 // top controls initiated resize occurs.
1382 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) { 1389 TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) {
1383 int topControlsHeight = 20; 1390 int topControlsHeight = 20;
1384 int visualViewportHeight = 450; 1391 int visualViewportHeight = 450;
1385 int layoutViewportHeight = 900; 1392 int layoutViewportHeight = 900;
1386 float pageScale = 2; 1393 float pageScale = 2;
(...skipping 17 matching lines...) Expand all
1404 EXPECT_SIZE_EQ( 1411 EXPECT_SIZE_EQ(
1405 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), 1412 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale),
1406 visualViewport.visibleRect().size()); 1413 visualViewport.visibleRect().size());
1407 EXPECT_SIZE_EQ( 1414 EXPECT_SIZE_EQ(
1408 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), 1415 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale),
1409 frameView.frameRect().size()); 1416 frameView.frameRect().size());
1410 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), 1417 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight),
1411 visualViewport.size()); 1418 visualViewport.size());
1412 1419
1413 // Scroll all the way to the bottom, hiding the top controls in the process. 1420 // Scroll all the way to the bottom, hiding the top controls in the process.
1414 visualViewport.move(FloatPoint(10000, 10000)); 1421 visualViewport.move(ScrollOffset(10000, 10000));
1415 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1422 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1416 webViewImpl()->topControls().setShownRatio(0); 1423 webViewImpl()->topControls().setShownRatio(0);
1417 1424
1418 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), 1425 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale),
1419 visualViewport.visibleRect().size()); 1426 visualViewport.visibleRect().size());
1420 1427
1421 IntPoint frameViewExpected = 1428 ScrollOffset frameViewExpected =
1422 expectedMaxFrameViewScrollOffset(visualViewport, frameView); 1429 expectedMaxFrameViewScrollOffset(visualViewport, frameView);
1423 FloatPoint visualViewportExpected = 1430 FloatPoint visualViewportExpected =
1424 FloatPoint(750, layoutViewportHeight - visualViewportHeight / pageScale); 1431 FloatPoint(750, layoutViewportHeight - visualViewportHeight / pageScale);
1425 1432
1426 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); 1433 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location());
1427 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); 1434 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset());
1428 1435
1429 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; 1436 FloatPoint totalExpected = visualViewportExpected + frameViewExpected;
1430 1437
1431 // Resize the widget to match the top controls adjustment. Ensure that the 1438 // Resize the widget to match the top controls adjustment. Ensure that the
1432 // total offset (i.e. what the user sees) doesn't change because of clamping 1439 // total offset (i.e. what the user sees) doesn't change because of clamping
1433 // the offsets to valid values. 1440 // the offsets to valid values.
1434 webViewImpl()->resizeWithTopControls(WebSize(500, visualViewportHeight), 20, 1441 webViewImpl()->resizeWithTopControls(WebSize(500, visualViewportHeight), 20,
1435 false); 1442 false);
1436 1443
1437 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); 1444 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size());
1438 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), 1445 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale),
1439 visualViewport.visibleRect().size()); 1446 visualViewport.visibleRect().size());
1440 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), 1447 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight),
1441 frameView.frameRect().size()); 1448 frameView.frameRect().size());
1442 EXPECT_POINT_EQ(totalExpected, 1449 EXPECT_POINT_EQ(totalExpected,
1443 frameView.scrollPosition() + visualViewport.location()); 1450 visualViewport.location() + frameView.scrollOffset());
1444 } 1451 }
1445 1452
1446 // Tests that a scroll all the way to the bottom while showing the top controls 1453 // Tests that a scroll all the way to the bottom while showing the top controls
1447 // doesn't cause a clamp to the viewport scroll offset when the top controls 1454 // doesn't cause a clamp to the viewport scroll offset when the top controls
1448 // initiated resize occurs. 1455 // initiated resize occurs.
1449 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) { 1456 TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) {
1450 int topControlsHeight = 20; 1457 int topControlsHeight = 20;
1451 int visualViewportHeight = 500; 1458 int visualViewportHeight = 500;
1452 int layoutViewportHeight = 1000; 1459 int layoutViewportHeight = 1000;
1453 int contentHeight = 2000; 1460 int contentHeight = 2000;
(...skipping 18 matching lines...) Expand all
1472 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), 1479 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale),
1473 visualViewport.visibleRect().size()); 1480 visualViewport.visibleRect().size());
1474 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), 1481 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight),
1475 frameView.frameRect().size()); 1482 frameView.frameRect().size());
1476 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); 1483 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size());
1477 1484
1478 // Scroll all the way to the bottom, showing the the top controls in the 1485 // Scroll all the way to the bottom, showing the the top controls in the
1479 // process. (This could happen via window.scrollTo during a scroll, for 1486 // process. (This could happen via window.scrollTo during a scroll, for
1480 // example). 1487 // example).
1481 webViewImpl()->topControls().setShownRatio(1); 1488 webViewImpl()->topControls().setShownRatio(1);
1482 visualViewport.move(FloatPoint(10000, 10000)); 1489 visualViewport.move(ScrollOffset(10000, 10000));
1483 frameView.scrollBy(IntSize(10000, 10000), UserScroll); 1490 frameView.scrollBy(ScrollOffset(10000, 10000), UserScroll);
1484 1491
1485 EXPECT_SIZE_EQ( 1492 EXPECT_SIZE_EQ(
1486 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), 1493 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale),
1487 visualViewport.visibleRect().size()); 1494 visualViewport.visibleRect().size());
1488 1495
1489 IntPoint frameViewExpected = IntPoint( 1496 ScrollOffset frameViewExpected(
1490 0, contentHeight - 1497 0, contentHeight -
1491 (layoutViewportHeight - topControlsHeight / minPageScale)); 1498 (layoutViewportHeight - topControlsHeight / minPageScale));
1492 FloatPoint visualViewportExpected = 1499 FloatPoint visualViewportExpected =
1493 FloatPoint(750, (layoutViewportHeight - topControlsHeight / minPageScale - 1500 FloatPoint(750, (layoutViewportHeight - topControlsHeight / minPageScale -
1494 visualViewport.visibleRect().height())); 1501 visualViewport.visibleRect().height()));
1495 1502
1496 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); 1503 EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location());
1497 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); 1504 EXPECT_SIZE_EQ(frameViewExpected, frameView.scrollOffset());
1498 1505
1499 FloatPoint totalExpected = visualViewportExpected + frameViewExpected; 1506 FloatPoint totalExpected = visualViewportExpected + frameViewExpected;
1500 1507
1501 // Resize the widget to match the top controls adjustment. Ensure that the 1508 // Resize the widget to match the top controls adjustment. Ensure that the
1502 // total offset (i.e. what the user sees) doesn't change because of clamping 1509 // total offset (i.e. what the user sees) doesn't change because of clamping
1503 // the offsets to valid values. 1510 // the offsets to valid values.
1504 webViewImpl()->resizeWithTopControls( 1511 webViewImpl()->resizeWithTopControls(
1505 WebSize(500, visualViewportHeight - topControlsHeight), 20, true); 1512 WebSize(500, visualViewportHeight - topControlsHeight), 20, true);
1506 1513
1507 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight), 1514 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - topControlsHeight),
1508 visualViewport.size()); 1515 visualViewport.size());
1509 EXPECT_SIZE_EQ( 1516 EXPECT_SIZE_EQ(
1510 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), 1517 IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale),
1511 visualViewport.visibleRect().size()); 1518 visualViewport.visibleRect().size());
1512 EXPECT_SIZE_EQ( 1519 EXPECT_SIZE_EQ(
1513 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), 1520 IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale),
1514 frameView.frameRect().size()); 1521 frameView.frameRect().size());
1515 EXPECT_POINT_EQ(totalExpected, 1522 EXPECT_POINT_EQ(totalExpected,
1516 frameView.scrollPosition() + visualViewport.location()); 1523 visualViewport.location() + frameView.scrollOffset());
1517 } 1524 }
1518 1525
1519 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the 1526 // Tests that a resize due to top controls hiding doesn't incorrectly clamp the
1520 // main frame's scroll offset. crbug.com/428193. 1527 // main frame's scroll offset. crbug.com/428193.
1521 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { 1528 TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) {
1522 initializeWithAndroidSettings(); 1529 initializeWithAndroidSettings();
1523 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false); 1530 webViewImpl()->resizeWithTopControls(webViewImpl()->size(), 500, false);
1524 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1531 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1525 WebFloatSize(), 1, 1); 1532 WebFloatSize(), 1, 1);
1526 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true); 1533 webViewImpl()->resizeWithTopControls(WebSize(1000, 1000), 500, true);
1527 1534
1528 registerMockedHttpURLLoad("content-width-1000.html"); 1535 registerMockedHttpURLLoad("content-width-1000.html");
1529 navigateTo(m_baseURL + "content-width-1000.html"); 1536 navigateTo(m_baseURL + "content-width-1000.html");
1530 1537
1531 // Scroll the FrameView to the bottom of the page but "hide" the top 1538 // Scroll the FrameView to the bottom of the page but "hide" the top
1532 // controls on the compositor side so the max scroll position should account 1539 // controls on the compositor side so the max scroll position should account
1533 // for the full viewport height. 1540 // for the full viewport height.
1534 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), 1541 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(),
1535 WebFloatSize(), 1, -1); 1542 WebFloatSize(), 1, -1);
1536 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1543 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1537 frameView.setScrollPosition(IntPoint(0, 10000), ProgrammaticScroll); 1544 frameView.setScrollOffset(ScrollOffset(0, 10000), ProgrammaticScroll);
1538 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); 1545 EXPECT_EQ(500, frameView.scrollOffset().height());
1539 1546
1540 // Now send the resize, make sure the scroll offset doesn't change. 1547 // Now send the resize, make sure the scroll offset doesn't change.
1541 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false); 1548 webViewImpl()->resizeWithTopControls(WebSize(1000, 1500), 500, false);
1542 EXPECT_EQ(500, frameView.scrollPositionDouble().y()); 1549 EXPECT_EQ(500, frameView.scrollOffset().height());
1543 } 1550 }
1544 1551
1545 static void configureHiddenScrollbarsSettings(WebSettings* settings) { 1552 static void configureHiddenScrollbarsSettings(WebSettings* settings) {
1546 VisualViewportTest::configureAndroidSettings(settings); 1553 VisualViewportTest::configureAndroidSettings(settings);
1547 settings->setHideScrollbars(true); 1554 settings->setHideScrollbars(true);
1548 } 1555 }
1549 1556
1550 // Tests that scrollbar layers are not attached to the inner viewport container 1557 // Tests that scrollbar layers are not attached to the inner viewport container
1551 // layer when hideScrollbars WebSetting is true. 1558 // layer when hideScrollbars WebSetting is true.
1552 TEST_F(VisualViewportTest, 1559 TEST_F(VisualViewportTest,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 initializeWithDesktopSettings(); 1611 initializeWithDesktopSettings();
1605 webViewImpl()->resize(IntSize(100, 200)); 1612 webViewImpl()->resize(IntSize(100, 200));
1606 1613
1607 navigateTo("about:blank"); 1614 navigateTo("about:blank");
1608 webViewImpl()->updateAllLifecyclePhases(); 1615 webViewImpl()->updateAllLifecyclePhases();
1609 1616
1610 webViewImpl()->resizeVisualViewport(IntSize(100, 100)); 1617 webViewImpl()->resizeVisualViewport(IntSize(100, 100));
1611 1618
1612 VisualViewport& visualViewport = 1619 VisualViewport& visualViewport =
1613 frame()->page()->frameHost().visualViewport(); 1620 frame()->page()->frameHost().visualViewport();
1614 visualViewport.move(FloatPoint(0, 100)); 1621 visualViewport.move(ScrollOffset(0, 100));
1615 1622
1616 EXPECT_EQ(100, visualViewport.location().y()); 1623 EXPECT_EQ(100, visualViewport.location().y());
1617 1624
1618 webViewImpl()->resizeVisualViewport(IntSize(100, 200)); 1625 webViewImpl()->resizeVisualViewport(IntSize(100, 200));
1619 1626
1620 EXPECT_EQ(0, visualViewport.location().y()); 1627 EXPECT_EQ(0, visualViewport.location().y());
1621 } 1628 }
1622 1629
1623 TEST_P(ParameterizedVisualViewportTest, 1630 TEST_P(ParameterizedVisualViewportTest,
1624 ElementBoundsInViewportSpaceAccountsForViewport) { 1631 ElementBoundsInViewportSpaceAccountsForViewport) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 TEST_P(ParameterizedVisualViewportTest, FractionalMaxScrollOffset) { 1779 TEST_P(ParameterizedVisualViewportTest, FractionalMaxScrollOffset) {
1773 initializeWithDesktopSettings(); 1780 initializeWithDesktopSettings();
1774 webViewImpl()->resize(IntSize(101, 201)); 1781 webViewImpl()->resize(IntSize(101, 201));
1775 navigateTo("about:blank"); 1782 navigateTo("about:blank");
1776 1783
1777 VisualViewport& visualViewport = 1784 VisualViewport& visualViewport =
1778 frame()->page()->frameHost().visualViewport(); 1785 frame()->page()->frameHost().visualViewport();
1779 ScrollableArea* scrollableArea = &visualViewport; 1786 ScrollableArea* scrollableArea = &visualViewport;
1780 1787
1781 webViewImpl()->setPageScaleFactor(1.0); 1788 webViewImpl()->setPageScaleFactor(1.0);
1782 EXPECT_FLOAT_POINT_EQ(DoublePoint(), 1789 EXPECT_SIZE_EQ(ScrollOffset(), scrollableArea->maximumScrollOffset());
1783 scrollableArea->maximumScrollPositionDouble());
1784 1790
1785 webViewImpl()->setPageScaleFactor(2); 1791 webViewImpl()->setPageScaleFactor(2);
1786 EXPECT_FLOAT_POINT_EQ(DoublePoint(101. / 2., 201. / 2.), 1792 EXPECT_SIZE_EQ(ScrollOffset(101. / 2., 201. / 2.),
1787 scrollableArea->maximumScrollPositionDouble()); 1793 scrollableArea->maximumScrollOffset());
1788 } 1794 }
1789 1795
1790 // Tests that the slow scrolling after an impl scroll on the visual viewport 1796 // Tests that the slow scrolling after an impl scroll on the visual viewport
1791 // is continuous. crbug.com/453460 was caused by the impl-path not updating the 1797 // is continuous. crbug.com/453460 was caused by the impl-path not updating the
1792 // ScrollAnimatorBase class. 1798 // ScrollAnimatorBase class.
1793 TEST_P(ParameterizedVisualViewportTest, SlowScrollAfterImplScroll) { 1799 TEST_P(ParameterizedVisualViewportTest, SlowScrollAfterImplScroll) {
1794 initializeWithDesktopSettings(); 1800 initializeWithDesktopSettings();
1795 webViewImpl()->resize(IntSize(800, 600)); 1801 webViewImpl()->resize(IntSize(800, 600));
1796 navigateTo("about:blank"); 1802 navigateTo("about:blank");
1797 1803
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 navigateTo(m_baseURL + "hit-test.html"); 1837 navigateTo(m_baseURL + "hit-test.html");
1832 1838
1833 webViewImpl()->resize(IntSize(500, 500)); 1839 webViewImpl()->resize(IntSize(500, 500));
1834 webViewImpl()->updateAllLifecyclePhases(); 1840 webViewImpl()->updateAllLifecyclePhases();
1835 1841
1836 WebDocument webDoc = webViewImpl()->mainFrame()->document(); 1842 WebDocument webDoc = webViewImpl()->mainFrame()->document();
1837 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1843 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1838 1844
1839 webViewImpl()->setPageScaleFactor(2); 1845 webViewImpl()->setPageScaleFactor(2);
1840 webViewImpl()->setVisualViewportOffset(WebFloatPoint(200, 230)); 1846 webViewImpl()->setVisualViewportOffset(WebFloatPoint(200, 230));
1841 frameView.layoutViewportScrollableArea()->setScrollPosition( 1847 frameView.layoutViewportScrollableArea()->setScrollOffset(
1842 DoublePoint(400, 1100), ProgrammaticScroll); 1848 ScrollOffset(400, 1100), ProgrammaticScroll);
1843 1849
1844 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state. 1850 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state.
1845 forceFullCompositingUpdate(); 1851 forceFullCompositingUpdate();
1846 1852
1847 // Because of where the visual viewport is located, this should hit the bottom right 1853 // Because of where the visual viewport is located, this should hit the bottom right
1848 // target (target 4). 1854 // target (target 4).
1849 WebAXObject hitNode = 1855 WebAXObject hitNode =
1850 webDoc.accessibilityObject().hitTest(WebPoint(154, 165)); 1856 webDoc.accessibilityObject().hitTest(WebPoint(154, 165));
1851 WebAXNameFrom nameFrom; 1857 WebAXNameFrom nameFrom;
1852 WebVector<WebAXObject> nameObjects; 1858 WebVector<WebAXObject> nameObjects;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1895
1890 // Test points that will cause non-integer values. 1896 // Test points that will cause non-integer values.
1891 EXPECT_FLOAT_POINT_EQ( 1897 EXPECT_FLOAT_POINT_EQ(
1892 FloatPoint(50.5, 62.4), 1898 FloatPoint(50.5, 62.4),
1893 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8))); 1899 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8)));
1894 EXPECT_FLOAT_POINT_EQ( 1900 EXPECT_FLOAT_POINT_EQ(
1895 FloatPoint(81, 100.8), 1901 FloatPoint(81, 100.8),
1896 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4))); 1902 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4)));
1897 1903
1898 // Scrolling the main frame should have no effect. 1904 // Scrolling the main frame should have no effect.
1899 frameView.layoutViewportScrollableArea()->setScrollPosition( 1905 frameView.layoutViewportScrollableArea()->setScrollOffset(
1900 DoublePoint(100, 120), ProgrammaticScroll); 1906 ScrollOffset(100, 120), ProgrammaticScroll);
1901 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame( 1907 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame(
1902 FloatPoint(80, 100))); 1908 FloatPoint(80, 100)));
1903 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), 1909 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100),
1904 visualViewport.rootFrameToViewport(FloatPoint(50, 62))); 1910 visualViewport.rootFrameToViewport(FloatPoint(50, 62)));
1905 } 1911 }
1906 1912
1907 // Tests that the window dimensions are available before a full layout occurs. 1913 // Tests that the window dimensions are available before a full layout occurs.
1908 // More specifically, it checks that the innerWidth and innerHeight window 1914 // More specifically, it checks that the innerWidth and innerHeight window
1909 // properties will trigger a layout which will cause an update to viewport 1915 // properties will trigger a layout which will cause an update to viewport
1910 // constraints and a refreshed initial scale. crbug.com/466718 1916 // constraints and a refreshed initial scale. crbug.com/466718
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 pinchUpdate.data.pinchUpdate.scale = 2; 1958 pinchUpdate.data.pinchUpdate.scale = 2;
1953 pinchUpdate.data.pinchUpdate.zoomDisabled = false; 1959 pinchUpdate.data.pinchUpdate.zoomDisabled = false;
1954 1960
1955 webViewImpl()->handleInputEvent(pinchUpdate); 1961 webViewImpl()->handleInputEvent(pinchUpdate);
1956 1962
1957 VisualViewport& visualViewport = 1963 VisualViewport& visualViewport =
1958 webViewImpl()->page()->frameHost().visualViewport(); 1964 webViewImpl()->page()->frameHost().visualViewport();
1959 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1965 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1960 1966
1961 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); 1967 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location());
1962 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); 1968 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frameView.scrollOffset());
1963 } 1969 }
1964 1970
1965 TEST_P(ParameterizedVisualViewportTest, ResizeWithScrollAnchoring) { 1971 TEST_P(ParameterizedVisualViewportTest, ResizeWithScrollAnchoring) {
1966 bool wasScrollAnchoringEnabled = 1972 bool wasScrollAnchoringEnabled =
1967 RuntimeEnabledFeatures::scrollAnchoringEnabled(); 1973 RuntimeEnabledFeatures::scrollAnchoringEnabled();
1968 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); 1974 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true);
1969 1975
1970 initializeWithDesktopSettings(); 1976 initializeWithDesktopSettings();
1971 webViewImpl()->resize(IntSize(800, 600)); 1977 webViewImpl()->resize(IntSize(800, 600));
1972 1978
1973 registerMockedHttpURLLoad("icb-relative-content.html"); 1979 registerMockedHttpURLLoad("icb-relative-content.html");
1974 navigateTo(m_baseURL + "icb-relative-content.html"); 1980 navigateTo(m_baseURL + "icb-relative-content.html");
1975 1981
1976 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1982 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1977 frameView.layoutViewportScrollableArea()->setScrollPosition( 1983 frameView.layoutViewportScrollableArea()->setScrollOffset(
1978 DoublePoint(700, 500), ProgrammaticScroll); 1984 ScrollOffset(700, 500), ProgrammaticScroll);
1979 1985
1980 webViewImpl()->resize(IntSize(800, 300)); 1986 webViewImpl()->resize(IntSize(800, 300));
1981 EXPECT_POINT_EQ( 1987 EXPECT_SIZE_EQ(ScrollOffset(700, 200),
1982 DoublePoint(700, 200), 1988 frameView.layoutViewportScrollableArea()->scrollOffset());
1983 frameView.layoutViewportScrollableArea()->scrollPositionDouble());
1984 1989
1985 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); 1990 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled);
1986 } 1991 }
1987 1992
1988 // Ensure that resize anchoring as happens when top controls hide/show affects 1993 // Ensure that resize anchoring as happens when top controls hide/show affects
1989 // the scrollable area that's currently set as the root scroller. 1994 // the scrollable area that's currently set as the root scroller.
1990 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) { 1995 TEST_P(ParameterizedVisualViewportTest, ResizeAnchoringWithRootScroller) {
1991 bool wasRootScrollerEnabled = 1996 bool wasRootScrollerEnabled =
1992 RuntimeEnabledFeatures::setRootScrollerEnabled(); 1997 RuntimeEnabledFeatures::setRootScrollerEnabled();
1993 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); 1998 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true);
1994 1999
1995 initializeWithAndroidSettings(); 2000 initializeWithAndroidSettings();
1996 webViewImpl()->resize(IntSize(800, 600)); 2001 webViewImpl()->resize(IntSize(800, 600));
1997 2002
1998 registerMockedHttpURLLoad("root-scroller-div.html"); 2003 registerMockedHttpURLLoad("root-scroller-div.html");
1999 navigateTo(m_baseURL + "root-scroller-div.html"); 2004 navigateTo(m_baseURL + "root-scroller-div.html");
2000 2005
2001 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 2006 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
2002 2007
2003 Element* scroller = frame()->document()->getElementById("rootScroller"); 2008 Element* scroller = frame()->document()->getElementById("rootScroller");
2004 NonThrowableExceptionState nonThrow; 2009 NonThrowableExceptionState nonThrow;
2005 frame()->document()->setRootScroller(scroller, nonThrow); 2010 frame()->document()->setRootScroller(scroller, nonThrow);
2006 2011
2007 webViewImpl()->setPageScaleFactor(3.f); 2012 webViewImpl()->setPageScaleFactor(3.f);
2008 frameView.getScrollableArea()->setScrollPosition(DoublePoint(0, 400), 2013 frameView.getScrollableArea()->setScrollOffset(ScrollOffset(0, 400),
2009 ProgrammaticScroll); 2014 ProgrammaticScroll);
2010 2015
2011 VisualViewport& visualViewport = 2016 VisualViewport& visualViewport =
2012 webViewImpl()->page()->frameHost().visualViewport(); 2017 webViewImpl()->page()->frameHost().visualViewport();
2013 visualViewport.setScrollPosition(DoublePoint(0, 400), ProgrammaticScroll); 2018 visualViewport.setScrollOffset(ScrollOffset(0, 400), ProgrammaticScroll);
2014 2019
2015 webViewImpl()->resize(IntSize(800, 500)); 2020 webViewImpl()->resize(IntSize(800, 500));
2016 2021
2017 EXPECT_POINT_EQ( 2022 EXPECT_SIZE_EQ(ScrollOffset(),
2018 DoublePoint(), 2023 frameView.layoutViewportScrollableArea()->scrollOffset());
2019 frameView.layoutViewportScrollableArea()->scrollPositionDouble());
2020 2024
2021 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); 2025 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled);
2022 } 2026 }
2023 2027
2024 // Ensure that resize anchoring as happens when the device is rotated affects 2028 // Ensure that resize anchoring as happens when the device is rotated affects
2025 // the scrollable area that's currently set as the root scroller. 2029 // the scrollable area that's currently set as the root scroller.
2026 TEST_P(ParameterizedVisualViewportTest, RotationAnchoringWithRootScroller) { 2030 TEST_P(ParameterizedVisualViewportTest, RotationAnchoringWithRootScroller) {
2027 bool wasRootScrollerEnabled = 2031 bool wasRootScrollerEnabled =
2028 RuntimeEnabledFeatures::setRootScrollerEnabled(); 2032 RuntimeEnabledFeatures::setRootScrollerEnabled();
2029 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); 2033 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true);
2030 2034
2031 initializeWithAndroidSettings(); 2035 initializeWithAndroidSettings();
2032 webViewImpl()->resize(IntSize(800, 600)); 2036 webViewImpl()->resize(IntSize(800, 600));
2033 2037
2034 registerMockedHttpURLLoad("root-scroller-div.html"); 2038 registerMockedHttpURLLoad("root-scroller-div.html");
2035 navigateTo(m_baseURL + "root-scroller-div.html"); 2039 navigateTo(m_baseURL + "root-scroller-div.html");
2036 2040
2037 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 2041 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
2038 2042
2039 Element* scroller = frame()->document()->getElementById("rootScroller"); 2043 Element* scroller = frame()->document()->getElementById("rootScroller");
2040 NonThrowableExceptionState nonThrow; 2044 NonThrowableExceptionState nonThrow;
2041 frame()->document()->setRootScroller(scroller, nonThrow); 2045 frame()->document()->setRootScroller(scroller, nonThrow);
2042 webViewImpl()->updateAllLifecyclePhases(); 2046 webViewImpl()->updateAllLifecyclePhases();
2043 2047
2044 scroller->setScrollTop(800); 2048 scroller->setScrollTop(800);
2045 2049
2046 webViewImpl()->resize(IntSize(600, 800)); 2050 webViewImpl()->resize(IntSize(600, 800));
2047 2051
2048 EXPECT_POINT_EQ( 2052 EXPECT_SIZE_EQ(ScrollOffset(),
2049 DoublePoint(), 2053 frameView.layoutViewportScrollableArea()->scrollOffset());
2050 frameView.layoutViewportScrollableArea()->scrollPositionDouble());
2051 EXPECT_EQ(600, scroller->scrollTop()); 2054 EXPECT_EQ(600, scroller->scrollTop());
2052 2055
2053 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); 2056 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled);
2054 } 2057 }
2055 2058
2056 } // namespace 2059 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698