Changeset 180974 in webkit


Ignore:
Timestamp:
Mar 3, 2015 5:36:51 PM (9 years ago)
Author:
Brent Fulgham
Message:

Move scroll animating functions from ScrollAnimator to ScrollController
https://bugs.webkit.org/show_bug.cgi?id=142102
<rdar://problem/20007161>

Reviewed by Simon Fraser.

Source/WebCore:

Tested by platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html.

Do some refactoring of the various scrolling classes:

  1. Consolidate animation times to RunLoop::Timer instead of a combination of WebCore::Timer and CFRunLoopTimers. Do this for Scroll Snap Point and Rubberband animations.
  2. Move ScrollController from platform/mac to platform/cocoa to enable sharing with iOS.
  3. Move code from ScrollAnimator{Mac} -> ScrollController.
  4. Rename scrollOffsetInAxis -> scrollOffsetOnAxis
  5. Rename immediateScrollInAxis -> immediateScrollOnAxis
  • WebCore.xcodeproj/project.pbxproj: Move ScrollController to 'platform/cocoa'
  • page/mac/EventHandlerMac.mm: Make sure the scroll controller is notified of end-of-scroll

events, just as is done for the "event not handled" case in EventHandler.cpp.
(WebCore::EventHandler::platformCompleteWheelEvent):

  • page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Remove timer and some delegate

methods, now that ScrollController is controlling this state.

  • page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:

(WebCore::ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac): We no longer
need to clean up the CFRunLoopTimer.
(WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Make sure scroll
state is updated after rubber band snap.
(WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Add temporary stub needed
until Bug1973 is completed.).
(WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto.
(WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted.

  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::ScrollAnimator):
(WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method.
(WebCore::ScrollAnimator::handleWheelEvent): Ditto.
(WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto.
(WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis.
(WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis.
(WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted.
(WebCore::ScrollAnimator::immediateScrollInAxis): Deleted.
(WebCore::ScrollAnimator::startScrollSnapTimer): Deleted.
(WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted.
(WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted.
(WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted.

  • platform/ScrollAnimator.h:
  • platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h.

(WebCore::ScrollControllerClient::startSnapRubberbandTimer):
(WebCore::ScrollControllerClient::stopSnapRubberbandTimer):
(WebCore::ScrollControllerClient::startScrollSnapTimer):
(WebCore::ScrollControllerClient::stopScrollSnapTimer):

  • platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm.

(WebCore::ScrollController::ScrollController): Update to initialize new timers.
(WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events.
(WebCore::ScrollController::startSnapRubberbandTimer): Added.
(WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not
require client to maintain timers.
(WebCore::ScrollController::snapRubberBand): Ditto.
(WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac)
(WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto.
(WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
(WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac.
(WebCore::ScrollController::immediateScrollOnAxis): Ditto.

  • platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis'
  • platform/mac/AxisScrollSnapAnimator.mm:

(WebCore::AxisScrollSnapAnimator::handleWheelEvent): Update for 'InAxis' to 'OnAxis' renaming.
(WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Ditto.
(WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Ditto.
(WebCore::AxisScrollSnapAnimator::computeSnapDelta): Ditto.
(WebCore::AxisScrollSnapAnimator::computeGlideDelta): Ditto.

  • platform/mac/ScrollAnimatorMac.h:
  • platform/mac/ScrollAnimatorMac.mm:

(WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is
controlled in the ScrollController)
(WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted.
(WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted.
(WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted.

  • platform/mac/ScrollController.h: Removed.
  • platform/mac/ScrollController.mm: Removed.

LayoutTests:

Add a new test that confirms that rubberband snap animations work properly when combined
with text zooming.

  • platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt: Added.
  • platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html: Added.
Location:
trunk
Files:
2 added
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r180966 r180974  
     12015-03-03  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Move scroll animating functions from ScrollAnimator to ScrollController
     4        https://bugs.webkit.org/show_bug.cgi?id=142102
     5        <rdar://problem/20007161>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Add a new test that confirms that rubberband snap animations work properly when combined
     10        with text zooming.
     11
     12        * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt: Added.
     13        * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html: Added.
     14
    1152015-03-03  Commit Queue  <commit-queue@webkit.org>
    216
  • trunk/Source/WebCore/ChangeLog

    r180966 r180974  
     12015-03-03  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Move scroll animating functions from ScrollAnimator to ScrollController
     4        https://bugs.webkit.org/show_bug.cgi?id=142102
     5        <rdar://problem/20007161>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Tested by platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html.
     10
     11        Do some refactoring of the various scrolling classes:
     12        1. Consolidate animation times to RunLoop::Timer instead of a combination of WebCore::Timer
     13           and CFRunLoopTimers. Do this for Scroll Snap Point and Rubberband animations.
     14        2. Move ScrollController from platform/mac to platform/cocoa to enable sharing with iOS.
     15        3. Move code from ScrollAnimator{Mac} -> ScrollController.
     16        4. Rename scrollOffsetInAxis -> scrollOffsetOnAxis
     17        5. Rename immediateScrollInAxis -> immediateScrollOnAxis
     18
     19        * WebCore.xcodeproj/project.pbxproj: Move ScrollController to 'platform/cocoa'
     20        * page/mac/EventHandlerMac.mm: Make sure the scroll controller is notified of end-of-scroll
     21        events, just as is done for the "event not handled" case in EventHandler.cpp.
     22        (WebCore::EventHandler::platformCompleteWheelEvent):
     23        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Remove timer and some delegate
     24        methods, now that ScrollController is controlling this state.
     25        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
     26        (WebCore::ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac): We no longer
     27        need to clean up the CFRunLoopTimer.
     28        (WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Make sure scroll
     29        state is updated after rubber band snap.
     30        (WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Add temporary stub needed
     31        until Bug1973 is completed.).
     32        (WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto.
     33        (WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted.
     34        * platform/ScrollAnimator.cpp:
     35        (WebCore::ScrollAnimator::ScrollAnimator):
     36        (WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method.
     37        (WebCore::ScrollAnimator::handleWheelEvent): Ditto.
     38        (WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto.
     39        (WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis.
     40        (WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis.
     41        (WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted.
     42        (WebCore::ScrollAnimator::immediateScrollInAxis): Deleted.
     43        (WebCore::ScrollAnimator::startScrollSnapTimer): Deleted.
     44        (WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted.
     45        (WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted.
     46        (WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted.
     47        * platform/ScrollAnimator.h:
     48        * platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h.
     49        (WebCore::ScrollControllerClient::startSnapRubberbandTimer):
     50        (WebCore::ScrollControllerClient::stopSnapRubberbandTimer):
     51        (WebCore::ScrollControllerClient::startScrollSnapTimer):
     52        (WebCore::ScrollControllerClient::stopScrollSnapTimer):
     53        * platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm.
     54        (WebCore::ScrollController::ScrollController): Update to initialize new timers.
     55        (WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events.
     56        (WebCore::ScrollController::startSnapRubberbandTimer): Added.
     57        (WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not
     58        require client to maintain timers.
     59        (WebCore::ScrollController::snapRubberBand): Ditto.
     60        (WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac)
     61        (WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer.
     62        (WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
     63        (WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
     64        (WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto.
     65        (WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
     66        (WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac.
     67        (WebCore::ScrollController::immediateScrollOnAxis): Ditto.
     68        * platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis'
     69        * platform/mac/AxisScrollSnapAnimator.mm:
     70        (WebCore::AxisScrollSnapAnimator::handleWheelEvent): Update for 'InAxis' to 'OnAxis' renaming.
     71        (WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Ditto.
     72        (WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Ditto.
     73        (WebCore::AxisScrollSnapAnimator::computeSnapDelta): Ditto.
     74        (WebCore::AxisScrollSnapAnimator::computeGlideDelta): Ditto.
     75        * platform/mac/ScrollAnimatorMac.h:
     76        * platform/mac/ScrollAnimatorMac.mm:
     77        (WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is
     78        controlled in the ScrollController)
     79        (WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted.
     80        (WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted.
     81        (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted.
     82        * platform/mac/ScrollController.h: Removed.
     83        * platform/mac/ScrollController.mm: Removed.
     84
    1852015-03-03  Commit Queue  <commit-queue@webkit.org>
    286
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r180915 r180974  
    1658816588                                BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */,
    1658916589                                BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */,
    16590                                 1AA84F03143BA7BD0051D153 /* ScrollController.h */,
    16591                                 1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
    1659216590                                9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */,
    1659316591                                077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */,
     
    1869918697                                1A0409DB1A4360B5009E47F3 /* MachSendRight.h */,
    1870018698                                ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */,
     18699                                1AA84F03143BA7BD0051D153 /* ScrollController.h */,
     18700                                1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
    1870118701                                5D5975B119635F1100D00878 /* SystemVersion.h */,
    1870218702                                5D5975B219635F1100D00878 /* SystemVersion.mm */,
  • trunk/Source/WebCore/page/mac/EventHandlerMac.mm

    r180915 r180974  
    962962    bool didHandleEvent = view ? view->wheelEvent(wheelEvent) : false;
    963963    m_isHandlingWheelEvent = false;
     964
     965#if ENABLE(CSS_SCROLL_SNAP)
     966    if (scrollableArea)
     967        platformNotifySnapIfNecessary(wheelEvent, *scrollableArea);
     968#endif
     969
    964970    return didHandleEvent;
    965971}
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h

    r180915 r180974  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5252
    5353    // ScrollController member functions.
    54     virtual bool allowsHorizontalStretching(const PlatformWheelEvent&) override;
    55     virtual bool allowsVerticalStretching(const PlatformWheelEvent&) override;
    56     virtual IntSize stretchAmount() override;
    57     virtual bool pinnedInDirection(const FloatSize&) override;
    58     virtual bool canScrollHorizontally() override;
    59     virtual bool canScrollVertically() override;
    60     virtual bool shouldRubberBandInDirection(ScrollDirection) override;
    61     virtual IntPoint absoluteScrollPosition() override;
    62     virtual void immediateScrollBy(const FloatSize&) override;
    63     virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
    64     virtual void startSnapRubberbandTimer() override;
    65     virtual void stopSnapRubberbandTimer() override;
    66     virtual void adjustScrollPositionToBoundsIfNecessary() override;
     54    bool allowsHorizontalStretching(const PlatformWheelEvent&) override;
     55    bool allowsVerticalStretching(const PlatformWheelEvent&) override;
     56    IntSize stretchAmount() override;
     57    bool pinnedInDirection(const FloatSize&) override;
     58    bool canScrollHorizontally() override;
     59    bool canScrollVertically() override;
     60    bool shouldRubberBandInDirection(ScrollDirection) override;
     61    IntPoint absoluteScrollPosition() override;
     62    void immediateScrollBy(const FloatSize&) override;
     63    void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
     64    void stopSnapRubberbandTimer() override;
     65    void adjustScrollPositionToBoundsIfNecessary() override;
    6766
    68     virtual FloatPoint scrollPosition() const override;
    69     virtual void setScrollPosition(const FloatPoint&) override;
    70     virtual void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override;
     67    FloatPoint scrollPosition() const override;
     68    void setScrollPosition(const FloatPoint&) override;
     69    void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override;
    7170
    72     virtual void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override;
     71    void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override;
    7372
    74     virtual void setScrollLayerPosition(const FloatPoint&) override;
     73    void setScrollLayerPosition(const FloatPoint&) override;
    7574
    76     virtual FloatPoint minimumScrollPosition() const override;
    77     virtual FloatPoint maximumScrollPosition() const override;
     75    FloatPoint minimumScrollPosition() const override;
     76    FloatPoint maximumScrollPosition() const override;
    7877
    7978    void updateMainFramePinState(const FloatPoint& scrollPosition);
     
    8180    bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
    8281
     82#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     83    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
     84    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
     85#endif
     86
    8387    void logExposedUnfilledArea();
    8488
    8589    ScrollController m_scrollController;
    86     RetainPtr<CFRunLoopTimerRef> m_snapRubberbandTimer;
    8790
    8891    RetainPtr<CALayer> m_scrollLayer;
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm

    r180915 r180974  
    11/*
    2  * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6767ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac()
    6868{
    69     if (m_snapRubberbandTimer)
    70         CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());
    7169}
    7270
     
    297295}
    298296
    299 void ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer()
    300 {
    301     ASSERT(!m_snapRubberbandTimer);
    302 
    303     CFTimeInterval timerInterval = 1.0 / 60.0;
    304 
    305     m_snapRubberbandTimer = adoptCF(CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + timerInterval, timerInterval, 0, 0, ^(CFRunLoopTimerRef) {
    306         m_scrollController.snapRubberBandTimerFired();
    307     }));
    308     CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_snapRubberbandTimer.get(), kCFRunLoopDefaultMode);
    309 }
    310 
    311297void ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer()
    312298{
    313     if (!m_snapRubberbandTimer)
    314         return;
    315 
    316299    scrollingTree().setMainFrameIsRubberBanding(false);
    317300
    318301    // Since the rubberband timer has stopped, totalContentsSizeForRubberBand can be synchronized with totalContentsSize.
    319302    setTotalContentsSizeForRubberBand(totalContentsSize());
    320 
    321     CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());
    322     m_snapRubberbandTimer = nullptr;
    323303}
    324304
     
    541521}
    542522
     523#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     524LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis)
     525{
     526    // Temporary stub until http://webkit.org/b/141973.
     527    return 0;
     528}
     529
     530void ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis(ScrollEventAxis, float)
     531{
     532    // Temporary stub until http://webkit.org/b/141973.
     533}
     534#endif
     535
    543536} // namespace WebCore
    544537
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r180915 r180974  
    5050ScrollAnimator::ScrollAnimator(ScrollableArea& scrollableArea)
    5151    : m_scrollableArea(scrollableArea)
     52#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
     53    , m_scrollController(this)
     54#endif
    5255    , m_currentPosX(0)
    5356    , m_currentPosY(0)
     
    8285
    8386#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    84 void ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
     87bool ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
    8588{
    86     if (m_verticalScrollSnapAnimator)
    87         m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent);
    88     if (m_horizontalScrollSnapAnimator)
    89         m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent);
     89    return m_scrollController.processWheelEventForScrollSnap(wheelEvent);
    9090}
    9191#endif
     
    9494{
    9595#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    96     if (m_verticalScrollSnapAnimator) {
    97         m_verticalScrollSnapAnimator->handleWheelEvent(e);
    98         if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(e))
    99             return false;
    100     }
    101     if (m_horizontalScrollSnapAnimator) {
    102         m_horizontalScrollSnapAnimator->handleWheelEvent(e);
    103         if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(e))
    104             return false;
    105     }
     96    if (!m_scrollController.processWheelEventForScrollSnap(e))
     97        return false;
    10698#endif
    10799#if PLATFORM(COCOA)
     
    184176void ScrollAnimator::updateScrollAnimatorsAndTimers()
    185177{
    186     // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated.
    187     if (m_scrollableArea.horizontalSnapOffsets()) {
    188         m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal);
    189         m_horizontalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::horizontalScrollSnapTimerFired);
    190     } else if (m_horizontalScrollSnapAnimator) {
    191         m_horizontalScrollSnapAnimator = nullptr;
    192         m_horizontalScrollSnapTimer = nullptr;
    193     }
    194     if (m_scrollableArea.verticalSnapOffsets()) {
    195         m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical);
    196         m_verticalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::verticalScrollSnapTimerFired);
    197     } else if (m_verticalScrollSnapAnimator) {
    198         m_verticalScrollSnapAnimator = nullptr;
    199         m_verticalScrollSnapTimer = nullptr;
    200     }
     178    m_scrollController.updateScrollAnimatorsAndTimers(m_scrollableArea);
    201179}
    202180
    203 LayoutUnit ScrollAnimator::scrollOffsetInAxis(ScrollEventAxis axis)
     181LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis)
    204182{
    205     FloatPoint currentPosition = this->currentPosition();
    206     return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y();
     183    return axis == ScrollEventAxis::Horizontal ? m_currentPosX : m_currentPosY;
    207184}
    208185
    209 void ScrollAnimator::immediateScrollInAxis(ScrollEventAxis axis, float delta)
     186void ScrollAnimator::immediateScrollOnAxis(ScrollEventAxis axis, float delta)
    210187{
    211188    FloatPoint currentPosition = this->currentPosition();
     
    215192        scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x(), currentPosition.y() + delta));
    216193}
    217 
    218 void ScrollAnimator::startScrollSnapTimer(ScrollEventAxis axis)
    219 {
    220     Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();
    221     if (!scrollSnapTimer->isActive())
    222         scrollSnapTimer->startRepeating(1.0 / 60.0);
    223 }
    224 
    225 void ScrollAnimator::stopScrollSnapTimer(ScrollEventAxis axis)
    226 {
    227     Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();
    228     if (scrollSnapTimer->isActive())
    229         scrollSnapTimer->stop();
    230 }
    231 
    232 void ScrollAnimator::horizontalScrollSnapTimerFired()
    233 {
    234     m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();
    235 }
    236 
    237 void ScrollAnimator::verticalScrollSnapTimerFired()
    238 {
    239     m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();
    240 }
    241194#endif
    242195
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r180915 r180974  
    3434
    3535#include "FloatSize.h"
     36#include "LayoutUnit.h"
    3637#include "PlatformWheelEvent.h"
    3738#include "ScrollTypes.h"
     
    3940#include <wtf/Forward.h>
    4041
    41 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    42 #include "AxisScrollSnapAnimator.h"
    43 #include "Timer.h"
     42#if (ENABLE(RUBBER_BANDING) || ENABLE(CSS_SCROLL_SNAP)) && PLATFORM(MAC)
     43#include "ScrollController.h"
    4444#endif
    4545
     
    5151class Scrollbar;
    5252
    53 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    54 class ScrollAnimator : public AxisScrollSnapAnimatorClient {
     53#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
     54class ScrollAnimator : private ScrollControllerClient {
    5555#else
    5656class ScrollAnimator {
     
    119119
    120120#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    121     void processWheelEventForScrollSnap(const PlatformWheelEvent&);
     121    bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
    122122    void updateScrollAnimatorsAndTimers();
    123     virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) override;
    124     virtual void immediateScrollInAxis(ScrollEventAxis, float delta) override;
    125     virtual void startScrollSnapTimer(ScrollEventAxis) override;
    126     virtual void stopScrollSnapTimer(ScrollEventAxis) override;
     123    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
     124    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
    127125#endif
    128126
     
    130128    virtual void notifyPositionChanged(const FloatSize& delta);
    131129
    132 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    133     // Trivial wrappers around the actual update loop in AxisScrollSnapAnimator, since WebCore Timer requires a Timer argument.
    134     void horizontalScrollSnapTimerFired();
    135     void verticalScrollSnapTimerFired();
     130    ScrollableArea& m_scrollableArea;
     131#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
     132    ScrollController m_scrollController;
    136133#endif
    137 
    138     ScrollableArea& m_scrollableArea;
    139134    float m_currentPosX; // We avoid using a FloatPoint in order to reduce
    140135    float m_currentPosY; // subclass code complexity.
    141 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    142     std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator;
    143     std::unique_ptr<Timer> m_horizontalScrollSnapTimer;
    144     // FIXME: Find a way to consolidate both timers into one variable.
    145     std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator;
    146     std::unique_ptr<Timer> m_verticalScrollSnapTimer;
    147 #endif
    148136};
    149137
  • trunk/Source/WebCore/platform/cocoa/ScrollController.h

    r180935 r180974  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011, 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333#include "ScrollTypes.h"
    3434#include <wtf/Noncopyable.h>
     35#include <wtf/RunLoop.h>
     36
     37#if ENABLE(CSS_SCROLL_SNAP)
     38#include "AxisScrollSnapAnimator.h"
     39#endif
    3540
    3641namespace WebCore {
    3742
    3843class PlatformWheelEvent;
     44class ScrollableArea;
    3945
    4046class ScrollControllerClient {
     
    5662    virtual void immediateScrollBy(const FloatSize&) = 0;
    5763    virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) = 0;
    58     virtual void startSnapRubberbandTimer() = 0;
    59     virtual void stopSnapRubberbandTimer() = 0;
     64    virtual void startSnapRubberbandTimer()
     65    {
     66        // Override to perform client-specific snap start logic
     67    }
    6068
     69    virtual void stopSnapRubberbandTimer()
     70    {
     71        // Override to perform client-specific snap end logic
     72    }
     73   
    6174    // If the current scroll position is within the overhang area, this function will cause
    6275    // the page to scroll to the nearest boundary point.
    6376    virtual void adjustScrollPositionToBoundsIfNecessary() = 0;
     77
     78#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     79    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
     80    virtual void immediateScrollOnAxis(ScrollEventAxis, float delta) = 0;
     81    virtual void startScrollSnapTimer(ScrollEventAxis)
     82    {
     83        // Override to perform client-specific scroll snap point start logic
     84    }
     85
     86    virtual void stopScrollSnapTimer(ScrollEventAxis)
     87    {
     88        // Override to perform client-specific scroll snap point end logic
     89       
     90    }
     91#endif
    6492};
    6593
     94#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     95class ScrollController : public AxisScrollSnapAnimatorClient {
     96#else
    6697class ScrollController {
     98#endif
    6799    WTF_MAKE_NONCOPYABLE(ScrollController);
    68100
     
    71103
    72104    bool handleWheelEvent(const PlatformWheelEvent&);
    73     void snapRubberBandTimerFired();
    74105
    75106    bool isRubberBandInProgress() const;
    76107
     108#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     109    bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
     110    void updateScrollAnimatorsAndTimers(const ScrollableArea&);
     111#endif
     112
    77113private:
     114    void startSnapRubberbandTimer();
    78115    void stopSnapRubberbandTimer();
    79116    void snapRubberBand();
     117    void snapRubberBandTimerFired();
    80118
    81119    bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&);
    82120
     121#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     122    void horizontalScrollSnapTimerFired();
     123    void verticalScrollSnapTimerFired();
     124    void startScrollSnapTimer(ScrollEventAxis) override;
     125    void stopScrollSnapTimer(ScrollEventAxis) override;
     126
     127    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
     128    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
     129#endif
     130
    83131    ScrollControllerClient* m_client;
    84 
    85     bool m_inScrollGesture;
    86     bool m_momentumScrollInProgress;
    87     bool m_ignoreMomentumScrolls;
    88132   
    89133    CFTimeInterval m_lastMomentumScrollTimestamp;
     
    97141    FloatPoint m_origOrigin;
    98142    FloatSize m_origVelocity;
     143    RunLoop::Timer<ScrollController> m_snapRubberbandTimer;
    99144
     145#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     146    // FIXME: Find a way to consolidate both timers into one variable.
     147    std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator;
     148    std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator;
     149    RunLoop::Timer<ScrollController> m_horizontalScrollSnapTimer;
     150    RunLoop::Timer<ScrollController> m_verticalScrollSnapTimer;
     151#endif
     152
     153    bool m_inScrollGesture;
     154    bool m_momentumScrollInProgress;
     155    bool m_ignoreMomentumScrolls;
    100156    bool m_snapRubberbandTimerIsActive;
    101157};
  • trunk/Source/WebCore/platform/cocoa/ScrollController.mm

    r180935 r180974  
    3232#include <sys/time.h>
    3333
     34#if ENABLE(CSS_SCROLL_SNAP)
     35#include "AxisScrollSnapAnimator.h"
     36#include "ScrollableArea.h"
     37#endif
     38
    3439#if ENABLE(RUBBER_BANDING)
    3540
     
    9297ScrollController::ScrollController(ScrollControllerClient* client)
    9398    : m_client(client)
     99    , m_lastMomentumScrollTimestamp(0)
     100    , m_startTime(0)
     101    , m_snapRubberbandTimer(RunLoop::current(), this, &ScrollController::snapRubberBandTimerFired)
     102#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     103    , m_horizontalScrollSnapTimer(RunLoop::current(), this, &ScrollController::horizontalScrollSnapTimerFired)
     104    , m_verticalScrollSnapTimer(RunLoop::current(), this, &ScrollController::verticalScrollSnapTimerFired)
     105#endif
    94106    , m_inScrollGesture(false)
    95107    , m_momentumScrollInProgress(false)
    96108    , m_ignoreMomentumScrolls(false)
    97     , m_lastMomentumScrollTimestamp(0)
    98     , m_startTime(0)
    99109    , m_snapRubberbandTimerIsActive(false)
    100110{
     
    103113bool ScrollController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
    104114{
     115#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     116    if (!processWheelEventForScrollSnap(wheelEvent))
     117        return false;
     118#endif
    105119    if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) {
    106120        // First, check if we should rubber-band at all.
     
    366380}
    367381
     382void ScrollController::startSnapRubberbandTimer()
     383{
     384    m_client->startSnapRubberbandTimer();
     385    m_snapRubberbandTimer.startRepeating(1.0 / 60.0);
     386}
     387
    368388void ScrollController::stopSnapRubberbandTimer()
    369389{
    370390    m_client->stopSnapRubberbandTimer();
     391    m_snapRubberbandTimer.stop();
    371392    m_snapRubberbandTimerIsActive = false;
    372393}
     
    388409    m_origVelocity = FloatSize();
    389410
    390     m_client->startSnapRubberbandTimer();
     411    startSnapRubberbandTimer();
    391412    m_snapRubberbandTimerIsActive = true;
    392413}
     
    402423}
    403424
     425#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     426bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
     427{
     428    if (m_verticalScrollSnapAnimator) {
     429        m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent);
     430        if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
     431            return false;
     432    }
     433    if (m_horizontalScrollSnapAnimator) {
     434        m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent);
     435        if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
     436            return false;
     437    }
     438
     439    return true;
     440}
     441
     442void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scrollableArea)
     443{
     444    // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated.
     445    if (scrollableArea.horizontalSnapOffsets())
     446        m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal);
     447    else if (m_horizontalScrollSnapAnimator)
     448        m_horizontalScrollSnapAnimator = nullptr;
     449
     450    if (scrollableArea.verticalSnapOffsets())
     451        m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical);
     452    else if (m_verticalScrollSnapAnimator)
     453        m_verticalScrollSnapAnimator = nullptr;
     454}
     455
     456void ScrollController::startScrollSnapTimer(ScrollEventAxis axis)
     457{
     458    RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
     459    if (!scrollSnapTimer.isActive())
     460        scrollSnapTimer.startRepeating(1.0 / 60.0);
     461}
     462
     463void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis)
     464{
     465    RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
     466    scrollSnapTimer.stop();
     467}
     468
     469void ScrollController::horizontalScrollSnapTimerFired()
     470{
     471    if (m_horizontalScrollSnapAnimator)
     472        m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();
     473}
     474
     475void ScrollController::verticalScrollSnapTimerFired()
     476{
     477    if (m_verticalScrollSnapAnimator)
     478        m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();
     479}
     480
     481LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis)
     482{
     483    return m_client->scrollOffsetOnAxis(axis);
     484}
     485
     486void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta)
     487{
     488    m_client->immediateScrollOnAxis(axis, delta);
     489}
     490#endif
     491
    404492} // namespace WebCore
    405493
  • trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.h

    r180915 r180974  
    5858
    5959public:
    60     virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) = 0;
    61     virtual void immediateScrollInAxis(ScrollEventAxis, float velocity) = 0;
     60    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
     61    virtual void immediateScrollOnAxis(ScrollEventAxis, float velocity) = 0;
    6262    virtual void startScrollSnapTimer(ScrollEventAxis) = 0;
    6363    virtual void stopScrollSnapTimer(ScrollEventAxis) = 0;
  • trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm

    r180915 r180974  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    118118        endScrollSnapAnimation(ScrollSnapState::UserInteraction);
    119119        pushInitialWheelDelta(wheelDelta);
    120         m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetInAxis(m_axis);
     120        m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetOnAxis(m_axis);
    121121        break;
    122122
     
    154154    float delta = m_currentState == ScrollSnapState::Snapping ? computeSnapDelta() : computeGlideDelta();
    155155    if (delta)
    156         m_client->immediateScrollInAxis(m_axis, delta);
     156        m_client->immediateScrollOnAxis(m_axis, delta);
    157157    else
    158158        endScrollSnapAnimation(ScrollSnapState::DestinationReached);
     
    162162{
    163163    ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
    164     LayoutUnit offset = m_client->scrollOffsetInAxis(m_axis);
     164    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
    165165    float initialWheelDelta = newState == ScrollSnapState::Gliding ? averageInitialWheelDelta() : 0;
    166166    LayoutUnit projectedScrollDestination = newState == ScrollSnapState::Gliding ? m_beginTrackingWheelDeltaOffset + LayoutUnit(projectedInertialScrollDistance(initialWheelDelta)) : offset;
     
    204204float AxisScrollSnapAnimator::computeSnapDelta() const
    205205{
    206     LayoutUnit offset = m_client->scrollOffsetInAxis(m_axis);
     206    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
    207207    bool canComputeSnap =  (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset);
    208208    if (m_currentState != ScrollSnapState::Snapping || !canComputeSnap)
     
    238238float AxisScrollSnapAnimator::computeGlideDelta() const
    239239{
    240     LayoutUnit offset = m_client->scrollOffsetInAxis(m_axis);
     240    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
    241241    bool canComputeGlide = (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset);
    242242    if (m_currentState != ScrollSnapState::Gliding || !canComputeGlide)
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h

    r180915 r180974  
    3333#include "FloatSize.h"
    3434#include "ScrollAnimator.h"
    35 #include "ScrollController.h"
    3635#include "Timer.h"
    3736#include <wtf/RetainPtr.h>
     
    4342typedef id ScrollbarPainterController;
    4443
    45 #if !ENABLE(RUBBER_BANDING)
    46 class ScrollControllerClient { };
    47 #endif
    48 
    4944namespace WebCore {
    5045
    5146class Scrollbar;
    5247
    53 class ScrollAnimatorMac : public ScrollAnimator, private ScrollControllerClient {
     48class ScrollAnimatorMac : public ScrollAnimator {
    5449
    5550public:
     
    151146    virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
    152147    virtual void immediateScrollBy(const FloatSize&) override;
    153     virtual void startSnapRubberbandTimer() override;
    154     virtual void stopSnapRubberbandTimer() override;
    155148    virtual void adjustScrollPositionToBoundsIfNecessary() override;
    156149
    157150    bool pinnedInDirection(float deltaX, float deltaY);
    158     void snapRubberBandTimerFired();
    159151
    160152    bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
    161 
    162     ScrollController m_scrollController;
    163     Timer m_snapRubberBandTimer;
    164153#endif
    165154
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r180915 r180974  
    644644    , m_initialScrollbarPaintTimer(*this, &ScrollAnimatorMac::initialScrollbarPaintTimerFired)
    645645    , m_sendContentAreaScrolledTimer(*this, &ScrollAnimatorMac::sendContentAreaScrolledTimerFired)
    646 #if ENABLE(RUBBER_BANDING)
    647     , m_scrollController(this)
    648     , m_snapRubberBandTimer(*this, &ScrollAnimatorMac::snapRubberBandTimerFired)
    649 #endif
    650646    , m_haveScrolledSincePageLoad(false)
    651647    , m_needsScrollerStyleUpdate(false)
     
    12711267    notifyPositionChanged(adjustedDelta);
    12721268}
    1273 
    1274 void ScrollAnimatorMac::startSnapRubberbandTimer()
    1275 {
    1276     m_snapRubberBandTimer.startRepeating(1.0 / 60.0);
    1277 }
    1278 
    1279 void ScrollAnimatorMac::stopSnapRubberbandTimer()
    1280 {
    1281     m_snapRubberBandTimer.stop();
    1282 }
    1283 
    1284 void ScrollAnimatorMac::snapRubberBandTimerFired()
    1285 {
    1286     m_scrollController.snapRubberBandTimerFired();
    1287 }
    12881269#endif
    12891270
Note: See TracChangeset for help on using the changeset viewer.