michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_TouchEvents_h__ michael@0: #define mozilla_TouchEvents_h__ michael@0: michael@0: #include michael@0: michael@0: #include "mozilla/dom/Touch.h" michael@0: #include "mozilla/MouseEvents.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsIDOMSimpleGestureEvent.h" michael@0: #include "nsTArray.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetGestureNotifyEvent michael@0: * michael@0: * This event is the first event generated when the user touches michael@0: * the screen with a finger, and it's meant to decide what kind michael@0: * of action we'll use for that touch interaction. michael@0: * michael@0: * The event is dispatched to the layout and based on what is underneath michael@0: * the initial contact point it's then decided if we should pan michael@0: * (finger scrolling) or drag the target element. michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetGestureNotifyEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage, michael@0: nsIWidget *aWidget) : michael@0: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_GESTURENOTIFY_EVENT), michael@0: panDirection(ePanNone), displayPanFeedback(false) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: // XXX Looks like this event is handled only in PostHandleEvent() of michael@0: // EventStateManager. Therefore, it might be possible to handle this michael@0: // in PreHandleEvent() and not to dispatch as a DOM event into the DOM michael@0: // tree like ContentQueryEvent. Then, this event doesn't need to michael@0: // support Duplicate(). michael@0: MOZ_ASSERT(eventStructType == NS_GESTURENOTIFY_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: WidgetGestureNotifyEvent* result = michael@0: new WidgetGestureNotifyEvent(false, message, nullptr); michael@0: result->AssignGestureNotifyEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: enum ePanDirection michael@0: { michael@0: ePanNone, michael@0: ePanVertical, michael@0: ePanHorizontal, michael@0: ePanBoth michael@0: }; michael@0: michael@0: ePanDirection panDirection; michael@0: bool displayPanFeedback; michael@0: michael@0: void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: panDirection = aEvent.panDirection; michael@0: displayPanFeedback = aEvent.displayPanFeedback; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetTouchEvent michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetSimpleGestureEvent : public WidgetMouseEventBase michael@0: { michael@0: public: michael@0: virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage, michael@0: nsIWidget* aWidget) michael@0: : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, michael@0: NS_SIMPLE_GESTURE_EVENT) michael@0: , allowedDirections(0) michael@0: , direction(0) michael@0: , delta(0.0) michael@0: , clickCount(0) michael@0: { michael@0: } michael@0: michael@0: WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther) michael@0: : WidgetMouseEventBase(aOther.mFlags.mIsTrusted, aOther.message, michael@0: aOther.widget, NS_SIMPLE_GESTURE_EVENT) michael@0: , allowedDirections(aOther.allowedDirections) michael@0: , direction(aOther.direction) michael@0: , delta(aOther.delta) michael@0: , clickCount(0) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_SIMPLE_GESTURE_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: WidgetSimpleGestureEvent* result = michael@0: new WidgetSimpleGestureEvent(false, message, nullptr); michael@0: result->AssignSimpleGestureEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: // See nsIDOMSimpleGestureEvent for values michael@0: uint32_t allowedDirections; michael@0: // See nsIDOMSimpleGestureEvent for values michael@0: uint32_t direction; michael@0: // Delta for magnify and rotate events michael@0: double delta; michael@0: // The number of taps for tap events michael@0: uint32_t clickCount; michael@0: michael@0: // XXX Not tested by test_assign_event_data.html michael@0: void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignMouseEventBaseData(aEvent, aCopyTargets); michael@0: michael@0: // allowedDirections isn't copied michael@0: direction = aEvent.direction; michael@0: delta = aEvent.delta; michael@0: clickCount = aEvent.clickCount; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetTouchEvent michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetTouchEvent : public WidgetInputEvent michael@0: { michael@0: public: michael@0: virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; } michael@0: michael@0: WidgetTouchEvent() michael@0: { michael@0: } michael@0: michael@0: WidgetTouchEvent(const WidgetTouchEvent& aOther) : michael@0: WidgetInputEvent(aOther.mFlags.mIsTrusted, aOther.message, aOther.widget, michael@0: NS_TOUCH_EVENT) michael@0: { michael@0: modifiers = aOther.modifiers; michael@0: time = aOther.time; michael@0: touches.AppendElements(aOther.touches); michael@0: mFlags.mCancelable = message != NS_TOUCH_CANCEL; michael@0: MOZ_COUNT_CTOR(WidgetTouchEvent); michael@0: } michael@0: michael@0: WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : michael@0: WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_TOUCH_EVENT) michael@0: { michael@0: MOZ_COUNT_CTOR(WidgetTouchEvent); michael@0: mFlags.mCancelable = message != NS_TOUCH_CANCEL; michael@0: } michael@0: michael@0: virtual ~WidgetTouchEvent() michael@0: { michael@0: MOZ_COUNT_DTOR(WidgetTouchEvent); michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_TOUCH_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: WidgetTouchEvent* result = new WidgetTouchEvent(false, message, nullptr); michael@0: result->AssignTouchEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsTArray> touches; michael@0: michael@0: void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets) michael@0: { michael@0: AssignInputEventData(aEvent, aCopyTargets); michael@0: michael@0: // Assign*EventData() assume that they're called only new instance. michael@0: MOZ_ASSERT(touches.IsEmpty()); michael@0: touches.AppendElements(aEvent.touches); michael@0: } michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_TouchEvents_h__