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/. */
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"
25 struct already_AddRefed
;
31 class APZInputBridgeChild
;
32 class PAPZInputBridgeParent
;
52 class MultiTouchInput
;
54 class PanGestureInput
;
55 class PinchGestureInput
;
56 class TapGestureInput
;
57 class ScrollWheelInput
;
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; \
70 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
71 return (type&)*this; \
74 /** Base input data class. Should never be instantiated. */
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
80 // Time that this data is relevant to. This only really matters when this data
81 // is used as an event.
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
;
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
);
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
{
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
136 SingleTouchData(int32_t aIdentifier
, ParentLayerPoint aLocalScreenPoint
,
137 ScreenSize aRadius
, float aRotationAngle
, float aForce
);
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
157 TimeStamp mTimeStamp
;
159 // The touch data of this historical sample.
160 ScreenIntPoint mScreenPoint
;
161 ParentLayerPoint mLocalScreenPoint
;
163 float mRotationAngle
= 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
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
188 float mRotationAngle
;
190 // How hard the screen is being pressed.
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
206 * Stores an array of SingleTouchData.
208 class MultiTouchInput
: public InputData
{
211 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
220 MultiTouchInput(MultiTouchType aType
, uint32_t aTime
, TimeStamp aTimeStamp
,
221 Modifiers aModifiers
);
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(
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
;
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
{
259 friend mozilla::layers::APZInputBridgeChild
;
260 friend mozilla::layers::PAPZInputBridgeParent
;
261 ALLOW_DEPRECATED_READPARAM
267 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
278 MOUSE_EXPLORE_BY_TOUCH
,
282 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
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 [[nodiscard
]] bool IsPointerEventType() const;
300 template <typename WidgetMouseOrPointerEvent
>
301 WidgetMouseOrPointerEvent
ToWidgetEvent(nsIWidget
* aWidget
) const;
303 // Warning, this class is serialized and sent over IPC. Any change to its
304 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
306 ButtonType mButtonType
;
307 uint16_t mInputSource
;
310 ParentLayerPoint mLocalOrigin
;
313 * If click event should not be fired in the content after the "mousedown"
314 * event or following "mouseup", set to true.
316 bool mPreventClickEvent
;
320 * Encapsulation class for pan events, can be used off-main-thread.
321 * These events are currently only used for scrolling on desktop.
323 class PanGestureInput
: public InputData
{
324 friend struct IPC::ParamTraits
<PanGestureInput
>;
327 friend mozilla::layers::APZInputBridgeChild
;
328 friend mozilla::layers::PAPZInputBridgeParent
;
329 ALLOW_DEPRECATED_READPARAM
335 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
337 // MayStart: Dispatched before any actual panning has occurred but when a
338 // pan gesture is probably about to start, for example when the user
339 // starts touching the touchpad. Should interrupt any ongoing APZ
340 // animation and can be used to trigger scrollability indicators (e.g.
341 // flashing overlay scrollbars).
344 // Cancelled: Dispatched after MayStart when no pan gesture is going to
345 // happen after all, for example when the user lifts their fingers from a
346 // touchpad without having done any scrolling.
347 PANGESTURE_CANCELLED
,
349 // Start: A pan gesture is starting.
350 // For devices that do not support the MayStart event type, this event can
351 // be used to interrupt ongoing APZ animations.
354 // Pan: The actual pan motion by mPanDisplacement.
357 // End: The pan gesture has ended, for example because the user has lifted
358 // their fingers from a touchpad after scrolling.
359 // Any potential momentum events fire after this event.
362 // The following momentum event types are used in order to control the pan
363 // momentum animation. Using these instead of our own animation ensures
364 // that the animation curve is OS native and that the animation stops
365 // reliably if it is cancelled by the user.
367 // MomentumStart: Dispatched between the End event of the actual
368 // user-controlled pan, and the first MomentumPan event of the momentum
370 PANGESTURE_MOMENTUMSTART
,
372 // MomentumPan: The actual momentum motion by mPanDisplacement.
373 PANGESTURE_MOMENTUMPAN
,
375 // MomentumEnd: The momentum animation has ended, for example because the
376 // momentum velocity has gone below the stopping threshold, or because the
377 // user has stopped the animation by putting their fingers on a touchpad.
378 PANGESTURE_MOMENTUMEND
,
380 // Interrupted:: A pan gesture started being handled by an APZC but
381 // subsequent pan events might have been consumed by other operations
382 // which haven't been handled by the APZC (e.g. full zoom).
383 PANGESTURE_INTERRUPTED
386 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
388 // There are three kinds of scroll delta modes in Gecko: "page", "line"
389 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
391 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
392 // (see AsyncPanZoomController::OnPan).
398 PanGestureInput(PanGestureType aType
, TimeStamp aTimeStamp
,
399 const ScreenPoint
& aPanStartPoint
,
400 const ScreenPoint
& aPanDisplacement
, Modifiers aModifiers
);
402 enum class IsEligibleForSwipe
: bool { No
, Yes
};
403 PanGestureInput(PanGestureType aType
, TimeStamp aTimeStamp
,
404 const ScreenPoint
& aPanStartPoint
,
405 const ScreenPoint
& aPanDisplacement
, Modifiers aModifiers
,
406 IsEligibleForSwipe aIsEligibleForSwipe
);
408 void SetLineOrPageDeltas(int32_t aLineOrPageDeltaX
,
409 int32_t aLineOrPageDeltaY
);
411 bool IsMomentum() const;
413 WidgetWheelEvent
ToWidgetEvent(nsIWidget
* aWidget
) const;
415 bool TransformToLocal(const ScreenToParentLayerMatrix4x4
& aTransform
);
417 ScreenPoint
UserMultipliedPanDisplacement() const;
418 ParentLayerPoint
UserMultipliedLocalPanDisplacement() const;
420 void SetHandledByAPZ(bool aHandled
) { mHandledByAPZ
= aHandled
; }
421 void SetOverscrollBehaviorAllowsSwipe(bool aAllows
) {
422 mOverscrollBehaviorAllowsSwipe
= aAllows
;
424 void SetSimulateMomentum(bool aSimulate
) { mSimulateMomentum
= aSimulate
; }
425 void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta
) {
426 mIsNoLineOrPageDelta
= aIsNoLineOrPageDelta
;
429 // Returns true if this pan gesture event is elligible for browser swipe
430 // gesture considering the overscroll-behavior property of the target
432 bool AllowsSwipe() const {
433 MOZ_ASSERT(mHandledByAPZ
);
434 return mMayTriggerSwipe
&& mOverscrollBehaviorAllowsSwipe
;
437 // Similar to above AllowsSwipe() but this doesn't care the
438 // overscroll-behavior property, this function should be only used for cases
439 // where APZ isn't involved.
440 bool MayTriggerSwipe() const { return mMayTriggerSwipe
; }
441 bool RequiresContentResponseIfCannotScrollHorizontallyInStartDirection();
443 static gfx::IntPoint
GetIntegerDeltaForEvent(bool aIsStart
, float x
, float y
);
445 // Warning, this class is serialized and sent over IPC. Any change to its
446 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
447 PanGestureType mType
;
448 ScreenPoint mPanStartPoint
;
450 // The delta. This can be non-zero on any type of event.
451 ScreenPoint mPanDisplacement
;
453 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
454 // coordinates of the APZC receiving the pan. These are set and used by APZ.
455 ParentLayerPoint mLocalPanStartPoint
;
456 ParentLayerPoint mLocalPanDisplacement
;
458 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
459 int32_t mLineOrPageDeltaX
;
460 int32_t mLineOrPageDeltaY
;
462 // User-set delta multipliers.
463 double mUserDeltaMultiplierX
;
464 double mUserDeltaMultiplierY
;
466 PanDeltaType mDeltaType
= PANDELTA_PIXEL
;
468 bool mHandledByAPZ
: 1;
470 // This is used by APZ to communicate to widget code whether the
471 // overscroll-behavior of the scroll frame handling this swipe allows
472 // non-local overscroll behaviors in the horizontal direction (such as
473 // swipe navigation).
474 bool mOverscrollBehaviorAllowsSwipe
: 1;
476 // true if APZ should do a fling animation after this pan ends, like
477 // it would with touchscreens. (For platforms that don't emit momentum
479 bool mSimulateMomentum
: 1;
481 // true if the creator of this object does not set the mLineOrPageDeltaX/Y
482 // fields and when/if WidgetWheelEvent's are generated from this object wants
483 // the corresponding mLineOrPageDeltaX/Y fields in the WidgetWheelEvent to be
484 // automatically calculated (upon event dispatch by the EventStateManager
486 bool mIsNoLineOrPageDelta
: 1;
489 // If this is true, and this event started a new input block that couldn't
490 // find a scrollable target which is scrollable in the horizontal component
491 // of the scroll start direction, then this input block needs to be put on
492 // hold until a content response has arrived, even if the block has a
494 // This is used by events that can result in a swipe instead of a scroll.
495 bool mMayTriggerSwipe
: 1;
496 void SetMayTriggerSwipe(bool aValue
) { mMayTriggerSwipe
= aValue
; }
500 * Encapsulation class for pinch events. In general, these will be generated by
501 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
502 * and determining whether or not the user was trying to do a gesture.
504 class PinchGestureInput
: public InputData
{
506 friend mozilla::layers::APZInputBridgeChild
;
507 friend mozilla::layers::PAPZInputBridgeParent
;
508 ALLOW_DEPRECATED_READPARAM
514 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
518 // The FINGERLIFTED state is used when a touch-based pinch gesture is
519 // terminated by lifting one of the two fingers. The position of the
520 // finger that's still down is populated as the focus point.
521 PINCHGESTURE_FINGERLIFTED
,
522 // The END state is used when the pinch gesture is completely terminated.
523 // In this state, the focus point should not be relied upon for having
528 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
529 PinchGestureSource
, (
530 UNKNOWN
, // Default initialization value. Should never actually be used.
531 TOUCH
, // From two-finger pinch gesture
532 ONE_TOUCH
, // From one-finger pinch gesture
533 TRACKPAD
, // From trackpad pinch gesture
534 MOUSEWHEEL
// Synthesized from modifier+mousewheel
536 // If adding more items here, increase n_values for the
537 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
541 // Construct a pinch gesture from a Screen point.
542 PinchGestureInput(PinchGestureType aType
, PinchGestureSource aSource
,
543 TimeStamp aTimeStamp
, const ExternalPoint
& aScreenOffset
,
544 const ScreenPoint
& aFocusPoint
, ScreenCoord aCurrentSpan
,
545 ScreenCoord aPreviousSpan
, Modifiers aModifiers
);
547 bool TransformToLocal(const ScreenToParentLayerMatrix4x4
& aTransform
);
549 WidgetWheelEvent
ToWidgetEvent(nsIWidget
* aWidget
) const;
551 double ComputeDeltaY(nsIWidget
* aWidget
) const;
553 // Set mLineOrPageDeltaY based on ComputeDeltaY().
554 // Return false if the caller should drop this event to ensure
555 // that preventDefault() is respected. (More specifically, this will be
556 // true for event types other than PINCHGESTURE_END if the computed
557 // mLineOrPageDeltaY is zero. In such cases, the resulting DOMMouseScroll
558 // event will not be dispatched, which is a problem if the page is relying
559 // on DOMMouseScroll to prevent browser zooming).
560 // Note that even if the function returns false, the delta from the event
561 // is accumulated and available to be sent in a later event.
562 bool SetLineOrPageDeltaY(nsIWidget
* aWidget
);
564 static gfx::IntPoint
GetIntegerDeltaForEvent(bool aIsStart
, float x
, float y
);
566 // Warning, this class is serialized and sent over IPC. Any change to its
567 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
568 PinchGestureType mType
;
570 // Some indication of the input device that generated this pinch gesture.
571 PinchGestureSource mSource
;
573 // Center point of the pinch gesture. That is, if there are two fingers on the
574 // screen, it is their midpoint. In the case of more than two fingers, the
575 // point is implementation-specific, but can for example be the midpoint
576 // between the very first and very last touch. This is in device pixels and
577 // are the coordinates on the screen of this midpoint.
578 // For PINCHGESTURE_END events, this may hold the last known focus point or
579 // just be empty; in any case for END events it should not be relied upon.
580 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
581 // that is still down.
582 ScreenPoint mFocusPoint
;
584 // The screen offset of the root widget. This can be changing along with
585 // the touch interaction, so we sstore it in the event.
586 ExternalPoint mScreenOffset
;
588 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
589 // by the hit. This is set and used by APZ.
590 ParentLayerPoint mLocalFocusPoint
;
592 // The distance between the touches responsible for the pinch gesture.
593 ScreenCoord mCurrentSpan
;
595 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
596 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
597 // of this type then there must have been a history of spans.
598 ScreenCoord mPreviousSpan
;
600 // We accumulate (via GetIntegerDeltaForEvent) the deltaY that would be
601 // computed by ToWidgetEvent, and then whenever we get a whole integer
602 // value we put it in mLineOrPageDeltaY. Since we only ever use deltaY we
603 // don't need a mLineOrPageDeltaX. This field is used to dispatch legacy mouse
604 // events which are only dispatched when the corresponding field on
605 // WidgetWheelEvent is non-zero.
606 int32_t mLineOrPageDeltaY
;
612 * Encapsulation class for tap events. In general, these will be generated by
613 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
614 * and determining whether or not the user was trying to do a gesture.
616 class TapGestureInput
: public InputData
{
618 friend mozilla::layers::APZInputBridgeChild
;
619 friend mozilla::layers::PAPZInputBridgeParent
;
620 ALLOW_DEPRECATED_READPARAM
626 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
631 TAPGESTURE_CONFIRMED
,
633 TAPGESTURE_SECOND
, // See GeckoContentController::TapType::eSecondTap
638 // Construct a tap gesture from a Screen point.
639 // mLocalPoint remains (0,0) unless it's set later.
640 TapGestureInput(TapGestureType aType
, TimeStamp aTimeStamp
,
641 const ScreenIntPoint
& aPoint
, Modifiers aModifiers
);
643 // Construct a tap gesture from a ParentLayer point.
644 // mPoint remains (0,0) unless it's set later.
645 TapGestureInput(TapGestureType aType
, TimeStamp aTimeStamp
,
646 const ParentLayerPoint
& aLocalPoint
, Modifiers aModifiers
);
648 bool TransformToLocal(const ScreenToParentLayerMatrix4x4
& aTransform
);
650 WidgetSimpleGestureEvent
ToWidgetEvent(nsIWidget
* aWidget
) const;
652 // Warning, this class is serialized and sent over IPC. Any change to its
653 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
654 TapGestureType mType
;
656 // The location of the tap in screen pixels.
657 ScreenIntPoint mPoint
;
659 // The location of the tap in the local coordinates of the APZC receiving it.
660 // This is set and used by APZ.
661 ParentLayerPoint mLocalPoint
;
664 // Encapsulation class for scroll-wheel events. These are generated by mice
665 // with physical scroll wheels, and on Windows by most touchpads when using
667 class ScrollWheelInput
: public InputData
{
669 friend mozilla::layers::APZInputBridgeChild
;
670 friend mozilla::layers::PAPZInputBridgeParent
;
671 ALLOW_DEPRECATED_READPARAM
673 typedef mozilla::layers::APZWheelAction APZWheelAction
;
679 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
681 // There are three kinds of scroll delta modes in Gecko: "page", "line"
688 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
696 ScrollWheelInput(TimeStamp aTimeStamp
, Modifiers aModifiers
,
697 ScrollMode aScrollMode
, ScrollDeltaType aDeltaType
,
698 const ScreenPoint
& aOrigin
, double aDeltaX
, double aDeltaY
,
699 bool aAllowToOverrideSystemScrollSpeed
,
700 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy
);
701 explicit ScrollWheelInput(const WidgetWheelEvent
& aEvent
);
703 static ScrollDeltaType
DeltaTypeForDeltaMode(uint32_t aDeltaMode
);
704 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType
);
705 static mozilla::ScrollUnit
ScrollUnitForDeltaType(ScrollDeltaType aDeltaType
);
707 WidgetWheelEvent
ToWidgetEvent(nsIWidget
* aWidget
) const;
708 bool TransformToLocal(const ScreenToParentLayerMatrix4x4
& aTransform
);
710 bool IsCustomizedByUserPrefs() const;
712 // The following two functions are for auto-dir scrolling. For detailed
713 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
714 bool IsAutoDir(bool aForce
= false) const {
719 switch (mWheelDeltaAdjustmentStrategy
) {
720 case WheelDeltaAdjustmentStrategy::eAutoDir
:
721 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour
:
724 // Prevent compilation errors generated by -Werror=switch
729 // Indicates which element this scroll honours if it's an auto-dir scroll.
730 // If true, honour the root element; otherwise, honour the currently scrolling
732 // Note that if IsAutoDir() returns false, then this function also returns
733 // false, but false in this case is meaningless as IsAutoDir() indicates it's
734 // not an auto-dir scroll.
735 // For detailed information on auto-dir,
736 // @see mozilla::WheelDeltaAdjustmentStrategy
737 bool HonoursRoot(bool aForce
= false) const {
738 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour
==
739 mWheelDeltaAdjustmentStrategy
||
743 // Warning, this class is serialized and sent over IPC. Any change to its
744 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
745 ScrollDeltaType mDeltaType
;
746 ScrollMode mScrollMode
;
751 // Deltas are in units corresponding to the delta type. For line deltas, they
752 // are the number of line units to scroll. The number of device pixels for a
753 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
754 // For pixel deltas, these values are in ScreenCoords.
756 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
757 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
762 // The number of scroll wheel ticks.
763 double mWheelTicksX
= 0.0;
764 double mWheelTicksY
= 0.0;
766 // The location of the scroll in local coordinates. This is set and used by
768 ParentLayerPoint mLocalOrigin
;
770 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
771 int32_t mLineOrPageDeltaX
;
772 int32_t mLineOrPageDeltaY
;
774 // Indicates the order in which this event was added to a transaction. The
775 // first event is 1; if not a member of a transaction, this is 0.
776 uint32_t mScrollSeriesNumber
;
778 // User-set delta multipliers.
779 double mUserDeltaMultiplierX
;
780 double mUserDeltaMultiplierY
;
782 bool mMayHaveMomentum
;
784 bool mAllowToOverrideSystemScrollSpeed
;
786 // Sometimes a wheel event input's wheel delta should be adjusted. This member
787 // specifies how to adjust the wheel delta.
788 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy
;
790 APZWheelAction mAPZAction
;
793 class KeyboardInput
: public InputData
{
795 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction
;
797 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
798 // other member, don't forget to update the minimum value in
799 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
801 enum KeyboardEventType
{
805 // Any other key event such as eAccessKeyNotFound
808 // Used as an upper bound for ContiguousEnumSerializer
812 explicit KeyboardInput(const WidgetKeyboardEvent
& aEvent
);
814 // Warning, this class is serialized and sent over IPC. Any change to its
815 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
817 KeyboardEventType mType
;
820 CopyableTArray
<ShortcutKeyCandidate
> mShortcutCandidates
;
824 // The scroll action to perform on a layer for this keyboard input. This is
825 // only used in APZ and is NOT serialized over IPC.
826 KeyboardScrollAction mAction
;
829 friend mozilla::layers::APZInputBridgeChild
;
830 friend mozilla::layers::PAPZInputBridgeParent
;
831 ALLOW_DEPRECATED_READPARAM
836 } // namespace mozilla
838 #endif // InputData_h__