- Revision
- 104853
- Author
- [email protected]
- Date
- 2012-01-12 13:28:51 -0800 (Thu, 12 Jan 2012)
Log Message
Move wheel event handling to ScrollElasticityController::handleWheelEvent
https://bugs.webkit.org/show_bug.cgi?id=76205
Reviewed by Andreas Kling.
Move the code in ScrollAnimatorMac::smoothScrollWithEvent to ScrollElasticityController::handleWheelEvent and
change ScrollAnimatorMac::handleWheelEvent to just call ScrollElasticityController::handleWheelEvent.
This means that we'll not set m_haveScrolledSincePageLoad = true anymore (we used to set it in ScrollAnimatorMac::smoothScrollWithEvent),
but we already set it to true in ScrollAnimatorMac::handleWheelEvent so it already had no effect.
* platform/mac/ScrollAnimatorMac.h:
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::handleWheelEvent):
* platform/mac/ScrollElasticityController.h:
* platform/mac/ScrollElasticityController.mm:
(WebCore::elasticDeltaForReboundDelta):
(WebCore::scrollWheelMultiplier):
(WebCore::ScrollElasticityController::handleWheelEvent):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (104852 => 104853)
--- trunk/Source/WebCore/ChangeLog 2012-01-12 21:26:58 UTC (rev 104852)
+++ trunk/Source/WebCore/ChangeLog 2012-01-12 21:28:51 UTC (rev 104853)
@@ -1,3 +1,24 @@
+2012-01-12 Anders Carlsson <[email protected]>
+
+ Move wheel event handling to ScrollElasticityController::handleWheelEvent
+ https://bugs.webkit.org/show_bug.cgi?id=76205
+
+ Reviewed by Andreas Kling.
+
+ Move the code in ScrollAnimatorMac::smoothScrollWithEvent to ScrollElasticityController::handleWheelEvent and
+ change ScrollAnimatorMac::handleWheelEvent to just call ScrollElasticityController::handleWheelEvent.
+ This means that we'll not set m_haveScrolledSincePageLoad = true anymore (we used to set it in ScrollAnimatorMac::smoothScrollWithEvent),
+ but we already set it to true in ScrollAnimatorMac::handleWheelEvent so it already had no effect.
+
+ * platform/mac/ScrollAnimatorMac.h:
+ * platform/mac/ScrollAnimatorMac.mm:
+ (WebCore::ScrollAnimatorMac::handleWheelEvent):
+ * platform/mac/ScrollElasticityController.h:
+ * platform/mac/ScrollElasticityController.mm:
+ (WebCore::elasticDeltaForReboundDelta):
+ (WebCore::scrollWheelMultiplier):
+ (WebCore::ScrollElasticityController::handleWheelEvent):
+
2012-01-12 Simon Fraser <[email protected]>
Borders and box masks behave incorrectly with overlapping offsets
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h (104852 => 104853)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h 2012-01-12 21:26:58 UTC (rev 104852)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h 2012-01-12 21:28:51 UTC (rev 104853)
@@ -140,7 +140,6 @@
bool pinnedInDirection(float deltaX, float deltaY);
void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*);
- bool smoothScrollWithEvent(const PlatformWheelEvent&);
void beginScrollGesture();
void endScrollGesture();
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (104852 => 104853)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2012-01-12 21:26:58 UTC (rev 104852)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2012-01-12 21:28:51 UTC (rev 104853)
@@ -877,30 +877,6 @@
#if ENABLE(RUBBER_BANDING)
-static const float scrollVelocityZeroingTimeout = 0.10f;
-static const float rubberbandStiffness = 20;
-static const float rubberbandDirectionLockStretchRatio = 1;
-static const float rubberbandMinimumRequiredDeltaBeforeStretch = 10;
-static const float rubberbandAmplitude = 0.31f;
-static const float rubberbandPeriod = 1.6f;
-
-static float elasticDeltaForReboundDelta(float delta)
-{
- float stiffness = std::max(rubberbandStiffness, 1.0f);
- return delta / stiffness;
-}
-
-static float scrollWheelMultiplier()
-{
- static float multiplier = -1;
- if (multiplier < 0) {
- multiplier = [[NSUserDefaults standardUserDefaults] floatForKey:@"NSScrollWheelMultiplier"];
- if (multiplier <= 0)
- multiplier = 1;
- }
- return multiplier;
-}
-
static inline bool isScrollingLeftAndShouldNotRubberBand(const PlatformWheelEvent& wheelEvent, ScrollableArea* scrollableArea)
{
return wheelEvent.deltaX() > 0 && !scrollableArea->shouldRubberBandInDirection(ScrollLeft);
@@ -958,7 +934,7 @@
}
}
- return smoothScrollWithEvent(wheelEvent);
+ return m_scrollElasticityController.handleWheelEvent(wheelEvent);
}
void ScrollAnimatorMac::handleGestureEvent(const PlatformGestureEvent& gestureEvent)
@@ -1092,159 +1068,6 @@
m_snapRubberBandTimer.stop();
}
-bool ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEvent)
-{
- bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhaseNone);
- if (m_scrollElasticityController.m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_scrollElasticityController.m_snapRubberbandTimerIsActive)) {
- if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) {
- m_scrollElasticityController.m_ignoreMomentumScrolls = false;
- return true;
- }
- return false;
- }
-
- m_haveScrolledSincePageLoad = true;
-
- float deltaX = m_scrollElasticityController.m_overflowScrollDelta.width();
- float deltaY = m_scrollElasticityController.m_overflowScrollDelta.height();
-
- // Reset overflow values because we may decide to remove delta at various points and put it into overflow.
- m_scrollElasticityController.m_overflowScrollDelta = FloatSize();
-
- float eventCoalescedDeltaX = -wheelEvent.deltaX();
- float eventCoalescedDeltaY = -wheelEvent.deltaY();
-
- deltaX += eventCoalescedDeltaX;
- deltaY += eventCoalescedDeltaY;
-
- // Slightly prefer scrolling vertically by applying the = case to deltaY
- if (fabsf(deltaY) >= fabsf(deltaX))
- deltaX = 0;
- else
- deltaY = 0;
-
- bool isVerticallyStretched = false;
- bool isHorizontallyStretched = false;
- bool shouldStretch = false;
-
- IntSize stretchAmount = m_scrollElasticityController.m_client->stretchAmount();
-
- isHorizontallyStretched = stretchAmount.width();
- isVerticallyStretched = stretchAmount.height();
-
- PlatformWheelEventPhase phase = wheelEvent.momentumPhase();
-
- // If we are starting momentum scrolling then do some setup.
- if (!m_scrollElasticityController.m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
- m_scrollElasticityController.m_momentumScrollInProgress = true;
-
- CFTimeInterval timeDelta = wheelEvent.timestamp() - m_scrollElasticityController.m_lastMomentumScrollTimestamp;
- if (m_scrollElasticityController.m_inScrollGesture || m_scrollElasticityController.m_momentumScrollInProgress) {
- if (m_scrollElasticityController.m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) {
- m_scrollElasticityController.m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta);
- m_scrollElasticityController.m_momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta);
- m_scrollElasticityController.m_lastMomentumScrollTimestamp = wheelEvent.timestamp();
- } else {
- m_scrollElasticityController.m_lastMomentumScrollTimestamp = wheelEvent.timestamp();
- m_scrollElasticityController.m_momentumVelocity = FloatSize();
- }
-
- if (isVerticallyStretched) {
- if (!isHorizontallyStretched && m_scrollElasticityController.m_client->pinnedInDirection(FloatSize(deltaX, 0))) {
- // Stretching only in the vertical.
- if (deltaY != 0 && (fabsf(deltaX / deltaY) < rubberbandDirectionLockStretchRatio))
- deltaX = 0;
- else if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) {
- m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX);
- deltaX = 0;
- } else
- m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX);
- }
- } else if (isHorizontallyStretched) {
- // Stretching only in the horizontal.
- if (m_scrollElasticityController.m_client->pinnedInDirection(FloatSize(0, deltaY))) {
- if (deltaX != 0 && (fabsf(deltaY / deltaX) < rubberbandDirectionLockStretchRatio))
- deltaY = 0;
- else if (fabsf(deltaY) < rubberbandMinimumRequiredDeltaBeforeStretch) {
- m_scrollElasticityController.m_overflowScrollDelta.setHeight(m_scrollElasticityController.m_overflowScrollDelta.height() + deltaY);
- deltaY = 0;
- } else
- m_scrollElasticityController.m_overflowScrollDelta.setHeight(m_scrollElasticityController.m_overflowScrollDelta.height() + deltaY);
- }
- } else {
- // Not stretching at all yet.
- if (m_scrollElasticityController.m_client->pinnedInDirection(FloatSize(deltaX, deltaY))) {
- if (fabsf(deltaY) >= fabsf(deltaX)) {
- if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) {
- m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX);
- deltaX = 0;
- } else
- m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX);
- }
- shouldStretch = true;
- }
- }
- }
-
- if (deltaX != 0 || deltaY != 0) {
- if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched)) {
- if (deltaY != 0) {
- deltaY *= scrollWheelMultiplier();
- m_scrollElasticityController.m_client->immediateScrollBy(FloatSize(0, deltaY));
- }
- if (deltaX != 0) {
- deltaX *= scrollWheelMultiplier();
- m_scrollElasticityController.m_client->immediateScrollBy(FloatSize(deltaX, 0));
- }
- } else {
- if (!m_scrollElasticityController.m_client->allowsHorizontalStretching()) {
- deltaX = 0;
- eventCoalescedDeltaX = 0;
- } else if ((deltaX != 0) && !isHorizontallyStretched && !pinnedInDirection(deltaX, 0)) {
- deltaX *= scrollWheelMultiplier();
-
- m_scrollElasticityController.m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(deltaX, 0));
- deltaX = 0;
- }
-
- if (!m_scrollElasticityController.m_client->allowsVerticalStretching()) {
- deltaY = 0;
- eventCoalescedDeltaY = 0;
- } else if ((deltaY != 0) && !isVerticallyStretched && !pinnedInDirection(0, deltaY)) {
- deltaY *= scrollWheelMultiplier();
-
- m_scrollElasticityController.m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(0, deltaY));
- deltaY = 0;
- }
-
- IntSize stretchAmount = m_scrollElasticityController.m_client->stretchAmount();
-
- if (m_scrollElasticityController.m_momentumScrollInProgress) {
- if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_scrollElasticityController.m_lastMomentumScrollTimestamp) {
- m_scrollElasticityController.m_ignoreMomentumScrolls = true;
- m_scrollElasticityController.m_momentumScrollInProgress = false;
- m_scrollElasticityController.snapRubberBand();
- }
- }
-
- m_scrollElasticityController.m_stretchScrollForce.setWidth(m_scrollElasticityController.m_stretchScrollForce.width() + deltaX);
- m_scrollElasticityController.m_stretchScrollForce.setHeight(m_scrollElasticityController.m_stretchScrollForce.height() + deltaY);
-
- FloatSize dampedDelta(ceilf(elasticDeltaForReboundDelta(m_scrollElasticityController.m_stretchScrollForce.width())), ceilf(elasticDeltaForReboundDelta(m_scrollElasticityController.m_stretchScrollForce.height())));
-
- m_scrollElasticityController.m_client->immediateScrollByWithoutContentEdgeConstraints(dampedDelta - stretchAmount);
- }
- }
-
- if (m_scrollElasticityController.m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
- m_scrollElasticityController.m_momentumScrollInProgress = false;
- m_scrollElasticityController.m_ignoreMomentumScrolls = false;
- m_scrollElasticityController.m_lastMomentumScrollTimestamp = 0;
- }
-
- return true;
-}
-
void ScrollAnimatorMac::beginScrollGesture()
{
didBeginScrollGesture();
Modified: trunk/Source/WebCore/platform/mac/ScrollElasticityController.h (104852 => 104853)
--- trunk/Source/WebCore/platform/mac/ScrollElasticityController.h 2012-01-12 21:26:58 UTC (rev 104852)
+++ trunk/Source/WebCore/platform/mac/ScrollElasticityController.h 2012-01-12 21:28:51 UTC (rev 104853)
@@ -34,6 +34,8 @@
namespace WebCore {
+class PlatformWheelEvent;
+
class ScrollElasticityControllerClient {
protected:
virtual ~ScrollElasticityControllerClient() { }
@@ -63,6 +65,7 @@
void beginScrollGesture();
+ bool handleWheelEvent(const PlatformWheelEvent&);
void snapRubberBandTimerFired();
private:
Modified: trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm (104852 => 104853)
--- trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm 2012-01-12 21:26:58 UTC (rev 104852)
+++ trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm 2012-01-12 21:28:51 UTC (rev 104853)
@@ -26,6 +26,7 @@
#include "config.h"
#include "ScrollElasticityController.h"
+#include "PlatformWheelEvent.h"
#include <sys/time.h>
#include <sys/sysctl.h>
@@ -67,6 +68,8 @@
static const float scrollVelocityZeroingTimeout = 0.10f;
static const float rubberbandStiffness = 20;
+static const float rubberbandDirectionLockStretchRatio = 1;
+static const float rubberbandMinimumRequiredDeltaBeforeStretch = 10;
static const float rubberbandAmplitude = 0.31f;
static const float rubberbandPeriod = 1.6f;
@@ -79,11 +82,28 @@
return (initialPosition + (-initialVelocity * elapsedTime * amplitude)) * criticalDampeningFactor;
}
+static float elasticDeltaForReboundDelta(float delta)
+{
+ float stiffness = std::max(rubberbandStiffness, 1.0f);
+ return delta / stiffness;
+}
+
static float reboundDeltaForElasticDelta(float delta)
{
return delta * rubberbandStiffness;
}
+static float scrollWheelMultiplier()
+{
+ static float multiplier = -1;
+ if (multiplier < 0) {
+ multiplier = [[NSUserDefaults standardUserDefaults] floatForKey:@"NSScrollWheelMultiplier"];
+ if (multiplier <= 0)
+ multiplier = 1;
+ }
+ return multiplier;
+}
+
ScrollElasticityController::ScrollElasticityController(ScrollElasticityControllerClient* client)
: m_client(client)
, m_inScrollGesture(false)
@@ -112,6 +132,157 @@
stopSnapRubberbandTimer();
}
+bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
+{
+ bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhaseNone);
+ if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberbandTimerIsActive)) {
+ if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) {
+ m_ignoreMomentumScrolls = false;
+ return true;
+ }
+ return false;
+ }
+
+ float deltaX = m_overflowScrollDelta.width();
+ float deltaY = m_overflowScrollDelta.height();
+
+ // Reset overflow values because we may decide to remove delta at various points and put it into overflow.
+ m_overflowScrollDelta = FloatSize();
+
+ float eventCoalescedDeltaX = -wheelEvent.deltaX();
+ float eventCoalescedDeltaY = -wheelEvent.deltaY();
+
+ deltaX += eventCoalescedDeltaX;
+ deltaY += eventCoalescedDeltaY;
+
+ // Slightly prefer scrolling vertically by applying the = case to deltaY
+ if (fabsf(deltaY) >= fabsf(deltaX))
+ deltaX = 0;
+ else
+ deltaY = 0;
+
+ bool isVerticallyStretched = false;
+ bool isHorizontallyStretched = false;
+ bool shouldStretch = false;
+
+ IntSize stretchAmount = m_client->stretchAmount();
+
+ isHorizontallyStretched = stretchAmount.width();
+ isVerticallyStretched = stretchAmount.height();
+
+ PlatformWheelEventPhase phase = wheelEvent.momentumPhase();
+
+ // If we are starting momentum scrolling then do some setup.
+ if (!m_momentumScrollInProgress && (phase == PlatformWheelEventPhaseBegan || phase == PlatformWheelEventPhaseChanged))
+ m_momentumScrollInProgress = true;
+
+ CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTimestamp;
+ if (m_inScrollGesture || m_momentumScrollInProgress) {
+ if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) {
+ m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta);
+ m_momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta);
+ m_lastMomentumScrollTimestamp = wheelEvent.timestamp();
+ } else {
+ m_lastMomentumScrollTimestamp = wheelEvent.timestamp();
+ m_momentumVelocity = FloatSize();
+ }
+
+ if (isVerticallyStretched) {
+ if (!isHorizontallyStretched && m_client->pinnedInDirection(FloatSize(deltaX, 0))) {
+ // Stretching only in the vertical.
+ if (deltaY != 0 && (fabsf(deltaX / deltaY) < rubberbandDirectionLockStretchRatio))
+ deltaX = 0;
+ else if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) {
+ m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);
+ deltaX = 0;
+ } else
+ m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);
+ }
+ } else if (isHorizontallyStretched) {
+ // Stretching only in the horizontal.
+ if (m_client->pinnedInDirection(FloatSize(0, deltaY))) {
+ if (deltaX != 0 && (fabsf(deltaY / deltaX) < rubberbandDirectionLockStretchRatio))
+ deltaY = 0;
+ else if (fabsf(deltaY) < rubberbandMinimumRequiredDeltaBeforeStretch) {
+ m_overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY);
+ deltaY = 0;
+ } else
+ m_overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY);
+ }
+ } else {
+ // Not stretching at all yet.
+ if (m_client->pinnedInDirection(FloatSize(deltaX, deltaY))) {
+ if (fabsf(deltaY) >= fabsf(deltaX)) {
+ if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) {
+ m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);
+ deltaX = 0;
+ } else
+ m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);
+ }
+ shouldStretch = true;
+ }
+ }
+ }
+
+ if (deltaX != 0 || deltaY != 0) {
+ if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched)) {
+ if (deltaY != 0) {
+ deltaY *= scrollWheelMultiplier();
+ m_client->immediateScrollBy(FloatSize(0, deltaY));
+ }
+ if (deltaX != 0) {
+ deltaX *= scrollWheelMultiplier();
+ m_client->immediateScrollBy(FloatSize(deltaX, 0));
+ }
+ } else {
+ if (!m_client->allowsHorizontalStretching()) {
+ deltaX = 0;
+ eventCoalescedDeltaX = 0;
+ } else if ((deltaX != 0) && !isHorizontallyStretched && !m_client->pinnedInDirection(FloatSize(deltaX, 0))) {
+ deltaX *= scrollWheelMultiplier();
+
+ m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(deltaX, 0));
+ deltaX = 0;
+ }
+
+ if (!m_client->allowsVerticalStretching()) {
+ deltaY = 0;
+ eventCoalescedDeltaY = 0;
+ } else if ((deltaY != 0) && !isVerticallyStretched && !m_client->pinnedInDirection(FloatSize(0, deltaY))) {
+ deltaY *= scrollWheelMultiplier();
+
+ m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(0, deltaY));
+ deltaY = 0;
+ }
+
+ IntSize stretchAmount = m_client->stretchAmount();
+
+ if (m_momentumScrollInProgress) {
+ if ((m_client->pinnedInDirection(FloatSize(eventCoalescedDeltaX, eventCoalescedDeltaY)) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) {
+ m_ignoreMomentumScrolls = true;
+ m_momentumScrollInProgress = false;
+ snapRubberBand();
+ }
+ }
+
+ m_stretchScrollForce.setWidth(m_stretchScrollForce.width() + deltaX);
+ m_stretchScrollForce.setHeight(m_stretchScrollForce.height() + deltaY);
+
+ FloatSize dampedDelta(ceilf(elasticDeltaForReboundDelta(m_stretchScrollForce.width())), ceilf(elasticDeltaForReboundDelta(m_stretchScrollForce.height())));
+
+ m_client->immediateScrollByWithoutContentEdgeConstraints(dampedDelta - stretchAmount);
+ }
+ }
+
+ if (m_momentumScrollInProgress && phase == PlatformWheelEventPhaseEnded) {
+ m_momentumScrollInProgress = false;
+ m_ignoreMomentumScrolls = false;
+ m_lastMomentumScrollTimestamp = 0;
+ }
+
+ return true;
+}
+
static inline float roundTowardZero(float num)
{
return num > 0 ? ceilf(num - 0.5f) : floorf(num + 0.5f);