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/. */
6 #ifndef mozilla_TouchEvents_h__
7 #define mozilla_TouchEvents_h__
11 #include "mozilla/dom/Touch.h"
12 #include "mozilla/MouseEvents.h"
13 #include "mozilla/RefPtr.h"
18 /******************************************************************************
19 * mozilla::WidgetGestureNotifyEvent
21 * This event is the first event generated when the user touches
22 * the screen with a finger, and it's meant to decide what kind
23 * of action we'll use for that touch interaction.
25 * The event is dispatched to the layout and based on what is underneath
26 * the initial contact point it's then decided if we should pan
27 * (finger scrolling) or drag the target element.
28 ******************************************************************************/
30 class WidgetGestureNotifyEvent
: public WidgetGUIEvent
{
32 virtual WidgetGestureNotifyEvent
* AsGestureNotifyEvent() override
{
36 WidgetGestureNotifyEvent(bool aIsTrusted
, EventMessage aMessage
,
38 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
, eGestureNotifyEventClass
),
39 mPanDirection(ePanNone
),
40 mDisplayPanFeedback(false) {}
42 virtual WidgetEvent
* Duplicate() const override
{
43 // XXX Looks like this event is handled only in PostHandleEvent() of
44 // EventStateManager. Therefore, it might be possible to handle this
45 // in PreHandleEvent() and not to dispatch as a DOM event into the DOM
46 // tree like ContentQueryEvent. Then, this event doesn't need to
47 // support Duplicate().
48 MOZ_ASSERT(mClass
== eGestureNotifyEventClass
,
49 "Duplicate() must be overridden by sub class");
50 // Not copying widget, it is a weak reference.
51 WidgetGestureNotifyEvent
* result
=
52 new WidgetGestureNotifyEvent(false, mMessage
, nullptr);
53 result
->AssignGestureNotifyEventData(*this, true);
54 result
->mFlags
= mFlags
;
58 typedef int8_t PanDirectionType
;
59 enum PanDirection
: PanDirectionType
{
66 PanDirection mPanDirection
;
67 bool mDisplayPanFeedback
;
69 void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent
& aEvent
,
71 AssignGUIEventData(aEvent
, aCopyTargets
);
73 mPanDirection
= aEvent
.mPanDirection
;
74 mDisplayPanFeedback
= aEvent
.mDisplayPanFeedback
;
78 /******************************************************************************
79 * mozilla::WidgetSimpleGestureEvent
80 ******************************************************************************/
82 class WidgetSimpleGestureEvent
: public WidgetMouseEventBase
{
84 virtual WidgetSimpleGestureEvent
* AsSimpleGestureEvent() override
{
88 WidgetSimpleGestureEvent(bool aIsTrusted
, EventMessage aMessage
,
90 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
,
91 eSimpleGestureEventClass
),
92 mAllowedDirections(0),
97 WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent
& aOther
)
98 : WidgetMouseEventBase(aOther
.IsTrusted(), aOther
.mMessage
,
99 aOther
.mWidget
, eSimpleGestureEventClass
),
100 mAllowedDirections(aOther
.mAllowedDirections
),
101 mDirection(aOther
.mDirection
),
103 mDelta(aOther
.mDelta
) {}
105 virtual WidgetEvent
* Duplicate() const override
{
106 MOZ_ASSERT(mClass
== eSimpleGestureEventClass
,
107 "Duplicate() must be overridden by sub class");
108 // Not copying widget, it is a weak reference.
109 WidgetSimpleGestureEvent
* result
=
110 new WidgetSimpleGestureEvent(false, mMessage
, nullptr);
111 result
->AssignSimpleGestureEventData(*this, true);
112 result
->mFlags
= mFlags
;
116 // See SimpleGestureEvent.webidl for values
117 uint32_t mAllowedDirections
;
118 // See SimpleGestureEvent.webidl for values
120 // The number of taps for tap events
121 uint32_t mClickCount
;
122 // Delta for magnify and rotate events
125 // XXX Not tested by test_assign_event_data.html
126 void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent
& aEvent
,
128 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
130 // mAllowedDirections isn't copied
131 mDirection
= aEvent
.mDirection
;
132 mDelta
= aEvent
.mDelta
;
133 mClickCount
= aEvent
.mClickCount
;
137 /******************************************************************************
138 * mozilla::WidgetTouchEvent
139 ******************************************************************************/
141 class WidgetTouchEvent final
: public WidgetInputEvent
{
143 typedef nsTArray
<RefPtr
<mozilla::dom::Touch
>> TouchArray
;
144 typedef AutoTArray
<RefPtr
<mozilla::dom::Touch
>, 10> AutoTouchArray
;
145 typedef AutoTouchArray::base_type TouchArrayBase
;
147 WidgetTouchEvent
* AsTouchEvent() override
{ return this; }
149 MOZ_COUNTED_DEFAULT_CTOR(WidgetTouchEvent
)
151 WidgetTouchEvent(const WidgetTouchEvent
& aOther
)
152 : WidgetInputEvent(aOther
.IsTrusted(), aOther
.mMessage
, aOther
.mWidget
,
154 MOZ_COUNT_CTOR(WidgetTouchEvent
);
155 mModifiers
= aOther
.mModifiers
;
156 mTimeStamp
= aOther
.mTimeStamp
;
157 mTouches
.AppendElements(aOther
.mTouches
);
158 mInputSource
= aOther
.mInputSource
;
159 mButton
= aOther
.mButton
;
160 mButtons
= aOther
.mButtons
;
161 mFlags
.mCancelable
= mMessage
!= eTouchCancel
;
162 mFlags
.mHandledByAPZ
= aOther
.mFlags
.mHandledByAPZ
;
165 WidgetTouchEvent(WidgetTouchEvent
&& aOther
)
166 : WidgetInputEvent(std::move(aOther
)) {
167 MOZ_COUNT_CTOR(WidgetTouchEvent
);
168 mModifiers
= aOther
.mModifiers
;
169 mTimeStamp
= aOther
.mTimeStamp
;
170 mTouches
= std::move(aOther
.mTouches
);
171 mInputSource
= aOther
.mInputSource
;
172 mButton
= aOther
.mButton
;
173 mButtons
= aOther
.mButtons
;
174 mFlags
= aOther
.mFlags
;
177 WidgetTouchEvent
& operator=(WidgetTouchEvent
&&) = default;
179 WidgetTouchEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
)
180 : WidgetInputEvent(aIsTrusted
, aMessage
, aWidget
, eTouchEventClass
) {
181 MOZ_COUNT_CTOR(WidgetTouchEvent
);
182 mFlags
.mCancelable
= mMessage
!= eTouchCancel
;
185 MOZ_COUNTED_DTOR_OVERRIDE(WidgetTouchEvent
)
187 WidgetEvent
* Duplicate() const override
{
188 MOZ_ASSERT(mClass
== eTouchEventClass
,
189 "Duplicate() must be overridden by sub class");
190 // Not copying widget, it is a weak reference.
191 WidgetTouchEvent
* result
= new WidgetTouchEvent(false, mMessage
, nullptr);
192 result
->AssignTouchEventData(*this, true);
193 result
->mFlags
= mFlags
;
198 uint16_t mInputSource
= 5; // MouseEvent_Binding::MOZ_SOURCE_TOUCH
199 int16_t mButton
= eNotPressed
;
200 int16_t mButtons
= 0;
202 void AssignTouchEventData(const WidgetTouchEvent
& aEvent
, bool aCopyTargets
) {
203 AssignInputEventData(aEvent
, aCopyTargets
);
205 // Assign*EventData() assume that they're called only new instance.
206 MOZ_ASSERT(mTouches
.IsEmpty());
207 mTouches
.AppendElements(aEvent
.mTouches
);
208 mInputSource
= aEvent
.mInputSource
;
212 } // namespace mozilla
214 #endif // mozilla_TouchEvents_h__