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

Side by Side Diff: Source/core/frame/RootFrameViewportTest.cpp

Issue 1298973004: Remove special wheel handling path from ScrollableArea (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed TODO Created 5 years, 4 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
« no previous file with comments | « Source/core/frame/RootFrameViewport.cpp ('k') | Source/core/input/EventHandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); 291 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar));
292 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); 292 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar));
293 293
294 // Horizontal scrolling should be unaffected. 294 // Horizontal scrolling should be unaffected.
295 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); 295 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300);
296 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble()) ; 296 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble()) ;
297 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble()); 297 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble());
298 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble ()); 298 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble ());
299 } 299 }
300 300
301 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition(), w heelHandler) 301 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition())
302 // work correctly when one of the subviewports is explicitly scrolled without us ing the 302 // work correctly when one of the subviewports is explicitly scrolled without us ing the
303 // RootFrameViewport interface. 303 // RootFrameViewport interface.
304 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) 304 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll)
305 { 305 {
306 IntSize viewportSize(100, 150); 306 IntSize viewportSize(100, 150);
307 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300)); 307 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300));
308 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize); 308 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize);
309 309
310 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr eate(*visualViewport.get(), *layoutViewport.get()); 310 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr eate(*visualViewport.get(), *layoutViewport.get());
311 311
312 visualViewport->setScale(2); 312 visualViewport->setScale(2);
313 313
314 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); 314 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll);
315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ()); 315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ());
316 316
317 // If the scroll animator doesn't update, it will still think it's at (0, 0) and so it 317 // If the scroll animator doesn't update, it will still think it's at (0, 0) and so it
318 // may early exit. 318 // may early exit.
319 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); 319 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll);
320 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() ); 320 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() );
321 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); 321 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
322 322
323 // Try again for scroll() 323 // Try again for userScroll()
324 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); 324 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll);
325 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ()); 325 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ());
326 326
327 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); 327 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50);
328 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( )); 328 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( ));
329 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); 329 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble());
330 330
331 // Try again for handleWheel.
332 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll);
333 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ());
334
335 PlatformWheelEvent wheelEvent(
336 IntPoint(10, 10), IntPoint(10, 10),
337 50, 75,
338 0, 0,
339 ScrollByPixelWheelEvent,
340 false, false, false, false);
341 rootFrameViewport->handleWheel(wheelEvent);
342 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() );
343 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
344
345 // Make sure the layout viewport is also accounted for. 331 // Make sure the layout viewport is also accounted for.
332 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll);
346 layoutViewport->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll) ; 333 layoutViewport->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll) ;
347 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub le()); 334 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub le());
348 335
349 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); 336 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100);
350 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble ()); 337 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble ());
351 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ; 338 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ;
352 } 339 }
353 340
354 // Test that the scrollIntoView correctly scrolls the main frame 341 // Test that the scrollIntoView correctly scrolls the main frame
355 // and visual viewport such that the given rect is centered in the viewport. 342 // and visual viewport such that the given rect is centered in the viewport.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo uble().size()); 466 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo uble().size());
480 467
481 visualViewport->setScale(2); 468 visualViewport->setScale(2);
482 469
483 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect( ).location()); 470 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect( ).location());
484 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD ouble().location()); 471 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD ouble().location());
485 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect() .size()); 472 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect() .size());
486 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect Double().size()); 473 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect Double().size());
487 } 474 }
488 475
489 // Tests that wheel events are correctly handled in the non-root layer scrolls
490 // path.
491 TEST_F(RootFrameViewportTest, BasicWheelEvent)
492 {
493 IntSize viewportSize(100, 100);
494 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300));
495 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize);
496
497 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr eate(*visualViewport.get(), *layoutViewport.get());
498
499 visualViewport->setScale(2);
500
501 PlatformWheelEvent wheelEvent(
502 IntPoint(10, 10), IntPoint(10, 10),
503 -500, -500,
504 0, 0,
505 ScrollByPixelWheelEvent,
506 false, false, false, false);
507
508 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent);
509
510 EXPECT_TRUE(result.didScroll());
511 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble()) ;
512 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport->scrollPositionDouble( ));
513 EXPECT_EQ(350, result.unusedScrollDeltaX);
514 EXPECT_EQ(250, result.unusedScrollDeltaY);
515 }
516
517 // Tests that the invert scroll order experiment scrolls the visual viewport 476 // Tests that the invert scroll order experiment scrolls the visual viewport
518 // before trying to scroll the layout viewport. 477 // before trying to scroll the layout viewport.
519 TEST_F(RootFrameViewportTest, ViewportScrollOrder) 478 TEST_F(RootFrameViewportTest, ViewportScrollOrder)
520 { 479 {
521 IntSize viewportSize(100, 100); 480 IntSize viewportSize(100, 100);
522 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300)); 481 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300));
523 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize); 482 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize);
524 483
525 bool invertScrollOrder = true; 484 bool invertScrollOrder = true;
526 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = 485 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport =
527 RootFrameViewport::create(*visualViewport.get(), *layoutViewport.get(), invertScrollOrder); 486 RootFrameViewport::create(*visualViewport.get(), *layoutViewport.get(), invertScrollOrder);
528 487
529 visualViewport->setScale(2); 488 visualViewport->setScale(2);
530 489
531 PlatformWheelEvent wheelEvent(
532 IntPoint(10, 10), IntPoint(10, 10),
533 -25, -25,
534 0, 0,
535 ScrollByPixelWheelEvent,
536 false, false, false, false);
537
538 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent);
539
540 EXPECT_TRUE(result.didScroll());
541 EXPECT_POINT_EQ(DoublePoint(25, 25), visualViewport->scrollPositionDouble()) ;
542 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
543 EXPECT_EQ(0, result.unusedScrollDeltaX);
544 EXPECT_EQ(0, result.unusedScrollDeltaY);
545
546 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll); 490 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll);
547 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble()) ; 491 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble()) ;
548 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); 492 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
549 493
550 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll ); 494 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll );
551 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble()) ; 495 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble()) ;
552 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble()) ; 496 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble()) ;
553 } 497 }
554 498
555 } // namespace blink 499 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/RootFrameViewport.cpp ('k') | Source/core/input/EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698