Bug 1854550 - pt 12. Allow inlining between mozjemalloc and PHC r=glandium
[gecko.git] / widget / InputData.h
blob855cfcd178bcbcd101c4ab5cbb448cba259195cb
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
281 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
282 ButtonType, (
283 PRIMARY_BUTTON,
284 MIDDLE_BUTTON,
285 SECONDARY_BUTTON,
286 NONE
288 // clang-format on
290 MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
291 int16_t aButtons, const ScreenPoint& aPoint, TimeStamp aTimeStamp,
292 Modifiers aModifiers);
293 explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
295 bool IsLeftButton() const;
297 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
298 WidgetMouseEvent ToWidgetEvent(nsIWidget* aWidget) const;
300 // Warning, this class is serialized and sent over IPC. Any change to its
301 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
302 MouseType mType;
303 ButtonType mButtonType;
304 uint16_t mInputSource;
305 int16_t mButtons;
306 ScreenPoint mOrigin;
307 ParentLayerPoint mLocalOrigin;
308 bool mHandledByAPZ;
310 * If click event should not be fired in the content after the "mousedown"
311 * event or following "mouseup", set to true.
313 bool mPreventClickEvent;
317 * Encapsulation class for pan events, can be used off-main-thread.
318 * These events are currently only used for scrolling on desktop.
320 class PanGestureInput : public InputData {
321 friend struct IPC::ParamTraits<PanGestureInput>;
323 protected:
324 friend mozilla::layers::APZInputBridgeChild;
325 friend mozilla::layers::PAPZInputBridgeParent;
326 ALLOW_DEPRECATED_READPARAM
328 PanGestureInput();
330 public:
331 // clang-format off
332 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
333 PanGestureType, (
334 // MayStart: Dispatched before any actual panning has occurred but when a
335 // pan gesture is probably about to start, for example when the user
336 // starts touching the touchpad. Should interrupt any ongoing APZ
337 // animation and can be used to trigger scrollability indicators (e.g.
338 // flashing overlay scrollbars).
339 PANGESTURE_MAYSTART,
341 // Cancelled: Dispatched after MayStart when no pan gesture is going to
342 // happen after all, for example when the user lifts their fingers from a
343 // touchpad without having done any scrolling.
344 PANGESTURE_CANCELLED,
346 // Start: A pan gesture is starting.
347 // For devices that do not support the MayStart event type, this event can
348 // be used to interrupt ongoing APZ animations.
349 PANGESTURE_START,
351 // Pan: The actual pan motion by mPanDisplacement.
352 PANGESTURE_PAN,
354 // End: The pan gesture has ended, for example because the user has lifted
355 // their fingers from a touchpad after scrolling.
356 // Any potential momentum events fire after this event.
357 PANGESTURE_END,
359 // The following momentum event types are used in order to control the pan
360 // momentum animation. Using these instead of our own animation ensures
361 // that the animation curve is OS native and that the animation stops
362 // reliably if it is cancelled by the user.
364 // MomentumStart: Dispatched between the End event of the actual
365 // user-controlled pan, and the first MomentumPan event of the momentum
366 // animation.
367 PANGESTURE_MOMENTUMSTART,
369 // MomentumPan: The actual momentum motion by mPanDisplacement.
370 PANGESTURE_MOMENTUMPAN,
372 // MomentumEnd: The momentum animation has ended, for example because the
373 // momentum velocity has gone below the stopping threshold, or because the
374 // user has stopped the animation by putting their fingers on a touchpad.
375 PANGESTURE_MOMENTUMEND,
377 // Interrupted:: A pan gesture started being handled by an APZC but
378 // subsequent pan events might have been consumed by other operations
379 // which haven't been handled by the APZC (e.g. full zoom).
380 PANGESTURE_INTERRUPTED
383 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
384 PanDeltaType, (
385 // There are three kinds of scroll delta modes in Gecko: "page", "line"
386 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
388 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
389 // (see AsyncPanZoomController::OnPan).
390 PANDELTA_PAGE,
391 PANDELTA_PIXEL
393 // clang-format on
395 PanGestureInput(PanGestureType aType, TimeStamp aTimeStamp,
396 const ScreenPoint& aPanStartPoint,
397 const ScreenPoint& aPanDisplacement, Modifiers aModifiers);
399 enum class IsEligibleForSwipe : bool { No, Yes };
400 PanGestureInput(PanGestureType aType, TimeStamp aTimeStamp,
401 const ScreenPoint& aPanStartPoint,
402 const ScreenPoint& aPanDisplacement, Modifiers aModifiers,
403 IsEligibleForSwipe aIsEligibleForSwipe);
405 void SetLineOrPageDeltas(int32_t aLineOrPageDeltaX,
406 int32_t aLineOrPageDeltaY);
408 bool IsMomentum() const;
410 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
412 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
414 ScreenPoint UserMultipliedPanDisplacement() const;
415 ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
417 void SetHandledByAPZ(bool aHandled) { mHandledByAPZ = aHandled; }
418 void SetOverscrollBehaviorAllowsSwipe(bool aAllows) {
419 mOverscrollBehaviorAllowsSwipe = aAllows;
421 void SetSimulateMomentum(bool aSimulate) { mSimulateMomentum = aSimulate; }
422 void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta) {
423 mIsNoLineOrPageDelta = aIsNoLineOrPageDelta;
426 // Returns true if this pan gesture event is elligible for browser swipe
427 // gesture considering the overscroll-behavior property of the target
428 // scroll container.
429 bool AllowsSwipe() const {
430 MOZ_ASSERT(mHandledByAPZ);
431 return mMayTriggerSwipe && mOverscrollBehaviorAllowsSwipe;
434 // Similar to above AllowsSwipe() but this doesn't care the
435 // overscroll-behavior property, this function should be only used for cases
436 // where APZ isn't involved.
437 bool MayTriggerSwipe() const { return mMayTriggerSwipe; }
438 bool RequiresContentResponseIfCannotScrollHorizontallyInStartDirection();
440 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
442 // Warning, this class is serialized and sent over IPC. Any change to its
443 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
444 PanGestureType mType;
445 ScreenPoint mPanStartPoint;
447 // The delta. This can be non-zero on any type of event.
448 ScreenPoint mPanDisplacement;
450 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
451 // coordinates of the APZC receiving the pan. These are set and used by APZ.
452 ParentLayerPoint mLocalPanStartPoint;
453 ParentLayerPoint mLocalPanDisplacement;
455 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
456 int32_t mLineOrPageDeltaX;
457 int32_t mLineOrPageDeltaY;
459 // User-set delta multipliers.
460 double mUserDeltaMultiplierX;
461 double mUserDeltaMultiplierY;
463 PanDeltaType mDeltaType = PANDELTA_PIXEL;
465 bool mHandledByAPZ : 1;
467 // This is used by APZ to communicate to widget code whether the
468 // overscroll-behavior of the scroll frame handling this swipe allows
469 // non-local overscroll behaviors in the horizontal direction (such as
470 // swipe navigation).
471 bool mOverscrollBehaviorAllowsSwipe : 1;
473 // true if APZ should do a fling animation after this pan ends, like
474 // it would with touchscreens. (For platforms that don't emit momentum
475 // events.)
476 bool mSimulateMomentum : 1;
478 // true if the creator of this object does not set the mLineOrPageDeltaX/Y
479 // fields and when/if WidgetWheelEvent's are generated from this object wants
480 // the corresponding mLineOrPageDeltaX/Y fields in the WidgetWheelEvent to be
481 // automatically calculated (upon event dispatch by the EventStateManager
482 // code).
483 bool mIsNoLineOrPageDelta : 1;
485 private:
486 // If this is true, and this event started a new input block that couldn't
487 // find a scrollable target which is scrollable in the horizontal component
488 // of the scroll start direction, then this input block needs to be put on
489 // hold until a content response has arrived, even if the block has a
490 // confirmed target.
491 // This is used by events that can result in a swipe instead of a scroll.
492 bool mMayTriggerSwipe : 1;
493 void SetMayTriggerSwipe(bool aValue) { mMayTriggerSwipe = aValue; }
497 * Encapsulation class for pinch events. In general, these will be generated by
498 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
499 * and determining whether or not the user was trying to do a gesture.
501 class PinchGestureInput : public InputData {
502 protected:
503 friend mozilla::layers::APZInputBridgeChild;
504 friend mozilla::layers::PAPZInputBridgeParent;
505 ALLOW_DEPRECATED_READPARAM
507 PinchGestureInput();
509 public:
510 // clang-format off
511 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
512 PinchGestureType, (
513 PINCHGESTURE_START,
514 PINCHGESTURE_SCALE,
515 // The FINGERLIFTED state is used when a touch-based pinch gesture is
516 // terminated by lifting one of the two fingers. The position of the
517 // finger that's still down is populated as the focus point.
518 PINCHGESTURE_FINGERLIFTED,
519 // The END state is used when the pinch gesture is completely terminated.
520 // In this state, the focus point should not be relied upon for having
521 // meaningful data.
522 PINCHGESTURE_END
525 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
526 PinchGestureSource, (
527 UNKNOWN, // Default initialization value. Should never actually be used.
528 TOUCH, // From two-finger pinch gesture
529 ONE_TOUCH, // From one-finger pinch gesture
530 TRACKPAD, // From trackpad pinch gesture
531 MOUSEWHEEL // Synthesized from modifier+mousewheel
533 // If adding more items here, increase n_values for the
534 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
536 // clang-format on
538 // Construct a pinch gesture from a Screen point.
539 PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
540 TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset,
541 const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
542 ScreenCoord aPreviousSpan, Modifiers aModifiers);
544 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
546 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
548 double ComputeDeltaY(nsIWidget* aWidget) const;
550 // Set mLineOrPageDeltaY based on ComputeDeltaY().
551 // Return false if the caller should drop this event to ensure
552 // that preventDefault() is respected. (More specifically, this will be
553 // true for event types other than PINCHGESTURE_END if the computed
554 // mLineOrPageDeltaY is zero. In such cases, the resulting DOMMouseScroll
555 // event will not be dispatched, which is a problem if the page is relying
556 // on DOMMouseScroll to prevent browser zooming).
557 // Note that even if the function returns false, the delta from the event
558 // is accumulated and available to be sent in a later event.
559 bool SetLineOrPageDeltaY(nsIWidget* aWidget);
561 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
563 // Warning, this class is serialized and sent over IPC. Any change to its
564 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
565 PinchGestureType mType;
567 // Some indication of the input device that generated this pinch gesture.
568 PinchGestureSource mSource;
570 // Center point of the pinch gesture. That is, if there are two fingers on the
571 // screen, it is their midpoint. In the case of more than two fingers, the
572 // point is implementation-specific, but can for example be the midpoint
573 // between the very first and very last touch. This is in device pixels and
574 // are the coordinates on the screen of this midpoint.
575 // For PINCHGESTURE_END events, this may hold the last known focus point or
576 // just be empty; in any case for END events it should not be relied upon.
577 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
578 // that is still down.
579 ScreenPoint mFocusPoint;
581 // The screen offset of the root widget. This can be changing along with
582 // the touch interaction, so we sstore it in the event.
583 ExternalPoint mScreenOffset;
585 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
586 // by the hit. This is set and used by APZ.
587 ParentLayerPoint mLocalFocusPoint;
589 // The distance between the touches responsible for the pinch gesture.
590 ScreenCoord mCurrentSpan;
592 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
593 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
594 // of this type then there must have been a history of spans.
595 ScreenCoord mPreviousSpan;
597 // We accumulate (via GetIntegerDeltaForEvent) the deltaY that would be
598 // computed by ToWidgetEvent, and then whenever we get a whole integer
599 // value we put it in mLineOrPageDeltaY. Since we only ever use deltaY we
600 // don't need a mLineOrPageDeltaX. This field is used to dispatch legacy mouse
601 // events which are only dispatched when the corresponding field on
602 // WidgetWheelEvent is non-zero.
603 int32_t mLineOrPageDeltaY;
605 bool mHandledByAPZ;
609 * Encapsulation class for tap events. In general, these will be generated by
610 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
611 * and determining whether or not the user was trying to do a gesture.
613 class TapGestureInput : public InputData {
614 protected:
615 friend mozilla::layers::APZInputBridgeChild;
616 friend mozilla::layers::PAPZInputBridgeParent;
617 ALLOW_DEPRECATED_READPARAM
619 TapGestureInput();
621 public:
622 // clang-format off
623 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
624 TapGestureType, (
625 TAPGESTURE_LONG,
626 TAPGESTURE_LONG_UP,
627 TAPGESTURE_UP,
628 TAPGESTURE_CONFIRMED,
629 TAPGESTURE_DOUBLE,
630 TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
631 TAPGESTURE_CANCEL
633 // clang-format on
635 // Construct a tap gesture from a Screen point.
636 // mLocalPoint remains (0,0) unless it's set later.
637 TapGestureInput(TapGestureType aType, TimeStamp aTimeStamp,
638 const ScreenIntPoint& aPoint, Modifiers aModifiers);
640 // Construct a tap gesture from a ParentLayer point.
641 // mPoint remains (0,0) unless it's set later.
642 TapGestureInput(TapGestureType aType, TimeStamp aTimeStamp,
643 const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
645 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
647 WidgetSimpleGestureEvent ToWidgetEvent(nsIWidget* aWidget) const;
649 // Warning, this class is serialized and sent over IPC. Any change to its
650 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
651 TapGestureType mType;
653 // The location of the tap in screen pixels.
654 ScreenIntPoint mPoint;
656 // The location of the tap in the local coordinates of the APZC receiving it.
657 // This is set and used by APZ.
658 ParentLayerPoint mLocalPoint;
661 // Encapsulation class for scroll-wheel events. These are generated by mice
662 // with physical scroll wheels, and on Windows by most touchpads when using
663 // scroll gestures.
664 class ScrollWheelInput : public InputData {
665 protected:
666 friend mozilla::layers::APZInputBridgeChild;
667 friend mozilla::layers::PAPZInputBridgeParent;
668 ALLOW_DEPRECATED_READPARAM
670 typedef mozilla::layers::APZWheelAction APZWheelAction;
672 ScrollWheelInput();
674 public:
675 // clang-format off
676 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
677 ScrollDeltaType, (
678 // There are three kinds of scroll delta modes in Gecko: "page", "line"
679 // and "pixel".
680 SCROLLDELTA_LINE,
681 SCROLLDELTA_PAGE,
682 SCROLLDELTA_PIXEL
685 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
686 ScrollMode, (
687 SCROLLMODE_INSTANT,
688 SCROLLMODE_SMOOTH
691 // clang-format on
693 ScrollWheelInput(TimeStamp aTimeStamp, Modifiers aModifiers,
694 ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
695 const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
696 bool aAllowToOverrideSystemScrollSpeed,
697 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
698 explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
700 static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
701 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
702 static mozilla::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
704 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
705 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
707 bool IsCustomizedByUserPrefs() const;
709 // The following two functions are for auto-dir scrolling. For detailed
710 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
711 bool IsAutoDir(bool aForce = false) const {
712 if (aForce) {
713 return true;
716 switch (mWheelDeltaAdjustmentStrategy) {
717 case WheelDeltaAdjustmentStrategy::eAutoDir:
718 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
719 return true;
720 default:
721 // Prevent compilation errors generated by -Werror=switch
722 break;
724 return false;
726 // Indicates which element this scroll honours if it's an auto-dir scroll.
727 // If true, honour the root element; otherwise, honour the currently scrolling
728 // target.
729 // Note that if IsAutoDir() returns false, then this function also returns
730 // false, but false in this case is meaningless as IsAutoDir() indicates it's
731 // not an auto-dir scroll.
732 // For detailed information on auto-dir,
733 // @see mozilla::WheelDeltaAdjustmentStrategy
734 bool HonoursRoot(bool aForce = false) const {
735 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
736 mWheelDeltaAdjustmentStrategy ||
737 aForce;
740 // Warning, this class is serialized and sent over IPC. Any change to its
741 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
742 ScrollDeltaType mDeltaType;
743 ScrollMode mScrollMode;
744 ScreenPoint mOrigin;
746 bool mHandledByAPZ;
748 // Deltas are in units corresponding to the delta type. For line deltas, they
749 // are the number of line units to scroll. The number of device pixels for a
750 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
751 // For pixel deltas, these values are in ScreenCoords.
753 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
754 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
755 // scrolling down.
756 double mDeltaX;
757 double mDeltaY;
759 // The number of scroll wheel ticks.
760 double mWheelTicksX = 0.0;
761 double mWheelTicksY = 0.0;
763 // The location of the scroll in local coordinates. This is set and used by
764 // APZ.
765 ParentLayerPoint mLocalOrigin;
767 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
768 int32_t mLineOrPageDeltaX;
769 int32_t mLineOrPageDeltaY;
771 // Indicates the order in which this event was added to a transaction. The
772 // first event is 1; if not a member of a transaction, this is 0.
773 uint32_t mScrollSeriesNumber;
775 // User-set delta multipliers.
776 double mUserDeltaMultiplierX;
777 double mUserDeltaMultiplierY;
779 bool mMayHaveMomentum;
780 bool mIsMomentum;
781 bool mAllowToOverrideSystemScrollSpeed;
783 // Sometimes a wheel event input's wheel delta should be adjusted. This member
784 // specifies how to adjust the wheel delta.
785 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
787 APZWheelAction mAPZAction;
790 class KeyboardInput : public InputData {
791 public:
792 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
794 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
795 // other member, don't forget to update the minimum value in
796 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
797 // accordingly.
798 enum KeyboardEventType {
799 KEY_DOWN,
800 KEY_PRESS,
801 KEY_UP,
802 // Any other key event such as eAccessKeyNotFound
803 KEY_OTHER,
805 // Used as an upper bound for ContiguousEnumSerializer
806 KEY_SENTINEL,
809 explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
811 // Warning, this class is serialized and sent over IPC. Any change to its
812 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
814 KeyboardEventType mType;
815 uint32_t mKeyCode;
816 uint32_t mCharCode;
817 CopyableTArray<ShortcutKeyCandidate> mShortcutCandidates;
819 bool mHandledByAPZ;
821 // The scroll action to perform on a layer for this keyboard input. This is
822 // only used in APZ and is NOT serialized over IPC.
823 KeyboardScrollAction mAction;
825 protected:
826 friend mozilla::layers::APZInputBridgeChild;
827 friend mozilla::layers::PAPZInputBridgeParent;
828 ALLOW_DEPRECATED_READPARAM
830 KeyboardInput();
833 } // namespace mozilla
835 #endif // InputData_h__