Bug 1335895 - part 11: Add Translate function to MultiTouchData r=kats,botond draft
authorRandall Barker <rbarker@mozilla.com>
Thu, 16 Feb 2017 10:45:44 -0800
changeset 565560 dd84c1777f8f826a4e66dc090ee373c86b5a2035
parent 565559 6633440b89e73cd585269992b04ee56fd1187206
child 565561 0e180ba567d7347ebbd1d7f5d5bf9769616891a8
push id54904
push userbmo:rbarker@mozilla.com
push dateThu, 20 Apr 2017 02:39:58 +0000
reviewerskats, botond
bugs1335895
milestone55.0a1
Bug 1335895 - part 11: Add Translate function to MultiTouchData 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
--- 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) {
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -203,16 +203,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);
+  void Translate(const ScreenPoint& aTranslation);
 
   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);