Bug 1232338 - part 1, Add better mouse support to InputData MouseInput r=kats
authorRandall Barker <rbarker@mozilla.com>
Wed, 17 Feb 2016 13:56:28 -0800
changeset 339595 ec3026e8cd6f3af1fb8da5283574c3e8308379f0
parent 339594 302353ddf84f0b78847b305583a1cbe713503718
child 339596 d297ed97eaa1b1a4f309bbe4daa1df4c64dfcef8
push id12762
push userbmo:rail@mozilla.com
push dateFri, 11 Mar 2016 19:47:45 +0000
reviewerskats
bugs1232338
milestone48.0a1
Bug 1232338 - part 1, Add better mouse support to InputData MouseInput r=kats
widget/InputData.cpp
widget/InputData.h
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -26,16 +26,19 @@ already_AddRefed<Touch> SingleTouchData:
                                   mRotationAngle,
                                   mForce);
   return touch.forget();
 }
 
 MouseInput::MouseInput(const WidgetMouseEventBase& aMouseEvent)
   : InputData(MOUSE_INPUT, aMouseEvent.time, aMouseEvent.timeStamp,
               aMouseEvent.modifiers)
+  , mType(MOUSE_NONE)
+  , mButtonType(NONE)
+  , mButtons(aMouseEvent.buttons)
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "Can only copy from WidgetTouchEvent on main thread");
 
   mButtonType = NONE;
 
   switch (aMouseEvent.button) {
     case WidgetMouseEventBase::eLeftButton:
@@ -60,34 +63,110 @@ MouseInput::MouseInput(const WidgetMouse
       mType = MOUSE_DOWN;
       break;
     case eDragStart:
       mType = MOUSE_DRAG_START;
       break;
     case eDragEnd:
       mType = MOUSE_DRAG_END;
       break;
+    case eMouseEnterIntoWidget:
+      mType = MOUSE_WIDGET_ENTER;
+      break;
+    case eMouseExitFromWidget:
+      mType = MOUSE_WIDGET_EXIT;
+      break;
     default:
       MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
       break;
   }
+
+  mOrigin =
+    ScreenPoint(ViewAs<ScreenPixel>(aMouseEvent.refPoint,
+      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
 }
 
 bool
 MouseInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
 {
   Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mOrigin);
   if (!point) {
     return false;
   }
   mLocalOrigin = *point;
 
   return true;
 }
 
+WidgetMouseEvent
+MouseInput::ToWidgetMouseEvent(nsIWidget* aWidget) const
+{
+  MOZ_ASSERT(NS_IsMainThread(),
+             "Can only convert To WidgetTouchEvent on main thread");
+
+  EventMessage msg = eVoidEvent;
+  switch (mType) {
+    case MOUSE_MOVE:
+      msg = eMouseMove;
+      break;
+    case MOUSE_UP:
+      msg = eMouseUp;
+      break;
+    case MOUSE_DOWN:
+      msg = eMouseDown;
+      break;
+    case MOUSE_DRAG_START:
+      msg = eDragStart;
+      break;
+    case MOUSE_DRAG_END:
+      msg = eDragEnd;
+      break;
+    case MOUSE_WIDGET_ENTER:
+      msg = eMouseEnterIntoWidget;
+      break;
+    case MOUSE_WIDGET_EXIT:
+      msg = eMouseExitFromWidget;
+      break;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent in MouseInput");
+      break;
+  }
+
+  WidgetMouseEvent event(true, msg, aWidget, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
+
+  if (msg == eVoidEvent) {
+    return event;
+  }
+
+  switch (mButtonType) {
+    case MouseInput::LEFT_BUTTON:
+      event.button = WidgetMouseEventBase::eLeftButton;
+      break;
+    case MouseInput::MIDDLE_BUTTON:
+      event.button = WidgetMouseEventBase::eMiddleButton;
+      break;
+    case MouseInput::RIGHT_BUTTON:
+      event.button = WidgetMouseEventBase::eRightButton;
+      break;
+    case MouseInput::NONE:
+    default:
+      break;
+  }
+
+  event.buttons = mButtons;
+  event.modifiers = modifiers;
+  event.time = mTime;
+  event.timeStamp = mTimeStamp;
+  event.refPoint =
+    RoundedToInt(ViewAs<LayoutDevicePixel>(mOrigin,
+      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
+
+  return event;
+}
+
 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
   : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.timeStamp,
               aTouchEvent.modifiers)
   , mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ)
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "Can only copy from WidgetTouchEvent on main thread");
 
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -249,50 +249,60 @@ public:
   bool mHandledByAPZ;
 };
 
 class MouseInput : public InputData
 {
 public:
   enum MouseType
   {
+    MOUSE_NONE,
     MOUSE_MOVE,
     MOUSE_DOWN,
     MOUSE_UP,
     MOUSE_DRAG_START,
     MOUSE_DRAG_END,
+    MOUSE_WIDGET_ENTER,
+    MOUSE_WIDGET_EXIT,
   };
 
   enum ButtonType
   {
     LEFT_BUTTON,
     MIDDLE_BUTTON,
     RIGHT_BUTTON,
     NONE
   };
 
-  MouseInput(MouseType aType, ButtonType aButtonType, uint32_t aTime,
-             TimeStamp aTimeStamp, Modifiers aModifiers)
+  MouseInput(MouseType aType, ButtonType aButtonType, int16_t aButtons, const ScreenPoint& aPoint,
+             uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers)
     : InputData(MOUSE_INPUT, aTime, aTimeStamp, aModifiers)
     , mType(aType)
     , mButtonType(aButtonType)
+    , mButtons(aButtons)
+    , mOrigin(aPoint)
   {}
 
   MouseInput()
     : InputData(MOUSE_INPUT)
+    , mType(MOUSE_NONE)
+    , mButtonType(NONE)
+    , mButtons(0)
   {}
 
   explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
 
   bool IsLeftButton() const { return mButtonType == LEFT_BUTTON; }
 
   bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
+  WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
 
   MouseType mType;
   ButtonType mButtonType;
+  int16_t mButtons;
   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.
  */