| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPositi
on(); | 49 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPositi
on(); |
| 50 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() :
scrollDimensions.height(); | 50 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() :
scrollDimensions.height(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void setUserInputScrollable(bool x, bool y) | 53 void setUserInputScrollable(bool x, bool y) |
| 54 { | 54 { |
| 55 m_userInputScrollableX = x; | 55 m_userInputScrollableX = x; |
| 56 m_userInputScrollableY = y; | 56 m_userInputScrollableY = y; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void setScrollPosition(const DoublePoint& pos, ScrollBehavior = ScrollBehavi
orInstant) override { scrollToOffsetWithoutAnimation(toFloatPoint(pos)); } | |
| 60 IntPoint scrollPosition() const override { return flooredIntPoint(m_scrollPo
sition); } | 59 IntPoint scrollPosition() const override { return flooredIntPoint(m_scrollPo
sition); } |
| 61 DoublePoint scrollPositionDouble() const override { return m_scrollPosition;
} | 60 DoublePoint scrollPositionDouble() const override { return m_scrollPosition;
} |
| 62 IntPoint minimumScrollPosition() const override { return IntPoint(); } | 61 IntPoint minimumScrollPosition() const override { return IntPoint(); } |
| 63 DoublePoint minimumScrollPositionDouble() const override { return DoublePoin
t(); } | 62 DoublePoint minimumScrollPositionDouble() const override { return DoublePoin
t(); } |
| 64 IntPoint maximumScrollPosition() const override { return flooredIntPoint(max
imumScrollPositionDouble()); } | 63 IntPoint maximumScrollPosition() const override { return flooredIntPoint(max
imumScrollPositionDouble()); } |
| 65 | 64 |
| 66 IntSize contentsSize() const override { return m_contentsSize; } | 65 IntSize contentsSize() const override { return m_contentsSize; } |
| 67 void setContentSize(const IntSize& contentsSize) | 66 void setContentSize(const IntSize& contentsSize) |
| 68 { | 67 { |
| 69 m_contentsSize = contentsSize; | 68 m_contentsSize = contentsSize; |
| 70 } | 69 } |
| 71 | 70 |
| 72 protected: | 71 protected: |
| 73 void setScrollOffset(const IntPoint& offset) override { m_scrollPosition = o
ffset; } | 72 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset; } |
| 74 void setScrollOffset(const DoublePoint& offset) override { m_scrollPosition
= offset; } | 73 void setScrollOffset(const DoublePoint& offset, ScrollType) override { m_scr
ollPosition = offset; } |
| 75 bool shouldUseIntegerScrollOffset() const override { return true; } | 74 bool shouldUseIntegerScrollOffset() const override { return true; } |
| 76 bool isActive() const override { return true; } | 75 bool isActive() const override { return true; } |
| 77 bool isScrollCornerVisible() const override { return true; } | 76 bool isScrollCornerVisible() const override { return true; } |
| 78 IntRect scrollCornerRect() const override { return IntRect(); } | 77 IntRect scrollCornerRect() const override { return IntRect(); } |
| 79 bool scrollbarsCanBeActive() const override { return true; } | 78 bool scrollbarsCanBeActive() const override { return true; } |
| 80 IntRect scrollableAreaBoundingBox() const override { return IntRect(); } | 79 IntRect scrollableAreaBoundingBox() const override { return IntRect(); } |
| 81 bool shouldPlaceVerticalScrollbarOnLeft() const override { return true; } | 80 bool shouldPlaceVerticalScrollbarOnLeft() const override { return true; } |
| 82 void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { } | 81 void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { } |
| 83 void invalidateScrollCornerRect(const IntRect&) override { } | 82 void invalidateScrollCornerRect(const IntRect&) override { } |
| 84 GraphicsLayer* layerForContainer() const override { return nullptr; } | 83 GraphicsLayer* layerForContainer() const override { return nullptr; } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 190 |
| 192 // Layout viewport shouldn't scroll since it's not horizontally scrollable, | 191 // Layout viewport shouldn't scroll since it's not horizontally scrollable, |
| 193 // but visual viewport should. | 192 // but visual viewport should. |
| 194 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 193 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 195 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 194 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 196 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); | 195 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); |
| 197 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); | 196 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); |
| 198 | 197 |
| 199 // Disable just the visual viewport's horizontal scrolling, only the layout | 198 // Disable just the visual viewport's horizontal scrolling, only the layout |
| 200 // viewport should scroll. | 199 // viewport should scroll. |
| 201 rootFrameViewport->setScrollPosition(DoublePoint()); | 200 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 202 layoutViewport.setUserInputScrollable(true, true); | 201 layoutViewport.setUserInputScrollable(true, true); |
| 203 visualViewport.setUserInputScrollable(false, true); | 202 visualViewport.setUserInputScrollable(false, true); |
| 204 | 203 |
| 205 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 204 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 206 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); | 205 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); |
| 207 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 206 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 208 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); | 207 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); |
| 209 | 208 |
| 210 // Disable both viewports' horizontal scrolling, all horizontal scrolling | 209 // Disable both viewports' horizontal scrolling, all horizontal scrolling |
| 211 // should now be blocked. | 210 // should now be blocked. |
| 212 rootFrameViewport->setScrollPosition(DoublePoint()); | 211 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 213 layoutViewport.setUserInputScrollable(false, true); | 212 layoutViewport.setUserInputScrollable(false, true); |
| 214 visualViewport.setUserInputScrollable(false, true); | 213 visualViewport.setUserInputScrollable(false, true); |
| 215 | 214 |
| 216 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 215 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 217 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 216 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 218 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 217 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 219 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 218 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 220 | 219 |
| 221 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 220 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 222 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 221 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 223 | 222 |
| 224 // Vertical scrolling should be unaffected. | 223 // Vertical scrolling should be unaffected. |
| 225 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 224 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 226 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 225 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 227 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 226 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 228 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); | 227 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); |
| 229 | 228 |
| 230 // Try the same checks as above but for the vertical direction. | 229 // Try the same checks as above but for the vertical direction. |
| 231 // =============================================== | 230 // =============================================== |
| 232 | 231 |
| 233 rootFrameViewport->setScrollPosition(DoublePoint()); | 232 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 234 | 233 |
| 235 // Disable just the layout viewport's vertical scrolling, the | 234 // Disable just the layout viewport's vertical scrolling, the |
| 236 // RootFrameViewport should remain scrollable overall. | 235 // RootFrameViewport should remain scrollable overall. |
| 237 layoutViewport.setUserInputScrollable(true, false); | 236 layoutViewport.setUserInputScrollable(true, false); |
| 238 visualViewport.setUserInputScrollable(true, true); | 237 visualViewport.setUserInputScrollable(true, true); |
| 239 | 238 |
| 240 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 239 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 241 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 240 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 242 | 241 |
| 243 // Layout viewport shouldn't scroll since it's not vertically scrollable, | 242 // Layout viewport shouldn't scroll since it's not vertically scrollable, |
| 244 // but visual viewport should. | 243 // but visual viewport should. |
| 245 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 244 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 246 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 245 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 247 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 246 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 248 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 247 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 249 | 248 |
| 250 // Disable just the visual viewport's vertical scrolling, only the layout | 249 // Disable just the visual viewport's vertical scrolling, only the layout |
| 251 // viewport should scroll. | 250 // viewport should scroll. |
| 252 rootFrameViewport->setScrollPosition(DoublePoint()); | 251 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 253 layoutViewport.setUserInputScrollable(true, true); | 252 layoutViewport.setUserInputScrollable(true, true); |
| 254 visualViewport.setUserInputScrollable(true, false); | 253 visualViewport.setUserInputScrollable(true, false); |
| 255 | 254 |
| 256 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 255 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 257 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 256 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 258 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 257 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 259 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 258 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 260 | 259 |
| 261 // Disable both viewports' horizontal scrolling, all vertical scrolling | 260 // Disable both viewports' horizontal scrolling, all vertical scrolling |
| 262 // should now be blocked. | 261 // should now be blocked. |
| 263 rootFrameViewport->setScrollPosition(DoublePoint()); | 262 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 264 layoutViewport.setUserInputScrollable(true, false); | 263 layoutViewport.setUserInputScrollable(true, false); |
| 265 visualViewport.setUserInputScrollable(true, false); | 264 visualViewport.setUserInputScrollable(true, false); |
| 266 | 265 |
| 267 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 266 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 268 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 267 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 269 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 268 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 270 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 269 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 271 | 270 |
| 272 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 271 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 273 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 272 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 286 { | 285 { |
| 287 IntSize viewportSize(100, 150); | 286 IntSize viewportSize(100, 150); |
| 288 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 287 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); |
| 289 VisualViewportStub visualViewport(viewportSize, viewportSize); | 288 VisualViewportStub visualViewport(viewportSize, viewportSize); |
| 290 | 289 |
| 291 OwnPtr<ScrollableArea> rootFrameViewport = | 290 OwnPtr<ScrollableArea> rootFrameViewport = |
| 292 RootFrameViewport::create(visualViewport, layoutViewport); | 291 RootFrameViewport::create(visualViewport, layoutViewport); |
| 293 | 292 |
| 294 visualViewport.setScale(2); | 293 visualViewport.setScale(2); |
| 295 | 294 |
| 296 visualViewport.setScrollPosition(DoublePoint(50, 75)); | 295 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 297 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 296 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 298 | 297 |
| 299 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it | 298 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it |
| 300 // may early exit. | 299 // may early exit. |
| 301 rootFrameViewport->setScrollPosition(DoublePoint(0, 0)); | 300 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); |
| 302 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 301 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 303 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 302 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 304 | 303 |
| 305 // Try again for scroll() | 304 // Try again for scroll() |
| 306 visualViewport.setScrollPosition(DoublePoint(50, 75)); | 305 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 307 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 306 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 308 | 307 |
| 309 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); | 308 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); |
| 310 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 309 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 311 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 310 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); |
| 312 | 311 |
| 313 // Try again for handleWheel. | 312 // Try again for handleWheel. |
| 314 visualViewport.setScrollPosition(DoublePoint(50, 75)); | 313 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 314 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 316 | 315 |
| 317 PlatformWheelEvent wheelEvent( | 316 PlatformWheelEvent wheelEvent( |
| 318 IntPoint(10, 10), IntPoint(10, 10), | 317 IntPoint(10, 10), IntPoint(10, 10), |
| 319 50, 75, | 318 50, 75, |
| 320 0, 0, | 319 0, 0, |
| 321 ScrollByPixelWheelEvent, | 320 ScrollByPixelWheelEvent, |
| 322 false, false, false, false); | 321 false, false, false, false); |
| 323 rootFrameViewport->handleWheel(wheelEvent); | 322 rootFrameViewport->handleWheel(wheelEvent); |
| 324 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 323 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 325 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 324 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 326 | 325 |
| 327 // Make sure the layout viewport is also accounted for. | 326 // Make sure the layout viewport is also accounted for. |
| 328 layoutViewport.setScrollPosition(DoublePoint(100, 150)); | 327 layoutViewport.setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll); |
| 329 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); | 328 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); |
| 330 | 329 |
| 331 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); | 330 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); |
| 332 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 331 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 333 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 332 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); |
| 334 } | 333 } |
| 335 | 334 |
| 336 // Test that the scrollIntoView correctly scrolls the main frame | 335 // Test that the scrollIntoView correctly scrolls the main frame |
| 337 // and pinch viewports such that the given rect is centered in the viewport. | 336 // and pinch viewports such that the given rect is centered in the viewport. |
| 338 TEST_F(RootFrameViewportTest, ScrollIntoView) | 337 TEST_F(RootFrameViewportTest, ScrollIntoView) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 358 rootFrameViewport->scrollIntoView( | 357 rootFrameViewport->scrollIntoView( |
| 359 LayoutRect(25, 75, 50, 50), | 358 LayoutRect(25, 75, 50, 50), |
| 360 ScrollAlignment::alignToEdgeIfNeeded, | 359 ScrollAlignment::alignToEdgeIfNeeded, |
| 361 ScrollAlignment::alignToEdgeIfNeeded); | 360 ScrollAlignment::alignToEdgeIfNeeded); |
| 362 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport.scrollPositionDouble()); | 361 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport.scrollPositionDouble()); |
| 363 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport.scrollPositionDouble()); | 362 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport.scrollPositionDouble()); |
| 364 | 363 |
| 365 // Reset the pinch viewport's size, scale the page and repeat the test | 364 // Reset the pinch viewport's size, scale the page and repeat the test |
| 366 visualViewport.setViewportSize(IntSize(100, 150)); | 365 visualViewport.setViewportSize(IntSize(100, 150)); |
| 367 visualViewport.setScale(2); | 366 visualViewport.setScale(2); |
| 368 rootFrameViewport->setScrollPosition(DoublePoint()); | 367 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 369 | 368 |
| 370 rootFrameViewport->scrollIntoView( | 369 rootFrameViewport->scrollIntoView( |
| 371 LayoutRect(50, 75, 50, 75), | 370 LayoutRect(50, 75, 50, 75), |
| 372 ScrollAlignment::alignToEdgeIfNeeded, | 371 ScrollAlignment::alignToEdgeIfNeeded, |
| 373 ScrollAlignment::alignToEdgeIfNeeded); | 372 ScrollAlignment::alignToEdgeIfNeeded); |
| 374 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport.scrollPositionDouble()); | 373 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport.scrollPositionDouble()); |
| 375 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 374 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 376 | 375 |
| 377 rootFrameViewport->scrollIntoView( | 376 rootFrameViewport->scrollIntoView( |
| 378 LayoutRect(190, 290, 10, 10), | 377 LayoutRect(190, 290, 10, 10), |
| 379 ScrollAlignment::alignToEdgeIfNeeded, | 378 ScrollAlignment::alignToEdgeIfNeeded, |
| 380 ScrollAlignment::alignToEdgeIfNeeded); | 379 ScrollAlignment::alignToEdgeIfNeeded); |
| 381 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport.scrollPositionDouble()
); | 380 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport.scrollPositionDouble()
); |
| 382 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport.scrollPositionDouble()); | 381 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport.scrollPositionDouble()); |
| 383 | 382 |
| 384 // Scrolling into view the viewport rect itself should be a no-op. | 383 // Scrolling into view the viewport rect itself should be a no-op. |
| 385 visualViewport.setViewportSize(IntSize(100, 100)); | 384 visualViewport.setViewportSize(IntSize(100, 100)); |
| 386 visualViewport.setScale(1.5f); | 385 visualViewport.setScale(1.5f); |
| 387 visualViewport.setScrollPosition(DoublePoint(0, 10)); | 386 visualViewport.setScrollPosition(DoublePoint(0, 10), ProgrammaticScroll); |
| 388 layoutViewport.setScrollPosition(DoublePoint(50, 50)); | 387 layoutViewport.setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); |
| 389 rootFrameViewport->notifyScrollPositionChanged(rootFrameViewport->scrollPosi
tionDouble()); | 388 rootFrameViewport->notifyScrollPositionChanged(rootFrameViewport->scrollPosi
tionDouble()); |
| 390 | 389 |
| 391 rootFrameViewport->scrollIntoView( | 390 rootFrameViewport->scrollIntoView( |
| 392 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), | 391 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), |
| 393 ScrollAlignment::alignToEdgeIfNeeded, | 392 ScrollAlignment::alignToEdgeIfNeeded, |
| 394 ScrollAlignment::alignToEdgeIfNeeded); | 393 ScrollAlignment::alignToEdgeIfNeeded); |
| 395 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport.scrollPositionDouble()); | 394 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport.scrollPositionDouble()); |
| 396 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport.scrollPositionDouble()); | 395 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport.scrollPositionDouble()); |
| 397 | 396 |
| 398 rootFrameViewport->scrollIntoView( | 397 rootFrameViewport->scrollIntoView( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 416 IntSize viewportSize(500, 500); | 415 IntSize viewportSize(500, 500); |
| 417 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); | 416 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); |
| 418 VisualViewportStub visualViewport(viewportSize, viewportSize); | 417 VisualViewportStub visualViewport(viewportSize, viewportSize); |
| 419 | 418 |
| 420 OwnPtr<ScrollableArea> rootFrameViewport = | 419 OwnPtr<ScrollableArea> rootFrameViewport = |
| 421 RootFrameViewport::create(visualViewport, layoutViewport); | 420 RootFrameViewport::create(visualViewport, layoutViewport); |
| 422 | 421 |
| 423 visualViewport.setScale(2); | 422 visualViewport.setScale(2); |
| 424 | 423 |
| 425 // Ensure that the layout viewport scrolls first. | 424 // Ensure that the layout viewport scrolls first. |
| 426 rootFrameViewport->setScrollPosition(DoublePoint(100, 100)); | 425 rootFrameViewport->setScrollPosition(DoublePoint(100, 100), ProgrammaticScro
ll); |
| 427 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 426 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 428 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport.scrollPositionDouble()
); | 427 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport.scrollPositionDouble()
); |
| 429 | 428 |
| 430 // Scroll to the layout viewport's extent, the visual viewport should scroll
the | 429 // Scroll to the layout viewport's extent, the visual viewport should scroll
the |
| 431 // remainder. | 430 // remainder. |
| 432 rootFrameViewport->setScrollPosition(DoublePoint(700, 1700)); | 431 rootFrameViewport->setScrollPosition(DoublePoint(700, 1700), ProgrammaticScr
oll); |
| 433 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport.scrollPositionDouble()
); | 432 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport.scrollPositionDouble()
); |
| 434 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); | 433 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); |
| 435 | 434 |
| 436 // Only the visual viewport should scroll further. Make sure it doesn't scro
ll | 435 // Only the visual viewport should scroll further. Make sure it doesn't scro
ll |
| 437 // out of bounds. | 436 // out of bounds. |
| 438 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780)); | 437 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScr
oll); |
| 439 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport.scrollPositionDouble()
); | 438 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport.scrollPositionDouble()
); |
| 440 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); | 439 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); |
| 441 | 440 |
| 442 // Scroll all the way back. | 441 // Scroll all the way back. |
| 443 rootFrameViewport->setScrollPosition(DoublePoint(0, 0)); | 442 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); |
| 444 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 443 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); |
| 445 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 444 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); |
| 446 } | 445 } |
| 447 | 446 |
| 448 // Tests that the visible rect (i.e. visual viewport rect) is correctly | 447 // Tests that the visible rect (i.e. visual viewport rect) is correctly |
| 449 // calculated, taking into account both viewports and page scale. | 448 // calculated, taking into account both viewports and page scale. |
| 450 TEST_F(RootFrameViewportTest, VisibleContentRect) | 449 TEST_F(RootFrameViewportTest, VisibleContentRect) |
| 451 { | 450 { |
| 452 IntSize viewportSize(500, 401); | 451 IntSize viewportSize(500, 401); |
| 453 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); | 452 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); |
| 454 VisualViewportStub visualViewport(viewportSize, viewportSize); | 453 VisualViewportStub visualViewport(viewportSize, viewportSize); |
| 455 | 454 |
| 456 OwnPtr<ScrollableArea> rootFrameViewport = | 455 OwnPtr<ScrollableArea> rootFrameViewport = |
| 457 RootFrameViewport::create(visualViewport, layoutViewport); | 456 RootFrameViewport::create(visualViewport, layoutViewport); |
| 458 | 457 |
| 459 rootFrameViewport->setScrollPosition(DoublePoint(100, 75)); | 458 rootFrameViewport->setScrollPosition(DoublePoint(100, 75), ProgrammaticScrol
l); |
| 460 | 459 |
| 461 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); | 460 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); |
| 462 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); | 461 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); |
| 463 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRect()
.size()); | 462 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRect()
.size()); |
| 464 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); | 463 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); |
| 465 | 464 |
| 466 visualViewport.setScale(2); | 465 visualViewport.setScale(2); |
| 467 | 466 |
| 468 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); | 467 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); |
| 469 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); | 468 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 494 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); | 493 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); |
| 495 | 494 |
| 496 EXPECT_TRUE(result.didScroll()); | 495 EXPECT_TRUE(result.didScroll()); |
| 497 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport.scrollPositionDouble()); | 496 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport.scrollPositionDouble()); |
| 498 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport.scrollPositionDouble()
); | 497 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport.scrollPositionDouble()
); |
| 499 EXPECT_EQ(-350, result.unusedScrollDeltaX); | 498 EXPECT_EQ(-350, result.unusedScrollDeltaX); |
| 500 EXPECT_EQ(-250, result.unusedScrollDeltaY); | 499 EXPECT_EQ(-250, result.unusedScrollDeltaY); |
| 501 } | 500 } |
| 502 | 501 |
| 503 } // namespace blink | 502 } // namespace blink |
| OLD | NEW |