| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 settings->setPreferCompositingToLCDTextEnabled(true); | 146 settings->setPreferCompositingToLCDTextEnabled(true); |
| 147 settings->setPinchVirtualViewportEnabled(true); | 147 settings->setPinchVirtualViewportEnabled(true); |
| 148 } | 148 } |
| 149 | 149 |
| 150 static void configureAndroidSettings(WebSettings* settings) | 150 static void configureAndroidSettings(WebSettings* settings) |
| 151 { | 151 { |
| 152 configureSettings(settings); | 152 configureSettings(settings); |
| 153 settings->setViewportEnabled(true); | 153 settings->setViewportEnabled(true); |
| 154 settings->setViewportMetaEnabled(true); | 154 settings->setViewportMetaEnabled(true); |
| 155 settings->setShrinksViewportContentToFit(true); | 155 settings->setShrinksViewportContentToFit(true); |
| 156 settings->setMainFrameResizesAreOrientationChanges(true); | |
| 157 } | 156 } |
| 158 | 157 |
| 159 protected: | 158 protected: |
| 160 std::string m_baseURL; | 159 std::string m_baseURL; |
| 161 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; | 160 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; |
| 162 | 161 |
| 163 private: | 162 private: |
| 164 FrameTestHelpers::WebViewHelper m_helper; | 163 FrameTestHelpers::WebViewHelper m_helper; |
| 165 }; | 164 }; |
| 166 | 165 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 187 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); | 186 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); |
| 188 EXPECT_SIZE_EQ(webViewSize, pinchViewport.size()); | 187 EXPECT_SIZE_EQ(webViewSize, pinchViewport.size()); |
| 189 | 188 |
| 190 // Resizing the pinch viewport shouldn't affect the WebView. | 189 // Resizing the pinch viewport shouldn't affect the WebView. |
| 191 IntSize newViewportSize = IntSize(320, 200); | 190 IntSize newViewportSize = IntSize(320, 200); |
| 192 pinchViewport.setSize(newViewportSize); | 191 pinchViewport.setSize(newViewportSize); |
| 193 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); | 192 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); |
| 194 EXPECT_SIZE_EQ(newViewportSize, pinchViewport.size()); | 193 EXPECT_SIZE_EQ(newViewportSize, pinchViewport.size()); |
| 195 } | 194 } |
| 196 | 195 |
| 197 // Test that the PinchViewport works as expected in case of a scaled | |
| 198 // and scrolled viewport - scroll down. | |
| 199 TEST_F(PinchViewportTest, TestResizeAfterVerticalScroll) | |
| 200 { | |
| 201 /* | |
| 202 200 200 | |
| 203 | | | | | |
| 204 | | | | | |
| 205 | | 800 | | 800 | |
| 206 |-------------------| | | | |
| 207 | | | | | |
| 208 | | | | | |
| 209 | | | | | |
| 210 | | --------> | | | |
| 211 | 300 | | | | |
| 212 | | | | | |
| 213 | 400 | | | | |
| 214 | | |-------------------| | |
| 215 | | | 75 | | |
| 216 | 50 | | 50 100| | |
| 217 o----- | o---- | | |
| 218 | | | | | 25 | | |
| 219 | |100 | |-------------------| | |
| 220 | | | | | | |
| 221 | | | | | | |
| 222 -------------------- -------------------- | |
| 223 | |
| 224 */ | |
| 225 | |
| 226 initializeWithAndroidSettings(); | |
| 227 | |
| 228 registerMockedHttpURLLoad("200-by-800-viewport.html"); | |
| 229 navigateTo(m_baseURL + "200-by-800-viewport.html"); | |
| 230 | |
| 231 webViewImpl()->resize(IntSize(100, 200)); | |
| 232 | |
| 233 // Scroll main frame to the bottom of the document | |
| 234 webViewImpl()->setMainFrameScrollOffset(WebPoint(0, 400)); | |
| 235 EXPECT_POINT_EQ(IntPoint(0, 400), frame()->view()->scrollPosition()); | |
| 236 | |
| 237 webViewImpl()->setPageScaleFactor(2.0); | |
| 238 | |
| 239 // Scroll pinch viewport to the bottom of the main frame | |
| 240 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
| 241 pinchViewport.setLocation(FloatPoint(0, 300)); | |
| 242 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 300), pinchViewport.location()); | |
| 243 | |
| 244 // Verify the initial size of the pinch viewport in the CSS pixels | |
| 245 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), pinchViewport.visibleRect().size())
; | |
| 246 | |
| 247 // Perform the resizing | |
| 248 webViewImpl()->resize(IntSize(200, 100)); | |
| 249 | |
| 250 // After resizing the scale changes 2.0 -> 4.0 | |
| 251 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), pinchViewport.visibleRect().size()); | |
| 252 | |
| 253 EXPECT_POINT_EQ(IntPoint(0, 625), frame()->view()->scrollPosition()); | |
| 254 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 75), pinchViewport.location()); | |
| 255 } | |
| 256 | |
| 257 // Test that the PinchViewport works as expected in case if a scaled | |
| 258 // and scrolled viewport - scroll right. | |
| 259 TEST_F(PinchViewportTest, TestResizeAfterHorizontalScroll) | |
| 260 { | |
| 261 /* | |
| 262 200 200 | |
| 263 ---------------o----- ---------------o----- | |
| 264 | | | | 25| | | |
| 265 | | | | -----| | |
| 266 | 100| | |100 50 | | |
| 267 | | | | | | |
| 268 | ---- | |-------------------| | |
| 269 | | | | | |
| 270 | | | | | |
| 271 | | | | | |
| 272 | | | | | |
| 273 | | | | | |
| 274 |400 | ---------> | | | |
| 275 | | | | | |
| 276 | | | | | |
| 277 | | | | | |
| 278 | | | | | |
| 279 | | | | | |
| 280 | | | | | |
| 281 | | | | | |
| 282 | | | | | |
| 283 |-------------------| | | | |
| 284 | | | | | |
| 285 | |
| 286 */ | |
| 287 | |
| 288 initializeWithAndroidSettings(); | |
| 289 | |
| 290 registerMockedHttpURLLoad("200-by-800-viewport.html"); | |
| 291 navigateTo(m_baseURL + "200-by-800-viewport.html"); | |
| 292 | |
| 293 webViewImpl()->resize(IntSize(100, 200)); | |
| 294 | |
| 295 // Outer viewport takes the whole width of the document. | |
| 296 | |
| 297 webViewImpl()->setPageScaleFactor(2.0); | |
| 298 | |
| 299 // Scroll pinch viewport to the right edge of the frame | |
| 300 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
| 301 pinchViewport.setLocation(FloatPoint(150, 0)); | |
| 302 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), pinchViewport.location()); | |
| 303 | |
| 304 // Verify the initial size of the pinch viewport in the CSS pixels | |
| 305 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), pinchViewport.visibleRect().size())
; | |
| 306 | |
| 307 webViewImpl()->resize(IntSize(200, 100)); | |
| 308 | |
| 309 // After resizing the scale changes 2.0 -> 4.0 | |
| 310 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), pinchViewport.visibleRect().size()); | |
| 311 | |
| 312 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); | |
| 313 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), pinchViewport.location()); | |
| 314 } | |
| 315 | |
| 316 static void disableAcceleratedCompositing(WebSettings* settings) | 196 static void disableAcceleratedCompositing(WebSettings* settings) |
| 317 { | 197 { |
| 318 PinchViewportTest::configureSettings(settings); | 198 PinchViewportTest::configureSettings(settings); |
| 319 // FIXME: This setting is being removed, so this test needs to be rewritten
to | 199 // FIXME: This setting is being removed, so this test needs to be rewritten
to |
| 320 // do something else. crbug.com/173949 | 200 // do something else. crbug.com/173949 |
| 321 settings->setAcceleratedCompositingEnabled(false); | 201 settings->setAcceleratedCompositingEnabled(false); |
| 322 } | 202 } |
| 323 | 203 |
| 324 // Test that the container layer gets sized properly if the WebView is resized | 204 // Test that the container layer gets sized properly if the WebView is resized |
| 325 // prior to the PinchViewport being attached to the layer tree. | 205 // prior to the PinchViewport being attached to the layer tree. |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); | 793 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); |
| 914 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); | 794 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); |
| 915 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); | 795 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); |
| 916 | 796 |
| 917 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); | 797 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); |
| 918 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 798 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
| 919 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); | 799 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); |
| 920 } | 800 } |
| 921 | 801 |
| 922 } // namespace | 802 } // namespace |
| OLD | NEW |