Bug 1199885 - Part 1: Add MouseInput InputData. r=kats
authorBenoit Girard <b56girard@gmail.com>
Mon, 28 Sep 2015 10:32:05 -0400
changeset 300076 c267e8cc7952253892b062498d21afd7b10559dd
parent 300075 97456e1a0b8a2974a33b873a883ddb1ee483c745
child 300077 60cbca9b66500267658a551be21c6ae7a0f5b213
push id5392
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:08:23 +0000
treeherdermozilla-beta@16ce8562a975 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1199885
milestone44.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 1199885 - Part 1: Add MouseInput InputData. r=kats
widget/InputData.cpp
widget/InputData.h
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -23,16 +23,59 @@ already_AddRefed<Touch> SingleTouchData:
   nsRefPtr<Touch> touch = new Touch(mIdentifier,
                                     LayoutDeviceIntPoint(mScreenPoint.x, mScreenPoint.y),
                                     nsIntPoint(mRadius.width, mRadius.height),
                                     mRotationAngle,
                                     mForce);
   return touch.forget();
 }
 
+MouseInput::MouseInput(const WidgetMouseEventBase& aMouseEvent)
+  : InputData(MOUSE_INPUT, aMouseEvent.time, aMouseEvent.timeStamp,
+              aMouseEvent.modifiers)
+{
+  MOZ_ASSERT(NS_IsMainThread(),
+             "Can only copy from WidgetTouchEvent on main thread");
+
+  mButtonType = NONE;
+
+  switch (aMouseEvent.button) {
+    case WidgetMouseEventBase::eLeftButton:
+      mButtonType = MouseInput::LEFT_BUTTON;
+      break;
+    case WidgetMouseEventBase::eMiddleButton:
+      mButtonType = MouseInput::MIDDLE_BUTTON;
+      break;
+    case WidgetMouseEventBase::eRightButton:
+      mButtonType = MouseInput::RIGHT_BUTTON;
+      break;
+  }
+
+  switch (aMouseEvent.mMessage) {
+    case eMouseMove:
+      mType = MOUSE_MOVE;
+      break;
+    case eMouseUp:
+      mType = MOUSE_UP;
+      break;
+    case eMouseDown:
+      mType = MOUSE_DOWN;
+      break;
+    case eDragStart:
+      mType = MOUSE_DRAG_START;
+      break;
+    case eDragEnd:
+      mType = MOUSE_DRAG_END;
+      break;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
+      break;
+  }
+}
+
 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
   : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.timeStamp,
               aTouchEvent.modifiers)
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "Can only copy from WidgetTouchEvent on main thread");
 
   switch (aTouchEvent.mMessage) {
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -25,23 +25,25 @@ class Touch;
 
 namespace gfx {
 class Matrix4x4;
 } // namespace gfx
 
 enum InputType
 {
   MULTITOUCH_INPUT,
+  MOUSE_INPUT,
   PANGESTURE_INPUT,
   PINCHGESTURE_INPUT,
   TAPGESTURE_INPUT,
   SCROLLWHEEL_INPUT
 };
 
 class MultiTouchInput;
+class MouseInput;
 class PanGestureInput;
 class PinchGestureInput;
 class TapGestureInput;
 class ScrollWheelInput;
 
 // This looks unnecessary now, but as we add more and more classes that derive
 // from InputType (eventually probably almost as many as *Events.h has), it
 // will be more and more clear what's going on with a macro that shortens the
@@ -71,16 +73,17 @@ public:
   uint32_t mTime;
   // Set in parallel to mTime until we determine it is safe to drop
   // platform-specific event times (see bug 77992).
   TimeStamp mTimeStamp;
 
   Modifiers modifiers;
 
   INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
+  INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
   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)
 
   explicit InputData(InputType aInputType)
     : mInputType(aInputType),
       mTime(0),
@@ -240,16 +243,57 @@ public:
   explicit MultiTouchInput(const WidgetMouseEvent& aMouseEvent);
 
   bool TransformToLocal(const gfx::Matrix4x4& aTransform);
 
   MultiTouchType mType;
   nsTArray<SingleTouchData> mTouches;
 };
 
+class MouseInput : public InputData
+{
+public:
+  enum MouseType
+  {
+    MOUSE_MOVE,
+    MOUSE_DOWN,
+    MOUSE_UP,
+    MOUSE_DRAG_START,
+    MOUSE_DRAG_END,
+  };
+
+  enum ButtonType
+  {
+    LEFT_BUTTON,
+    MIDDLE_BUTTON,
+    RIGHT_BUTTON,
+    NONE
+  };
+
+  MouseInput(MouseType aType, ButtonType aButtonType, uint32_t aTime,
+             TimeStamp aTimeStamp, Modifiers aModifiers)
+    : InputData(MOUSE_INPUT, aTime, aTimeStamp, aModifiers)
+    , mType(aType)
+    , mButtonType(aButtonType)
+  {}
+
+  MouseInput()
+    : InputData(MOUSE_INPUT)
+  {}
+
+  explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
+
+  bool IsLeftButton() const { return mButtonType == LEFT_BUTTON; }
+
+  MouseType mType;
+  ButtonType mButtonType;
+  ScreenPoint mOrigin;
+  ParentLayerPoint mLocalOrigin;
+};
+
 /**
  * Encapsulation class for pan events, can be used off-main-thread.
  * These events are currently only used for scrolling on desktop.
  */
 class PanGestureInput : public InputData
 {
 public:
   enum PanGestureType