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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/frame/PinchViewport.h" | 7 #include "core/frame/PinchViewport.h" |
8 | 8 |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 settings->setShrinksViewportContentToFit(true); | 155 settings->setShrinksViewportContentToFit(true); |
156 settings->setMainFrameResizesAreOrientationChanges(true); | 156 settings->setMainFrameResizesAreOrientationChanges(true); |
157 } | 157 } |
158 | 158 |
159 protected: | 159 protected: |
160 std::string m_baseURL; | 160 std::string m_baseURL; |
161 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; | 161 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; |
162 | 162 |
163 private: | 163 private: |
164 FrameTestHelpers::WebViewHelper m_helper; | 164 FrameTestHelpers::WebViewHelper m_helper; |
| 165 |
| 166 // To prevent platform differneces in content rendering, use mock |
| 167 // scrollbars. This is especially needed for Mac, where the presence |
| 168 // or absence of a mouse will change frame sizes because of different |
| 169 // scrollbar themes. |
| 170 FrameTestHelpers::UseMockScrollbarSettings m_useMockScrollbars; |
165 }; | 171 }; |
166 | 172 |
167 // Test that resizing the PinchViewport works as expected and that resizing the | 173 // Test that resizing the PinchViewport works as expected and that resizing the |
168 // WebView resizes the PinchViewport. | 174 // WebView resizes the PinchViewport. |
169 TEST_F(PinchViewportTest, TestResize) | 175 TEST_F(PinchViewportTest, TestResize) |
170 { | 176 { |
171 initializeWithDesktopSettings(); | 177 initializeWithDesktopSettings(); |
172 webViewImpl()->resize(IntSize(320, 240)); | 178 webViewImpl()->resize(IntSize(320, 240)); |
173 | 179 |
174 navigateTo("about:blank"); | 180 navigateTo("about:blank"); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 pinchViewport.setLocation(FloatPoint(200, 200)); | 521 pinchViewport.setLocation(FloatPoint(200, 200)); |
516 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), pinchViewport.visibleRect().loca
tion()); | 522 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), pinchViewport.visibleRect().loca
tion()); |
517 | 523 |
518 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by
2X it should | 524 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by
2X it should |
519 // allow us to scroll by 5px more. | 525 // allow us to scroll by 5px more. |
520 pinchViewport.setSize(IntSize(310, 230)); | 526 pinchViewport.setSize(IntSize(310, 230)); |
521 pinchViewport.setLocation(FloatPoint(200, 200)); | 527 pinchViewport.setLocation(FloatPoint(200, 200)); |
522 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), pinchViewport.visibleRect().loca
tion()); | 528 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), pinchViewport.visibleRect().loca
tion()); |
523 | 529 |
524 // The viewport can be larger than the main frame (currently 320, 240) thoug
h typically | 530 // The viewport can be larger than the main frame (currently 320, 240) thoug
h typically |
525 // the scale will be clamped to prevent it from actually being larger. Make
sure size | 531 // the scale will be clamped to prevent it from actually being larger. |
526 // changes clamp the offset so the inner remains within the outer. | |
527 pinchViewport.setSize(IntSize(330, 250)); | 532 pinchViewport.setSize(IntSize(330, 250)); |
528 EXPECT_SIZE_EQ(IntSize(330, 250), pinchViewport.size()); | 533 EXPECT_SIZE_EQ(IntSize(330, 250), pinchViewport.size()); |
529 EXPECT_FLOAT_POINT_EQ(FloatPoint(155, 115), pinchViewport.visibleRect().loca
tion()); | |
530 pinchViewport.setLocation(FloatPoint(200, 200)); | |
531 EXPECT_FLOAT_POINT_EQ(FloatPoint(155, 115), pinchViewport.visibleRect().loca
tion()); | |
532 | 534 |
533 // Resize both the viewport and the frame to be larger. | 535 // Resize both the viewport and the frame to be larger. |
534 webViewImpl()->resize(IntSize(640, 480)); | 536 webViewImpl()->resize(IntSize(640, 480)); |
535 webViewImpl()->layout(); | 537 webViewImpl()->layout(); |
536 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), pinchViewport.size()); | 538 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), pinchViewport.size()); |
537 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), frame()->view()->frameRect().
size()); | 539 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), frame()->view()->frameRect().
size()); |
538 pinchViewport.setLocation(FloatPoint(1000, 1000)); | 540 pinchViewport.setLocation(FloatPoint(1000, 1000)); |
539 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), pinchViewport.visibleRect().loca
tion()); | 541 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), pinchViewport.visibleRect().loca
tion()); |
540 | 542 |
541 // Make sure resizing the viewport doesn't change its offset if the resize d
oesn't make | 543 // Make sure resizing the viewport doesn't change its offset if the resize d
oesn't make |
542 // the viewport go out of bounds. | 544 // the viewport go out of bounds. |
543 pinchViewport.setLocation(FloatPoint(200, 200)); | 545 pinchViewport.setLocation(FloatPoint(200, 200)); |
544 pinchViewport.setSize(IntSize(880, 560)); | 546 pinchViewport.setSize(IntSize(880, 560)); |
545 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), pinchViewport.visibleRect().loca
tion()); | 547 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), pinchViewport.visibleRect().loca
tion()); |
546 | |
547 // Resizing the viewport such that the viewport is out of bounds should move
the | |
548 // viewport. | |
549 pinchViewport.setSize(IntSize(920, 640)); | |
550 EXPECT_FLOAT_POINT_EQ(FloatPoint(180, 160), pinchViewport.visibleRect().loca
tion()); | |
551 } | 548 } |
552 | 549 |
553 // The main FrameView's size should be set such that its the size of the pinch v
iewport | 550 // The main FrameView's size should be set such that its the size of the pinch v
iewport |
554 // at minimum scale. If there's no explicit minimum scale set, the FrameView sho
uld be | 551 // at minimum scale. If there's no explicit minimum scale set, the FrameView sho
uld be |
555 // set to the content width and height derived by the aspect ratio. | 552 // set to the content width and height derived by the aspect ratio. |
556 TEST_F(PinchViewportTest, TestFrameViewSizedToContent) | 553 TEST_F(PinchViewportTest, TestFrameViewSizedToContent) |
557 { | 554 { |
558 initializeWithAndroidSettings(); | 555 initializeWithAndroidSettings(); |
559 webViewImpl()->resize(IntSize(320, 240)); | 556 webViewImpl()->resize(IntSize(320, 240)); |
560 | 557 |
561 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 558 registerMockedHttpURLLoad("200-by-300-viewport.html"); |
562 navigateTo(m_baseURL + "200-by-300-viewport.html"); | 559 navigateTo(m_baseURL + "200-by-300-viewport.html"); |
563 | 560 |
564 webViewImpl()->resize(IntSize(600, 800)); | 561 webViewImpl()->resize(IntSize(600, 800)); |
565 webViewImpl()->layout(); | 562 webViewImpl()->layout(); |
566 | 563 |
567 EXPECT_SIZE_EQ(IntSize(200, 266), | 564 // Note: the size is ceiled and should match the behavior in CC's LayerImpl:
:bounds(). |
| 565 EXPECT_SIZE_EQ(IntSize(200, 267), |
568 webViewImpl()->mainFrameImpl()->frameView()->frameRect().size()); | 566 webViewImpl()->mainFrameImpl()->frameView()->frameRect().size()); |
569 } | 567 } |
570 | 568 |
571 // The main FrameView's size should be set such that its the size of the pinch v
iewport | 569 // The main FrameView's size should be set such that its the size of the pinch v
iewport |
572 // at minimum scale. On Desktop, the minimum scale is set at 1 so make sure the
FrameView | 570 // at minimum scale. On Desktop, the minimum scale is set at 1 so make sure the
FrameView |
573 // is sized to the viewport. | 571 // is sized to the viewport. |
574 TEST_F(PinchViewportTest, TestFrameViewSizedToMinimumScale) | 572 TEST_F(PinchViewportTest, TestFrameViewSizedToMinimumScale) |
575 { | 573 { |
576 initializeWithDesktopSettings(); | 574 initializeWithDesktopSettings(); |
577 webViewImpl()->resize(IntSize(320, 240)); | 575 webViewImpl()->resize(IntSize(320, 240)); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 | 958 |
961 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); | 959 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); |
962 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); | 960 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); |
963 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); | 961 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); |
964 | 962 |
965 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); | 963 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); |
966 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 964 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
967 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); | 965 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); |
968 } | 966 } |
969 | 967 |
| 968 static IntPoint expectedMaxFrameViewScrollOffset(PinchViewport& pinchViewport, F
rameView& frameView) |
| 969 { |
| 970 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewport.visi
bleRect().height(); |
| 971 float newHeight = frameView.frameRect().width() / aspectRatio; |
| 972 return IntPoint( |
| 973 frameView.contentsSize().width() - frameView.frameRect().width(), |
| 974 frameView.contentsSize().height() - newHeight); |
| 975 } |
| 976 |
| 977 TEST_F(PinchViewportTest, TestTopControlsAdjustment) |
| 978 { |
| 979 initializeWithAndroidSettings(); |
| 980 webViewImpl()->resize(IntSize(100, 150)); |
| 981 |
| 982 registerMockedHttpURLLoad("content-width-1000.html"); |
| 983 navigateTo(m_baseURL + "content-width-1000.html"); |
| 984 |
| 985 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 986 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 987 |
| 988 pinchViewport.setScale(1); |
| 989 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.visibleRect().size()); |
| 990 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
| 991 |
| 992 // Simulate bringing down the top controls by 20px. |
| 993 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); |
| 994 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.visibleRect().size()); |
| 995 |
| 996 // Test that the scroll bounds are adjusted appropriately: the pinch viewpor
t |
| 997 // should be shrunk by 20px to 130px. The outer viewport was shrunk to maint
ain the |
| 998 // aspect ratio so it's height is 1300px. |
| 999 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1000 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
| 1001 |
| 1002 // The outer viewport (FrameView) should be affected as well. |
| 1003 frameView.scrollBy(IntSize(10000, 10000)); |
| 1004 EXPECT_POINT_EQ( |
| 1005 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
| 1006 frameView.scrollPosition()); |
| 1007 |
| 1008 // Simulate bringing up the top controls by 10.5px. |
| 1009 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, -10.5f); |
| 1010 EXPECT_SIZE_EQ(FloatSize(100, 140.5f), pinchViewport.visibleRect().size()); |
| 1011 |
| 1012 // maximumScrollPosition floors the final values. |
| 1013 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1014 EXPECT_POINT_EQ(FloatPoint(900, floor(1405 - 140.5f)), pinchViewport.locatio
n()); |
| 1015 |
| 1016 // The outer viewport (FrameView) should be affected as well. |
| 1017 frameView.scrollBy(IntSize(10000, 10000)); |
| 1018 EXPECT_POINT_EQ( |
| 1019 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
| 1020 frameView.scrollPosition()); |
| 1021 } |
| 1022 |
| 1023 TEST_F(PinchViewportTest, TestTopControlsAdjustmentWithScale) |
| 1024 { |
| 1025 initializeWithAndroidSettings(); |
| 1026 webViewImpl()->resize(IntSize(100, 150)); |
| 1027 |
| 1028 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1029 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1030 |
| 1031 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 1032 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1033 |
| 1034 pinchViewport.setScale(2); |
| 1035 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); |
| 1036 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
| 1037 |
| 1038 // Simulate bringing down the top controls by 20px. Since we're zoomed in, |
| 1039 // the top controls take up half as much space (in document-space) than |
| 1040 // they do at an unzoomed level. |
| 1041 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); |
| 1042 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); |
| 1043 |
| 1044 // Test that the scroll bounds are adjusted appropriately. |
| 1045 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1046 EXPECT_POINT_EQ(FloatPoint(950, 1300 - 65), pinchViewport.location()); |
| 1047 |
| 1048 // The outer viewport (FrameView) should be affected as well. |
| 1049 frameView.scrollBy(IntSize(10000, 10000)); |
| 1050 IntPoint expected = expectedMaxFrameViewScrollOffset(pinchViewport, frameVie
w); |
| 1051 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
| 1052 |
| 1053 // Scale back out, FrameView max scroll shouldn't have changed. Pinch |
| 1054 // viewport should be moved up to accomodate larger view. |
| 1055 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.5f, 0); |
| 1056 EXPECT_EQ(1, pinchViewport.scale()); |
| 1057 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
| 1058 frameView.scrollBy(IntSize(10000, 10000)); |
| 1059 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); |
| 1060 |
| 1061 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
| 1062 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1063 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); |
| 1064 |
| 1065 // Scale out, use a scale that causes fractional rects. |
| 1066 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.8f, -20); |
| 1067 EXPECT_SIZE_EQ(FloatSize(125, 187.5), pinchViewport.visibleRect().size()); |
| 1068 |
| 1069 // Bring out the top controls by 11px. |
| 1070 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 11); |
| 1071 EXPECT_SIZE_EQ(FloatSize(125, 173.75), pinchViewport.visibleRect().size()); |
| 1072 |
| 1073 // Ensure max scroll offsets are updated properly. |
| 1074 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1075 EXPECT_POINT_EQ(FloatPoint(875, floor(1390 - 173.75)), pinchViewport.locatio
n()); |
| 1076 |
| 1077 frameView.scrollBy(IntSize(10000, 10000)); |
| 1078 EXPECT_POINT_EQ( |
| 1079 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), |
| 1080 frameView.scrollPosition()); |
| 1081 |
| 1082 } |
| 1083 |
| 1084 TEST_F(PinchViewportTest, TestTopControlsAdjustmentAndResize) |
| 1085 { |
| 1086 initializeWithAndroidSettings(); |
| 1087 webViewImpl()->resize(IntSize(100, 150)); |
| 1088 |
| 1089 registerMockedHttpURLLoad("content-width-1000.html"); |
| 1090 navigateTo(m_baseURL + "content-width-1000.html"); |
| 1091 |
| 1092 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 1093 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| 1094 |
| 1095 pinchViewport.setScale(2); |
| 1096 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); |
| 1097 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); |
| 1098 |
| 1099 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); |
| 1100 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.size()); |
| 1101 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); |
| 1102 |
| 1103 // Scroll all the way to the bottom. |
| 1104 pinchViewport.move(FloatPoint(10000, 10000)); |
| 1105 frameView.scrollBy(IntSize(10000, 10000)); |
| 1106 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(pinchViewport,
frameView); |
| 1107 FloatPoint pinchViewportExpected = FloatPoint(950, 1300 - 65); |
| 1108 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); |
| 1109 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1110 |
| 1111 // Resize the widget to match the top controls adjustment. Ensure that scrol
l |
| 1112 // offsets don't get clamped in the the process. |
| 1113 webViewImpl()->setTopControlsLayoutHeight(20); |
| 1114 webViewImpl()->resize(WebSize(100, 130)); |
| 1115 |
| 1116 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.size()); |
| 1117 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); |
| 1118 EXPECT_SIZE_EQ(IntSize(1000, 1300), frameView.frameRect().size()); |
| 1119 |
| 1120 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| 1121 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); |
| 1122 } |
| 1123 |
970 } // namespace | 1124 } // namespace |
OLD | NEW |