Bug 1892041 - Part 3: Update test exclusions. r=spidermonkey-reviewers,dminor
[gecko.git] / widget / InputData.h
blobfa011f8451e37d7d1352b5368612be88cff117b6
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"
22 #include "mozilla/ipc/IPCForwards.h"
24 template <class E>
25 struct already_AddRefed;
26 class nsIWidget;
28 namespace mozilla {
30 namespace layers {
31 class APZInputBridgeChild;
32 class PAPZInputBridgeParent;
33 } // namespace layers
35 namespace dom {
36 class Touch;
37 } // namespace dom
39 // clang-format off
40 MOZ_DEFINE_ENUM(
41 InputType, (
42 MULTITOUCH_INPUT,
43 MOUSE_INPUT,
44 PANGESTURE_INPUT,
45 PINCHGESTURE_INPUT,
46 TAPGESTURE_INPUT,
47 SCROLLWHEEL_INPUT,
48 KEYBOARD_INPUT
49 ));
50 // clang-format on
52 class MultiTouchInput;
53 class MouseInput;
54 class PanGestureInput;
55 class PinchGestureInput;
56 class TapGestureInput;
57 class ScrollWheelInput;
58 class KeyboardInput;
60 // This looks unnecessary now, but as we add more and more classes that derive
61 // from InputType (eventually probably almost as many as *Events.h has), it
62 // will be more and more clear what's going on with a macro that shortens the
63 // definition of the RTTI functions.
64 #define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
65 const type& As##type() const { \
66 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
67 return (const type&)*this; \
68 } \
69 type& As##type() { \
70 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
71 return (type&)*this; \
74 /** Base input data class. Should never be instantiated. */
75 class InputData {
76 public:
77 // Warning, this class is serialized and sent over IPC. Any change to its
78 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
79 InputType mInputType;
80 // Time that this data is relevant to. This only really matters when this data
81 // is used as an event.
82 TimeStamp mTimeStamp;
83 // The sequence number of the last potentially focus changing event handled
84 // by APZ. This is used to track when that event has been processed by
85 // content, and focus can be reconfirmed for async keyboard scrolling.
86 uint64_t mFocusSequenceNumber;
88 // The LayersId of the content process that the corresponding WidgetEvent
89 // should be dispatched to.
90 layers::LayersId mLayersId;
92 Modifiers modifiers;
94 INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
95 INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
96 INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
97 INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
98 INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
99 INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
100 INPUTDATA_AS_CHILD_TYPE(KeyboardInput, KEYBOARD_INPUT)
102 virtual ~InputData();
103 explicit InputData(InputType aInputType);
105 protected:
106 InputData(InputType aInputType, TimeStamp aTimeStamp, Modifiers aModifiers);
110 * Data container for a single touch input. Similar to dom::Touch, but used in
111 * off-main-thread situations. This is more for just storing touch data, whereas
112 * dom::Touch is more useful for dispatching through the DOM (which can only
113 * happen on the main thread). dom::Touch also bears the problem of storing
114 * pointers to nsIWidget instances which can only be used on the main thread,
115 * so if instead we used dom::Touch and ever set these pointers
116 * off-main-thread, Bad Things Can Happen(tm).
118 * Note that this doesn't inherit from InputData because this itself is not an
119 * event. It is only a container/struct that should have any number of instances
120 * within a MultiTouchInput.
122 * fixme/bug 775746: Make dom::Touch inherit from this class.
124 class SingleTouchData {
125 public:
126 // Construct a SingleTouchData from a Screen point.
127 // mLocalScreenPoint remains (0,0) unless it's set later.
128 SingleTouchData(int32_t aIdentifier, ScreenIntPoint aScreenPoint,
129 ScreenSize aRadius, float aRotationAngle, float aForce);
131 // Construct a SingleTouchData from a ParentLayer point.
132 // mScreenPoint remains (0,0) unless it's set later.
133 // Note: if APZ starts using the radius for anything, we should add a local
134 // version of that too, and have this constructor take it as a
135 // ParentLayerSize.
136 SingleTouchData(int32_t aIdentifier, ParentLayerPoint aLocalScreenPoint,
137 ScreenSize aRadius, float aRotationAngle, float aForce);
139 SingleTouchData();
141 already_AddRefed<dom::Touch> ToNewDOMTouch() const;
143 // Warning, this class is serialized and sent over IPC. Any change to its
144 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
146 // Historical data of this touch, which was coalesced into this event.
147 // Touch event coalescing can happen at the system level when the touch
148 // screen's sampling frequency is higher than the vsync rate, or when the
149 // UI thread is busy. When multiple "samples" of touch data are coalesced into
150 // one touch event, the touch event's regular position information is the
151 // information from the last sample. And the previous, "coalesced-away"
152 // samples are stored in mHistoricalData.
154 struct HistoricalTouchData {
155 // The timestamp at which the information in this "sample" was originally
156 // sampled.
157 TimeStamp mTimeStamp;
159 // The touch data of this historical sample.
160 ScreenIntPoint mScreenPoint;
161 ParentLayerPoint mLocalScreenPoint;
162 ScreenSize mRadius;
163 float mRotationAngle = 0.0f;
164 float mForce = 0.0f;
166 CopyableTArray<HistoricalTouchData> mHistoricalData;
168 // A unique number assigned to each SingleTouchData within a MultiTouchInput
169 // so that they can be easily distinguished when handling a touch
170 // start/move/end.
171 int32_t mIdentifier;
173 // Point on the screen that the touch hit, in device pixels. They are
174 // coordinates on the screen.
175 ScreenIntPoint mScreenPoint;
177 // |mScreenPoint| transformed to the local coordinates of the APZC targeted
178 // by the hit. This is set and used by APZ.
179 ParentLayerPoint mLocalScreenPoint;
181 // Radius that the touch covers, i.e. if you're using your thumb it will
182 // probably be larger than using your pinky, even with the same force.
183 // Radius can be different along x and y. For example, if you press down with
184 // your entire finger vertically, the y radius will be much larger than the x
185 // radius.
186 ScreenSize mRadius;
188 float mRotationAngle;
190 // How hard the screen is being pressed.
191 float mForce;
193 int32_t mTiltX = 0;
194 int32_t mTiltY = 0;
195 int32_t mTwist = 0;
199 * Similar to WidgetTouchEvent, but for use off-main-thread. Also only stores a
200 * screen touch point instead of the many different coordinate spaces
201 * WidgetTouchEvent stores its touch point in. This includes a way to initialize
202 * itself from a WidgetTouchEvent by copying all relevant data over. Note that
203 * this copying from WidgetTouchEvent functionality can only be used on the main
204 * thread.
206 * Stores an array of SingleTouchData.
208 class MultiTouchInput : public InputData {
209 public:
210 // clang-format off
211 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
212 MultiTouchType, (
213 MULTITOUCH_START,
214 MULTITOUCH_MOVE,
215 MULTITOUCH_END,
216 MULTITOUCH_CANCEL
218 // clang-format on
220 MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
221 Modifiers aModifiers);
222 MultiTouchInput();
223 MultiTouchInput(MultiTouchInput&&) = default;
224 MultiTouchInput(const MultiTouchInput&) = default;
225 explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
227 MultiTouchInput& operator=(MultiTouchInput&&) = default;
228 MultiTouchInput& operator=(const MultiTouchInput&) = default;
230 void Translate(const ScreenPoint& aTranslation);
232 WidgetTouchEvent ToWidgetEvent(
233 nsIWidget* aWidget,
234 uint16_t aInputSource =
235 /* MouseEvent_Binding::MOZ_SOURCE_TOUCH = */ 5) const;
237 // Return the index into mTouches of the SingleTouchData with the given
238 // identifier, or -1 if there is no such SingleTouchData.
239 int32_t IndexOfTouch(int32_t aTouchIdentifier);
241 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
243 // Warning, this class is serialized and sent over IPC. Any change to its
244 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
245 MultiTouchType mType;
246 CopyableTArray<SingleTouchData> mTouches;
247 // The screen offset of the root widget. This can be changing along with
248 // the touch interaction, so we sstore it in the event.
249 ExternalPoint mScreenOffset;
250 bool mHandledByAPZ;
251 // These button fields match to the corresponding fields in
252 // WidgetMouseEventBase, except mButton defaults to -1 to follow PointerEvent.
253 int16_t mButton = eNotPressed;
254 int16_t mButtons = 0;
257 class MouseInput : public InputData {
258 protected:
259 friend mozilla::layers::APZInputBridgeChild;
260 friend mozilla::layers::PAPZInputBridgeParent;
261 ALLOW_DEPRECATED_READPARAM
263 MouseInput();
265 public:
266 // clang-format off
267 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
268 MouseType, (
269 MOUSE_NONE,
270 MOUSE_MOVE,
271 MOUSE_DOWN,
272 MOUSE_UP,
273 MOUSE_DRAG_START,
274 MOUSE_DRAG_END,
275 MOUSE_WIDGET_ENTER,
276 MOUSE_WIDGET_EXIT,
277 MOUSE_HITTEST,
278 MOUSE_EXPLORE_BY_TOUCH,
279 MOUSE_CONTEXTMENU
282 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
283 ButtonType, (
284 PRIMARY_BUTTON,
285 MIDDLE_BUTTON,
286 SECONDARY_BUTTON,
287 NONE
289 // clang-format on
291 MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
292 int16_t aButtons, const ScreenPoint& aPoint, TimeStamp aTimeStamp,
293 Modifiers aModifiers);
294 explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
296 bool IsLeftButton() const;
298 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
299 WidgetMouseEvent ToWidgetEvent(nsIWidget* aWidget) const;
301 // Warning, this class is serialized and sent over IPC. Any change to its
302 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
303 MouseType mType;
304 ButtonType mButtonType;
305 uint16_t mInputSource;
306 int16_t mButtons;
307 ScreenPoint mOrigin;
308 ParentLayerPoint mLocalOrigin;
309 bool mHandledByAPZ;
311 * If click event should not be fired in the content after the "mousedown"
312 * event or following "mouseup", set to true.
314 bool mPreventClickEvent;
318 * Encapsulation class for pan events, can be used off-main-thread.
319 * These events are currently only used for scrolling on desktop.
321 class PanGestureInput : public InputData {
322 friend struct IPC::ParamTraits<PanGestureInput>;
324 protected:
325 friend mozilla::layers::APZInputBridgeChild;
326 friend mozilla::layers::PAPZInputBridgeParent;
327 ALLOW_DEPRECATED_READPARAM
329 PanGestureInput();
331 public:
332 // clang-format off
333 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
334 PanGestureType, (
335 // MayStart: Dispatched before any actual panning has occurred but when a
336 // pan gesture is probably about to start, for example when the user
337 // starts touching the touchpad. Should interrupt any ongoing APZ
338 // animation and can be used to trigger scrollability indicators (e.g.
339 // flashing overlay scrollbars).
340 PANGESTURE_MAYSTART,
342 // Cancelled: Dispatched after MayStart when no pan gesture is going to
343 // happen after all, for example when the user lifts their fingers from a
344 // touchpad without having done any scrolling.
345 PANGESTURE_CANCELLED,
347 // Start: A pan gesture is starting.
348 // For devices that do not support the MayStart event type, this event can
349 // be used to interrupt ongoing APZ animations.
350 PANGESTURE_START,
352 // Pan: The actual pan motion by mPanDisplacement.
353 PANGESTURE_PAN,
355 // End: The pan gesture has ended, for example because the user has lifted
356 // their fingers from a touchpad after scrolling.
357 // Any potential momentum events fire after this event.
358 PANGESTURE_END,
360 // The following momentum event types are used in order to control the pan
361 // momentum animation. Using these instead of our own animation ensures
362 // that the animation curve is OS native and that the animation stops
363 // reliably if it is cancelled by the user.
365 // MomentumStart: Dispatched between the End event of the actual
366 // user-controlled pan, and the first MomentumPan event of the momentum
367 // animation.
368 PANGESTURE_MOMENTUMSTART,
370 // MomentumPan: The actual momentum motion by mPanDisplacement.
371 PANGESTURE_MOMENTUMPAN,
373 // MomentumEnd: The momentum animation has ended, for example because the
374 // momentum velocity has gone below the stopping threshold, or because the
375 // user has stopped the animation by putting their fingers on a touchpad.
376 PANGESTURE_MOMENTUMEND,
378 // Interrupted:: A pan gesture started being handled by an APZC but
379 // subsequent pan events might have been consumed by other operations
380 // which haven't been handled by the APZC (e.g. full zoom).
381 PANGESTURE_INTERRUPTED
384 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
385 PanDeltaType, (
386 // There are three kinds of scroll delta modes in Gecko: "page", "line"
387 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
389 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
390 // (see AsyncPanZoomController::OnPan).
391 PANDELTA_PAGE,
392 PANDELTA_PIXEL
394 // clang-format on
396 PanGestureInput(PanGestureType aType, TimeStamp aTimeStamp,
397 const ScreenPoint& aPanStartPoint,
398 const ScreenPoint& aPanDisplacement, Modifiers aModifiers);
400 enum class IsEligibleForSwipe : bool { No, Yes };
401 PanGestureInput(PanGestureType aType, TimeStamp aTimeStamp,
402 const ScreenPoint& aPanStartPoint,
403 const ScreenPoint& aPanDisplacement, Modifiers aModifiers,
404 IsEligibleForSwipe aIsEligibleForSwipe);
406 void SetLineOrPageDeltas(int32_t aLineOrPageDeltaX,
407 int32_t aLineOrPageDeltaY);
409 bool IsMomentum() const;
411 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
413 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
415 ScreenPoint UserMultipliedPanDisplacement() const;
416 ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
418 void SetHandledByAPZ(bool aHandled) { mHandledByAPZ = aHandled; }
419 void SetOverscrollBehaviorAllowsSwipe(bool aAllows) {
420 mOverscrollBehaviorAllowsSwipe = aAllows;
422 void SetSimulateMomentum(bool aSimulate) { mSimulateMomentum = aSimulate; }
423 void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta) {
424 mIsNoLineOrPageDelta = aIsNoLineOrPageDelta;
427 // Returns true if this pan gesture event is elligible for browser swipe
428 // gesture considering the overscroll-behavior property of the target
429 // scroll container.
430 bool AllowsSwipe() const {
431 MOZ_ASSERT(mHandledByAPZ);
432 return mMayTriggerSwipe && mOverscrollBehaviorAllowsSwipe;
435 // Similar to above AllowsSwipe() but this doesn't care the
436 // overscroll-behavior property, this function should be only used for cases
437 // where APZ isn't involved.
438 bool MayTriggerSwipe() const { return mMayTriggerSwipe; }
439 bool RequiresContentResponseIfCannotScrollHorizontallyInStartDirection();
441 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
443 // Warning, this class is serialized and sent over IPC. Any change to its
444 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
445 PanGestureType mType;
446 ScreenPoint mPanStartPoint;
448 // The delta. This can be non-zero on any type of event.
449 ScreenPoint mPanDisplacement;
451 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
452 // coordinates of the APZC receiving the pan. These are set and used by APZ.
453 ParentLayerPoint mLocalPanStartPoint;
454 ParentLayerPoint mLocalPanDisplacement;
456 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
457 int32_t mLineOrPageDeltaX;
458 int32_t mLineOrPageDeltaY;
460 // User-set delta multipliers.
461 double mUserDeltaMultiplierX;
462 double mUserDeltaMultiplierY;
464 PanDeltaType mDeltaType = PANDELTA_PIXEL;
466 bool mHandledByAPZ : 1;
468 // This is used by APZ to communicate to widget code whether the
469 // overscroll-behavior of the scroll frame handling this swipe allows
470 // non-local overscroll behaviors in the horizontal direction (such as
471 // swipe navigation).
472 bool mOverscrollBehaviorAllowsSwipe : 1;
474 // true if APZ should do a fling animation after this pan ends, like
475 // it would with touchscreens. (For platforms that don't emit momentum
476 // events.)
477 bool mSimulateMomentum : 1;
479 // true if the creator of this object does not set the mLineOrPageDeltaX/Y
480 // fields and when/if WidgetWheelEvent's are generated from this object wants
481 // the corresponding mLineOrPageDeltaX/Y fields in the WidgetWheelEvent to be
482 // automatically calculated (upon event dispatch by the EventStateManager
483 // code).
484 bool mIsNoLineOrPageDelta : 1;
486 private:
487 // If this is true, and this event started a new input block that couldn't
488 // find a scrollable target which is scrollable in the horizontal component
489 // of the scroll start direction, then this input block needs to be put on
490 // hold until a content response has arrived, even if the block has a
491 // confirmed target.
492 // This is used by events that can result in a swipe instead of a scroll.
493 bool mMayTriggerSwipe : 1;
494 void SetMayTriggerSwipe(bool aValue) { mMayTriggerSwipe = aValue; }
498 * Encapsulation class for pinch events. In general, these will be generated by
499 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
500 * and determining whether or not the user was trying to do a gesture.
502 class PinchGestureInput : public InputData {
503 protected:
504 friend mozilla::layers::APZInputBridgeChild;
505 friend mozilla::layers::PAPZInputBridgeParent;
506 ALLOW_DEPRECATED_READPARAM
508 PinchGestureInput();
510 public:
511 // clang-format off
512 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
513 PinchGestureType, (
514 PINCHGESTURE_START,
515 PINCHGESTURE_SCALE,
516 // The FINGERLIFTED state is used when a touch-based pinch gesture is
517 // terminated by lifting one of the two fingers. The position of the
518 // finger that's still down is populated as the focus point.
519 PINCHGESTURE_FINGERLIFTED,
520 // The END state is used when the pinch gesture is completely terminated.
521 // In this state, the focus point should not be relied upon for having
522 // meaningful data.
523 PINCHGESTURE_END
526 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
527 PinchGestureSource, (
528 UNKNOWN, // Default initialization value. Should never actually be used.
529 TOUCH, // From two-finger pinch gesture
530 ONE_TOUCH, // From one-finger pinch gesture
531 TRACKPAD, // From trackpad pinch gesture
532 MOUSEWHEEL // Synthesized from modifier+mousewheel
534 // If adding more items here, increase n_values for the
535 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
537 // clang-format on
539 // Construct a pinch gesture from a Screen point.
540 PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
541 TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset,
542 const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
543 ScreenCoord aPreviousSpan, Modifiers aModifiers);
545 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
547 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
549 double ComputeDeltaY(nsIWidget* aWidget) const;
551 // Set mLineOrPageDeltaY based on ComputeDeltaY().
552 // Return false if the caller should drop this event to ensure
553 // that preventDefault() is respected. (More specifically, this will be
554 // true for event types other than PINCHGESTURE_END if the computed
555 // mLineOrPageDeltaY is zero. In such cases, the resulting DOMMouseScroll
556 // event will not be dispatched, which is a problem if the page is relying
557 // on DOMMouseScroll to prevent browser zooming).
558 // Note that even if the function returns false, the delta from the event
559 // is accumulated and available to be sent in a later event.
560 bool SetLineOrPageDeltaY(nsIWidget* aWidget);
562 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
564 // Warning, this class is serialized and sent over IPC. Any change to its
565 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
566 PinchGestureType mType;
568 // Some indication of the input device that generated this pinch gesture.
569 PinchGestureSource mSource;
571 // Center point of the pinch gesture. That is, if there are two fingers on the
572 // screen, it is their midpoint. In the case of more than two fingers, the
573 // point is implementation-specific, but can for example be the midpoint
574 // between the very first and very last touch. This is in device pixels and
575 // are the coordinates on the screen of this midpoint.
576 // For PINCHGESTURE_END events, this may hold the last known focus point or
577 // just be empty; in any case for END events it should not be relied upon.
578 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
579 // that is still down.
580 ScreenPoint mFocusPoint;
582 // The screen offset of the root widget. This can be changing along with
583 // the touch interaction, so we sstore it in the event.
584 ExternalPoint mScreenOffset;
586 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
587 // by the hit. This is set and used by APZ.
588 ParentLayerPoint mLocalFocusPoint;
590 // The distance between the touches responsible for the pinch gesture.
591 ScreenCoord mCurrentSpan;
593 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
594 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
595 // of this type then there must have been a history of spans.
596 ScreenCoord mPreviousSpan;
598 // We accumulate (via GetIntegerDeltaForEvent) the deltaY that would be
599 // computed by ToWidgetEvent, and then whenever we get a whole integer
600 // value we put it in mLineOrPageDeltaY. Since we only ever use deltaY we
601 // don't need a mLineOrPageDeltaX. This field is used to dispatch legacy mouse
602 // events which are only dispatched when the corresponding field on
603 // WidgetWheelEvent is non-zero.
604 int32_t mLineOrPageDeltaY;
606 bool mHandledByAPZ;
610 * Encapsulation class for tap events. In general, these will be generated by
611 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
612 * and determining whether or not the user was trying to do a gesture.
614 class TapGestureInput : public InputData {
615 protected:
616 friend mozilla::layers::APZInputBridgeChild;
617 friend mozilla::layers::PAPZInputBridgeParent;
618 ALLOW_DEPRECATED_READPARAM
620 TapGestureInput();
622 public:
623 // clang-format off
624 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
625 TapGestureType, (
626 TAPGESTURE_LONG,
627 TAPGESTURE_LONG_UP,
628 TAPGESTURE_UP,
629 TAPGESTURE_CONFIRMED,
630 TAPGESTURE_DOUBLE,
631 TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
632 TAPGESTURE_CANCEL
634 // clang-format on
636 // Construct a tap gesture from a Screen point.
637 // mLocalPoint remains (0,0) unless it's set later.
638 TapGestureInput(TapGestureType aType, TimeStamp aTimeStamp,
639 const ScreenIntPoint& aPoint, Modifiers aModifiers);
641 // Construct a tap gesture from a ParentLayer point.
642 // mPoint remains (0,0) unless it's set later.
643 TapGestureInput(TapGestureType aType, TimeStamp aTimeStamp,
644 const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
646 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
648 WidgetSimpleGestureEvent ToWidgetEvent(nsIWidget* aWidget) const;
650 // Warning, this class is serialized and sent over IPC. Any change to its
651 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
652 TapGestureType mType;
654 // The location of the tap in screen pixels.
655 ScreenIntPoint mPoint;
657 // The location of the tap in the local coordinates of the APZC receiving it.
658 // This is set and used by APZ.
659 ParentLayerPoint mLocalPoint;
662 // Encapsulation class for scroll-wheel events. These are generated by mice
663 // with physical scroll wheels, and on Windows by most touchpads when using
664 // scroll gestures.
665 class ScrollWheelInput : public InputData {
666 protected:
667 friend mozilla::layers::APZInputBridgeChild;
668 friend mozilla::layers::PAPZInputBridgeParent;
669 ALLOW_DEPRECATED_READPARAM
671 typedef mozilla::layers::APZWheelAction APZWheelAction;
673 ScrollWheelInput();
675 public:
676 // clang-format off
677 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
678 ScrollDeltaType, (
679 // There are three kinds of scroll delta modes in Gecko: "page", "line"
680 // and "pixel".
681 SCROLLDELTA_LINE,
682 SCROLLDELTA_PAGE,
683 SCROLLDELTA_PIXEL
686 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
687 ScrollMode, (
688 SCROLLMODE_INSTANT,
689 SCROLLMODE_SMOOTH
692 // clang-format on
694 ScrollWheelInput(TimeStamp aTimeStamp, Modifiers aModifiers,
695 ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
696 const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
697 bool aAllowToOverrideSystemScrollSpeed,
698 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
699 explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
701 static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
702 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
703 static mozilla::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
705 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
706 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
708 bool IsCustomizedByUserPrefs() const;
710 // The following two functions are for auto-dir scrolling. For detailed
711 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
712 bool IsAutoDir(bool aForce = false) const {
713 if (aForce) {
714 return true;
717 switch (mWheelDeltaAdjustmentStrategy) {
718 case WheelDeltaAdjustmentStrategy::eAutoDir:
719 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
720 return true;
721 default:
722 // Prevent compilation errors generated by -Werror=switch
723 break;
725 return false;
727 // Indicates which element this scroll honours if it's an auto-dir scroll.
728 // If true, honour the root element; otherwise, honour the currently scrolling
729 // target.
730 // Note that if IsAutoDir() returns false, then this function also returns
731 // false, but false in this case is meaningless as IsAutoDir() indicates it's
732 // not an auto-dir scroll.
733 // For detailed information on auto-dir,
734 // @see mozilla::WheelDeltaAdjustmentStrategy
735 bool HonoursRoot(bool aForce = false) const {
736 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
737 mWheelDeltaAdjustmentStrategy ||
738 aForce;
741 // Warning, this class is serialized and sent over IPC. Any change to its
742 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
743 ScrollDeltaType mDeltaType;
744 ScrollMode mScrollMode;
745 ScreenPoint mOrigin;
747 bool mHandledByAPZ;
749 // Deltas are in units corresponding to the delta type. For line deltas, they
750 // are the number of line units to scroll. The number of device pixels for a
751 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
752 // For pixel deltas, these values are in ScreenCoords.
754 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
755 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
756 // scrolling down.
757 double mDeltaX;
758 double mDeltaY;
760 // The number of scroll wheel ticks.
761 double mWheelTicksX = 0.0;
762 double mWheelTicksY = 0.0;
764 // The location of the scroll in local coordinates. This is set and used by
765 // APZ.
766 ParentLayerPoint mLocalOrigin;
768 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
769 int32_t mLineOrPageDeltaX;
770 int32_t mLineOrPageDeltaY;
772 // Indicates the order in which this event was added to a transaction. The
773 // first event is 1; if not a member of a transaction, this is 0.
774 uint32_t mScrollSeriesNumber;
776 // User-set delta multipliers.
777 double mUserDeltaMultiplierX;
778 double mUserDeltaMultiplierY;
780 bool mMayHaveMomentum;
781 bool mIsMomentum;
782 bool mAllowToOverrideSystemScrollSpeed;
784 // Sometimes a wheel event input's wheel delta should be adjusted. This member
785 // specifies how to adjust the wheel delta.
786 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
788 APZWheelAction mAPZAction;
791 class KeyboardInput : public InputData {
792 public:
793 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
795 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
796 // other member, don't forget to update the minimum value in
797 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
798 // accordingly.
799 enum KeyboardEventType {
800 KEY_DOWN,
801 KEY_PRESS,
802 KEY_UP,
803 // Any other key event such as eAccessKeyNotFound
804 KEY_OTHER,
806 // Used as an upper bound for ContiguousEnumSerializer
807 KEY_SENTINEL,
810 explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
812 // Warning, this class is serialized and sent over IPC. Any change to its
813 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
815 KeyboardEventType mType;
816 uint32_t mKeyCode;
817 uint32_t mCharCode;
818 CopyableTArray<ShortcutKeyCandidate> mShortcutCandidates;
820 bool mHandledByAPZ;
822 // The scroll action to perform on a layer for this keyboard input. This is
823 // only used in APZ and is NOT serialized over IPC.
824 KeyboardScrollAction mAction;
826 protected:
827 friend mozilla::layers::APZInputBridgeChild;
828 friend mozilla::layers::PAPZInputBridgeParent;
829 ALLOW_DEPRECATED_READPARAM
831 KeyboardInput();
834 } // namespace mozilla
836 #endif // InputData_h__