Bug 1016035 - Add a MozSwipeGestureMayStart event. r=kats

Having this event means that we don't have to wait for content to find out whether it's scrollable in the case that no swipe should be happening anyway.

IGNORE IDL because I'm only changing comments in the IDL files.

--HG--
extra : commitid : 22814fSLcIz
extra : rebase_source : e51b4db26333275c9bcb3fd7fece78b7d3653275
This commit is contained in:
Markus Stange 2015-08-27 15:06:21 -04:00
Родитель 0297e0ac04
Коммит 0441fca5af
9 изменённых файлов: 74 добавлений и 45 удалений

Просмотреть файл

@ -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;
},
/**

Просмотреть файл

@ -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;

Просмотреть файл

@ -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")

Просмотреть файл

@ -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,

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

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

Просмотреть файл

@ -51,6 +51,7 @@ SwipeTracker::SwipeTracker(nsChildView& aWidget,
, mEventsHaveStartedNewGesture(false)
, mRegisteredWithRefreshDriver(false)
{
SendSwipeEvent(NS_SIMPLE_GESTURE_SWIPE_START, 0, 0.0);
ProcessEvent(aSwipeStartEvent);
}

Просмотреть файл

@ -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;