Bug 1199885 - Part 1: Add MouseInput InputData. r=kats

--HG--
extra : commitid : Koa5TunrB2K
extra : rebase_source : 982a5bb2f320dd2c55410ef53904a44de1b06db5
This commit is contained in:
Benoit Girard 2015-09-28 10:32:05 -04:00
parent 53d634c95b
commit 3ccd3e736b
2 changed files with 87 additions and 0 deletions

View File

@ -28,6 +28,49 @@ already_AddRefed<Touch> SingleTouchData::ToNewDOMTouch() const
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)

View File

@ -30,6 +30,7 @@ class Matrix4x4;
enum InputType
{
MULTITOUCH_INPUT,
MOUSE_INPUT,
PANGESTURE_INPUT,
PINCHGESTURE_INPUT,
TAPGESTURE_INPUT,
@ -37,6 +38,7 @@ enum InputType
};
class MultiTouchInput;
class MouseInput;
class PanGestureInput;
class PinchGestureInput;
class TapGestureInput;
@ -76,6 +78,7 @@ public:
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)
@ -245,6 +248,47 @@ public:
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.