Changeset 96644 in webkit


Ignore:
Timestamp:
Oct 4, 2011 2:18:53 PM (12 years ago)
Author:
andersca@apple.com
Message:

Add a ScrollElasticityController class and move some members over from ScrollAnimatorMac
https://bugs.webkit.org/show_bug.cgi?id=69373

Reviewed by David Hyatt.

ScrollElasticityController is a new class that will handle the rubber-banding when handling scroll events.

  • WebCore.xcodeproj/project.pbxproj:
  • platform/mac/ScrollAnimatorMac.h:
  • platform/mac/ScrollAnimatorMac.mm:

(WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
(WebCore::ScrollAnimatorMac::handleWheelEvent):
(WebCore::ScrollAnimatorMac::smoothScrollWithEvent):
(WebCore::ScrollAnimatorMac::beginScrollGesture):
(WebCore::ScrollAnimatorMac::snapRubberBand):
(WebCore::ScrollAnimatorMac::snapRubberBandTimerFired):

  • platform/mac/ScrollElasticityController.h: Added.

(WebCore::ScrollElasticityControllerClient::~ScrollElasticityControllerClient):

  • platform/mac/ScrollElasticityController.mm: Added.

(WebCore::ScrollElasticityController::ScrollElasticityController):

Location:
trunk/Source/WebCore
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96643 r96644  
     12011-10-04  Anders Carlsson  <andersca@apple.com>
     2
     3        Add a ScrollElasticityController class and move some members over from ScrollAnimatorMac
     4        https://bugs.webkit.org/show_bug.cgi?id=69373
     5
     6        Reviewed by David Hyatt.
     7
     8        ScrollElasticityController is a new class that will handle the rubber-banding when handling scroll events.
     9
     10        * WebCore.xcodeproj/project.pbxproj:
     11        * platform/mac/ScrollAnimatorMac.h:
     12        * platform/mac/ScrollAnimatorMac.mm:
     13        (WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
     14        (WebCore::ScrollAnimatorMac::handleWheelEvent):
     15        (WebCore::ScrollAnimatorMac::smoothScrollWithEvent):
     16        (WebCore::ScrollAnimatorMac::beginScrollGesture):
     17        (WebCore::ScrollAnimatorMac::snapRubberBand):
     18        (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired):
     19        * platform/mac/ScrollElasticityController.h: Added.
     20        (WebCore::ScrollElasticityControllerClient::~ScrollElasticityControllerClient):
     21        * platform/mac/ScrollElasticityController.mm: Added.
     22        (WebCore::ScrollElasticityController::ScrollElasticityController):
     23
    1242011-10-04  David Hyatt  <hyatt@apple.com>
    225
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r96545 r96644  
    444444                1A927FD41416A15B003A83C8 /* nptypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD11416A15B003A83C8 /* nptypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
    445445                1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */; };
     446                1AA84F04143BA7BD0051D153 /* ScrollElasticityController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */; };
     447                1AA84F05143BA7BD0051D153 /* ScrollElasticityController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */; };
    446448                1AA8799011CBE846003C664F /* PluginStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA8798F11CBE846003C664F /* PluginStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
    447449                1AB1AE7A0C051FDE00139F4F /* zoomInCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AB1AE780C051FDE00139F4F /* zoomInCursor.png */; };
     
    69866988                1A927FD11416A15B003A83C8 /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = "<group>"; };
    69876989                1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURLCFNet.cpp; sourceTree = "<group>"; };
     6990                1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollElasticityController.mm; sourceTree = "<group>"; };
     6991                1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollElasticityController.h; sourceTree = "<group>"; };
    69886992                1AA8798F11CBE846003C664F /* PluginStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginStrategy.h; sourceTree = "<group>"; };
    69896993                1AB1AE780C051FDE00139F4F /* zoomInCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zoomInCursor.png; sourceTree = "<group>"; };
     
    1460214606                                BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */,
    1460314607                                BC51156D12B1749C00C96754 /* ScrollAnimatorMac.mm */,
     14608                                1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */,
     14609                                1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */,
    1460414610                                BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */,
    1460514611                                BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */,
     
    2354923555                                BCEB179C143379F50052EAE9 /* RenderBoxRegionInfo.h in Headers */,
    2355023556                                59102FBC14327D3B003C9D04 /* ContentSearchUtils.h in Headers */,
     23557                                1AA84F05143BA7BD0051D153 /* ScrollElasticityController.h in Headers */,
    2355123558                        );
    2355223559                        runOnlyForDeploymentPostprocessing = 0;
     
    2638926396                                319AE069142D78DD006563A1 /* FilterOperations.cpp in Sources */,
    2639026397                                59102FBB14327D3B003C9D04 /* ContentSearchUtils.cpp in Sources */,
     26398                                1AA84F04143BA7BD0051D153 /* ScrollElasticityController.mm in Sources */,
    2639126399                        );
    2639226400                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h

    r96639 r96644  
    3333#include "FloatSize.h"
    3434#include "ScrollAnimator.h"
     35#include "ScrollElasticityController.h"
    3536#include "Timer.h"
    3637#include <wtf/RetainPtr.h>
     
    5051#endif
    5152
     53#if !ENABLE(RUBBER_BANDING)
     54class ScrollElasticityControllerClient { };
     55#endif
     56
    5257namespace WebCore {
    5358
    5459class Scrollbar;
    5560
    56 class ScrollAnimatorMac : public ScrollAnimator {
     61class ScrollAnimatorMac : public ScrollAnimator, private ScrollElasticityControllerClient {
     62
    5763public:
    5864    ScrollAnimatorMac(ScrollableArea*);
     
    142148    void endScrollGesture();
    143149
    144     bool m_inScrollGesture;
    145     bool m_momentumScrollInProgress;
    146     bool m_ignoreMomentumScrolls;
    147     bool m_scrollerInitiallyPinnedOnLeft;
    148     bool m_scrollerInitiallyPinnedOnRight;
     150    ScrollElasticityController m_scrollElasticityController;
     151
    149152    int m_cumulativeHorizontalScroll;
    150153    bool m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin;
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r96639 r96644  
    459459#endif
    460460#if ENABLE(RUBBER_BANDING)
    461     , m_inScrollGesture(false)
    462     , m_momentumScrollInProgress(false)
    463     , m_ignoreMomentumScrolls(false)
     461    , m_scrollElasticityController(this)
    464462    , m_lastMomentumScrollTimestamp(0)
    465463    , m_startTime(0)
     
    819817            // and we ended up scrolling to the right, we rubber band.
    820818            m_cumulativeHorizontalScroll += wheelEvent.deltaX();
    821             if (m_scrollerInitiallyPinnedOnLeft && m_cumulativeHorizontalScroll < 0)
     819            if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft && m_cumulativeHorizontalScroll < 0)
    822820                m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
    823             if (m_scrollerInitiallyPinnedOnRight && m_cumulativeHorizontalScroll > 0)
     821            if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight && m_cumulativeHorizontalScroll > 0)
    824822                m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
    825823        }
     
    831829        if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseNone && !m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin) {
    832830            if ((isScrollingLeftAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
    833                 m_scrollerInitiallyPinnedOnLeft &&
     831                m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft &&
    834832                m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition()) ||
    835833                (isScrollingRightAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
    836                 m_scrollerInitiallyPinnedOnRight &&
     834                m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight &&
    837835                m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition())) {
    838836                return ScrollAnimator::handleWheelEvent(wheelEvent);
     
    842840
    843841    bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhaseNone);
    844     if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberBandTimer.isActive())) {
     842    if (m_scrollElasticityController.m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberBandTimer.isActive())) {
    845843        if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) {
    846             m_ignoreMomentumScrolls = false;
     844            m_scrollElasticityController.m_ignoreMomentumScrolls = false;
    847845            return true;
    848846        }
     
    958956
    959957    // If we are starting momentum scrolling then do some setup.
    960     if (!m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
    961         m_momentumScrollInProgress = true;
     958    if (!m_scrollElasticityController.m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
     959        m_scrollElasticityController.m_momentumScrollInProgress = true;
    962960
    963961    CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTimestamp;
    964     if (m_inScrollGesture || m_momentumScrollInProgress) {
     962    if (m_scrollElasticityController.m_inScrollGesture || m_scrollElasticityController.m_momentumScrollInProgress) {
    965963        if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) {
    966964            m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta);
     
    10481046            IntSize stretchAmount = m_scrollableArea->overhangAmount();
    10491047       
    1050             if (m_momentumScrollInProgress) {
     1048            if (m_scrollElasticityController.m_momentumScrollInProgress) {
    10511049                if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) {
    1052                     m_ignoreMomentumScrolls = true;
    1053                     m_momentumScrollInProgress = false;
     1050                    m_scrollElasticityController.m_ignoreMomentumScrolls = true;
     1051                    m_scrollElasticityController.m_momentumScrollInProgress = false;
    10541052                    snapRubberBand();
    10551053                }
     
    10711069    }
    10721070
    1073     if (m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
    1074         m_momentumScrollInProgress = false;
    1075         m_ignoreMomentumScrolls = false;
     1071    if (m_scrollElasticityController.m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
     1072        m_scrollElasticityController.m_momentumScrollInProgress = false;
     1073        m_scrollElasticityController.m_ignoreMomentumScrolls = false;
    10761074        m_lastMomentumScrollTimestamp = 0;
    10771075    }
     
    10831081
    10841082    m_haveScrolledSincePageLoad = true;
    1085     m_inScrollGesture = true;
    1086     m_momentumScrollInProgress = false;
    1087     m_ignoreMomentumScrolls = false;
     1083    m_scrollElasticityController.m_inScrollGesture = true;
     1084    m_scrollElasticityController.m_momentumScrollInProgress = false;
     1085    m_scrollElasticityController.m_ignoreMomentumScrolls = false;
    10881086    m_lastMomentumScrollTimestamp = 0;
    10891087    m_momentumVelocity = FloatSize();
    1090     m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
    1091     m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
     1088    m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
     1089    m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
    10921090    m_cumulativeHorizontalScroll = 0;
    10931091    m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;
     
    11161114        m_momentumVelocity = FloatSize();
    11171115
    1118     m_inScrollGesture = false;
     1116    m_scrollElasticityController.m_inScrollGesture = false;
    11191117
    11201118    if (m_snapRubberBandTimer.isActive())
     
    11451143void ScrollAnimatorMac::snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*)
    11461144{
    1147     if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) {
     1145    if (!m_scrollElasticityController.m_momentumScrollInProgress || m_scrollElasticityController.m_ignoreMomentumScrolls) {
    11481146        CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_startTime;
    11491147
Note: See TracChangeset for help on using the changeset viewer.