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 "nsAutoPtr.h"
14 #include "nsIDOMSimpleGestureEvent.h"
19 /******************************************************************************
20 * mozilla::WidgetGestureNotifyEvent
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.
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 ******************************************************************************/
31 class WidgetGestureNotifyEvent
: public WidgetGUIEvent
34 virtual WidgetGestureNotifyEvent
* AsGestureNotifyEvent() MOZ_OVERRIDE
39 WidgetGestureNotifyEvent(bool aIsTrusted
, uint32_t aMessage
,
41 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
, eGestureNotifyEventClass
)
42 , panDirection(ePanNone
)
43 , displayPanFeedback(false)
47 virtual WidgetEvent
* Duplicate() const MOZ_OVERRIDE
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, message
, nullptr);
59 result
->AssignGestureNotifyEventData(*this, true);
60 result
->mFlags
= mFlags
;
72 ePanDirection panDirection
;
73 bool displayPanFeedback
;
75 void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent
& aEvent
,
78 AssignGUIEventData(aEvent
, aCopyTargets
);
80 panDirection
= aEvent
.panDirection
;
81 displayPanFeedback
= aEvent
.displayPanFeedback
;
85 /******************************************************************************
86 * mozilla::WidgetTouchEvent
87 ******************************************************************************/
89 class WidgetSimpleGestureEvent
: public WidgetMouseEventBase
92 virtual WidgetSimpleGestureEvent
* AsSimpleGestureEvent() MOZ_OVERRIDE
97 WidgetSimpleGestureEvent(bool aIsTrusted
, uint32_t aMessage
,
99 : WidgetMouseEventBase(aIsTrusted
, aMessage
, aWidget
,
100 eSimpleGestureEventClass
)
101 , allowedDirections(0)
108 WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent
& aOther
)
109 : WidgetMouseEventBase(aOther
.mFlags
.mIsTrusted
, aOther
.message
,
110 aOther
.widget
, eSimpleGestureEventClass
)
111 , allowedDirections(aOther
.allowedDirections
)
112 , direction(aOther
.direction
)
113 , delta(aOther
.delta
)
118 virtual WidgetEvent
* Duplicate() const MOZ_OVERRIDE
120 MOZ_ASSERT(mClass
== eSimpleGestureEventClass
,
121 "Duplicate() must be overridden by sub class");
122 // Not copying widget, it is a weak reference.
123 WidgetSimpleGestureEvent
* result
=
124 new WidgetSimpleGestureEvent(false, message
, nullptr);
125 result
->AssignSimpleGestureEventData(*this, true);
126 result
->mFlags
= mFlags
;
130 // See nsIDOMSimpleGestureEvent for values
131 uint32_t allowedDirections
;
132 // See nsIDOMSimpleGestureEvent for values
134 // Delta for magnify and rotate events
136 // The number of taps for tap events
139 // XXX Not tested by test_assign_event_data.html
140 void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent
& aEvent
,
143 AssignMouseEventBaseData(aEvent
, aCopyTargets
);
145 // allowedDirections isn't copied
146 direction
= aEvent
.direction
;
147 delta
= aEvent
.delta
;
148 clickCount
= aEvent
.clickCount
;
152 /******************************************************************************
153 * mozilla::WidgetTouchEvent
154 ******************************************************************************/
156 class WidgetTouchEvent
: public WidgetInputEvent
159 typedef nsTArray
<nsRefPtr
<mozilla::dom::Touch
>> TouchArray
;
160 typedef nsAutoTArray
<nsRefPtr
<mozilla::dom::Touch
>, 10> AutoTouchArray
;
162 virtual WidgetTouchEvent
* AsTouchEvent() MOZ_OVERRIDE
{ return this; }
168 WidgetTouchEvent(const WidgetTouchEvent
& aOther
)
169 : WidgetInputEvent(aOther
.mFlags
.mIsTrusted
, aOther
.message
, aOther
.widget
,
172 modifiers
= aOther
.modifiers
;
174 timeStamp
= aOther
.timeStamp
;
175 touches
.AppendElements(aOther
.touches
);
176 mFlags
.mCancelable
= message
!= NS_TOUCH_CANCEL
;
177 MOZ_COUNT_CTOR(WidgetTouchEvent
);
180 WidgetTouchEvent(bool aIsTrusted
, uint32_t aMessage
, nsIWidget
* aWidget
)
181 : WidgetInputEvent(aIsTrusted
, aMessage
, aWidget
, eTouchEventClass
)
183 MOZ_COUNT_CTOR(WidgetTouchEvent
);
184 mFlags
.mCancelable
= message
!= NS_TOUCH_CANCEL
;
187 virtual ~WidgetTouchEvent()
189 MOZ_COUNT_DTOR(WidgetTouchEvent
);
192 virtual WidgetEvent
* Duplicate() const MOZ_OVERRIDE
194 MOZ_ASSERT(mClass
== eTouchEventClass
,
195 "Duplicate() must be overridden by sub class");
196 // Not copying widget, it is a weak reference.
197 WidgetTouchEvent
* result
= new WidgetTouchEvent(false, message
, nullptr);
198 result
->AssignTouchEventData(*this, true);
199 result
->mFlags
= mFlags
;
205 void AssignTouchEventData(const WidgetTouchEvent
& aEvent
, bool aCopyTargets
)
207 AssignInputEventData(aEvent
, aCopyTargets
);
209 // Assign*EventData() assume that they're called only new instance.
210 MOZ_ASSERT(touches
.IsEmpty());
211 touches
.AppendElements(aEvent
.touches
);
215 } // namespace mozilla
217 #endif // mozilla_TouchEvents_h__