Bug 1710317 - Part 2: Add mButton[s] to WidgetTouchEvent r=aklotz,edgar
authorKagami Sascha Rosylight <krosylight@mozilla.com>
Mon, 31 May 2021 13:39:18 +0000
changeset 653981 d92899c7f5cc41e105285e7e22332439c394d76f
parent 653980 9d16301a367579afa707827ae0965770d09aa33d
child 653982 bf55ea848e01fbcfb2af62376c5145d9f003dfc9
push id2623
push userffxbld-merge
push dateMon, 02 Aug 2021 14:47:51 +0000
treeherdermozilla-release@8500ce65f7c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz, edgar
bugs1710317
milestone90.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 1710317 - Part 2: Add mButton[s] to WidgetTouchEvent r=aklotz,edgar It's not ideal to have mButton[s] only to pass them to PointerEvent, but it's required anyway. Differential Revision: https://phabricator.services.mozilla.com/D115509
dom/events/PointerEventHandler.cpp
widget/InputData.cpp
widget/InputData.h
widget/TouchEvents.h
widget/nsGUIEventIPC.h
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
--- a/dom/events/PointerEventHandler.cpp
+++ b/dom/events/PointerEventHandler.cpp
@@ -528,22 +528,26 @@ void PointerEventHandler::InitPointerEve
 
 /* static */
 void PointerEventHandler::InitPointerEventFromTouch(
     WidgetPointerEvent* aPointerEvent, WidgetTouchEvent* aTouchEvent,
     mozilla::dom::Touch* aTouch, bool aIsPrimary) {
   MOZ_ASSERT(aPointerEvent);
   MOZ_ASSERT(aTouchEvent);
 
+  // Use mButton/mButtons only when mButton got a value (from pen input)
   int16_t button = aTouchEvent->mMessage == eTouchMove
                        ? MouseButton::eNotPressed
+                   : aTouchEvent->mButton != MouseButton::eNotPressed
+                       ? aTouchEvent->mButton
                        : MouseButton::ePrimary;
-
   int16_t buttons = aTouchEvent->mMessage == eTouchEnd
                         ? MouseButtonsFlag::eNoButtons
+                    : aTouchEvent->mButton != MouseButton::eNotPressed
+                        ? aTouchEvent->mButtons
                         : MouseButtonsFlag::ePrimaryFlag;
 
   aPointerEvent->mIsPrimary = aIsPrimary;
   aPointerEvent->pointerId = aTouch->Identifier();
   aPointerEvent->mRefPoint = aTouch->mRefPoint;
   aPointerEvent->mModifiers = aTouchEvent->mModifiers;
   aPointerEvent->mWidth = aTouch->RadiusX(CallerType::System);
   aPointerEvent->mHeight = aTouch->RadiusY(CallerType::System);
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -86,24 +86,28 @@ MultiTouchInput::MultiTouchInput()
       mType(MULTITOUCH_START),
       mHandledByAPZ(false) {}
 
 MultiTouchInput::MultiTouchInput(const MultiTouchInput& aOther)
     : InputData(MULTITOUCH_INPUT, aOther.mTime, aOther.mTimeStamp,
                 aOther.modifiers),
       mType(aOther.mType),
       mScreenOffset(aOther.mScreenOffset),
-      mHandledByAPZ(aOther.mHandledByAPZ) {
+      mHandledByAPZ(aOther.mHandledByAPZ),
+      mButton(aOther.mButton),
+      mButtons(aOther.mButtons) {
   mTouches.AppendElements(aOther.mTouches);
 }
 
 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
     : InputData(MULTITOUCH_INPUT, aTouchEvent.mTime, aTouchEvent.mTimeStamp,
                 aTouchEvent.mModifiers),
-      mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ) {
+      mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ),
+      mButton(aTouchEvent.mButton),
+      mButtons(aTouchEvent.mButtons) {
   MOZ_ASSERT(NS_IsMainThread(),
              "Can only copy from WidgetTouchEvent on main thread");
 
   switch (aTouchEvent.mMessage) {
     case eTouchStart:
       mType = MULTITOUCH_START;
       break;
     case eTouchMove:
@@ -134,17 +138,17 @@ MultiTouchInput::MultiTouchInput(const W
     float rotationAngle = domTouch->RotationAngle(CallerType::System);
     float force = domTouch->Force(CallerType::System);
 
     SingleTouchData data(
         identifier,
         ViewAs<ScreenPixel>(
             domTouch->mRefPoint,
             PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
-        ScreenSize(radiusX, radiusY), rotationAngle, force);
+        ScreenSize((float)radiusX, (float)radiusY), rotationAngle, force);
 
     mTouches.AppendElement(data);
   }
 }
 
 void MultiTouchInput::Translate(const ScreenPoint& aTranslation) {
   const int32_t xTranslation = (int32_t)(aTranslation.x + 0.5f);
   const int32_t yTranslation = (int32_t)(aTranslation.y + 0.5f);
@@ -192,16 +196,18 @@ WidgetTouchEvent MultiTouchInput::ToWidg
 
   event.mModifiers = this->modifiers;
   event.mTime = this->mTime;
   event.mTimeStamp = this->mTimeStamp;
   event.mFlags.mHandledByAPZ = mHandledByAPZ;
   event.mFocusSequenceNumber = mFocusSequenceNumber;
   event.mLayersId = mLayersId;
   event.mInputSource = aInputSource;
+  event.mButton = mButton;
+  event.mButtons = mButtons;
 
   for (size_t i = 0; i < mTouches.Length(); i++) {
     *event.mTouches.AppendElement() = mTouches[i].ToNewDOMTouch();
   }
 
   return event;
 }
 
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -249,16 +249,20 @@ class MultiTouchInput : public InputData
   // Warning, this class is serialized and sent over IPC. Any change to its
   // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
   MultiTouchType mType;
   CopyableTArray<SingleTouchData> mTouches;
   // The screen offset of the root widget. This can be changing along with
   // the touch interaction, so we sstore it in the event.
   ExternalPoint mScreenOffset;
   bool mHandledByAPZ;
+  // These button fields match to the corresponding fields in
+  // WidgetMouseEventBase.
+  int16_t mButton = 0;
+  int16_t mButtons = 0;
 };
 
 class MouseInput : public InputData {
  protected:
   friend mozilla::layers::APZInputBridgeChild;
   friend mozilla::layers::PAPZInputBridgeParent;
 
   MouseInput();
--- a/widget/TouchEvents.h
+++ b/widget/TouchEvents.h
@@ -145,23 +145,25 @@ class WidgetTouchEvent : public WidgetIn
   typedef AutoTouchArray::base_type TouchArrayBase;
 
   virtual WidgetTouchEvent* AsTouchEvent() override { return this; }
 
   MOZ_COUNTED_DEFAULT_CTOR(WidgetTouchEvent)
 
   WidgetTouchEvent(const WidgetTouchEvent& aOther)
       : WidgetInputEvent(aOther.IsTrusted(), aOther.mMessage, aOther.mWidget,
-                         eTouchEventClass),
-        mInputSource(aOther.mInputSource) {
+                         eTouchEventClass) {
     MOZ_COUNT_CTOR(WidgetTouchEvent);
     mModifiers = aOther.mModifiers;
     mTime = aOther.mTime;
     mTimeStamp = aOther.mTimeStamp;
     mTouches.AppendElements(aOther.mTouches);
+    mInputSource = aOther.mInputSource;
+    mButton = aOther.mButton;
+    mButtons = aOther.mButtons;
     mFlags.mCancelable = mMessage != eTouchCancel;
     mFlags.mHandledByAPZ = aOther.mFlags.mHandledByAPZ;
   }
 
   WidgetTouchEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
       : WidgetInputEvent(aIsTrusted, aMessage, aWidget, eTouchEventClass) {
     MOZ_COUNT_CTOR(WidgetTouchEvent);
     mFlags.mCancelable = mMessage != eTouchCancel;
@@ -176,16 +178,18 @@ class WidgetTouchEvent : public WidgetIn
     WidgetTouchEvent* result = new WidgetTouchEvent(false, mMessage, nullptr);
     result->AssignTouchEventData(*this, true);
     result->mFlags = mFlags;
     return result;
   }
 
   TouchArray mTouches;
   uint16_t mInputSource = 5;  // MouseEvent_Binding::MOZ_SOURCE_TOUCH
+  int16_t mButton = eNotPressed;
+  int16_t mButtons = 0;
 
   void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets) {
     AssignInputEventData(aEvent, aCopyTargets);
 
     // Assign*EventData() assume that they're called only new instance.
     MOZ_ASSERT(mTouches.IsEmpty());
     mTouches.AppendElements(aEvent.mTouches);
     mInputSource = aEvent.mInputSource;
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -331,16 +331,18 @@ struct ParamTraits<mozilla::WidgetPointe
 
 template <>
 struct ParamTraits<mozilla::WidgetTouchEvent> {
   using paramType = mozilla::WidgetTouchEvent;
 
   static void Write(Message* aMsg, const paramType& aParam) {
     WriteParam(aMsg, static_cast<const mozilla::WidgetInputEvent&>(aParam));
     WriteParam(aMsg, aParam.mInputSource);
+    WriteParam(aMsg, aParam.mButton);
+    WriteParam(aMsg, aParam.mButtons);
     // Sigh, Touch bites us again!  We want to be able to do
     //   WriteParam(aMsg, aParam.mTouches);
     const paramType::TouchArray& touches = aParam.mTouches;
     WriteParam(aMsg, touches.Length());
     for (uint32_t i = 0; i < touches.Length(); ++i) {
       mozilla::dom::Touch* touch = touches[i];
       WriteParam(aMsg, touch->mIdentifier);
       WriteParam(aMsg, touch->mRefPoint);
@@ -354,16 +356,18 @@ struct ParamTraits<mozilla::WidgetTouchE
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter,
                    paramType* aResult) {
     paramType::TouchArray::size_type numTouches;
     if (!ReadParam(aMsg, aIter,
                    static_cast<mozilla::WidgetInputEvent*>(aResult)) ||
         !ReadParam(aMsg, aIter, &aResult->mInputSource) ||
+        !ReadParam(aMsg, aIter, &aResult->mButton) ||
+        !ReadParam(aMsg, aIter, &aResult->mButtons) ||
         !ReadParam(aMsg, aIter, &numTouches)) {
       return false;
     }
     for (uint32_t i = 0; i < numTouches; ++i) {
       int32_t identifier;
       mozilla::LayoutDeviceIntPoint refPoint;
       mozilla::LayoutDeviceIntPoint radius;
       float rotationAngle;
@@ -1157,33 +1161,37 @@ template <>
 struct ParamTraits<mozilla::MultiTouchInput::MultiTouchType>
     : public ContiguousEnumSerializerInclusive<
           mozilla::MultiTouchInput::MultiTouchType,
           mozilla::MultiTouchInput::MultiTouchType::MULTITOUCH_START,
           mozilla::MultiTouchInput::sHighestMultiTouchType> {};
 
 template <>
 struct ParamTraits<mozilla::MultiTouchInput> {
-  typedef mozilla::MultiTouchInput paramType;
+  using paramType = mozilla::MultiTouchInput;
 
   static void Write(Message* aMsg, const paramType& aParam) {
     WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mTouches);
     WriteParam(aMsg, aParam.mHandledByAPZ);
     WriteParam(aMsg, aParam.mScreenOffset);
+    WriteParam(aMsg, aParam.mButton);
+    WriteParam(aMsg, aParam.mButtons);
   }
 
   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->mTouches) &&
            ReadParam(aMsg, aIter, &aResult->mHandledByAPZ) &&
-           ReadParam(aMsg, aIter, &aResult->mScreenOffset);
+           ReadParam(aMsg, aIter, &aResult->mScreenOffset) &&
+           ReadParam(aMsg, aIter, &aResult->mButton) &&
+           ReadParam(aMsg, aIter, &aResult->mButtons);
   }
 };
 
 template <>
 struct ParamTraits<mozilla::MouseInput::MouseType>
     : public ContiguousEnumSerializerInclusive<
           mozilla::MouseInput::MouseType,
           mozilla::MouseInput::MouseType::MOUSE_NONE,
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -8553,17 +8553,18 @@ bool nsWindow::WidgetTypeSupportsAcceler
   // Also see bug 1150376, D3D11 composition can cause issues on some devices
   // on Windows 7 where presentation fails randomly for windows with drop
   // shadows.
   return mTransparencyMode != eTransparencyTransparent &&
          !(IsPopup() && DeviceManagerDx::Get()->IsWARP());
 }
 
 bool nsWindow::DispatchTouchEventFromWMPointer(
-    UINT msg, LPARAM aLParam, const WinPointerInfo& aPointerInfo) {
+    UINT msg, LPARAM aLParam, const WinPointerInfo& aPointerInfo,
+    mozilla::MouseButton aButton) {
   MultiTouchInput::MultiTouchType touchType;
   switch (msg) {
     case WM_POINTERDOWN:
       touchType = MultiTouchInput::MULTITOUCH_START;
       break;
     case WM_POINTERUPDATE:
       if (aPointerInfo.mPressure == 0) {
         return false;  // hover
@@ -8592,16 +8593,18 @@ bool nsWindow::DispatchTouchEventFromWMP
   touchData.mTwist = aPointerInfo.twist;
 
   MultiTouchInput touchInput;
   touchInput.mType = touchType;
   touchInput.mTime = ::GetMessageTime();
   touchInput.mTimeStamp =
       GetMessageTimeStamp(static_cast<long>(touchInput.mTime));
   touchInput.mTouches.AppendElement(touchData);
+  touchInput.mButton = aButton;
+  touchInput.mButtons = aPointerInfo.mButtons;
 
   // POINTER_INFO.dwKeyStates can't be used as it only supports Shift and Ctrl
   ModifierKeyState modifierKeyState;
   touchInput.modifiers = modifierKeyState.GetModifiers();
 
   DispatchTouchInput(touchInput, MouseEvent_Binding::MOZ_SOURCE_PEN);
   return true;
 }
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -511,17 +511,18 @@ class nsWindow final : public nsWindowBa
   void SetWindowTranslucencyInner(nsTransparencyMode aMode);
   nsTransparencyMode GetWindowTranslucencyInner() const {
     return mTransparencyMode;
   }
   void UpdateGlass();
   bool WithinDraggableRegion(int32_t clientX, int32_t clientY);
 
   bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam,
-                                       const WinPointerInfo& aPointerInfo);
+                                       const WinPointerInfo& aPointerInfo,
+                                       mozilla::MouseButton aButton);
 
  protected:
 #endif  // MOZ_XUL
 
   static bool IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult);
   void IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam);
 
   /**