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/. */
25 class MultiTouchInput
;
26 class PinchGestureInput
;
27 class TapGestureInput
;
29 // This looks unnecessary now, but as we add more and more classes that derive
30 // from InputType (eventually probably almost as many as nsGUIEvent.h has), it
31 // will be more and more clear what's going on with a macro that shortens the
32 // definition of the RTTI functions.
33 #define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
34 const type& As##type() const \
36 NS_ABORT_IF_FALSE(mInputType == enumID, "Invalid cast of InputData."); \
37 return (const type&) *this; \
40 /** Base input data class. Should never be instantiated. */
45 // Time in milliseconds that this data is relevant to. This only really
46 // matters when this data is used as an event. We use uint32_t instead of
47 // TimeStamp because it is easier to convert from nsInputEvent. The time is
48 // platform-specific but it in the case of B2G and Fennec it is since startup.
51 INPUTDATA_AS_CHILD_TYPE(MultiTouchInput
, MULTITOUCH_INPUT
)
52 INPUTDATA_AS_CHILD_TYPE(PinchGestureInput
, PINCHGESTURE_INPUT
)
53 INPUTDATA_AS_CHILD_TYPE(TapGestureInput
, TAPGESTURE_INPUT
)
60 InputData(InputType aInputType
, uint32_t aTime
)
61 : mInputType(aInputType
),
70 * Data container for a single touch input. Similar to dom::Touch, but used in
71 * off-main-thread situations. This is more for just storing touch data, whereas
72 * dom::Touch derives from nsIDOMTouch so it is more useful for dispatching
73 * through the DOM (which can only happen on the main thread). dom::Touch also
74 * bears the problem of storing pointers to nsIWidget instances which can only
75 * be used on the main thread, so if instead we used dom::Touch and ever set
76 * these pointers off-main-thread, Bad Things Can Happen(tm).
78 * Note that this doesn't inherit from InputData because this itself is not an
79 * event. It is only a container/struct that should have any number of instances
80 * within a MultiTouchInput.
82 * fixme/bug 775746: Make dom::Touch inherit from this class.
87 SingleTouchData(int32_t aIdentifier
,
88 nsIntPoint aScreenPoint
,
92 : mIdentifier(aIdentifier
),
93 mScreenPoint(aScreenPoint
),
95 mRotationAngle(aRotationAngle
),
106 // A unique number assigned to each SingleTouchData within a MultiTouchInput so
107 // that they can be easily distinguished when handling a touch start/move/end.
110 // Point on the screen that the touch hit, in device pixels. They are
111 // coordinates on the screen.
112 nsIntPoint mScreenPoint
;
114 // Radius that the touch covers, i.e. if you're using your thumb it will
115 // probably be larger than using your pinky, even with the same force.
116 // Radius can be different along x and y. For example, if you press down with
117 // your entire finger vertically, the y radius will be much larger than the x
121 float mRotationAngle
;
123 // How hard the screen is being pressed.
128 * Similar to nsTouchEvent, but for use off-main-thread. Also only stores a
129 * screen touch point instead of the many different coordinate spaces nsTouchEvent
130 * stores its touch point in. This includes a way to initialize itself from an
131 * nsTouchEvent by copying all relevant data over. Note that this copying from
132 * nsTouchEvent functionality can only be used on the main thread.
134 * Stores an array of SingleTouchData.
136 class MultiTouchInput
: public InputData
149 MultiTouchInput(MultiTouchType aType
, uint32_t aTime
)
150 : InputData(MULTITOUCH_INPUT
, aTime
),
161 MultiTouchInput(const nsTouchEvent
& aTouchEvent
);
163 // This conversion from nsMouseEvent to MultiTouchInput is needed because on
164 // the B2G emulator we can only receive mouse events, but we need to be able
165 // to pan correctly. To do this, we convert the events into a format that the
166 // panning code can handle. This code is very limited and only supports
167 // SingleTouchData. It also sends garbage for the identifier, radius, force
168 // and rotation angle.
169 MultiTouchInput(const nsMouseEvent
& aMouseEvent
);
171 MultiTouchType mType
;
172 nsTArray
<SingleTouchData
> mTouches
;
176 * Encapsulation class for pinch events. In general, these will be generated by
177 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
178 * determining whether or not the user was trying to do a gesture.
180 class PinchGestureInput
: public InputData
183 enum PinchGestureType
190 PinchGestureInput(PinchGestureType aType
,
192 const nsIntPoint
& aFocusPoint
,
195 : InputData(PINCHGESTURE_INPUT
, aTime
),
197 mFocusPoint(aFocusPoint
),
198 mCurrentSpan(aCurrentSpan
),
199 mPreviousSpan(aPreviousSpan
)
205 PinchGestureType mType
;
207 // Center point of the pinch gesture. That is, if there are two fingers on the
208 // screen, it is their midpoint. In the case of more than two fingers, the
209 // point is implementation-specific, but can for example be the midpoint
210 // between the very first and very last touch. This is in device pixels and
211 // are the coordinates on the screen of this midpoint.
212 nsIntPoint mFocusPoint
;
214 // The distance in device pixels (though as a float for increased precision
215 // and because it is the distance along both the x and y axis) between the
216 // touches responsible for the pinch gesture.
219 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
220 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
221 // of this type then there must have been a history of spans.
226 * Encapsulation class for tap events. In general, these will be generated by
227 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
228 * determining whether or not the user was trying to do a gesture.
230 class TapGestureInput
: public InputData
237 TAPGESTURE_CONFIRMED
,
242 TapGestureInput(TapGestureType aType
, uint32_t aTime
, const nsIntPoint
& aPoint
)
243 : InputData(TAPGESTURE_INPUT
, aTime
),
251 TapGestureType mType
;
257 #endif // InputData_h__