Bug 1049136 - Add a method to convert MultiTouchInputs to WidgetTouchEvents. r=mwu

Original code by Mason Chang posted on bug 970751; modified by Kartikaya Gupta
for use in bug 1049136.
This commit is contained in:
Mason Chang 2014-08-08 18:15:37 -04:00
parent 297a4e1d44
commit 0430af5cbc
2 changed files with 46 additions and 3 deletions

View File

@ -14,6 +14,7 @@
#include "mozilla/TimeStamp.h"
template<class E> struct already_AddRefed;
class nsIWidget;
namespace mozilla {
@ -124,7 +125,7 @@ public:
{
}
already_AddRefed<dom::Touch> ToNewDOMTouch();
already_AddRefed<dom::Touch> ToNewDOMTouch() const;
// A unique number assigned to each SingleTouchData within a MultiTouchInput so
// that they can be easily distinguished when handling a touch start/move/end.
@ -188,6 +189,7 @@ public:
}
MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
WidgetTouchEvent ToWidgetTouchEvent(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

View File

@ -15,7 +15,7 @@ namespace mozilla {
using namespace dom;
already_AddRefed<Touch> SingleTouchData::ToNewDOMTouch()
already_AddRefed<Touch> SingleTouchData::ToNewDOMTouch() const
{
NS_ABORT_IF_FALSE(NS_IsMainThread(),
"Can only create dom::Touch instances on main thread");
@ -48,7 +48,7 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
mType = MULTITOUCH_CANCEL;
break;
default:
NS_WARNING("Did not assign a type to a MultiTouchInput");
MOZ_ASSERT_UNREACHABLE("Did not assign a type to a MultiTouchInput");
break;
}
@ -74,6 +74,47 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
}
}
WidgetTouchEvent
MultiTouchInput::ToWidgetTouchEvent(nsIWidget* aWidget) const
{
NS_ABORT_IF_FALSE(NS_IsMainThread(),
"Can only convert To WidgetTouchEvent on main thread");
uint32_t touchType = NS_EVENT_NULL;
switch (mType) {
case MULTITOUCH_START:
touchType = NS_TOUCH_START;
break;
case MULTITOUCH_MOVE:
touchType = NS_TOUCH_MOVE;
break;
case MULTITOUCH_END:
touchType = NS_TOUCH_END;
break;
case MULTITOUCH_CANCEL:
touchType = NS_TOUCH_CANCEL;
break;
default:
MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetTouchEvent in MultiTouchInput");
break;
}
WidgetTouchEvent event(true, touchType, aWidget);
if (touchType == NS_EVENT_NULL) {
return event;
}
event.modifiers = this->modifiers;
event.time = this->mTime;
event.timeStamp = this->mTimeStamp;
for (size_t i = 0; i < mTouches.Length(); i++) {
*event.touches.AppendElement() = mTouches[i].ToNewDOMTouch();
}
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