Bug 1627708 - Add a PinchGestureSource enum that indicates the source of a PinchGestureInput event. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 06 Jun 2020 00:32:19 +0000
changeset 534242 7b356f85d775897e81541c48e3aeec1b48e345ba
parent 534241 0f152045a4a04b7e37e89f6b57603108039e18eb
child 534243 b830bc407224b171a91ed3e9e128030c020b7fdd
push id37484
push userdluca@mozilla.com
push dateSat, 06 Jun 2020 09:46:03 +0000
treeherdermozilla-central@6237102f005d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1627708
milestone79.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 1627708 - Add a PinchGestureSource enum that indicates the source of a PinchGestureInput event. r=botond Differential Revision: https://phabricator.services.mozilla.com/D77828
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/GestureEventListener.cpp
gfx/layers/apz/test/gtest/APZTestCommon.h
widget/InputData.cpp
widget/InputData.h
widget/cocoa/nsChildView.mm
widget/nsGUIEventIPC.h
widget/windows/DirectManipulationOwner.cpp
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -2245,40 +2245,44 @@ void APZCTreeManager::SynthesizePinchGes
   // Compute span values based on the wheel delta.
   ScreenCoord oldSpan = 100;
   ScreenCoord newSpan = oldSpan + aWheelInput.mDeltaY;
 
   // There's no ambiguity as to the target for pinch gesture events.
   TargetConfirmationFlags confFlags{true};
 
   PinchGestureInput pinchStart{PinchGestureInput::PINCHGESTURE_START,
+                               PinchGestureInput::MOUSEWHEEL,
                                aWheelInput.mTime,
                                aWheelInput.mTimeStamp,
                                ExternalPoint(0, 0),
                                focusPoint,
                                oldSpan,
                                oldSpan,
                                aWheelInput.modifiers};
   PinchGestureInput pinchScale1{PinchGestureInput::PINCHGESTURE_SCALE,
+                                PinchGestureInput::MOUSEWHEEL,
                                 aWheelInput.mTime,
                                 aWheelInput.mTimeStamp,
                                 ExternalPoint(0, 0),
                                 focusPoint,
                                 oldSpan,
                                 oldSpan,
                                 aWheelInput.modifiers};
   PinchGestureInput pinchScale2{PinchGestureInput::PINCHGESTURE_SCALE,
+                                PinchGestureInput::MOUSEWHEEL,
                                 aWheelInput.mTime,
                                 aWheelInput.mTimeStamp,
                                 ExternalPoint(0, 0),
                                 focusPoint,
                                 oldSpan,
                                 newSpan,
                                 aWheelInput.modifiers};
   PinchGestureInput pinchEnd{PinchGestureInput::PINCHGESTURE_END,
+                             PinchGestureInput::MOUSEWHEEL,
                              aWheelInput.mTime,
                              aWheelInput.mTimeStamp,
                              ExternalPoint(0, 0),
                              focusPoint,
                              newSpan,
                              newSpan,
                              aWheelInput.modifiers};
 
--- a/gfx/layers/apz/src/GestureEventListener.cpp
+++ b/gfx/layers/apz/src/GestureEventListener.cpp
@@ -317,19 +317,20 @@ nsEventStatus GestureEventListener::Hand
 
         ScreenCoord currentSpan = 1.0f;
         ScreenPoint currentFocus = mTouchStartPosition;
 
         // save the position that the one-touch-pinch gesture actually begins
         mOneTouchPinchStartPosition = mLastTouchInput.mTouches[0].mScreenPoint;
 
         PinchGestureInput pinchEvent(
-            PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime,
-            mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
-            currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers);
+            PinchGestureInput::PINCHGESTURE_START, PinchGestureInput::ONE_TOUCH,
+            mLastTouchInput.mTime, mLastTouchInput.mTimeStamp,
+            mLastTouchInput.mScreenOffset, currentFocus, currentSpan,
+            currentSpan, mLastTouchInput.modifiers);
 
         rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
 
         mPreviousSpan = currentSpan;
         mPreviousFocus = currentFocus;
       }
       break;
     }
@@ -346,19 +347,20 @@ nsEventStatus GestureEventListener::Hand
       ScreenPoint currentFocus = GetCurrentFocus(mLastTouchInput);
 
       mSpanChange += fabsf(currentSpan - mPreviousSpan);
       mFocusChange += (currentFocus - mPreviousFocus).Length();
       if (mSpanChange > PINCH_START_THRESHOLD ||
           mFocusChange > PINCH_START_THRESHOLD) {
         SetState(GESTURE_PINCH);
         PinchGestureInput pinchEvent(
-            PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime,
-            mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
-            currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers);
+            PinchGestureInput::PINCHGESTURE_START, PinchGestureInput::TOUCH,
+            mLastTouchInput.mTime, mLastTouchInput.mTimeStamp,
+            mLastTouchInput.mScreenOffset, currentFocus, currentSpan,
+            currentSpan, mLastTouchInput.modifiers);
 
         rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
       } else {
         // Prevent APZC::OnTouchMove from processing a move event when two
         // touches are active
         rv = nsEventStatus_eConsumeNoDefault;
       }
 
@@ -374,20 +376,20 @@ nsEventStatus GestureEventListener::Hand
         // Prevent APZC::OnTouchMove() from handling this wrong input
         rv = nsEventStatus_eConsumeNoDefault;
         break;
       }
 
       ScreenCoord currentSpan = GetCurrentSpan(mLastTouchInput);
 
       PinchGestureInput pinchEvent(
-          PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime,
-          mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
-          GetCurrentFocus(mLastTouchInput), currentSpan, mPreviousSpan,
-          mLastTouchInput.modifiers);
+          PinchGestureInput::PINCHGESTURE_SCALE, PinchGestureInput::TOUCH,
+          mLastTouchInput.mTime, mLastTouchInput.mTimeStamp,
+          mLastTouchInput.mScreenOffset, GetCurrentFocus(mLastTouchInput),
+          currentSpan, mPreviousSpan, mLastTouchInput.modifiers);
 
       rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
       mPreviousSpan = currentSpan;
 
       break;
     }
 
     case GESTURE_ONE_TOUCH_PINCH: {
@@ -397,20 +399,20 @@ nsEventStatus GestureEventListener::Hand
       ScreenPoint currentFocus = mTouchStartPosition;
 
       // Invert zoom.
       if (currentSpan.value < 0) {
         effectiveSpan = 1.0f / effectiveSpan;
       }
 
       PinchGestureInput pinchEvent(
-          PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime,
-          mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
-          currentFocus, effectiveSpan, mPreviousSpan,
-          mLastTouchInput.modifiers);
+          PinchGestureInput::PINCHGESTURE_SCALE, PinchGestureInput::ONE_TOUCH,
+          mLastTouchInput.mTime, mLastTouchInput.mTimeStamp,
+          mLastTouchInput.mScreenOffset, currentFocus, effectiveSpan,
+          mPreviousSpan, mLastTouchInput.modifiers);
 
       rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
       mPreviousSpan = effectiveSpan;
 
       break;
     }
 
     default:
@@ -484,33 +486,34 @@ nsEventStatus GestureEventListener::Hand
             PinchGestureInput::PINCHGESTURE_END;
         ScreenPoint point;
         if (mTouches.Length() == 1) {
           // As user still keeps one finger down the event's focus point should
           // contain meaningful data.
           type = PinchGestureInput::PINCHGESTURE_FINGERLIFTED;
           point = mTouches[0].mScreenPoint;
         }
-        PinchGestureInput pinchEvent(type, mLastTouchInput.mTime,
-                                     mLastTouchInput.mTimeStamp,
-                                     mLastTouchInput.mScreenOffset, point, 1.0f,
-                                     1.0f, mLastTouchInput.modifiers);
+        PinchGestureInput pinchEvent(
+            type, PinchGestureInput::TOUCH, mLastTouchInput.mTime,
+            mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, point,
+            1.0f, 1.0f, mLastTouchInput.modifiers);
         mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
       }
 
       rv = nsEventStatus_eConsumeNoDefault;
 
       break;
 
     case GESTURE_ONE_TOUCH_PINCH: {
       SetState(GESTURE_NONE);
       PinchGestureInput pinchEvent(
-          PinchGestureInput::PINCHGESTURE_END, mLastTouchInput.mTime,
-          mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
-          ScreenPoint(), 1.0f, 1.0f, mLastTouchInput.modifiers);
+          PinchGestureInput::PINCHGESTURE_END, PinchGestureInput::ONE_TOUCH,
+          mLastTouchInput.mTime, mLastTouchInput.mTimeStamp,
+          mLastTouchInput.mScreenOffset, ScreenPoint(), 1.0f, 1.0f,
+          mLastTouchInput.modifiers);
       mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
 
       rv = nsEventStatus_eConsumeNoDefault;
 
       break;
     }
 
     default:
--- a/gfx/layers/apz/test/gtest/APZTestCommon.h
+++ b/gfx/layers/apz/test/gtest/APZTestCommon.h
@@ -71,19 +71,19 @@ inline SingleTouchData CreateSingleTouch
                                              ScreenIntCoord aY) {
   return CreateSingleTouchData(aIdentifier, ScreenIntPoint(aX, aY));
 }
 
 inline PinchGestureInput CreatePinchGestureInput(
     PinchGestureInput::PinchGestureType aType, const ScreenPoint& aFocus,
     float aCurrentSpan, float aPreviousSpan, TimeStamp timestamp) {
   ParentLayerPoint localFocus(aFocus.x, aFocus.y);
-  PinchGestureInput result(aType, MillisecondsSinceStartup(timestamp),
-                           timestamp, ExternalPoint(0, 0), aFocus, aCurrentSpan,
-                           aPreviousSpan, 0);
+  PinchGestureInput result(
+      aType, PinchGestureInput::UNKNOWN, MillisecondsSinceStartup(timestamp),
+      timestamp, ExternalPoint(0, 0), aFocus, aCurrentSpan, aPreviousSpan, 0);
   return result;
 }
 
 template <class SetArg, class Storage>
 class ScopedGfxSetting {
  public:
   ScopedGfxSetting(const std::function<SetArg(void)>& aGetPrefFunc,
                    const std::function<void(SetArg)>& aSetPrefFunc, SetArg aVal)
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -533,24 +533,27 @@ ScreenPoint PanGestureInput::UserMultipl
 ParentLayerPoint PanGestureInput::UserMultipliedLocalPanDisplacement() const {
   return ParentLayerPoint(mLocalPanDisplacement.x * mUserDeltaMultiplierX,
                           mLocalPanDisplacement.y * mUserDeltaMultiplierY);
 }
 
 PinchGestureInput::PinchGestureInput()
     : InputData(PINCHGESTURE_INPUT),
       mType(PINCHGESTURE_START),
+      mSource(UNKNOWN),
       mHandledByAPZ(false) {}
 
 PinchGestureInput::PinchGestureInput(
-    PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
-    const ExternalPoint& aScreenOffset, const ScreenPoint& aFocusPoint,
-    ScreenCoord aCurrentSpan, ScreenCoord aPreviousSpan, Modifiers aModifiers)
+    PinchGestureType aType, PinchGestureSource aSource, uint32_t aTime,
+    TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset,
+    const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
+    ScreenCoord aPreviousSpan, Modifiers aModifiers)
     : InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers),
       mType(aType),
+      mSource(aSource),
       mFocusPoint(aFocusPoint),
       mScreenOffset(aScreenOffset),
       mCurrentSpan(aCurrentSpan),
       mPreviousSpan(aPreviousSpan),
       mHandledByAPZ(false) {}
 
 bool PinchGestureInput::TransformToLocal(
     const ScreenToParentLayerMatrix4x4& aTransform) {
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -444,32 +444,45 @@ class PinchGestureInput : public InputDa
       // terminated by lifting one of the two fingers. The position of the
       // finger that's still down is populated as the focus point.
       PINCHGESTURE_FINGERLIFTED,
       // The END state is used when the pinch gesture is completely terminated.
       // In this state, the focus point should not be relied upon for having
       // meaningful data.
       PINCHGESTURE_END
   ));
+
+  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
+    PinchGestureSource, (
+      UNKNOWN, // Default initialization value. Should never actually be used.
+      TOUCH, // From two-finger pinch gesture
+      ONE_TOUCH, // From one-finger pinch gesture
+      TRACKPAD, // From trackpad pinch gesture
+      MOUSEWHEEL // Synthesized from modifier+mousewheel
+  ));
   // clang-format on
 
   // Construct a pinch gesture from a Screen point.
-  PinchGestureInput(PinchGestureType aType, uint32_t aTime,
-                    TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset,
+  PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
+                    uint32_t aTime, TimeStamp aTimeStamp,
+                    const ExternalPoint& aScreenOffset,
                     const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
                     ScreenCoord aPreviousSpan, Modifiers aModifiers);
 
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
 
   WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
 
   // Warning, this class is serialized and sent over IPC. Any change to its
   // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
   PinchGestureType mType;
 
+  // Some indication of the input device that generated this pinch gesture.
+  PinchGestureSource mSource;
+
   // Center point of the pinch gesture. That is, if there are two fingers on the
   // screen, it is their midpoint. In the case of more than two fingers, the
   // point is implementation-specific, but can for example be the midpoint
   // between the very first and very last touch. This is in device pixels and
   // are the coordinates on the screen of this midpoint.
   // For PINCHGESTURE_END events, this may hold the last known focus point or
   // just be empty; in any case for END events it should not be relied upon.
   // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2832,16 +2832,17 @@ NSEvent* gLastDragMouseDownEvent = nil; 
     }
     default: {
       NS_WARNING("Unexpected phase for pinch gesture event.");
       return;
     }
   }
 
   PinchGestureInput event{pinchGestureType,
+                          PinchGestureInput::TRACKPAD,
                           eventIntervalTime,
                           eventTimeStamp,
                           screenOffset,
                           position,
                           100.0,
                           100.0 * (1.0 - [anEvent magnification]),
                           nsCocoaUtils::ModifiersForEvent(anEvent)};
 
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -1281,34 +1281,44 @@ struct ParamTraits<mozilla::PanGestureIn
 template <>
 struct ParamTraits<mozilla::PinchGestureInput::PinchGestureType>
     : public ContiguousEnumSerializerInclusive<
           mozilla::PinchGestureInput::PinchGestureType,
           mozilla::PinchGestureInput::PinchGestureType::PINCHGESTURE_START,
           mozilla::PinchGestureInput::sHighestPinchGestureType> {};
 
 template <>
+struct ParamTraits<mozilla::PinchGestureInput::PinchGestureSource>
+    : public ContiguousEnumSerializerInclusive<
+          mozilla::PinchGestureInput::PinchGestureSource,
+          // Set the min to TOUCH, to ensure UNKNOWN is never sent over IPC
+          mozilla::PinchGestureInput::PinchGestureSource::TOUCH,
+          mozilla::PinchGestureInput::sHighestPinchGestureSource> {};
+
+template <>
 struct ParamTraits<mozilla::PinchGestureInput> {
   typedef mozilla::PinchGestureInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam) {
     WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
+    WriteParam(aMsg, aParam.mSource);
     WriteParam(aMsg, aParam.mScreenOffset);
     WriteParam(aMsg, aParam.mFocusPoint);
     WriteParam(aMsg, aParam.mLocalFocusPoint);
     WriteParam(aMsg, aParam.mCurrentSpan);
     WriteParam(aMsg, aParam.mPreviousSpan);
     WriteParam(aMsg, aParam.mHandledByAPZ);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter,
                    paramType* aResult) {
     return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
            ReadParam(aMsg, aIter, &aResult->mType) &&
+           ReadParam(aMsg, aIter, &aResult->mSource) &&
            ReadParam(aMsg, aIter, &aResult->mScreenOffset) &&
            ReadParam(aMsg, aIter, &aResult->mFocusPoint) &&
            ReadParam(aMsg, aIter, &aResult->mLocalFocusPoint) &&
            ReadParam(aMsg, aIter, &aResult->mCurrentSpan) &&
            ReadParam(aMsg, aIter, &aResult->mPreviousSpan) &&
            ReadParam(aMsg, aIter, &aResult->mHandledByAPZ);
   }
 };
--- a/widget/windows/DirectManipulationOwner.cpp
+++ b/widget/windows/DirectManipulationOwner.cpp
@@ -388,16 +388,17 @@ void DManipEventHandler::SendPinch(Phase
   POINT cursor_pos;
   ::GetCursorPos(&cursor_pos);
   HWND wnd = static_cast<HWND>(mWindow->GetNativeData(NS_NATIVE_WINDOW));
   ::ScreenToClient(wnd, &cursor_pos);
   ScreenPoint position = {(float)cursor_pos.x, (float)cursor_pos.y};
 
   PinchGestureInput event{
       pinchGestureType,
+      PinchGestureInput::TRACKPAD,
       eventIntervalTime,
       eventTimeStamp,
       screenOffset,
       position,
       100.0 * ((aPhase != Phase::eMiddle) ? 1.f : aScale),
       100.0 * ((aPhase != Phase::eMiddle) ? 1.f : mLastScale),
       mods};