diff --git a/browser/base/content/browser-gestureSupport.js b/browser/base/content/browser-gestureSupport.js index 2b1674dee290..0f420bbd27c5 100644 --- a/browser/base/content/browser-gestureSupport.js +++ b/browser/base/content/browser-gestureSupport.js @@ -25,7 +25,7 @@ let gGestureSupport = { * True to add/init listeners and false to remove/uninit */ init: function GS_init(aAddListener) { - const gestureEvents = ["SwipeGestureStart", + const gestureEvents = ["SwipeGestureMayStart", "SwipeGestureStart", "SwipeGestureUpdate", "SwipeGestureEnd", "SwipeGesture", "MagnifyGestureStart", "MagnifyGestureUpdate", "MagnifyGesture", "RotateGestureStart", "RotateGestureUpdate", "RotateGesture", @@ -58,11 +58,15 @@ let gGestureSupport = { ({ threshold: aThreshold, latched: !!aLatched }); switch (aEvent.type) { - case "MozSwipeGestureStart": - if (this._setupSwipeGesture(aEvent)) { + case "MozSwipeGestureMayStart": + if (this._shouldDoSwipeGesture(aEvent)) { aEvent.preventDefault(); } break; + case "MozSwipeGestureStart": + aEvent.preventDefault(); + this._setupSwipeGesture(); + break; case "MozSwipeGestureUpdate": aEvent.preventDefault(); this._doUpdate(aEvent); @@ -173,15 +177,15 @@ let gGestureSupport = { }, /** - * Sets up swipe gestures. This includes setting up swipe animations for the - * gesture, if enabled. + * Checks whether we want to start a swipe for aEvent and sets + * aEvent.allowedDirections to the right values. * * @param aEvent - * The swipe gesture start event. - * @return true if swipe gestures could successfully be set up, false - * othwerwise. + * The swipe gesture "MayStart" event. + * @return true if we're willing to start a swipe for this event, false + * otherwise. */ - _setupSwipeGesture: function GS__setupSwipeGesture(aEvent) { + _shouldDoSwipeGesture: function GS__shouldDoSwipeGesture(aEvent) { if (!this._swipeNavigatesHistory(aEvent)) { return false; } @@ -217,7 +221,20 @@ let gGestureSupport = { aEvent.DIRECTION_LEFT; } - gHistorySwipeAnimation.startAnimation(isVerticalSwipe); + return true; + }, + + /** + * Sets up swipe gestures. This includes setting up swipe animations for the + * gesture, if enabled. + * + * @param aEvent + * The swipe gesture start event. + * @return true if swipe gestures could successfully be set up, false + * othwerwise. + */ + _setupSwipeGesture: function GS__setupSwipeGesture() { + gHistorySwipeAnimation.startAnimation(false); this._doUpdate = function GS__doUpdate(aEvent) { gHistorySwipeAnimation.updateAnimation(aEvent.delta); @@ -229,8 +246,6 @@ let gGestureSupport = { this._doUpdate = function (aEvent) {}; this._doEnd = function (aEvent) {}; } - - return true; }, /** diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index aa096016f111..644be126ee30 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1315,7 +1315,9 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType, return NS_ERROR_FAILURE; EventMessage msg; - if (aType.EqualsLiteral("MozSwipeGestureStart")) + if (aType.EqualsLiteral("MozSwipeGestureMayStart")) + msg = NS_SIMPLE_GESTURE_SWIPE_MAY_START; + else if (aType.EqualsLiteral("MozSwipeGestureStart")) msg = NS_SIMPLE_GESTURE_SWIPE_START; else if (aType.EqualsLiteral("MozSwipeGestureUpdate")) msg = NS_SIMPLE_GESTURE_SWIPE_UPDATE; diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index c82344e6ce43..588cd5029e6e 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -1863,6 +1863,7 @@ GK_ATOM(seconds, "seconds") GK_ATOM(secondsFromDateTime, "seconds-from-dateTime") // Simple gestures support +GK_ATOM(onMozSwipeGestureMayStart, "onMozSwipeGestureMayStart") GK_ATOM(onMozSwipeGestureStart, "onMozSwipeGestureStart") GK_ATOM(onMozSwipeGestureUpdate, "onMozSwipeGestureUpdate") GK_ATOM(onMozSwipeGestureEnd, "onMozSwipeGestureEnd") diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h index 48ab186d5632..f13f33d352cc 100644 --- a/dom/events/EventNameList.h +++ b/dom/events/EventNameList.h @@ -839,6 +839,10 @@ NON_IDL_EVENT(gamepaddisconnected, #endif // Simple gesture events +NON_IDL_EVENT(MozSwipeGestureMayStart, + NS_SIMPLE_GESTURE_SWIPE_MAY_START, + EventNameType_None, + eSimpleGestureEventClass) NON_IDL_EVENT(MozSwipeGestureStart, NS_SIMPLE_GESTURE_SWIPE_START, EventNameType_None, diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 42fe5afb9f47..d0f8489ce5e6 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -819,11 +819,11 @@ interface nsIDOMWindowUtils : nsISupports { void runNextCollectorTimer(); /** Synthesize a simple gesture event for a window. The event types - * supported are: MozSwipeGestureStart, MozSwipeGestureUpdate, - * MozSwipeGestureEnd, MozSwipeGesture, MozMagnifyGestureStart, - * MozMagnifyGestureUpdate, MozMagnifyGesture, MozRotateGestureStart, - * MozRotateGestureUpdate, MozRotateGesture, MozPressTapGesture, - * MozTapGesture, and MozEdgeUIGesture. + * supported are: MozSwipeGestureMayStart, MozSwipeGestureStart, + * MozSwipeGestureUpdate, MozSwipeGestureEnd, MozSwipeGesture, + * MozMagnifyGestureStart, MozMagnifyGestureUpdate, MozMagnifyGesture, + * MozRotateGestureStart, MozRotateGestureUpdate, MozRotateGesture, + * MozPressTapGesture, MozTapGesture, and MozEdgeUIGesture. * * Cannot be accessed from unprivileged context (not * content-accessible) Will throw a DOM security error if called diff --git a/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl b/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl index 346bd6f6edbf..e3642752ce38 100644 --- a/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl +++ b/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl @@ -12,20 +12,25 @@ * * The following events are generated: * - * MozSwipeGestureStart - Generated when the user starts a horizontal - * swipe across the input device. This event not only acts as a signal, - * but also asks two questions: Should a swipe really be started, and + * MozSwipeGestureMayStart - Generated when the user starts a horizontal + * swipe across the input device, but before we know whether the user + * is actually scrolling past a scroll edge. + * This event asks two questions: Should a swipe really be started, and * in which directions should the user be able to swipe? The first * question is answered by event listeners by calling or not calling * preventDefault() on the event. Since a swipe swallows all scroll * events, the default action of the swipe start event is *not* to * start a swipe. Call preventDefault() if you want a swipe to be - * started. + * started. Doing so won't necessarily result in a swipe being started, + * it only communicates an intention. Once Gecko determines whether a + * swipe should actually be started, it will send a MozSwipeGestureStart + * event. * The second question (swipe-able directions) is answered in the * allowedDirections field. - * If this event has preventDefault() called on it (and thus starts - * a swipe), it guarantees a future MozSwipeGestureEnd event that - * will signal the end of a swipe animation. + * + * MozSwipeGestureStart - This event signals the start of a swipe. + * It guarantees a future MozSwipeGestureEnd event that will signal + * the end of a swipe animation. * * MozSwipeGestureUpdate - Generated periodically while the user is * continuing a horizontal swipe gesture. The "delta" value represents @@ -117,14 +122,14 @@ interface nsIDOMSimpleGestureEvent : nsIDOMMouseEvent * Reports the directions that can be swiped to; multiple directions * should be OR'ed together. * - * The allowedDirections field is designed to be set on SwipeGestureStart + * The allowedDirections field is designed to be set on SwipeGestureMayStart * events by event listeners. Its value after event dispatch determines - * the behavior of the swipe animation that is about to begin. + * the behavior of the swipe animation that might be about to begin. * Specifically, if the user swipes in a direction that can't be swiped * to, the animation will have a bounce effect. * Future SwipeGestureUpdate, SwipeGesture and SwipeGestureEnd events - * will carry the allowDirections value that was set on the SwipeStart - * event. Changing this field on non-SwipeGestureStart events doesn't + * will carry the allowDirections value that was set on the SwipeMayStart + * event. Changing this field on non-SwipeGestureMayStart events doesn't * have any effect. */ attribute unsigned long allowedDirections; diff --git a/widget/EventMessageList.h b/widget/EventMessageList.h index b16303cf8083..8aad5ec80b23 100644 --- a/widget/EventMessageList.h +++ b/widget/EventMessageList.h @@ -272,21 +272,22 @@ NS_EVENT_MESSAGE(NS_AFTERPAINT, NS_NOTIFYPAINT_START) // Simple gesture events NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EVENT_START, 3500) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_START, NS_SIMPLE_GESTURE_EVENT_START) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 1) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_END, NS_SIMPLE_GESTURE_EVENT_START + 2) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE, NS_SIMPLE_GESTURE_EVENT_START + 3) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY_START, NS_SIMPLE_GESTURE_EVENT_START + 4) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 5) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY, NS_SIMPLE_GESTURE_EVENT_START + 6) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE_START, NS_SIMPLE_GESTURE_EVENT_START + 7) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 8) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE, NS_SIMPLE_GESTURE_EVENT_START + 9) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_TAP, NS_SIMPLE_GESTURE_EVENT_START + 10) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_PRESSTAP, NS_SIMPLE_GESTURE_EVENT_START + 11) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_STARTED, NS_SIMPLE_GESTURE_EVENT_START + 12) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_CANCELED, NS_SIMPLE_GESTURE_EVENT_START + 13) -NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_COMPLETED, NS_SIMPLE_GESTURE_EVENT_START + 14) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_MAY_START,NS_SIMPLE_GESTURE_EVENT_START) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_START, NS_SIMPLE_GESTURE_EVENT_START + 1) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 2) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE_END, NS_SIMPLE_GESTURE_EVENT_START + 3) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_SWIPE, NS_SIMPLE_GESTURE_EVENT_START + 4) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY_START, NS_SIMPLE_GESTURE_EVENT_START + 5) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 6) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_MAGNIFY, NS_SIMPLE_GESTURE_EVENT_START + 7) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE_START, NS_SIMPLE_GESTURE_EVENT_START + 8) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE_UPDATE, NS_SIMPLE_GESTURE_EVENT_START + 9) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_ROTATE, NS_SIMPLE_GESTURE_EVENT_START + 10) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_TAP, NS_SIMPLE_GESTURE_EVENT_START + 11) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_PRESSTAP, NS_SIMPLE_GESTURE_EVENT_START + 12) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_STARTED, NS_SIMPLE_GESTURE_EVENT_START + 13) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_CANCELED, NS_SIMPLE_GESTURE_EVENT_START + 14) +NS_EVENT_MESSAGE(NS_SIMPLE_GESTURE_EDGE_COMPLETED, NS_SIMPLE_GESTURE_EVENT_START + 15) // These are used to send native events to plugins. NS_EVENT_MESSAGE(NS_PLUGIN_EVENT_START, 3600) diff --git a/widget/cocoa/SwipeTracker.mm b/widget/cocoa/SwipeTracker.mm index 7b9777e09d61..efa0ce452a1c 100644 --- a/widget/cocoa/SwipeTracker.mm +++ b/widget/cocoa/SwipeTracker.mm @@ -51,6 +51,7 @@ SwipeTracker::SwipeTracker(nsChildView& aWidget, , mEventsHaveStartedNewGesture(false) , mRegisteredWithRefreshDriver(false) { + SendSwipeEvent(NS_SIMPLE_GESTURE_SWIPE_START, 0, 0.0); ProcessEvent(aSwipeStartEvent); } diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 7ec15c0ce117..b852ea67cf11 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -2585,7 +2585,7 @@ nsChildView::MaybeTrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipe LayoutDeviceIntPoint position = RoundedToInt(aSwipeStartEvent.mPanStartPoint * ScreenToLayoutDeviceScale(1)); WidgetSimpleGestureEvent geckoEvent = - SwipeTracker::CreateSwipeGestureEvent(NS_SIMPLE_GESTURE_SWIPE_START, this, position); + SwipeTracker::CreateSwipeGestureEvent(NS_SIMPLE_GESTURE_SWIPE_MAY_START, this, position); geckoEvent.direction = direction; geckoEvent.delta = 0.0; geckoEvent.allowedDirections = 0;