Bug 1335895 - part 11: Add Translate function to InputData types r=kats,botond draft
authorRandall Barker <rbarker@mozilla.com>
Thu, 16 Feb 2017 10:45:44 -0800
changeset 561577 100081487894817076fd1d7ff260ca31003ee281
parent 561576 ab06251aae2a489e969d319078491a589cbb92fc
child 561578 8061808880771bf73eff116df69bd95d4a467dfc
push id53787
push userbmo:rbarker@mozilla.com
push dateWed, 12 Apr 2017 22:56:58 +0000
reviewerskats, botond
bugs1335895
milestone55.0a1
Bug 1335895 - part 11: Add Translate function to InputData types r=kats,botond Compile fix: widget/nsGUIEventIPC.h needed to have all static_cast<InputData> changed to static_cast<const InputData&> MozReview-Commit-ID: EEiXCeHjrUG
widget/InputData.cpp
widget/InputData.h
widget/nsGUIEventIPC.h
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -176,16 +176,27 @@ MultiTouchInput::MultiTouchInput(const W
   mTouches.AppendElement(SingleTouchData(0,
                                          ViewAs<ScreenPixel>(aMouseEvent.mRefPoint,
                                                              PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
                                          ScreenSize(1, 1),
                                          180.0f,
                                          1.0f));
 }
 
+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);
+
+  for (auto iter = mTouches.begin(); iter != mTouches.end(); iter++) {
+    iter->mScreenPoint.MoveBy(xTranslation, yTranslation);
+  }
+}
+
 WidgetTouchEvent
 MultiTouchInput::ToWidgetTouchEvent(nsIWidget* aWidget) const
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "Can only convert To WidgetTouchEvent on main thread");
 
   EventMessage touchEventMessage = eVoidEvent;
   switch (mType) {
@@ -367,16 +378,22 @@ MouseInput::MouseInput(const WidgetMouse
       break;
   }
 
   mOrigin =
     ScreenPoint(ViewAs<ScreenPixel>(aMouseEvent.mRefPoint,
       PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
 }
 
+void
+MouseInput::Translate(const ScreenPoint& aTranslation)
+{
+  mOrigin.MoveBy(aTranslation.x, aTranslation.y);
+}
+
 bool
 MouseInput::IsLeftButton() const
 {
   return mButtonType == LEFT_BUTTON;
 }
 
 bool
 MouseInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
@@ -489,16 +506,22 @@ PanGestureInput::PanGestureInput(PanGest
   , mUserDeltaMultiplierX(1.0)
   , mUserDeltaMultiplierY(1.0)
   , mHandledByAPZ(false)
   , mFollowedByMomentum(false)
   , mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false)
 {
 }
 
+void
+PanGestureInput::Translate(const ScreenPoint& aTranslation)
+{
+  mPanStartPoint.MoveBy(aTranslation.x, aTranslation.y);
+}
+
 bool
 PanGestureInput::IsMomentum() const
 {
   switch (mType) {
     case PanGestureInput::PANGESTURE_MOMENTUMSTART:
     case PanGestureInput::PANGESTURE_MOMENTUMPAN:
     case PanGestureInput::PANGESTURE_MOMENTUMEND:
       return true;
@@ -574,16 +597,22 @@ PinchGestureInput::PinchGestureInput(Pin
   : InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
   , mType(aType)
   , mLocalFocusPoint(aLocalFocusPoint)
   , mCurrentSpan(aCurrentSpan)
   , mPreviousSpan(aPreviousSpan)
 {
 }
 
+void
+PinchGestureInput::Translate(const ScreenPoint& aTranslation)
+{
+  mFocusPoint.MoveBy(aTranslation.x, aTranslation.y);
+}
+
 bool
 PinchGestureInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
 { 
   Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mFocusPoint);
   if (!point) {
     return false;
   }
   mLocalFocusPoint = *point;
@@ -610,16 +639,22 @@ TapGestureInput::TapGestureInput(TapGest
                                  const ParentLayerPoint& aLocalPoint,
                                  Modifiers aModifiers)
   : InputData(TAPGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
   , mType(aType)
   , mLocalPoint(aLocalPoint)
 {
 }
 
+void
+TapGestureInput::Translate(const ScreenPoint& aTranslation)
+{
+  mPoint.MoveBy(aTranslation.x, aTranslation.y);
+}
+
 bool
 TapGestureInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
 {
   Maybe<ParentLayerIntPoint> point = UntransformBy(aTransform, mPoint);
   if (!point) {
     return false;
   }
   mLocalPoint = *point;
@@ -697,16 +732,22 @@ ScrollWheelInput::DeltaTypeForDeltaMode(
   case nsIDOMWheelEvent::DOM_DELTA_PIXEL:
     return SCROLLDELTA_PIXEL;
   default:
     MOZ_CRASH();
   }
   return SCROLLDELTA_LINE;
 }
 
+void
+ScrollWheelInput::Translate(const ScreenPoint& aTranslation)
+{
+  mOrigin.MoveBy(aTranslation.x, aTranslation.y);
+}
+
 uint32_t
 ScrollWheelInput::DeltaModeForDeltaType(ScrollDeltaType aDeltaType)
 {
   switch (aDeltaType) {
   case ScrollWheelInput::SCROLLDELTA_LINE:
     return nsIDOMWheelEvent::DOM_DELTA_LINE;
   case ScrollWheelInput::SCROLLDELTA_PAGE:
     return nsIDOMWheelEvent::DOM_DELTA_PAGE;
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -92,16 +92,18 @@ public:
   INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
 
   virtual ~InputData();
   explicit InputData(InputType aInputType);
 
+  virtual void Translate(const ScreenPoint& aTranslation) = 0;
+
 protected:
   InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
             Modifiers aModifiers);
 };
 
 /**
  * Data container for a single touch input. Similar to dom::Touch, but used in
  * off-main-thread situations. This is more for just storing touch data, whereas
@@ -203,16 +205,17 @@ public:
   explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
   // This conversion from WidgetMouseEvent to MultiTouchInput is needed because
   // on the B2G emulator we can only receive mouse events, but we need to be
   // able to pan correctly. To do this, we convert the events into a format that
   // the panning code can handle. This code is very limited and only supports
   // SingleTouchData. It also sends garbage for the identifier, radius, force
   // and rotation angle.
   explicit MultiTouchInput(const WidgetMouseEvent& aMouseEvent);
+  virtual void Translate(const ScreenPoint& aTranslation) override;
 
   WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
   WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
 
   // Return the index into mTouches of the SingleTouchData with the given
   // identifier, or -1 if there is no such SingleTouchData.
   int32_t IndexOfTouch(int32_t aTouchIdentifier);
 
@@ -263,16 +266,17 @@ public:
     // Used as an upper bound for ContiguousEnumSerializer
     BUTTON_SENTINEL,
   };
 
   MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
              int16_t aButtons, const ScreenPoint& aPoint, uint32_t aTime,
              TimeStamp aTimeStamp, Modifiers aModifiers);
   explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
+  virtual void Translate(const ScreenPoint& aTranslation) override;
 
   bool IsLeftButton() const;
 
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
   WidgetMouseEvent ToWidgetMouseEvent(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
@@ -351,16 +355,17 @@ public:
   };
 
   PanGestureInput(PanGestureType aType,
                   uint32_t aTime,
                   TimeStamp aTimeStamp,
                   const ScreenPoint& aPanStartPoint,
                   const ScreenPoint& aPanDisplacement,
                   Modifiers aModifiers);
+  virtual void Translate(const ScreenPoint& aTranslation) override;
 
   bool IsMomentum() const;
 
   WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
 
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
 
   ScreenPoint UserMultipliedPanDisplacement() const;
@@ -430,16 +435,18 @@ public:
 
   // Construct a pinch gesture from a ParentLayer point.
   // mFocusPoint remains (0,0) unless it's set later.
   PinchGestureInput(PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
                     const ParentLayerPoint& aLocalFocusPoint,
                     ParentLayerCoord aCurrentSpan,
                     ParentLayerCoord aPreviousSpan, Modifiers aModifiers);
 
+  virtual void Translate(const ScreenPoint& aTranslation) override;
+
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
 
   // 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;
 
   // 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
@@ -498,16 +505,17 @@ public:
   // mLocalPoint remains (0,0) unless it's set later.
   TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
                   const ScreenIntPoint& aPoint, Modifiers aModifiers);
 
   // Construct a tap gesture from a ParentLayer point.
   // mPoint remains (0,0) unless it's set later.
   TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
                   const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
+  virtual void Translate(const ScreenPoint& aTranslation) override;
 
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
 
   // Warning, this class is serialized and sent over IPC. Any change to its
   // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
   TapGestureType mType;
 
   // The location of the tap in screen pixels.
@@ -557,16 +565,17 @@ public:
     SCROLLMODE_SENTINEL,
   };
 
   ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers,
                    ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
                    const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
                    bool aAllowToOverrideSystemScrollSpeed);
   explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
+  virtual void Translate(const ScreenPoint& aTranslation) override;
 
   static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
   static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
   static nsIScrollableFrame::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
 
   WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
 
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -1095,17 +1095,17 @@ struct ParamTraits<mozilla::MultiTouchIn
 
 template<>
 struct ParamTraits<mozilla::MultiTouchInput>
 {
   typedef mozilla::MultiTouchInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mTouches);
     WriteParam(aMsg, aParam.mHandledByAPZ);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
@@ -1133,17 +1133,17 @@ struct ParamTraits<mozilla::MouseInput::
 
 template<>
 struct ParamTraits<mozilla::MouseInput>
 {
   typedef mozilla::MouseInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mButtonType);
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mInputSource);
     WriteParam(aMsg, aParam.mButtons);
     WriteParam(aMsg, aParam.mOrigin);
     WriteParam(aMsg, aParam.mLocalOrigin);
     WriteParam(aMsg, aParam.mHandledByAPZ);
   }
@@ -1171,17 +1171,17 @@ struct ParamTraits<mozilla::PanGestureIn
 
 template<>
 struct ParamTraits<mozilla::PanGestureInput>
 {
   typedef mozilla::PanGestureInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mPanStartPoint);
     WriteParam(aMsg, aParam.mPanDisplacement);
     WriteParam(aMsg, aParam.mLocalPanStartPoint);
     WriteParam(aMsg, aParam.mLocalPanDisplacement);
     WriteParam(aMsg, aParam.mLineOrPageDeltaX);
     WriteParam(aMsg, aParam.mLineOrPageDeltaY);
     WriteParam(aMsg, aParam.mUserDeltaMultiplierX);
@@ -1219,17 +1219,17 @@ struct ParamTraits<mozilla::PinchGesture
 
 template<>
 struct ParamTraits<mozilla::PinchGestureInput>
 {
   typedef mozilla::PinchGestureInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mFocusPoint);
     WriteParam(aMsg, aParam.mLocalFocusPoint);
     WriteParam(aMsg, aParam.mCurrentSpan);
     WriteParam(aMsg, aParam.mPreviousSpan);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
@@ -1253,17 +1253,17 @@ struct ParamTraits<mozilla::TapGestureIn
 
 template<>
 struct ParamTraits<mozilla::TapGestureInput>
 {
   typedef mozilla::TapGestureInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mPoint);
     WriteParam(aMsg, aParam.mLocalPoint);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
@@ -1291,17 +1291,17 @@ struct ParamTraits<mozilla::ScrollWheelI
 
 template<>
 struct ParamTraits<mozilla::ScrollWheelInput>
 {
   typedef mozilla::ScrollWheelInput paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
-    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
     WriteParam(aMsg, aParam.mDeltaType);
     WriteParam(aMsg, aParam.mScrollMode);
     WriteParam(aMsg, aParam.mOrigin);
     WriteParam(aMsg, aParam.mHandledByAPZ);
     WriteParam(aMsg, aParam.mDeltaX);
     WriteParam(aMsg, aParam.mDeltaY);
     WriteParam(aMsg, aParam.mLocalOrigin);
     WriteParam(aMsg, aParam.mLineOrPageDeltaX);