Commit 90f99c25 authored by andersca@apple.com's avatar andersca@apple.com

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):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 34c7902c
2011-10-04 Anders Carlsson <andersca@apple.com>
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):
2011-10-04 David Hyatt <hyatt@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=69372
......@@ -443,6 +443,8 @@
1A927FD31416A15B003A83C8 /* npruntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD01416A15B003A83C8 /* npruntime.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A927FD41416A15B003A83C8 /* nptypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD11416A15B003A83C8 /* nptypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */; };
1AA84F04143BA7BD0051D153 /* ScrollElasticityController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */; };
1AA84F05143BA7BD0051D153 /* ScrollElasticityController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */; };
1AA8799011CBE846003C664F /* PluginStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA8798F11CBE846003C664F /* PluginStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
1AB1AE7A0C051FDE00139F4F /* zoomInCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AB1AE780C051FDE00139F4F /* zoomInCursor.png */; };
1AB1AE7B0C051FDE00139F4F /* zoomOutCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AB1AE790C051FDE00139F4F /* zoomOutCursor.png */; };
......@@ -6985,6 +6987,8 @@
1A927FD01416A15B003A83C8 /* npruntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = npruntime.h; sourceTree = "<group>"; };
1A927FD11416A15B003A83C8 /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = "<group>"; };
1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURLCFNet.cpp; sourceTree = "<group>"; };
1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollElasticityController.mm; sourceTree = "<group>"; };
1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollElasticityController.h; sourceTree = "<group>"; };
1AA8798F11CBE846003C664F /* PluginStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginStrategy.h; sourceTree = "<group>"; };
1AB1AE780C051FDE00139F4F /* zoomInCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zoomInCursor.png; sourceTree = "<group>"; };
1AB1AE790C051FDE00139F4F /* zoomOutCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zoomOutCursor.png; sourceTree = "<group>"; };
......@@ -14601,6 +14605,8 @@
1CE24F960D7CAF0E007E04C2 /* SchedulePairMac.mm */,
BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */,
BC51156D12B1749C00C96754 /* ScrollAnimatorMac.mm */,
1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */,
1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */,
BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */,
BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */,
9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */,
......@@ -23548,6 +23554,7 @@
0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */,
BCEB179C143379F50052EAE9 /* RenderBoxRegionInfo.h in Headers */,
59102FBC14327D3B003C9D04 /* ContentSearchUtils.h in Headers */,
1AA84F05143BA7BD0051D153 /* ScrollElasticityController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -26388,6 +26395,7 @@
319AE063142D6B24006563A1 /* StyleFilterData.cpp in Sources */,
319AE069142D78DD006563A1 /* FilterOperations.cpp in Sources */,
59102FBB14327D3B003C9D04 /* ContentSearchUtils.cpp in Sources */,
1AA84F04143BA7BD0051D153 /* ScrollElasticityController.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -32,6 +32,7 @@
#include "FloatPoint.h"
#include "FloatSize.h"
#include "ScrollAnimator.h"
#include "ScrollElasticityController.h"
#include "Timer.h"
#include <wtf/RetainPtr.h>
......@@ -49,11 +50,16 @@ class WebScrollbarPainterDelegate;
typedef id ScrollbarPainterController;
#endif
#if !ENABLE(RUBBER_BANDING)
class ScrollElasticityControllerClient { };
#endif
namespace WebCore {
class Scrollbar;
class ScrollAnimatorMac : public ScrollAnimator {
class ScrollAnimatorMac : public ScrollAnimator, private ScrollElasticityControllerClient {
public:
ScrollAnimatorMac(ScrollableArea*);
virtual ~ScrollAnimatorMac();
......@@ -141,11 +147,8 @@ private:
void beginScrollGesture();
void endScrollGesture();
bool m_inScrollGesture;
bool m_momentumScrollInProgress;
bool m_ignoreMomentumScrolls;
bool m_scrollerInitiallyPinnedOnLeft;
bool m_scrollerInitiallyPinnedOnRight;
ScrollElasticityController m_scrollElasticityController;
int m_cumulativeHorizontalScroll;
bool m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin;
......
......@@ -458,9 +458,7 @@ ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea)
, m_initialScrollbarPaintTimer(this, &ScrollAnimatorMac::initialScrollbarPaintTimerFired)
#endif
#if ENABLE(RUBBER_BANDING)
, m_inScrollGesture(false)
, m_momentumScrollInProgress(false)
, m_ignoreMomentumScrolls(false)
, m_scrollElasticityController(this)
, m_lastMomentumScrollTimestamp(0)
, m_startTime(0)
, m_snapRubberBandTimer(this, &ScrollAnimatorMac::snapRubberBandTimerFired)
......@@ -818,9 +816,9 @@ bool ScrollAnimatorMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
// boolean, and rubber band. That is, if we were pinned to the left,
// and we ended up scrolling to the right, we rubber band.
m_cumulativeHorizontalScroll += wheelEvent.deltaX();
if (m_scrollerInitiallyPinnedOnLeft && m_cumulativeHorizontalScroll < 0)
if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft && m_cumulativeHorizontalScroll < 0)
m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
if (m_scrollerInitiallyPinnedOnRight && m_cumulativeHorizontalScroll > 0)
if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight && m_cumulativeHorizontalScroll > 0)
m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
}
......@@ -830,10 +828,10 @@ bool ScrollAnimatorMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
// 1 PlatformWheelEventPhaseEnded if there was at least one changed event
if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseNone && !m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin) {
if ((isScrollingLeftAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
m_scrollerInitiallyPinnedOnLeft &&
m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft &&
m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition()) ||
(isScrollingRightAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
m_scrollerInitiallyPinnedOnRight &&
m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight &&
m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition())) {
return ScrollAnimator::handleWheelEvent(wheelEvent);
}
......@@ -841,9 +839,9 @@ bool ScrollAnimatorMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
}
bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhaseNone);
if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberBandTimer.isActive())) {
if (m_scrollElasticityController.m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberBandTimer.isActive())) {
if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) {
m_ignoreMomentumScrolls = false;
m_scrollElasticityController.m_ignoreMomentumScrolls = false;
return true;
}
return false;
......@@ -957,11 +955,11 @@ void ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEve
PlatformWheelEventPhase phase = wheelEvent.momentumPhase();
// If we are starting momentum scrolling then do some setup.
if (!m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
m_momentumScrollInProgress = true;
if (!m_scrollElasticityController.m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
m_scrollElasticityController.m_momentumScrollInProgress = true;
CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTimestamp;
if (m_inScrollGesture || m_momentumScrollInProgress) {
if (m_scrollElasticityController.m_inScrollGesture || m_scrollElasticityController.m_momentumScrollInProgress) {
if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) {
m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta);
m_momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta);
......@@ -1047,10 +1045,10 @@ void ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEve
IntSize stretchAmount = m_scrollableArea->overhangAmount();
if (m_momentumScrollInProgress) {
if (m_scrollElasticityController.m_momentumScrollInProgress) {
if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) {
m_ignoreMomentumScrolls = true;
m_momentumScrollInProgress = false;
m_scrollElasticityController.m_ignoreMomentumScrolls = true;
m_scrollElasticityController.m_momentumScrollInProgress = false;
snapRubberBand();
}
}
......@@ -1070,9 +1068,9 @@ void ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEve
}
}
if (m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
m_momentumScrollInProgress = false;
m_ignoreMomentumScrolls = false;
if (m_scrollElasticityController.m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
m_scrollElasticityController.m_momentumScrollInProgress = false;
m_scrollElasticityController.m_ignoreMomentumScrolls = false;
m_lastMomentumScrollTimestamp = 0;
}
}
......@@ -1082,13 +1080,13 @@ void ScrollAnimatorMac::beginScrollGesture()
didBeginScrollGesture();
m_haveScrolledSincePageLoad = true;
m_inScrollGesture = true;
m_momentumScrollInProgress = false;
m_ignoreMomentumScrolls = false;
m_scrollElasticityController.m_inScrollGesture = true;
m_scrollElasticityController.m_momentumScrollInProgress = false;
m_scrollElasticityController.m_ignoreMomentumScrolls = false;
m_lastMomentumScrollTimestamp = 0;
m_momentumVelocity = FloatSize();
m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
m_cumulativeHorizontalScroll = 0;
m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;
......@@ -1115,7 +1113,7 @@ void ScrollAnimatorMac::snapRubberBand()
if (m_lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout)
m_momentumVelocity = FloatSize();
m_inScrollGesture = false;
m_scrollElasticityController.m_inScrollGesture = false;
if (m_snapRubberBandTimer.isActive())
return;
......@@ -1144,7 +1142,7 @@ static inline float roundToDevicePixelTowardZero(float num)
void ScrollAnimatorMac::snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*)
{
if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) {
if (!m_scrollElasticityController.m_momentumScrollInProgress || m_scrollElasticityController.m_ignoreMomentumScrolls) {
CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_startTime;
if (m_startStretch == FloatSize()) {
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ScrollElasticityController_h
#define ScrollElasticityController_h
#if ENABLE(RUBBER_BANDING)
#include <wtf/Noncopyable.h>
namespace WebCore {
class ScrollElasticityControllerClient {
public:
virtual ~ScrollElasticityControllerClient() { }
};
class ScrollElasticityController {
WTF_MAKE_NONCOPYABLE(ScrollElasticityController);
public:
explicit ScrollElasticityController(ScrollElasticityControllerClient*);
private:
ScrollElasticityControllerClient* m_client;
// FIXME: These member variables should be private. They are currently public as a stop-gap measure, while
// the rubber-band related code from ScrollAnimatorMac is being moved over.
public:
bool m_inScrollGesture;
bool m_momentumScrollInProgress;
bool m_ignoreMomentumScrolls;
bool m_scrollerInitiallyPinnedOnLeft;
bool m_scrollerInitiallyPinnedOnRight;
};
} // namespace WebCore
#endif // ENABLE(RUBBER_BANDING)
#endif // ScrollElasticityController_h
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ScrollElasticityController.h"
#if ENABLE(RUBBER_BANDING)
namespace WebCore {
ScrollElasticityController::ScrollElasticityController(ScrollElasticityControllerClient* client)
: m_client(client)
, m_inScrollGesture(false)
, m_momentumScrollInProgress(false)
, m_ignoreMomentumScrolls(false)
, m_scrollerInitiallyPinnedOnLeft(false)
, m_scrollerInitiallyPinnedOnRight(false)
{
}
} // namespace WebCore
#endif // ENABLE(RUBBER_BANDING)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment