Bug 1087608 - ensuring multitap gestures do not resolve to explore. r=eeejay, a=ritu
authorYura Zenevich <yzenevich@mozilla.com>
Mon, 21 Mar 2016 17:26:49 -0400
changeset 325707 5e58ca6ae7033872ae13d95fc8ee92f7f0eedd8a
parent 325706 3e3bdbc7ac120e442fe099adcab8ffc6b4eb1d02
child 325708 bc5fc975a47a6c864f215a63003ffcf6ab4eaef3
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay, ritu
bugs1087608
milestone47.0a2
Bug 1087608 - ensuring multitap gestures do not resolve to explore. r=eeejay, a=ritu MozReview-Commit-ID: 9CZm709gGMC
accessible/jsat/Gestures.jsm
--- a/accessible/jsat/Gestures.jsm
+++ b/accessible/jsat/Gestures.jsm
@@ -8,20 +8,18 @@
 /******************************************************************************
   All gestures have the following pathways when being resolved(v)/rejected(x):
                Tap -> DoubleTap        (x)
                    -> Dwell            (x)
                    -> Swipe            (x)
 
          DoubleTap -> TripleTap        (x)
                    -> TapHold          (x)
-                   -> Explore          (x)
 
          TripleTap -> DoubleTapHold    (x)
-                   -> Explore          (x)
 
              Dwell -> DwellEnd         (v)
 
              Swipe -> Explore          (x)
 
            TapHold -> TapHoldEnd       (v)
 
      DoubleTapHold -> DoubleTapHoldEnd (v)
@@ -34,17 +32,16 @@
 
         ExploreEnd -> Explore          (x)
 
            Explore -> ExploreEnd       (v)
 ******************************************************************************/
 
 'use strict';
 
-const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = ['GestureSettings', 'GestureTracker']; // jshint ignore:line
 
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 
 XPCOMUtils.defineLazyModuleGetter(this, 'Utils', // jshint ignore:line
   'resource://gre/modules/accessibility/Utils.jsm');
@@ -68,18 +65,16 @@ const MAX_CONSECUTIVE_GESTURE_DELAY = 20
 const DWELL_THRESHOLD = 250;
 // Minimal swipe distance in inches
 const SWIPE_MIN_DISTANCE = 0.4;
 // Maximum distance the pointer could move during a tap in inches
 const TAP_MAX_RADIUS = 0.2;
 // Directness coefficient. It is based on the maximum 15 degree angle between
 // consequent pointer move lines.
 const DIRECTNESS_COEFF = 1.44;
-// The virtual touch ID generated by a mouse event.
-const MOUSE_ID = 'mouse';
 // Amount in inches from the edges of the screen for it to be an edge swipe
 const EDGE = 0.1;
 // Multiply timeouts by this constant, x2 works great too for slower users.
 const TIMEOUT_MULTIPLIER = 1;
 // A single pointer down/up sequence periodically precedes the tripple swipe
 // gesture on Android. This delay acounts for that.
 const IS_ANDROID = Utils.MozBuildApp === 'mobile/android' &&
   Utils.AndroidSdkVersion >= 14;
@@ -206,17 +201,16 @@ this.GestureTracker = { // jshint ignore
    * @param  {Number} aTimeStamp A new pointer event timeStamp.
    * @param  {Function} aGesture A gesture constructor (default: Tap).
    */
   _init: function GestureTracker__init(aDetail, aTimeStamp, aGesture) {
     // Only create a new gesture on |pointerdown| event.
     if (aDetail.type !== 'pointerdown') {
       return;
     }
-    let points = aDetail.points;
     let GestureConstructor = aGesture || (IS_ANDROID ? DoubleTap : Tap);
     this._create(GestureConstructor);
     this._update(aDetail, aTimeStamp);
   },
 
   /**
    * Handle the incoming pointer event with the existing gesture object(if
    * present) or with the newly created one.
@@ -265,16 +259,17 @@ this.GestureTracker = { // jshint ignore
     if (!current || current.id !== id) {
       return;
     }
     // Only create a gesture if we got a constructor.
     if (gestureType) {
       this._create(gestureType, current.startTime, current.points,
         current.lastEvent);
     } else {
+      this.current.clearTimer();
       delete this.current;
     }
   }
 };
 
 /**
  * Compile a mozAccessFuGesture detail structure.
  * @param  {String} aType A gesture type.
@@ -603,16 +598,19 @@ function TravelGesture(aTimeStamp, aPoin
 
 TravelGesture.prototype = Object.create(Gesture.prototype);
 
 /**
  * Test the gesture points for travel. The gesture will be rejected to
  * this._travelTo gesture iff at least one point crosses this._threshold.
  */
 TravelGesture.prototype.test = function TravelGesture_test() {
+  if (!this._travelTo) {
+    return;
+  }
   for (let identifier in this.points) {
     let point = this.points[identifier];
     if (point.totalDistanceTraveled / Utils.dpi > this._threshold) {
       this._deferred.reject(this._travelTo);
       return;
     }
   }
 };
@@ -675,20 +673,20 @@ DoubleTapHoldEnd.prototype.type = 'doubl
  * A common tap gesture object.
  * @param {Number} aTimeStamp An original pointer event's timeStamp that started
  * the gesture resolution sequence.
  * @param {Object} aPoints An existing set of points (from previous events).
  * @param {?String} aLastEvent Last pointer event type.
  * @param {Function} aRejectToOnWait A constructor for the next gesture to
  * reject to in case no pointermove or pointerup happens within the
  * GestureSettings.dwellThreshold.
+ * @param {Function} aTravelTo An optional constuctor for the next gesture to
+ * reject to in case the the TravelGesture test fails.
  * @param {Function} aRejectToOnPointerDown A constructor for the gesture to
  * reject to if a finger comes down immediately after the tap.
- * @param {Function} aTravelTo An optional constuctor for the next gesture to
- * reject to in case the the TravelGesture test fails.
  */
 function TapGesture(aTimeStamp, aPoints, aLastEvent, aRejectToOnWait, aTravelTo, aRejectToOnPointerDown) {
   this._rejectToOnWait = aRejectToOnWait;
   this._rejectToOnPointerDown = aRejectToOnPointerDown;
   // If the pointer travels, reject to aTravelTo.
   TravelGesture.call(this, aTimeStamp, aPoints, aLastEvent, aTravelTo,
     TAP_MAX_RADIUS);
 }
@@ -717,21 +715,22 @@ TapGesture.prototype.pointerup = functio
         }
       }
     } else {
       TravelGesture.prototype.pointerup.call(this, aPoints);
     }
 };
 
 TapGesture.prototype.pointerdown = function TapGesture_pointerdown(aPoints, aTimeStamp) {
-  TravelGesture.prototype.pointerdown.call(this, aPoints, aTimeStamp);
   if (this._pointerUpTimer) {
     clearTimeout(this._pointerUpTimer);
     delete this._pointerUpTimer;
     this._deferred.reject(this._rejectToOnPointerDown);
+  } else {
+    TravelGesture.prototype.pointerdown.call(this, aPoints, aTimeStamp);
   }
 };
 
 
 /**
  * Tap gesture.
  * @param {Number} aTimeStamp An original pointer event's timeStamp that started
  * the gesture resolution sequence.
@@ -766,17 +765,17 @@ DoubleTap.prototype.type = 'doubletap';
  * Triple Tap gesture.
  * @param {Number} aTimeStamp An original pointer event's timeStamp that started
  * the gesture resolution sequence.
  * @param {Object} aPoints An existing set of points (from previous events).
  * @param {?String} aLastEvent Last pointer event type.
  */
 function TripleTap(aTimeStamp, aPoints, aLastEvent) {
   this._inProgress = true;
-  TapGesture.call(this, aTimeStamp, aPoints, aLastEvent, DoubleTapHold);
+  TapGesture.call(this, aTimeStamp, aPoints, aLastEvent, DoubleTapHold, null, null);
 }
 
 TripleTap.prototype = Object.create(TapGesture.prototype);
 TripleTap.prototype.type = 'tripletap';
 
 /**
  * Common base object for gestures that are created as resolved.
  * @param {Number} aTimeStamp An original pointer event's timeStamp that started