Bug 1463139: calculate Y-span for one-touch-pinch gesture from point that gesture began (which occurs after a brief delay) instead of first touch point. r=kats
authorAdam D. Walling <adam.walling@gmail.com>
Mon, 11 Jun 2018 11:52:52 -0400
changeset 422304 90d7fb47fbe9
parent 422303 d241a10ff148
child 422305 4bed64165131
push id104210
push userkgupta@mozilla.com
push dateMon, 11 Jun 2018 20:18:01 +0000
treeherdermozilla-inbound@90d7fb47fbe9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1463139
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1463139: calculate Y-span for one-touch-pinch gesture from point that gesture began (which occurs after a brief delay) instead of first touch point. r=kats
gfx/layers/apz/src/GestureEventListener.cpp
gfx/layers/apz/src/GestureEventListener.h
--- a/gfx/layers/apz/src/GestureEventListener.cpp
+++ b/gfx/layers/apz/src/GestureEventListener.cpp
@@ -47,19 +47,20 @@ ParentLayerPoint GetCurrentFocus(const M
 ParentLayerCoord GetCurrentSpan(const MultiTouchInput& aEvent)
 {
   const ParentLayerPoint& firstTouch = aEvent.mTouches[0].mLocalScreenPoint;
   const ParentLayerPoint& secondTouch = aEvent.mTouches[1].mLocalScreenPoint;
   ParentLayerPoint delta = secondTouch - firstTouch;
   return delta.Length();
 }
 
-ParentLayerCoord GestureEventListener::GetYSpanFromStartPoint()
+ParentLayerCoord GestureEventListener::GetYSpanFromGestureStartPoint()
 {
-  const ParentLayerPoint start = mTouchStartPosition;
+  // use the position that began the one-touch-pinch gesture rather mTouchStartPosition
+  const ParentLayerPoint start = mOneTouchPinchStartPosition;
   const ParentLayerPoint& current = mTouches[0].mLocalScreenPoint;
   return current.y - start.y;
 }
 
 TapGestureInput CreateTapEvent(const MultiTouchInput& aTouch, TapGestureInput::TapGestureType aType)
 {
   return TapGestureInput(aType,
                          aTouch.mTime,
@@ -308,16 +309,19 @@ nsEventStatus GestureEventListener::Hand
         break;
       }
 
       SetState(GESTURE_ONE_TOUCH_PINCH);
 
       ParentLayerCoord currentSpan = 1.0f;
       ParentLayerPoint currentFocus = mTouchStartPosition;
 
+      // save the position that the one-touch-pinch gesture actually begins
+      mOneTouchPinchStartPosition = mLastTouchInput.mTouches[0].mLocalScreenPoint;
+
       PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_START,
                                    mLastTouchInput.mTime,
                                    mLastTouchInput.mTimeStamp,
                                    currentFocus,
                                    currentSpan,
                                    currentSpan,
                                    mLastTouchInput.modifiers);
 
@@ -383,17 +387,17 @@ nsEventStatus GestureEventListener::Hand
 
     rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
     mPreviousSpan = currentSpan;
 
     break;
   }
 
   case GESTURE_ONE_TOUCH_PINCH: {
-    ParentLayerCoord currentSpan = GetYSpanFromStartPoint();
+    ParentLayerCoord currentSpan = GetYSpanFromGestureStartPoint();
     float effectiveSpan = 1.0f + (fabsf(currentSpan.value) * ONE_TOUCH_PINCH_SPEED);
     ParentLayerPoint currentFocus = mTouchStartPosition;
 
     // Invert zoom.
     if (currentSpan.value < 0) {
       effectiveSpan = 1.0f / effectiveSpan;
     }
 
--- a/gfx/layers/apz/src/GestureEventListener.h
+++ b/gfx/layers/apz/src/GestureEventListener.h
@@ -145,20 +145,20 @@ private:
 
   void TriggerSingleTapConfirmedEvent();
 
   bool MoveDistanceExceeds(ScreenCoord aThreshold) const;
   bool MoveDistanceIsLarge() const;
   bool SecondTapIsFar() const;
 
   /**
-   * Returns current vertical span, counting from the where the user first put
-   * her finger down.
+   * Returns current vertical span, counting from the where the gesture first
+   * began (after a brief delay detecting the gesture from first touch).
    */
-  ParentLayerCoord GetYSpanFromStartPoint();
+  ParentLayerCoord GetYSpanFromGestureStartPoint();
 
   /**
    * Do actual state transition and reset substates.
    */
   void SetState(GestureState aState);
 
   RefPtr<AsyncPanZoomController> mAsyncPanZoomController;
 
@@ -204,16 +204,26 @@ private:
    * In the situation when we have a tap followed by a pinch we lose info
    * about tap since we keep only last input and to dispatch it correctly
    * we save last tap copy into this variable.
    * For more info see bug 947892.
    */
   MultiTouchInput mLastTapInput;
 
   /**
+   * Position of the last touch that exceeds the GetTouchStartTolerance when
+   * performing a one-touch-pinch gesture; using the mTouchStartPosition is
+   * slightly inaccurate because by the time the touch position has passed
+   * the threshold for the gesture, there is already a span that the zoom
+   * is calculated from, instead of starting at 1.0 when the threshold gets
+   * passed.
+   */
+  ParentLayerPoint mOneTouchPinchStartPosition;
+
+  /**
    * Position of the last touch starting. This is only valid during an attempt
    * to determine if a touch is a tap. If a touch point moves away from
    * mTouchStartPosition to the distance greater than
    * AsyncPanZoomController::GetTouchStartTolerance() while in
    * GESTURE_FIRST_SINGLE_TOUCH_DOWN, GESTURE_FIRST_SINGLE_TOUCH_MAX_TAP_DOWN
    * or GESTURE_SECOND_SINGLE_TOUCH_DOWN then we're certain the gesture is
    * not tap.
    */