| 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/RootFrameViewport.h" | 7 #include "core/frame/RootFrameViewport.h" |
| 8 | 8 |
| 9 #include "core/layout/ScrollAlignment.h" | 9 #include "core/layout/ScrollAlignment.h" |
| 10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Disable just the layout viewport's horizontal scrolling, the | 184 // Disable just the layout viewport's horizontal scrolling, the |
| 185 // RootFrameViewport should remain scrollable overall. | 185 // RootFrameViewport should remain scrollable overall. |
| 186 layoutViewport.setUserInputScrollable(false, true); | 186 layoutViewport.setUserInputScrollable(false, true); |
| 187 visualViewport.setUserInputScrollable(true, true); | 187 visualViewport.setUserInputScrollable(true, true); |
| 188 | 188 |
| 189 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 189 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 190 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 190 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 191 | 191 |
| 192 // Layout viewport shouldn't scroll since it's not horizontally scrollable, | 192 // Layout viewport shouldn't scroll since it's not horizontally scrollable, |
| 193 // but visual viewport should. | 193 // but visual viewport should. |
| 194 rootFrameViewport->scroll(ScrollRight, ScrollByPixel, 300); | 194 rootFrameViewport->scroll(ScrollPhysicalRight, ScrollByPixel, 300); |
| 195 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 195 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 196 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); | 196 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); |
| 197 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); | 197 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); |
| 198 | 198 |
| 199 // Disable just the visual viewport's horizontal scrolling, only the layout | 199 // Disable just the visual viewport's horizontal scrolling, only the layout |
| 200 // viewport should scroll. | 200 // viewport should scroll. |
| 201 rootFrameViewport->setScrollPosition(DoublePoint()); | 201 rootFrameViewport->setScrollPosition(DoublePoint()); |
| 202 layoutViewport.setUserInputScrollable(true, true); | 202 layoutViewport.setUserInputScrollable(true, true); |
| 203 visualViewport.setUserInputScrollable(false, true); | 203 visualViewport.setUserInputScrollable(false, true); |
| 204 | 204 |
| 205 rootFrameViewport->scroll(ScrollRight, ScrollByPixel, 300); | 205 rootFrameViewport->scroll(ScrollPhysicalRight, ScrollByPixel, 300); |
| 206 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); | 206 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); |
| 207 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 207 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 208 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); | 208 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); |
| 209 | 209 |
| 210 // Disable both viewports' horizontal scrolling, all horizontal scrolling | 210 // Disable both viewports' horizontal scrolling, all horizontal scrolling |
| 211 // should now be blocked. | 211 // should now be blocked. |
| 212 rootFrameViewport->setScrollPosition(DoublePoint()); | 212 rootFrameViewport->setScrollPosition(DoublePoint()); |
| 213 layoutViewport.setUserInputScrollable(false, true); | 213 layoutViewport.setUserInputScrollable(false, true); |
| 214 visualViewport.setUserInputScrollable(false, true); | 214 visualViewport.setUserInputScrollable(false, true); |
| 215 | 215 |
| 216 rootFrameViewport->scroll(ScrollRight, ScrollByPixel, 300); | 216 rootFrameViewport->scroll(ScrollPhysicalRight, ScrollByPixel, 300); |
| 217 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 217 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 218 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 218 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 219 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 219 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 220 | 220 |
| 221 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 221 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 222 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 222 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 223 | 223 |
| 224 // Vertical scrolling should be unaffected. | 224 // Vertical scrolling should be unaffected. |
| 225 rootFrameViewport->scroll(ScrollDown, ScrollByPixel, 300); | 225 rootFrameViewport->scroll(ScrollPhysicalDown, ScrollByPixel, 300); |
| 226 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 226 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 227 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 227 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 228 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); | 228 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); |
| 229 | 229 |
| 230 // Try the same checks as above but for the vertical direction. | 230 // Try the same checks as above but for the vertical direction. |
| 231 // =============================================== | 231 // =============================================== |
| 232 | 232 |
| 233 rootFrameViewport->setScrollPosition(DoublePoint()); | 233 rootFrameViewport->setScrollPosition(DoublePoint()); |
| 234 | 234 |
| 235 // Disable just the layout viewport's vertical scrolling, the | 235 // Disable just the layout viewport's vertical scrolling, the |
| 236 // RootFrameViewport should remain scrollable overall. | 236 // RootFrameViewport should remain scrollable overall. |
| 237 layoutViewport.setUserInputScrollable(true, false); | 237 layoutViewport.setUserInputScrollable(true, false); |
| 238 visualViewport.setUserInputScrollable(true, true); | 238 visualViewport.setUserInputScrollable(true, true); |
| 239 | 239 |
| 240 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 240 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 241 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 241 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 242 | 242 |
| 243 // Layout viewport shouldn't scroll since it's not vertically scrollable, | 243 // Layout viewport shouldn't scroll since it's not vertically scrollable, |
| 244 // but visual viewport should. | 244 // but visual viewport should. |
| 245 rootFrameViewport->scroll(ScrollDown, ScrollByPixel, 300); | 245 rootFrameViewport->scroll(ScrollPhysicalDown, ScrollByPixel, 300); |
| 246 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 246 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 247 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 247 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 248 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 248 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 249 | 249 |
| 250 // Disable just the visual viewport's vertical scrolling, only the layout | 250 // Disable just the visual viewport's vertical scrolling, only the layout |
| 251 // viewport should scroll. | 251 // viewport should scroll. |
| 252 rootFrameViewport->setScrollPosition(DoublePoint()); | 252 rootFrameViewport->setScrollPosition(DoublePoint()); |
| 253 layoutViewport.setUserInputScrollable(true, true); | 253 layoutViewport.setUserInputScrollable(true, true); |
| 254 visualViewport.setUserInputScrollable(true, false); | 254 visualViewport.setUserInputScrollable(true, false); |
| 255 | 255 |
| 256 rootFrameViewport->scroll(ScrollDown, ScrollByPixel, 300); | 256 rootFrameViewport->scroll(ScrollPhysicalDown, ScrollByPixel, 300); |
| 257 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 257 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 258 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 258 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 259 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 259 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 260 | 260 |
| 261 // Disable both viewports' horizontal scrolling, all vertical scrolling | 261 // Disable both viewports' horizontal scrolling, all vertical scrolling |
| 262 // should now be blocked. | 262 // should now be blocked. |
| 263 rootFrameViewport->setScrollPosition(DoublePoint()); | 263 rootFrameViewport->setScrollPosition(DoublePoint()); |
| 264 layoutViewport.setUserInputScrollable(true, false); | 264 layoutViewport.setUserInputScrollable(true, false); |
| 265 visualViewport.setUserInputScrollable(true, false); | 265 visualViewport.setUserInputScrollable(true, false); |
| 266 | 266 |
| 267 rootFrameViewport->scroll(ScrollDown, ScrollByPixel, 300); | 267 rootFrameViewport->scroll(ScrollPhysicalDown, ScrollByPixel, 300); |
| 268 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 268 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 269 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 269 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 270 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 270 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 271 | 271 |
| 272 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 272 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 273 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 273 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 274 | 274 |
| 275 // Horizontal scrolling should be unaffected. | 275 // Horizontal scrolling should be unaffected. |
| 276 rootFrameViewport->scroll(ScrollRight, ScrollByPixel, 300); | 276 rootFrameViewport->scroll(ScrollPhysicalRight, ScrollByPixel, 300); |
| 277 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); | 277 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); |
| 278 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); | 278 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); |
| 279 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble
()); | 279 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble
()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition(), w
heelHandler) | 282 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition(), w
heelHandler) |
| 283 // work correctly when one of the subviewports is explicitly scrolled without us
ing the | 283 // work correctly when one of the subviewports is explicitly scrolled without us
ing the |
| 284 // RootFrameViewport interface. | 284 // RootFrameViewport interface. |
| 285 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) | 285 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) |
| 286 { | 286 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it | 299 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it |
| 300 // may early exit. | 300 // may early exit. |
| 301 rootFrameViewport->setScrollPosition(DoublePoint(0, 0)); | 301 rootFrameViewport->setScrollPosition(DoublePoint(0, 0)); |
| 302 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 302 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 303 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 303 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 304 | 304 |
| 305 // Try again for scroll() | 305 // Try again for scroll() |
| 306 visualViewport.setScrollPosition(DoublePoint(50, 75)); | 306 visualViewport.setScrollPosition(DoublePoint(50, 75)); |
| 307 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 307 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 308 | 308 |
| 309 rootFrameViewport->scroll(ScrollLeft, ScrollByPixel, 50); | 309 rootFrameViewport->scroll(ScrollPhysicalLeft, ScrollByPixel, 50); |
| 310 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 310 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 311 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 311 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 312 | 312 |
| 313 // Try again for handleWheel. | 313 // Try again for handleWheel. |
| 314 visualViewport.setScrollPosition(DoublePoint(50, 75)); | 314 visualViewport.setScrollPosition(DoublePoint(50, 75)); |
| 315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 316 | 316 |
| 317 PlatformWheelEvent wheelEvent( | 317 PlatformWheelEvent wheelEvent( |
| 318 IntPoint(10, 10), IntPoint(10, 10), | 318 IntPoint(10, 10), IntPoint(10, 10), |
| 319 50, 75, | 319 50, 75, |
| 320 0, 0, | 320 0, 0, |
| 321 ScrollByPixelWheelEvent, | 321 ScrollByPixelWheelEvent, |
| 322 false, false, false, false); | 322 false, false, false, false); |
| 323 rootFrameViewport->handleWheel(wheelEvent); | 323 rootFrameViewport->handleWheel(wheelEvent); |
| 324 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 324 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 325 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 325 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 326 | 326 |
| 327 // Make sure the layout viewport is also accounted for. | 327 // Make sure the layout viewport is also accounted for. |
| 328 layoutViewport.setScrollPosition(DoublePoint(100, 150)); | 328 layoutViewport.setScrollPosition(DoublePoint(100, 150)); |
| 329 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); | 329 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); |
| 330 | 330 |
| 331 rootFrameViewport->scroll(ScrollLeft, ScrollByPixel, 100); | 331 rootFrameViewport->scroll(ScrollPhysicalLeft, ScrollByPixel, 100); |
| 332 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 332 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 333 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 333 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 334 } | 334 } |
| 335 | 335 |
| 336 // Test that the scrollIntoView correctly scrolls the main frame | 336 // Test that the scrollIntoView correctly scrolls the main frame |
| 337 // and pinch viewports such that the given rect is centered in the viewport. | 337 // and pinch viewports such that the given rect is centered in the viewport. |
| 338 TEST_F(RootFrameViewportTest, ScrollIntoView) | 338 TEST_F(RootFrameViewportTest, ScrollIntoView) |
| 339 { | 339 { |
| 340 IntSize viewportSize(100, 150); | 340 IntSize viewportSize(100, 150); |
| 341 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 341 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); | 494 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); |
| 495 | 495 |
| 496 EXPECT_TRUE(result.didScroll); | 496 EXPECT_TRUE(result.didScroll); |
| 497 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport.scrollPositionDouble()); | 497 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport.scrollPositionDouble()); |
| 498 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport.scrollPositionDouble()
); | 498 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport.scrollPositionDouble()
); |
| 499 EXPECT_EQ(-350, result.unusedScrollDeltaX); | 499 EXPECT_EQ(-350, result.unusedScrollDeltaX); |
| 500 EXPECT_EQ(-250, result.unusedScrollDeltaY); | 500 EXPECT_EQ(-250, result.unusedScrollDeltaY); |
| 501 } | 501 } |
| 502 | 502 |
| 503 } // namespace blink | 503 } // namespace blink |
| OLD | NEW |