Bug 920036 - Move ToWidgetMouseEvent into MultiTouchInput. r=mwu
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 10 Jan 2015 13:54:24 -0500
changeset 223258 22f8aee2e0e050bb14d80c9fd2e5ba96c2702d05
parent 223257 affad3660b5e626f3b28850ebb6378532effb057
child 223259 8cae7aeb3a741d0bd7019dd60a0a888266bf6170
push id10769
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 14:15:52 +0000
treeherderfx-team@0e9765732906 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs920036
milestone37.0a1
Bug 920036 - Move ToWidgetMouseEvent into MultiTouchInput. r=mwu
widget/InputData.cpp
widget/InputData.h
widget/gonk/GeckoTouchDispatcher.cpp
widget/gonk/GeckoTouchDispatcher.h
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -110,16 +110,58 @@ MultiTouchInput::ToWidgetTouchEvent(nsIW
 
   for (size_t i = 0; i < mTouches.Length(); i++) {
     *event.touches.AppendElement() = mTouches[i].ToNewDOMTouch();
   }
 
   return event;
 }
 
+WidgetMouseEvent
+MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const
+{
+  NS_ABORT_IF_FALSE(NS_IsMainThread(),
+                    "Can only convert To WidgetMouseEvent on main thread");
+
+  uint32_t mouseEventType = NS_EVENT_NULL;
+  switch (mType) {
+    case MultiTouchInput::MULTITOUCH_START:
+      mouseEventType = NS_MOUSE_BUTTON_DOWN;
+      break;
+    case MultiTouchInput::MULTITOUCH_MOVE:
+      mouseEventType = NS_MOUSE_MOVE;
+      break;
+    case MultiTouchInput::MULTITOUCH_CANCEL:
+    case MultiTouchInput::MULTITOUCH_END:
+      mouseEventType = NS_MOUSE_BUTTON_UP;
+      break;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
+      break;
+  }
+
+  WidgetMouseEvent event(true, mouseEventType, aWidget,
+                         WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
+
+  const SingleTouchData& firstTouch = mTouches[0];
+  event.refPoint.x = firstTouch.mScreenPoint.x;
+  event.refPoint.y = firstTouch.mScreenPoint.y;
+
+  event.time = mTime;
+  event.button = WidgetMouseEvent::eLeftButton;
+  event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
+  event.modifiers = modifiers;
+
+  if (mouseEventType != NS_MOUSE_MOVE) {
+    event.clickCount = 1;
+  }
+
+  return event;
+}
+
 // 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.
 MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent)
   : InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.timeStamp,
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -211,16 +211,17 @@ public:
                 aOther.mTimeStamp, aOther.modifiers)
     , mType(aOther.mType)
   {
     mTouches.AppendElements(aOther.mTouches);
   }
 
   explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
   WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
+  WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
 
   // 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);
--- a/widget/gonk/GeckoTouchDispatcher.cpp
+++ b/widget/gonk/GeckoTouchDispatcher.cpp
@@ -334,17 +334,17 @@ GeckoTouchDispatcher::ResampleTouchMoves
 }
 
 // Some touch events get sent as mouse events. If APZ doesn't capture the event
 // and if a touch only has 1 touch input, we can send a mouse event.
 void
 GeckoTouchDispatcher::DispatchMouseEvent(MultiTouchInput& aMultiTouch,
                                          bool aForwardToChildren)
 {
-  WidgetMouseEvent mouseEvent = ToWidgetMouseEvent(aMultiTouch, nullptr);
+  WidgetMouseEvent mouseEvent = aMultiTouch.ToWidgetMouseEvent(nullptr);
   if (mouseEvent.message == NS_EVENT_NULL) {
     return;
   }
 
   mouseEvent.mFlags.mNoCrossProcessBoundaryForwarding = !aForwardToChildren;
   nsWindow::DispatchInputEvent(mouseEvent);
 }
 
@@ -397,52 +397,9 @@ GeckoTouchDispatcher::DispatchTouchEvent
   }
 
   if (!captured && (aMultiTouch.mTouches.Length() == 1)) {
     bool forwardToChildren = status != nsEventStatus_eConsumeNoDefault;
     DispatchMouseEvent(aMultiTouch, forwardToChildren);
   }
 }
 
-WidgetMouseEvent
-GeckoTouchDispatcher::ToWidgetMouseEvent(const MultiTouchInput& aMultiTouch,
-                                         nsIWidget* aWidget) const
-{
-  NS_ABORT_IF_FALSE(NS_IsMainThread(),
-                    "Can only convert To WidgetMouseEvent on main thread");
-
-  uint32_t mouseEventType = NS_EVENT_NULL;
-  switch (aMultiTouch.mType) {
-    case MultiTouchInput::MULTITOUCH_START:
-      mouseEventType = NS_MOUSE_BUTTON_DOWN;
-      break;
-    case MultiTouchInput::MULTITOUCH_MOVE:
-      mouseEventType = NS_MOUSE_MOVE;
-      break;
-    case MultiTouchInput::MULTITOUCH_CANCEL:
-    case MultiTouchInput::MULTITOUCH_END:
-      mouseEventType = NS_MOUSE_BUTTON_UP;
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
-      break;
-  }
-
-  WidgetMouseEvent event(true, mouseEventType, aWidget,
-                         WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
-
-  const SingleTouchData& firstTouch = aMultiTouch.mTouches[0];
-  event.refPoint.x = firstTouch.mScreenPoint.x;
-  event.refPoint.y = firstTouch.mScreenPoint.y;
-
-  event.time = aMultiTouch.mTime;
-  event.button = WidgetMouseEvent::eLeftButton;
-  event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
-  event.modifiers = aMultiTouch.modifiers;
-
-  if (mouseEventType != NS_MOUSE_MOVE) {
-    event.clickCount = 1;
-  }
-
-  return event;
-}
-
 } // namespace mozilla
--- a/widget/gonk/GeckoTouchDispatcher.h
+++ b/widget/gonk/GeckoTouchDispatcher.h
@@ -55,17 +55,16 @@ public:
   static bool NotifyVsync(TimeStamp aVsyncTimestamp);
   static void SetCompositorVsyncObserver(layers::CompositorVsyncObserver* aObserver);
 
 private:
   void ResampleTouchMoves(MultiTouchInput& aOutTouch, TimeStamp vsyncTime);
   void SendTouchEvent(MultiTouchInput& aData);
   void DispatchMouseEvent(MultiTouchInput& aMultiTouch,
                           bool aForwardToChildren);
-  WidgetMouseEvent ToWidgetMouseEvent(const MultiTouchInput& aData, nsIWidget* aWidget) const;
 
   // mTouchQueueLock are used to protect the vector below
   // as it is accessed on the vsync thread and main thread
   Mutex mTouchQueueLock;
   std::vector<MultiTouchInput> mTouchMoveEvents;
 
   bool mResamplingEnabled;
   bool mTouchEventsFiltered;