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