diff --git a/widget/InputData.h b/widget/InputData.h index 1869e3a7eca8..96abd7131727 100644 --- a/widget/InputData.h +++ b/widget/InputData.h @@ -14,6 +14,7 @@ #include "mozilla/TimeStamp.h" template struct already_AddRefed; +class nsIWidget; namespace mozilla { @@ -124,7 +125,7 @@ public: { } - already_AddRefed ToNewDOMTouch(); + already_AddRefed 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 diff --git a/widget/xpwidgets/InputData.cpp b/widget/xpwidgets/InputData.cpp index 476919f7e78c..06798b5c3153 100644 --- a/widget/xpwidgets/InputData.cpp +++ b/widget/xpwidgets/InputData.cpp @@ -15,7 +15,7 @@ namespace mozilla { using namespace dom; -already_AddRefed SingleTouchData::ToNewDOMTouch() +already_AddRefed 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