Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_TouchEvents_h__ |
michael@0 | 7 | #define mozilla_TouchEvents_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/dom/Touch.h" |
michael@0 | 12 | #include "mozilla/MouseEvents.h" |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | #include "nsIDOMSimpleGestureEvent.h" |
michael@0 | 15 | #include "nsTArray.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | /****************************************************************************** |
michael@0 | 20 | * mozilla::WidgetGestureNotifyEvent |
michael@0 | 21 | * |
michael@0 | 22 | * This event is the first event generated when the user touches |
michael@0 | 23 | * the screen with a finger, and it's meant to decide what kind |
michael@0 | 24 | * of action we'll use for that touch interaction. |
michael@0 | 25 | * |
michael@0 | 26 | * The event is dispatched to the layout and based on what is underneath |
michael@0 | 27 | * the initial contact point it's then decided if we should pan |
michael@0 | 28 | * (finger scrolling) or drag the target element. |
michael@0 | 29 | ******************************************************************************/ |
michael@0 | 30 | |
michael@0 | 31 | class WidgetGestureNotifyEvent : public WidgetGUIEvent |
michael@0 | 32 | { |
michael@0 | 33 | public: |
michael@0 | 34 | virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() MOZ_OVERRIDE |
michael@0 | 35 | { |
michael@0 | 36 | return this; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage, |
michael@0 | 40 | nsIWidget *aWidget) : |
michael@0 | 41 | WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_GESTURENOTIFY_EVENT), |
michael@0 | 42 | panDirection(ePanNone), displayPanFeedback(false) |
michael@0 | 43 | { |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 47 | { |
michael@0 | 48 | // XXX Looks like this event is handled only in PostHandleEvent() of |
michael@0 | 49 | // EventStateManager. Therefore, it might be possible to handle this |
michael@0 | 50 | // in PreHandleEvent() and not to dispatch as a DOM event into the DOM |
michael@0 | 51 | // tree like ContentQueryEvent. Then, this event doesn't need to |
michael@0 | 52 | // support Duplicate(). |
michael@0 | 53 | MOZ_ASSERT(eventStructType == NS_GESTURENOTIFY_EVENT, |
michael@0 | 54 | "Duplicate() must be overridden by sub class"); |
michael@0 | 55 | // Not copying widget, it is a weak reference. |
michael@0 | 56 | WidgetGestureNotifyEvent* result = |
michael@0 | 57 | new WidgetGestureNotifyEvent(false, message, nullptr); |
michael@0 | 58 | result->AssignGestureNotifyEventData(*this, true); |
michael@0 | 59 | result->mFlags = mFlags; |
michael@0 | 60 | return result; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | enum ePanDirection |
michael@0 | 64 | { |
michael@0 | 65 | ePanNone, |
michael@0 | 66 | ePanVertical, |
michael@0 | 67 | ePanHorizontal, |
michael@0 | 68 | ePanBoth |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | ePanDirection panDirection; |
michael@0 | 72 | bool displayPanFeedback; |
michael@0 | 73 | |
michael@0 | 74 | void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent, |
michael@0 | 75 | bool aCopyTargets) |
michael@0 | 76 | { |
michael@0 | 77 | AssignGUIEventData(aEvent, aCopyTargets); |
michael@0 | 78 | |
michael@0 | 79 | panDirection = aEvent.panDirection; |
michael@0 | 80 | displayPanFeedback = aEvent.displayPanFeedback; |
michael@0 | 81 | } |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | /****************************************************************************** |
michael@0 | 85 | * mozilla::WidgetTouchEvent |
michael@0 | 86 | ******************************************************************************/ |
michael@0 | 87 | |
michael@0 | 88 | class WidgetSimpleGestureEvent : public WidgetMouseEventBase |
michael@0 | 89 | { |
michael@0 | 90 | public: |
michael@0 | 91 | virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() MOZ_OVERRIDE |
michael@0 | 92 | { |
michael@0 | 93 | return this; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage, |
michael@0 | 97 | nsIWidget* aWidget) |
michael@0 | 98 | : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, |
michael@0 | 99 | NS_SIMPLE_GESTURE_EVENT) |
michael@0 | 100 | , allowedDirections(0) |
michael@0 | 101 | , direction(0) |
michael@0 | 102 | , delta(0.0) |
michael@0 | 103 | , clickCount(0) |
michael@0 | 104 | { |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther) |
michael@0 | 108 | : WidgetMouseEventBase(aOther.mFlags.mIsTrusted, aOther.message, |
michael@0 | 109 | aOther.widget, NS_SIMPLE_GESTURE_EVENT) |
michael@0 | 110 | , allowedDirections(aOther.allowedDirections) |
michael@0 | 111 | , direction(aOther.direction) |
michael@0 | 112 | , delta(aOther.delta) |
michael@0 | 113 | , clickCount(0) |
michael@0 | 114 | { |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 118 | { |
michael@0 | 119 | MOZ_ASSERT(eventStructType == NS_SIMPLE_GESTURE_EVENT, |
michael@0 | 120 | "Duplicate() must be overridden by sub class"); |
michael@0 | 121 | // Not copying widget, it is a weak reference. |
michael@0 | 122 | WidgetSimpleGestureEvent* result = |
michael@0 | 123 | new WidgetSimpleGestureEvent(false, message, nullptr); |
michael@0 | 124 | result->AssignSimpleGestureEventData(*this, true); |
michael@0 | 125 | result->mFlags = mFlags; |
michael@0 | 126 | return result; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | // See nsIDOMSimpleGestureEvent for values |
michael@0 | 130 | uint32_t allowedDirections; |
michael@0 | 131 | // See nsIDOMSimpleGestureEvent for values |
michael@0 | 132 | uint32_t direction; |
michael@0 | 133 | // Delta for magnify and rotate events |
michael@0 | 134 | double delta; |
michael@0 | 135 | // The number of taps for tap events |
michael@0 | 136 | uint32_t clickCount; |
michael@0 | 137 | |
michael@0 | 138 | // XXX Not tested by test_assign_event_data.html |
michael@0 | 139 | void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent, |
michael@0 | 140 | bool aCopyTargets) |
michael@0 | 141 | { |
michael@0 | 142 | AssignMouseEventBaseData(aEvent, aCopyTargets); |
michael@0 | 143 | |
michael@0 | 144 | // allowedDirections isn't copied |
michael@0 | 145 | direction = aEvent.direction; |
michael@0 | 146 | delta = aEvent.delta; |
michael@0 | 147 | clickCount = aEvent.clickCount; |
michael@0 | 148 | } |
michael@0 | 149 | }; |
michael@0 | 150 | |
michael@0 | 151 | /****************************************************************************** |
michael@0 | 152 | * mozilla::WidgetTouchEvent |
michael@0 | 153 | ******************************************************************************/ |
michael@0 | 154 | |
michael@0 | 155 | class WidgetTouchEvent : public WidgetInputEvent |
michael@0 | 156 | { |
michael@0 | 157 | public: |
michael@0 | 158 | virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; } |
michael@0 | 159 | |
michael@0 | 160 | WidgetTouchEvent() |
michael@0 | 161 | { |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | WidgetTouchEvent(const WidgetTouchEvent& aOther) : |
michael@0 | 165 | WidgetInputEvent(aOther.mFlags.mIsTrusted, aOther.message, aOther.widget, |
michael@0 | 166 | NS_TOUCH_EVENT) |
michael@0 | 167 | { |
michael@0 | 168 | modifiers = aOther.modifiers; |
michael@0 | 169 | time = aOther.time; |
michael@0 | 170 | touches.AppendElements(aOther.touches); |
michael@0 | 171 | mFlags.mCancelable = message != NS_TOUCH_CANCEL; |
michael@0 | 172 | MOZ_COUNT_CTOR(WidgetTouchEvent); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : |
michael@0 | 176 | WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_TOUCH_EVENT) |
michael@0 | 177 | { |
michael@0 | 178 | MOZ_COUNT_CTOR(WidgetTouchEvent); |
michael@0 | 179 | mFlags.mCancelable = message != NS_TOUCH_CANCEL; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | virtual ~WidgetTouchEvent() |
michael@0 | 183 | { |
michael@0 | 184 | MOZ_COUNT_DTOR(WidgetTouchEvent); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 188 | { |
michael@0 | 189 | MOZ_ASSERT(eventStructType == NS_TOUCH_EVENT, |
michael@0 | 190 | "Duplicate() must be overridden by sub class"); |
michael@0 | 191 | // Not copying widget, it is a weak reference. |
michael@0 | 192 | WidgetTouchEvent* result = new WidgetTouchEvent(false, message, nullptr); |
michael@0 | 193 | result->AssignTouchEventData(*this, true); |
michael@0 | 194 | result->mFlags = mFlags; |
michael@0 | 195 | return result; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | nsTArray<nsRefPtr<mozilla::dom::Touch>> touches; |
michael@0 | 199 | |
michael@0 | 200 | void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets) |
michael@0 | 201 | { |
michael@0 | 202 | AssignInputEventData(aEvent, aCopyTargets); |
michael@0 | 203 | |
michael@0 | 204 | // Assign*EventData() assume that they're called only new instance. |
michael@0 | 205 | MOZ_ASSERT(touches.IsEmpty()); |
michael@0 | 206 | touches.AppendElements(aEvent.touches); |
michael@0 | 207 | } |
michael@0 | 208 | }; |
michael@0 | 209 | |
michael@0 | 210 | } // namespace mozilla |
michael@0 | 211 | |
michael@0 | 212 | #endif // mozilla_TouchEvents_h__ |