From e6453f4c35edbb8dbde638984b74d1d7f6c4ecf2 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Mon, 28 Mar 2016 14:56:28 -0400 Subject: [PATCH] Bug 1254275 - Inspect the event queue to find out whether momentum events are following. r=kats a=ritu MozReview-Commit-ID: 6k3SaJ6X7Mr --- gfx/layers/apz/src/AsyncPanZoomController.cpp | 4 ++++ widget/InputData.h | 5 +++++ widget/cocoa/nsChildView.mm | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 3b62337fc40..0b6cbe45c02 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -1992,6 +1992,10 @@ nsEventStatus AsyncPanZoomController::OnPanEnd(const PanGestureInput& aEvent) { SetState(NOTHING); RequestContentRepaint(); + if (!aEvent.mFollowedByMomentum) { + RequestSnap(); + } + return nsEventStatus_eConsumeNoDefault; } diff --git a/widget/InputData.h b/widget/InputData.h index 304fbd539df..a96f155897f 100644 --- a/widget/InputData.h +++ b/widget/InputData.h @@ -358,6 +358,7 @@ public: mLineOrPageDeltaX(0), mLineOrPageDeltaY(0), mHandledByAPZ(false), + mFollowedByMomentum(false), mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false) { } @@ -385,6 +386,10 @@ public: bool mHandledByAPZ; + // true if this is a PANGESTURE_END event that will be followed by a + // PANGESTURE_MOMENTUMSTART event. + bool mFollowedByMomentum; + // If this is true, and this event started a new input block that couldn't // find a scrollable target which is scrollable in the horizontal component // of the scroll start direction, then this input block needs to be put on diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 2f7795ef51d..e003c3cbf9e 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -4963,6 +4963,20 @@ PanGestureTypeForEvent(NSEvent* aEvent) panEvent.mLineOrPageDeltaX = lineOrPageDeltaX; panEvent.mLineOrPageDeltaY = lineOrPageDeltaY; + if (panEvent.mType == PanGestureInput::PANGESTURE_END) { + // Check if there's a momentum start event in the event queue, so that we + // can annotate this event. + NSEvent* nextWheelEvent = + [NSApp nextEventMatchingMask:NSScrollWheelMask + untilDate:[NSDate distantPast] + inMode:NSDefaultRunLoopMode + dequeue:NO]; + if (nextWheelEvent && + PanGestureTypeForEvent(nextWheelEvent) == PanGestureInput::PANGESTURE_MOMENTUMSTART) { + panEvent.mFollowedByMomentum = true; + } + } + bool canTriggerSwipe = [self shouldConsiderStartingSwipeFromEvent:theEvent]; panEvent.mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection = canTriggerSwipe; mGeckoChild->DispatchAPZWheelInputEvent(panEvent, canTriggerSwipe);