Bug 1649121: part 26) Move `CollectTopMostChildContentsCompletelyInRange`. r=masayuki
[gecko.git] / widget / InputData.h
blobf925cde8cf499d13846eb062993cf26968a4ad72
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/APZUtils.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 // A unique number assigned to each SingleTouchData within a MultiTouchInput
153 // so that they can be easily distinguished when handling a touch
154 // start/move/end.
155 int32_t mIdentifier;
157 // Point on the screen that the touch hit, in device pixels. They are
158 // coordinates on the screen.
159 ScreenIntPoint mScreenPoint;
161 // |mScreenPoint| transformed to the local coordinates of the APZC targeted
162 // by the hit. This is set and used by APZ.
163 ParentLayerPoint mLocalScreenPoint;
165 // Radius that the touch covers, i.e. if you're using your thumb it will
166 // probably be larger than using your pinky, even with the same force.
167 // Radius can be different along x and y. For example, if you press down with
168 // your entire finger vertically, the y radius will be much larger than the x
169 // radius.
170 ScreenSize mRadius;
172 float mRotationAngle;
174 // How hard the screen is being pressed.
175 float mForce;
179 * Similar to WidgetTouchEvent, but for use off-main-thread. Also only stores a
180 * screen touch point instead of the many different coordinate spaces
181 * WidgetTouchEvent stores its touch point in. This includes a way to initialize
182 * itself from a WidgetTouchEvent by copying all relevant data over. Note that
183 * this copying from WidgetTouchEvent functionality can only be used on the main
184 * thread.
186 * Stores an array of SingleTouchData.
188 class MultiTouchInput : public InputData {
189 public:
190 // clang-format off
191 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
192 MultiTouchType, (
193 MULTITOUCH_START,
194 MULTITOUCH_MOVE,
195 MULTITOUCH_END,
196 MULTITOUCH_CANCEL
198 // clang-format on
200 MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
201 Modifiers aModifiers);
202 MultiTouchInput();
203 MultiTouchInput(const MultiTouchInput& aOther);
204 explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
205 void Translate(const ScreenPoint& aTranslation);
207 WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
209 // Return the index into mTouches of the SingleTouchData with the given
210 // identifier, or -1 if there is no such SingleTouchData.
211 int32_t IndexOfTouch(int32_t aTouchIdentifier);
213 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
215 // Warning, this class is serialized and sent over IPC. Any change to its
216 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
217 MultiTouchType mType;
218 CopyableTArray<SingleTouchData> mTouches;
219 // The screen offset of the root widget. This can be changing along with
220 // the touch interaction, so we sstore it in the event.
221 ExternalPoint mScreenOffset;
222 bool mHandledByAPZ;
225 class MouseInput : public InputData {
226 protected:
227 friend mozilla::layers::APZInputBridgeChild;
228 friend mozilla::layers::PAPZInputBridgeParent;
230 MouseInput();
232 public:
233 // clang-format off
234 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
235 MouseType, (
236 MOUSE_NONE,
237 MOUSE_MOVE,
238 MOUSE_DOWN,
239 MOUSE_UP,
240 MOUSE_DRAG_START,
241 MOUSE_DRAG_END,
242 MOUSE_WIDGET_ENTER,
243 MOUSE_WIDGET_EXIT,
244 MOUSE_HITTEST
247 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
248 ButtonType, (
249 PRIMARY_BUTTON,
250 MIDDLE_BUTTON,
251 SECONDARY_BUTTON,
252 NONE
254 // clang-format on
256 MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
257 int16_t aButtons, const ScreenPoint& aPoint, uint32_t aTime,
258 TimeStamp aTimeStamp, Modifiers aModifiers);
259 explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
261 bool IsLeftButton() const;
263 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
264 WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
266 // Warning, this class is serialized and sent over IPC. Any change to its
267 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
268 MouseType mType;
269 ButtonType mButtonType;
270 uint16_t mInputSource;
271 int16_t mButtons;
272 ScreenPoint mOrigin;
273 ParentLayerPoint mLocalOrigin;
274 bool mHandledByAPZ;
278 * Encapsulation class for pan events, can be used off-main-thread.
279 * These events are currently only used for scrolling on desktop.
281 class PanGestureInput : public InputData {
282 protected:
283 friend mozilla::layers::APZInputBridgeChild;
284 friend mozilla::layers::PAPZInputBridgeParent;
286 PanGestureInput();
288 public:
289 // clang-format off
290 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
291 PanGestureType, (
292 // MayStart: Dispatched before any actual panning has occurred but when a
293 // pan gesture is probably about to start, for example when the user
294 // starts touching the touchpad. Should interrupt any ongoing APZ
295 // animation and can be used to trigger scrollability indicators (e.g.
296 // flashing overlay scrollbars).
297 PANGESTURE_MAYSTART,
299 // Cancelled: Dispatched after MayStart when no pan gesture is going to
300 // happen after all, for example when the user lifts their fingers from a
301 // touchpad without having done any scrolling.
302 PANGESTURE_CANCELLED,
304 // Start: A pan gesture is starting.
305 // For devices that do not support the MayStart event type, this event can
306 // be used to interrupt ongoing APZ animations.
307 PANGESTURE_START,
309 // Pan: The actual pan motion by mPanDisplacement.
310 PANGESTURE_PAN,
312 // End: The pan gesture has ended, for example because the user has lifted
313 // their fingers from a touchpad after scrolling.
314 // Any potential momentum events fire after this event.
315 PANGESTURE_END,
317 // The following momentum event types are used in order to control the pan
318 // momentum animation. Using these instead of our own animation ensures
319 // that the animation curve is OS native and that the animation stops
320 // reliably if it is cancelled by the user.
322 // MomentumStart: Dispatched between the End event of the actual
323 // user-controlled pan, and the first MomentumPan event of the momentum
324 // animation.
325 PANGESTURE_MOMENTUMSTART,
327 // MomentumPan: The actual momentum motion by mPanDisplacement.
328 PANGESTURE_MOMENTUMPAN,
330 // MomentumEnd: The momentum animation has ended, for example because the
331 // momentum velocity has gone below the stopping threshold, or because the
332 // user has stopped the animation by putting their fingers on a touchpad.
333 PANGESTURE_MOMENTUMEND
336 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
337 PanDeltaType, (
338 // There are three kinds of scroll delta modes in Gecko: "page", "line"
339 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
341 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
342 // (see AsyncPanZoomController::OnPan).
343 PANDELTA_PAGE,
344 PANDELTA_PIXEL
346 // clang-format on
348 PanGestureInput(PanGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
349 const ScreenPoint& aPanStartPoint,
350 const ScreenPoint& aPanDisplacement, Modifiers aModifiers);
352 bool IsMomentum() const;
354 WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
356 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
358 ScreenPoint UserMultipliedPanDisplacement() const;
359 ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
361 // Warning, this class is serialized and sent over IPC. Any change to its
362 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
363 PanGestureType mType;
364 ScreenPoint mPanStartPoint;
366 // The delta. This can be non-zero on any type of event.
367 ScreenPoint mPanDisplacement;
369 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
370 // coordinates of the APZC receiving the pan. These are set and used by APZ.
371 ParentLayerPoint mLocalPanStartPoint;
372 ParentLayerPoint mLocalPanDisplacement;
374 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
375 int32_t mLineOrPageDeltaX;
376 int32_t mLineOrPageDeltaY;
378 // User-set delta multipliers.
379 double mUserDeltaMultiplierX;
380 double mUserDeltaMultiplierY;
382 PanDeltaType mDeltaType = PANDELTA_PIXEL;
384 bool mHandledByAPZ : 1;
386 // true if this is a PANGESTURE_END event that will be followed by a
387 // PANGESTURE_MOMENTUMSTART event.
388 bool mFollowedByMomentum : 1;
390 // If this is true, and this event started a new input block that couldn't
391 // find a scrollable target which is scrollable in the horizontal component
392 // of the scroll start direction, then this input block needs to be put on
393 // hold until a content response has arrived, even if the block has a
394 // confirmed target.
395 // This is used by events that can result in a swipe instead of a scroll.
396 bool mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection : 1;
398 // This is used by APZ to communicate to the macOS widget code whether
399 // the overscroll-behavior of the scroll frame handling this swipe allows
400 // non-local overscroll behaviors in the horizontal direction (such as
401 // swipe navigation).
402 bool mOverscrollBehaviorAllowsSwipe : 1;
404 // true if APZ should do a fling animation after this pan ends, like
405 // it would with touchscreens. (For platforms that don't emit momentum
406 // events.)
407 bool mSimulateMomentum : 1;
409 void SetHandledByAPZ(bool aHandled) { mHandledByAPZ = aHandled; }
410 void SetFollowedByMomentum(bool aFollowed) {
411 mFollowedByMomentum = aFollowed;
413 void SetRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(
414 bool aRequires) {
415 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection =
416 aRequires;
418 void SetOverscrollBehaviorAllowsSwipe(bool aAllows) {
419 mOverscrollBehaviorAllowsSwipe = aAllows;
421 void SetSimulateMomentum(bool aSimulate) { mSimulateMomentum = aSimulate; }
425 * Encapsulation class for pinch events. In general, these will be generated by
426 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
427 * and determining whether or not the user was trying to do a gesture.
429 class PinchGestureInput : public InputData {
430 protected:
431 friend mozilla::layers::APZInputBridgeChild;
432 friend mozilla::layers::PAPZInputBridgeParent;
434 PinchGestureInput();
436 public:
437 // clang-format off
438 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
439 PinchGestureType, (
440 PINCHGESTURE_START,
441 PINCHGESTURE_SCALE,
442 // The FINGERLIFTED state is used when a touch-based pinch gesture is
443 // terminated by lifting one of the two fingers. The position of the
444 // finger that's still down is populated as the focus point.
445 PINCHGESTURE_FINGERLIFTED,
446 // The END state is used when the pinch gesture is completely terminated.
447 // In this state, the focus point should not be relied upon for having
448 // meaningful data.
449 PINCHGESTURE_END
452 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
453 PinchGestureSource, (
454 UNKNOWN, // Default initialization value. Should never actually be used.
455 TOUCH, // From two-finger pinch gesture
456 ONE_TOUCH, // From one-finger pinch gesture
457 TRACKPAD, // From trackpad pinch gesture
458 MOUSEWHEEL // Synthesized from modifier+mousewheel
460 // If adding more items here, increase n_values for the
461 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
463 // clang-format on
465 // Construct a pinch gesture from a Screen point.
466 PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
467 uint32_t aTime, TimeStamp aTimeStamp,
468 const ExternalPoint& aScreenOffset,
469 const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
470 ScreenCoord aPreviousSpan, Modifiers aModifiers);
472 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
474 WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
476 // Warning, this class is serialized and sent over IPC. Any change to its
477 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
478 PinchGestureType mType;
480 // Some indication of the input device that generated this pinch gesture.
481 PinchGestureSource mSource;
483 // Center point of the pinch gesture. That is, if there are two fingers on the
484 // screen, it is their midpoint. In the case of more than two fingers, the
485 // point is implementation-specific, but can for example be the midpoint
486 // between the very first and very last touch. This is in device pixels and
487 // are the coordinates on the screen of this midpoint.
488 // For PINCHGESTURE_END events, this may hold the last known focus point or
489 // just be empty; in any case for END events it should not be relied upon.
490 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
491 // that is still down.
492 ScreenPoint mFocusPoint;
494 // The screen offset of the root widget. This can be changing along with
495 // the touch interaction, so we sstore it in the event.
496 ExternalPoint mScreenOffset;
498 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
499 // by the hit. This is set and used by APZ.
500 ParentLayerPoint mLocalFocusPoint;
502 // The distance between the touches responsible for the pinch gesture.
503 ScreenCoord mCurrentSpan;
505 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
506 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
507 // of this type then there must have been a history of spans.
508 ScreenCoord mPreviousSpan;
510 bool mHandledByAPZ;
514 * Encapsulation class for tap events. In general, these will be generated by
515 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
516 * and determining whether or not the user was trying to do a gesture.
518 class TapGestureInput : public InputData {
519 protected:
520 friend mozilla::layers::APZInputBridgeChild;
521 friend mozilla::layers::PAPZInputBridgeParent;
523 TapGestureInput();
525 public:
526 // clang-format off
527 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
528 TapGestureType, (
529 TAPGESTURE_LONG,
530 TAPGESTURE_LONG_UP,
531 TAPGESTURE_UP,
532 TAPGESTURE_CONFIRMED,
533 TAPGESTURE_DOUBLE,
534 TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
535 TAPGESTURE_CANCEL
537 // clang-format on
539 // Construct a tap gesture from a Screen point.
540 // mLocalPoint remains (0,0) unless it's set later.
541 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
542 const ScreenIntPoint& aPoint, Modifiers aModifiers);
544 // Construct a tap gesture from a ParentLayer point.
545 // mPoint remains (0,0) unless it's set later.
546 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
547 const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
549 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
551 // Warning, this class is serialized and sent over IPC. Any change to its
552 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
553 TapGestureType mType;
555 // The location of the tap in screen pixels.
556 ScreenIntPoint mPoint;
558 // The location of the tap in the local coordinates of the APZC receiving it.
559 // This is set and used by APZ.
560 ParentLayerPoint mLocalPoint;
563 // Encapsulation class for scroll-wheel events. These are generated by mice
564 // with physical scroll wheels, and on Windows by most touchpads when using
565 // scroll gestures.
566 class ScrollWheelInput : public InputData {
567 protected:
568 friend mozilla::layers::APZInputBridgeChild;
569 friend mozilla::layers::PAPZInputBridgeParent;
571 typedef mozilla::layers::APZWheelAction APZWheelAction;
573 ScrollWheelInput();
575 public:
576 // clang-format off
577 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
578 ScrollDeltaType, (
579 // There are three kinds of scroll delta modes in Gecko: "page", "line"
580 // and "pixel".
581 SCROLLDELTA_LINE,
582 SCROLLDELTA_PAGE,
583 SCROLLDELTA_PIXEL
586 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
587 ScrollMode, (
588 SCROLLMODE_INSTANT,
589 SCROLLMODE_SMOOTH
592 // clang-format on
594 ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers,
595 ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
596 const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
597 bool aAllowToOverrideSystemScrollSpeed,
598 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
599 explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
601 static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
602 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
603 static mozilla::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
605 WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
606 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
608 bool IsCustomizedByUserPrefs() const;
610 // The following two functions are for auto-dir scrolling. For detailed
611 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
612 bool IsAutoDir() const {
613 switch (mWheelDeltaAdjustmentStrategy) {
614 case WheelDeltaAdjustmentStrategy::eAutoDir:
615 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
616 return true;
617 default:
618 // Prevent compilation errors generated by -Werror=switch
619 break;
621 return false;
623 // Indicates which element this scroll honours if it's an auto-dir scroll.
624 // If true, honour the root element; otherwise, honour the currently scrolling
625 // target.
626 // Note that if IsAutoDir() returns false, then this function also returns
627 // false, but false in this case is meaningless as IsAutoDir() indicates it's
628 // not an auto-dir scroll.
629 // For detailed information on auto-dir,
630 // @see mozilla::WheelDeltaAdjustmentStrategy
631 bool HonoursRoot() const {
632 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
633 mWheelDeltaAdjustmentStrategy;
636 // Warning, this class is serialized and sent over IPC. Any change to its
637 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
638 ScrollDeltaType mDeltaType;
639 ScrollMode mScrollMode;
640 ScreenPoint mOrigin;
642 bool mHandledByAPZ;
644 // Deltas are in units corresponding to the delta type. For line deltas, they
645 // are the number of line units to scroll. The number of device pixels for a
646 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
647 // For pixel deltas, these values are in ScreenCoords.
649 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
650 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
651 // scrolling down.
652 double mDeltaX;
653 double mDeltaY;
655 // The location of the scroll in local coordinates. This is set and used by
656 // APZ.
657 ParentLayerPoint mLocalOrigin;
659 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
660 int32_t mLineOrPageDeltaX;
661 int32_t mLineOrPageDeltaY;
663 // Indicates the order in which this event was added to a transaction. The
664 // first event is 1; if not a member of a transaction, this is 0.
665 uint32_t mScrollSeriesNumber;
667 // User-set delta multipliers.
668 double mUserDeltaMultiplierX;
669 double mUserDeltaMultiplierY;
671 bool mMayHaveMomentum;
672 bool mIsMomentum;
673 bool mAllowToOverrideSystemScrollSpeed;
675 // Sometimes a wheel event input's wheel delta should be adjusted. This member
676 // specifies how to adjust the wheel delta.
677 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
679 APZWheelAction mAPZAction;
682 class KeyboardInput : public InputData {
683 public:
684 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
686 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
687 // other member, don't forget to update the minimum value in
688 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
689 // accordingly.
690 enum KeyboardEventType {
691 KEY_DOWN,
692 KEY_PRESS,
693 KEY_UP,
694 // Any other key event such as eKeyDownOnPlugin
695 KEY_OTHER,
697 // Used as an upper bound for ContiguousEnumSerializer
698 KEY_SENTINEL,
701 explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
703 // Warning, this class is serialized and sent over IPC. Any change to its
704 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
706 KeyboardEventType mType;
707 uint32_t mKeyCode;
708 uint32_t mCharCode;
709 CopyableTArray<ShortcutKeyCandidate> mShortcutCandidates;
711 bool mHandledByAPZ;
713 // The scroll action to perform on a layer for this keyboard input. This is
714 // only used in APZ and is NOT serialized over IPC.
715 KeyboardScrollAction mAction;
717 protected:
718 friend mozilla::layers::APZInputBridgeChild;
719 friend mozilla::layers::PAPZInputBridgeParent;
721 KeyboardInput();
724 } // namespace mozilla
726 #endif // InputData_h__