Index: Source/platform/mac/ScrollElasticityController.mm |
diff --git a/Source/platform/mac/ScrollElasticityController.mm b/Source/platform/mac/ScrollElasticityController.mm |
index 0ab305b6ab91823e3ff09e4e30feebf082a77ac4..5013e4d09e173c6b04a6bf72ac3621dc21ca74fe 100644 |
--- a/Source/platform/mac/ScrollElasticityController.mm |
+++ b/Source/platform/mac/ScrollElasticityController.mm |
@@ -99,6 +99,7 @@ static float scrollWheelMultiplier() |
ScrollElasticityController::ScrollElasticityController(ScrollElasticityControllerClient* client) |
: m_client(client) |
, m_inScrollGesture(false) |
+ , m_hasScrolled(false) |
, m_momentumScrollInProgress(false) |
, m_ignoreMomentumScrolls(false) |
, m_lastMomentumScrollTimestamp(0) |
@@ -109,13 +110,11 @@ ScrollElasticityController::ScrollElasticityController(ScrollElasticityControlle |
bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& wheelEvent) |
{ |
+ // When a new gesture begins, reset all state that might have been carried |
+ // over from the last event. |
if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { |
- // First, check if we should rubber-band at all. |
- if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) && |
- !shouldRubberBandInHorizontalDirection(wheelEvent)) |
- return false; |
- |
m_inScrollGesture = true; |
+ m_hasScrolled = false; |
m_momentumScrollInProgress = false; |
m_ignoreMomentumScrolls = false; |
m_lastMomentumScrollTimestamp = 0; |
@@ -128,10 +127,10 @@ bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee |
stopSnapRubberbandTimer(); |
- return true; |
+ return shouldHandleEvent(wheelEvent); |
} |
- if (wheelEvent.phase() == PlatformWheelEventPhaseEnded) { |
+ if (wheelEvent.phase() == PlatformWheelEventPhaseEnded || wheelEvent.phase() == PlatformWheelEventPhaseCancelled) { |
erikchen
2014/03/24 22:12:05
this change wasn't necessary to make this CL work,
|
bool wasRubberBandInProgress = isRubberBandInProgress(); |
// Call snapRubberBand() even if isRubberBandInProgress() is false. For example, |
// m_inScrollGesture may be true (and needs to be reset on a phase end) even if |
@@ -149,6 +148,9 @@ bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee |
return false; |
} |
+ if (!shouldHandleEvent(wheelEvent)) |
+ return false; |
+ |
float deltaX = m_overflowScrollDelta.width(); |
float deltaY = m_overflowScrollDelta.height(); |
@@ -241,6 +243,7 @@ bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee |
} |
if (deltaX != 0 || deltaY != 0) { |
+ m_hasScrolled = true; |
if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched)) { |
if (deltaY != 0) { |
deltaY *= scrollWheelMultiplier(); |
@@ -413,12 +416,17 @@ void ScrollElasticityController::snapRubberBand() |
m_snapRubberbandTimerIsActive = true; |
} |
-bool ScrollElasticityController::shouldRubberBandInHorizontalDirection(const PlatformWheelEvent& wheelEvent) |
+bool ScrollElasticityController::shouldHandleEvent(const PlatformWheelEvent& wheelEvent) |
{ |
- if (wheelEvent.deltaX() > 0) |
- return m_client->shouldRubberBandInDirection(ScrollLeft); |
- if (wheelEvent.deltaX() < 0) |
- return m_client->shouldRubberBandInDirection(ScrollRight); |
+ if (m_hasScrolled) |
+ return true; |
+ if (!m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0))) |
+ return true; |
+ |
+ if (wheelEvent.deltaX() > 0 && !wheelEvent.canRubberbandLeft()) |
+ return false; |
+ if (wheelEvent.deltaX() < 0 && !wheelEvent.canRubberbandRight()) |
+ return false; |
return true; |
} |