Bug 1756130 [wpt PR 32898] - [CSP] Enhance unsafe-eval test to check both realms...
[gecko.git] / widget / InputData.h
blobe967336304a325c974a98eb35c7004e71df3e186
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 InputData_h__
7 #define InputData_h__
9 #include "nsDebug.h"
10 #include "nsPoint.h"
11 #include "nsTArray.h"
12 #include "Units.h"
13 #include "mozilla/ScrollTypes.h"
14 #include "mozilla/DefineEnum.h"
15 #include "mozilla/EventForwards.h"
16 #include "mozilla/TimeStamp.h"
17 #include "mozilla/WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
18 #include "mozilla/gfx/MatrixFwd.h"
19 #include "mozilla/layers/APZPublicUtils.h"
20 #include "mozilla/layers/KeyboardScrollAction.h"
21 #include "mozilla/TextEvents.h"
23 template <class E>
24 struct already_AddRefed;
25 class nsIWidget;
27 namespace mozilla {
29 namespace layers {
30 class APZInputBridgeChild;
31 class PAPZInputBridgeParent;
32 } // namespace layers
34 namespace dom {
35 class Touch;
36 } // namespace dom
38 // clang-format off
39 MOZ_DEFINE_ENUM(
40 InputType, (
41 MULTITOUCH_INPUT,
42 MOUSE_INPUT,
43 PANGESTURE_INPUT,
44 PINCHGESTURE_INPUT,
45 TAPGESTURE_INPUT,
46 SCROLLWHEEL_INPUT,
47 KEYBOARD_INPUT
48 ));
49 // clang-format on
51 class MultiTouchInput;
52 class MouseInput;
53 class PanGestureInput;
54 class PinchGestureInput;
55 class TapGestureInput;
56 class ScrollWheelInput;
57 class KeyboardInput;
59 // This looks unnecessary now, but as we add more and more classes that derive
60 // from InputType (eventually probably almost as many as *Events.h has), it
61 // will be more and more clear what's going on with a macro that shortens the
62 // definition of the RTTI functions.
63 #define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
64 const type& As##type() const { \
65 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
66 return (const type&)*this; \
67 } \
68 type& As##type() { \
69 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
70 return (type&)*this; \
73 /** Base input data class. Should never be instantiated. */
74 class InputData {
75 public:
76 // Warning, this class is serialized and sent over IPC. Any change to its
77 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
78 InputType mInputType;
79 // Time in milliseconds that this data is relevant to. This only really
80 // matters when this data is used as an event. We use uint32_t instead of
81 // TimeStamp because it is easier to convert from WidgetInputEvent. The time
82 // is platform-specific but it in the case of B2G and Fennec it is since
83 // startup.
84 uint32_t mTime;
85 // Set in parallel to mTime until we determine it is safe to drop
86 // platform-specific event times (see bug 77992).
87 TimeStamp mTimeStamp;
88 // The sequence number of the last potentially focus changing event handled
89 // by APZ. This is used to track when that event has been processed by
90 // content, and focus can be reconfirmed for async keyboard scrolling.
91 uint64_t mFocusSequenceNumber;
93 // The LayersId of the content process that the corresponding WidgetEvent
94 // should be dispatched to.
95 layers::LayersId mLayersId;
97 Modifiers modifiers;
99 INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
100 INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
101 INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
102 INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
103 INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
104 INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
105 INPUTDATA_AS_CHILD_TYPE(KeyboardInput, KEYBOARD_INPUT)
107 virtual ~InputData();
108 explicit InputData(InputType aInputType);
110 protected:
111 InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
112 Modifiers aModifiers);
116 * Data container for a single touch input. Similar to dom::Touch, but used in
117 * off-main-thread situations. This is more for just storing touch data, whereas
118 * dom::Touch is more useful for dispatching through the DOM (which can only
119 * happen on the main thread). dom::Touch also bears the problem of storing
120 * pointers to nsIWidget instances which can only be used on the main thread,
121 * so if instead we used dom::Touch and ever set these pointers
122 * off-main-thread, Bad Things Can Happen(tm).
124 * Note that this doesn't inherit from InputData because this itself is not an
125 * event. It is only a container/struct that should have any number of instances
126 * within a MultiTouchInput.
128 * fixme/bug 775746: Make dom::Touch inherit from this class.
130 class SingleTouchData {
131 public:
132 // Construct a SingleTouchData from a Screen point.
133 // mLocalScreenPoint remains (0,0) unless it's set later.
134 SingleTouchData(int32_t aIdentifier, ScreenIntPoint aScreenPoint,
135 ScreenSize aRadius, float aRotationAngle, float aForce);
137 // Construct a SingleTouchData from a ParentLayer point.
138 // mScreenPoint remains (0,0) unless it's set later.
139 // Note: if APZ starts using the radius for anything, we should add a local
140 // version of that too, and have this constructor take it as a
141 // ParentLayerSize.
142 SingleTouchData(int32_t aIdentifier, ParentLayerPoint aLocalScreenPoint,
143 ScreenSize aRadius, float aRotationAngle, float aForce);
145 SingleTouchData();
147 already_AddRefed<dom::Touch> ToNewDOMTouch() const;
149 // Warning, this class is serialized and sent over IPC. Any change to its
150 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
152 // Historical data of this touch, which was coalesced into this event.
153 // Touch event coalescing can happen at the system level when the touch
154 // screen's sampling frequency is higher than the vsync rate, or when the
155 // UI thread is busy. When multiple "samples" of touch data are coalesced into
156 // one touch event, the touch event's regular position information is the
157 // information from the last sample. And the previous, "coalesced-away"
158 // samples are stored in mHistoricalData.
160 struct HistoricalTouchData {
161 // The timestamp at which the information in this "sample" was originally
162 // sampled.
163 TimeStamp mTimeStamp;
165 // The touch data of this historical sample.
166 ScreenIntPoint mScreenPoint;
167 ParentLayerPoint mLocalScreenPoint;
168 ScreenSize mRadius;
169 float mRotationAngle = 0.0f;
170 float mForce = 0.0f;
172 CopyableTArray<HistoricalTouchData> mHistoricalData;
174 // A unique number assigned to each SingleTouchData within a MultiTouchInput
175 // so that they can be easily distinguished when handling a touch
176 // start/move/end.
177 int32_t mIdentifier;
179 // Point on the screen that the touch hit, in device pixels. They are
180 // coordinates on the screen.
181 ScreenIntPoint mScreenPoint;
183 // |mScreenPoint| transformed to the local coordinates of the APZC targeted
184 // by the hit. This is set and used by APZ.
185 ParentLayerPoint mLocalScreenPoint;
187 // Radius that the touch covers, i.e. if you're using your thumb it will
188 // probably be larger than using your pinky, even with the same force.
189 // Radius can be different along x and y. For example, if you press down with
190 // your entire finger vertically, the y radius will be much larger than the x
191 // radius.
192 ScreenSize mRadius;
194 float mRotationAngle;
196 // How hard the screen is being pressed.
197 float mForce;
199 uint32_t mTiltX = 0;
200 uint32_t mTiltY = 0;
201 uint32_t mTwist = 0;
205 * Similar to WidgetTouchEvent, but for use off-main-thread. Also only stores a
206 * screen touch point instead of the many different coordinate spaces
207 * WidgetTouchEvent stores its touch point in. This includes a way to initialize
208 * itself from a WidgetTouchEvent by copying all relevant data over. Note that
209 * this copying from WidgetTouchEvent functionality can only be used on the main
210 * thread.
212 * Stores an array of SingleTouchData.
214 class MultiTouchInput : public InputData {
215 public:
216 // clang-format off
217 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
218 MultiTouchType, (
219 MULTITOUCH_START,
220 MULTITOUCH_MOVE,
221 MULTITOUCH_END,
222 MULTITOUCH_CANCEL
224 // clang-format on
226 MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
227 Modifiers aModifiers);
228 MultiTouchInput();
229 MultiTouchInput(MultiTouchInput&&) = default;
230 MultiTouchInput(const MultiTouchInput& aOther);
231 explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
233 MultiTouchInput& operator=(MultiTouchInput&&) = default;
234 MultiTouchInput& operator=(const MultiTouchInput&) = default;
236 void Translate(const ScreenPoint& aTranslation);
238 WidgetTouchEvent ToWidgetEvent(
239 nsIWidget* aWidget,
240 uint16_t aInputSource =
241 /* MouseEvent_Binding::MOZ_SOURCE_TOUCH = */ 5) const;
243 // Return the index into mTouches of the SingleTouchData with the given
244 // identifier, or -1 if there is no such SingleTouchData.
245 int32_t IndexOfTouch(int32_t aTouchIdentifier);
247 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
249 // Warning, this class is serialized and sent over IPC. Any change to its
250 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
251 MultiTouchType mType;
252 CopyableTArray<SingleTouchData> mTouches;
253 // The screen offset of the root widget. This can be changing along with
254 // the touch interaction, so we sstore it in the event.
255 ExternalPoint mScreenOffset;
256 bool mHandledByAPZ;
257 // These button fields match to the corresponding fields in
258 // WidgetMouseEventBase, except mButton defaults to -1 to follow PointerEvent.
259 int16_t mButton = eNotPressed;
260 int16_t mButtons = 0;
263 class MouseInput : public InputData {
264 protected:
265 friend mozilla::layers::APZInputBridgeChild;
266 friend mozilla::layers::PAPZInputBridgeParent;
268 MouseInput();
270 public:
271 // clang-format off
272 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
273 MouseType, (
274 MOUSE_NONE,
275 MOUSE_MOVE,
276 MOUSE_DOWN,
277 MOUSE_UP,
278 MOUSE_DRAG_START,
279 MOUSE_DRAG_END,
280 MOUSE_WIDGET_ENTER,
281 MOUSE_WIDGET_EXIT,
282 MOUSE_HITTEST,
283 MOUSE_EXPLORE_BY_TOUCH
286 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
287 ButtonType, (
288 PRIMARY_BUTTON,
289 MIDDLE_BUTTON,
290 SECONDARY_BUTTON,
291 NONE
293 // clang-format on
295 MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
296 int16_t aButtons, const ScreenPoint& aPoint, uint32_t aTime,
297 TimeStamp aTimeStamp, Modifiers aModifiers);
298 explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
300 bool IsLeftButton() const;
302 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
303 WidgetMouseEvent ToWidgetEvent(nsIWidget* aWidget) const;
305 // Warning, this class is serialized and sent over IPC. Any change to its
306 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
307 MouseType mType;
308 ButtonType mButtonType;
309 uint16_t mInputSource;
310 int16_t mButtons;
311 ScreenPoint mOrigin;
312 ParentLayerPoint mLocalOrigin;
313 bool mHandledByAPZ;
315 * If click event should not be fired in the content after the "mousedown"
316 * event or following "mouseup", set to true.
318 bool mPreventClickEvent;
322 * Encapsulation class for pan events, can be used off-main-thread.
323 * These events are currently only used for scrolling on desktop.
325 class PanGestureInput : public InputData {
326 protected:
327 friend mozilla::layers::APZInputBridgeChild;
328 friend mozilla::layers::PAPZInputBridgeParent;
330 PanGestureInput();
332 public:
333 // clang-format off
334 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
335 PanGestureType, (
336 // MayStart: Dispatched before any actual panning has occurred but when a
337 // pan gesture is probably about to start, for example when the user
338 // starts touching the touchpad. Should interrupt any ongoing APZ
339 // animation and can be used to trigger scrollability indicators (e.g.
340 // flashing overlay scrollbars).
341 PANGESTURE_MAYSTART,
343 // Cancelled: Dispatched after MayStart when no pan gesture is going to
344 // happen after all, for example when the user lifts their fingers from a
345 // touchpad without having done any scrolling.
346 PANGESTURE_CANCELLED,
348 // Start: A pan gesture is starting.
349 // For devices that do not support the MayStart event type, this event can
350 // be used to interrupt ongoing APZ animations.
351 PANGESTURE_START,
353 // Pan: The actual pan motion by mPanDisplacement.
354 PANGESTURE_PAN,
356 // End: The pan gesture has ended, for example because the user has lifted
357 // their fingers from a touchpad after scrolling.
358 // Any potential momentum events fire after this event.
359 PANGESTURE_END,
361 // The following momentum event types are used in order to control the pan
362 // momentum animation. Using these instead of our own animation ensures
363 // that the animation curve is OS native and that the animation stops
364 // reliably if it is cancelled by the user.
366 // MomentumStart: Dispatched between the End event of the actual
367 // user-controlled pan, and the first MomentumPan event of the momentum
368 // animation.
369 PANGESTURE_MOMENTUMSTART,
371 // MomentumPan: The actual momentum motion by mPanDisplacement.
372 PANGESTURE_MOMENTUMPAN,
374 // MomentumEnd: The momentum animation has ended, for example because the
375 // momentum velocity has gone below the stopping threshold, or because the
376 // user has stopped the animation by putting their fingers on a touchpad.
377 PANGESTURE_MOMENTUMEND,
379 // Interrupted:: A pan gesture started being handled by an APZC but
380 // subsequent pan events might have been consumed by other operations
381 // which haven't been handled by the APZC (e.g. full zoom).
382 PANGESTURE_INTERRUPTED
385 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
386 PanDeltaType, (
387 // There are three kinds of scroll delta modes in Gecko: "page", "line"
388 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
390 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
391 // (see AsyncPanZoomController::OnPan).
392 PANDELTA_PAGE,
393 PANDELTA_PIXEL
395 // clang-format on
397 PanGestureInput(PanGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
398 const ScreenPoint& aPanStartPoint,
399 const ScreenPoint& aPanDisplacement, Modifiers aModifiers);
401 void SetLineOrPageDeltas(int32_t aLineOrPageDeltaX,
402 int32_t aLineOrPageDeltaY);
404 bool IsMomentum() const;
406 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
408 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
410 ScreenPoint UserMultipliedPanDisplacement() const;
411 ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
413 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
415 // Warning, this class is serialized and sent over IPC. Any change to its
416 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
417 PanGestureType mType;
418 ScreenPoint mPanStartPoint;
420 // The delta. This can be non-zero on any type of event.
421 ScreenPoint mPanDisplacement;
423 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
424 // coordinates of the APZC receiving the pan. These are set and used by APZ.
425 ParentLayerPoint mLocalPanStartPoint;
426 ParentLayerPoint mLocalPanDisplacement;
428 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
429 int32_t mLineOrPageDeltaX;
430 int32_t mLineOrPageDeltaY;
432 // User-set delta multipliers.
433 double mUserDeltaMultiplierX;
434 double mUserDeltaMultiplierY;
436 PanDeltaType mDeltaType = PANDELTA_PIXEL;
438 bool mHandledByAPZ : 1;
440 // If this is true, and this event started a new input block that couldn't
441 // find a scrollable target which is scrollable in the horizontal component
442 // of the scroll start direction, then this input block needs to be put on
443 // hold until a content response has arrived, even if the block has a
444 // confirmed target.
445 // This is used by events that can result in a swipe instead of a scroll.
446 bool mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection : 1;
448 // This is used by APZ to communicate to the macOS widget code whether
449 // the overscroll-behavior of the scroll frame handling this swipe allows
450 // non-local overscroll behaviors in the horizontal direction (such as
451 // swipe navigation).
452 bool mOverscrollBehaviorAllowsSwipe : 1;
454 // true if APZ should do a fling animation after this pan ends, like
455 // it would with touchscreens. (For platforms that don't emit momentum
456 // events.)
457 bool mSimulateMomentum : 1;
459 // true if the creator of this object does not set the mLineOrPageDeltaX/Y
460 // fields and when/if WidgetWheelEvent's are generated from this object wants
461 // the corresponding mLineOrPageDeltaX/Y fields in the WidgetWheelEvent to be
462 // automatically calculated (upon event dispatch by the EventStateManager
463 // code).
464 bool mIsNoLineOrPageDelta : 1;
466 void SetHandledByAPZ(bool aHandled) { mHandledByAPZ = aHandled; }
467 void SetRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(
468 bool aRequires) {
469 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection =
470 aRequires;
472 void SetOverscrollBehaviorAllowsSwipe(bool aAllows) {
473 mOverscrollBehaviorAllowsSwipe = aAllows;
475 void SetSimulateMomentum(bool aSimulate) { mSimulateMomentum = aSimulate; }
476 void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta) {
477 mIsNoLineOrPageDelta = aIsNoLineOrPageDelta;
482 * Encapsulation class for pinch events. In general, these will be generated by
483 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
484 * and determining whether or not the user was trying to do a gesture.
486 class PinchGestureInput : public InputData {
487 protected:
488 friend mozilla::layers::APZInputBridgeChild;
489 friend mozilla::layers::PAPZInputBridgeParent;
491 PinchGestureInput();
493 public:
494 // clang-format off
495 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
496 PinchGestureType, (
497 PINCHGESTURE_START,
498 PINCHGESTURE_SCALE,
499 // The FINGERLIFTED state is used when a touch-based pinch gesture is
500 // terminated by lifting one of the two fingers. The position of the
501 // finger that's still down is populated as the focus point.
502 PINCHGESTURE_FINGERLIFTED,
503 // The END state is used when the pinch gesture is completely terminated.
504 // In this state, the focus point should not be relied upon for having
505 // meaningful data.
506 PINCHGESTURE_END
509 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
510 PinchGestureSource, (
511 UNKNOWN, // Default initialization value. Should never actually be used.
512 TOUCH, // From two-finger pinch gesture
513 ONE_TOUCH, // From one-finger pinch gesture
514 TRACKPAD, // From trackpad pinch gesture
515 MOUSEWHEEL // Synthesized from modifier+mousewheel
517 // If adding more items here, increase n_values for the
518 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
520 // clang-format on
522 // Construct a pinch gesture from a Screen point.
523 PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
524 uint32_t aTime, TimeStamp aTimeStamp,
525 const ExternalPoint& aScreenOffset,
526 const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
527 ScreenCoord aPreviousSpan, Modifiers aModifiers);
529 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
531 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
533 double ComputeDeltaY(nsIWidget* aWidget) const;
535 // Set mLineOrPageDeltaY based on ComputeDeltaY().
536 // Return false if the caller should drop this event to ensure
537 // that preventDefault() is respected. (More specifically, this will be
538 // true for event types other than PINCHGESTURE_END if the computed
539 // mLineOrPageDeltaY is zero. In such cases, the resulting DOMMouseScroll
540 // event will not be dispatched, which is a problem if the page is relying
541 // on DOMMouseScroll to prevent browser zooming).
542 // Note that even if the function returns false, the delta from the event
543 // is accumulated and available to be sent in a later event.
544 bool SetLineOrPageDeltaY(nsIWidget* aWidget);
546 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
548 // Warning, this class is serialized and sent over IPC. Any change to its
549 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
550 PinchGestureType mType;
552 // Some indication of the input device that generated this pinch gesture.
553 PinchGestureSource mSource;
555 // Center point of the pinch gesture. That is, if there are two fingers on the
556 // screen, it is their midpoint. In the case of more than two fingers, the
557 // point is implementation-specific, but can for example be the midpoint
558 // between the very first and very last touch. This is in device pixels and
559 // are the coordinates on the screen of this midpoint.
560 // For PINCHGESTURE_END events, this may hold the last known focus point or
561 // just be empty; in any case for END events it should not be relied upon.
562 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
563 // that is still down.
564 ScreenPoint mFocusPoint;
566 // The screen offset of the root widget. This can be changing along with
567 // the touch interaction, so we sstore it in the event.
568 ExternalPoint mScreenOffset;
570 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
571 // by the hit. This is set and used by APZ.
572 ParentLayerPoint mLocalFocusPoint;
574 // The distance between the touches responsible for the pinch gesture.
575 ScreenCoord mCurrentSpan;
577 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
578 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
579 // of this type then there must have been a history of spans.
580 ScreenCoord mPreviousSpan;
582 // We accumulate (via GetIntegerDeltaForEvent) the deltaY that would be
583 // computed by ToWidgetEvent, and then whenever we get a whole integer
584 // value we put it in mLineOrPageDeltaY. Since we only ever use deltaY we
585 // don't need a mLineOrPageDeltaX. This field is used to dispatch legacy mouse
586 // events which are only dispatched when the corresponding field on
587 // WidgetWheelEvent is non-zero.
588 int32_t mLineOrPageDeltaY;
590 bool mHandledByAPZ;
594 * Encapsulation class for tap events. In general, these will be generated by
595 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
596 * and determining whether or not the user was trying to do a gesture.
598 class TapGestureInput : public InputData {
599 protected:
600 friend mozilla::layers::APZInputBridgeChild;
601 friend mozilla::layers::PAPZInputBridgeParent;
603 TapGestureInput();
605 public:
606 // clang-format off
607 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
608 TapGestureType, (
609 TAPGESTURE_LONG,
610 TAPGESTURE_LONG_UP,
611 TAPGESTURE_UP,
612 TAPGESTURE_CONFIRMED,
613 TAPGESTURE_DOUBLE,
614 TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
615 TAPGESTURE_CANCEL
617 // clang-format on
619 // Construct a tap gesture from a Screen point.
620 // mLocalPoint remains (0,0) unless it's set later.
621 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
622 const ScreenIntPoint& aPoint, Modifiers aModifiers);
624 // Construct a tap gesture from a ParentLayer point.
625 // mPoint remains (0,0) unless it's set later.
626 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
627 const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
629 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
631 WidgetSimpleGestureEvent ToWidgetEvent(nsIWidget* aWidget) const;
633 // Warning, this class is serialized and sent over IPC. Any change to its
634 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
635 TapGestureType mType;
637 // The location of the tap in screen pixels.
638 ScreenIntPoint mPoint;
640 // The location of the tap in the local coordinates of the APZC receiving it.
641 // This is set and used by APZ.
642 ParentLayerPoint mLocalPoint;
645 // Encapsulation class for scroll-wheel events. These are generated by mice
646 // with physical scroll wheels, and on Windows by most touchpads when using
647 // scroll gestures.
648 class ScrollWheelInput : public InputData {
649 protected:
650 friend mozilla::layers::APZInputBridgeChild;
651 friend mozilla::layers::PAPZInputBridgeParent;
653 typedef mozilla::layers::APZWheelAction APZWheelAction;
655 ScrollWheelInput();
657 public:
658 // clang-format off
659 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
660 ScrollDeltaType, (
661 // There are three kinds of scroll delta modes in Gecko: "page", "line"
662 // and "pixel".
663 SCROLLDELTA_LINE,
664 SCROLLDELTA_PAGE,
665 SCROLLDELTA_PIXEL
668 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
669 ScrollMode, (
670 SCROLLMODE_INSTANT,
671 SCROLLMODE_SMOOTH
674 // clang-format on
676 ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers,
677 ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
678 const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
679 bool aAllowToOverrideSystemScrollSpeed,
680 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
681 explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
683 static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
684 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
685 static mozilla::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
687 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
688 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
690 bool IsCustomizedByUserPrefs() const;
692 // The following two functions are for auto-dir scrolling. For detailed
693 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
694 bool IsAutoDir(bool aForce = false) const {
695 if (aForce) {
696 return true;
699 switch (mWheelDeltaAdjustmentStrategy) {
700 case WheelDeltaAdjustmentStrategy::eAutoDir:
701 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
702 return true;
703 default:
704 // Prevent compilation errors generated by -Werror=switch
705 break;
707 return false;
709 // Indicates which element this scroll honours if it's an auto-dir scroll.
710 // If true, honour the root element; otherwise, honour the currently scrolling
711 // target.
712 // Note that if IsAutoDir() returns false, then this function also returns
713 // false, but false in this case is meaningless as IsAutoDir() indicates it's
714 // not an auto-dir scroll.
715 // For detailed information on auto-dir,
716 // @see mozilla::WheelDeltaAdjustmentStrategy
717 bool HonoursRoot(bool aForce = false) const {
718 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
719 mWheelDeltaAdjustmentStrategy ||
720 aForce;
723 // Warning, this class is serialized and sent over IPC. Any change to its
724 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
725 ScrollDeltaType mDeltaType;
726 ScrollMode mScrollMode;
727 ScreenPoint mOrigin;
729 bool mHandledByAPZ;
731 // Deltas are in units corresponding to the delta type. For line deltas, they
732 // are the number of line units to scroll. The number of device pixels for a
733 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
734 // For pixel deltas, these values are in ScreenCoords.
736 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
737 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
738 // scrolling down.
739 double mDeltaX;
740 double mDeltaY;
742 // The number of scroll wheel ticks.
743 double mWheelTicksX = 0.0;
744 double mWheelTicksY = 0.0;
746 // The location of the scroll in local coordinates. This is set and used by
747 // APZ.
748 ParentLayerPoint mLocalOrigin;
750 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
751 int32_t mLineOrPageDeltaX;
752 int32_t mLineOrPageDeltaY;
754 // Indicates the order in which this event was added to a transaction. The
755 // first event is 1; if not a member of a transaction, this is 0.
756 uint32_t mScrollSeriesNumber;
758 // User-set delta multipliers.
759 double mUserDeltaMultiplierX;
760 double mUserDeltaMultiplierY;
762 bool mMayHaveMomentum;
763 bool mIsMomentum;
764 bool mAllowToOverrideSystemScrollSpeed;
766 // Sometimes a wheel event input's wheel delta should be adjusted. This member
767 // specifies how to adjust the wheel delta.
768 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
770 APZWheelAction mAPZAction;
773 class KeyboardInput : public InputData {
774 public:
775 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
777 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
778 // other member, don't forget to update the minimum value in
779 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
780 // accordingly.
781 enum KeyboardEventType {
782 KEY_DOWN,
783 KEY_PRESS,
784 KEY_UP,
785 // Any other key event such as eKeyDownOnPlugin
786 KEY_OTHER,
788 // Used as an upper bound for ContiguousEnumSerializer
789 KEY_SENTINEL,
792 explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
794 // Warning, this class is serialized and sent over IPC. Any change to its
795 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
797 KeyboardEventType mType;
798 uint32_t mKeyCode;
799 uint32_t mCharCode;
800 CopyableTArray<ShortcutKeyCandidate> mShortcutCandidates;
802 bool mHandledByAPZ;
804 // The scroll action to perform on a layer for this keyboard input. This is
805 // only used in APZ and is NOT serialized over IPC.
806 KeyboardScrollAction mAction;
808 protected:
809 friend mozilla::layers::APZInputBridgeChild;
810 friend mozilla::layers::PAPZInputBridgeParent;
812 KeyboardInput();
815 } // namespace mozilla
817 #endif // InputData_h__