Bug 1700051: part 34) Reduce accessibility of `mSoftText.mValue` to `private`. r...
[gecko.git] / widget / InputData.h
blob26eb4c6264a18c9366153b7c206a19ee60129ab6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef InputData_h__
7 #define InputData_h__
9 #include "nsDebug.h"
10 #include "nsPoint.h"
11 #include "nsTArray.h"
12 #include "Units.h"
13 #include "mozilla/ScrollTypes.h"
14 #include "mozilla/DefineEnum.h"
15 #include "mozilla/EventForwards.h"
16 #include "mozilla/TimeStamp.h"
17 #include "mozilla/WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
18 #include "mozilla/gfx/MatrixFwd.h"
19 #include "mozilla/layers/APZPublicUtils.h"
20 #include "mozilla/layers/KeyboardScrollAction.h"
21 #include "mozilla/TextEvents.h"
23 template <class E>
24 struct already_AddRefed;
25 class nsIWidget;
27 namespace mozilla {
29 namespace layers {
30 class APZInputBridgeChild;
31 class PAPZInputBridgeParent;
32 } // namespace layers
34 namespace dom {
35 class Touch;
36 } // namespace dom
38 // clang-format off
39 MOZ_DEFINE_ENUM(
40 InputType, (
41 MULTITOUCH_INPUT,
42 MOUSE_INPUT,
43 PANGESTURE_INPUT,
44 PINCHGESTURE_INPUT,
45 TAPGESTURE_INPUT,
46 SCROLLWHEEL_INPUT,
47 KEYBOARD_INPUT
48 ));
49 // clang-format on
51 class MultiTouchInput;
52 class MouseInput;
53 class PanGestureInput;
54 class PinchGestureInput;
55 class TapGestureInput;
56 class ScrollWheelInput;
57 class KeyboardInput;
59 // This looks unnecessary now, but as we add more and more classes that derive
60 // from InputType (eventually probably almost as many as *Events.h has), it
61 // will be more and more clear what's going on with a macro that shortens the
62 // definition of the RTTI functions.
63 #define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
64 const type& As##type() const { \
65 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
66 return (const type&)*this; \
67 } \
68 type& As##type() { \
69 MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
70 return (type&)*this; \
73 /** Base input data class. Should never be instantiated. */
74 class InputData {
75 public:
76 // Warning, this class is serialized and sent over IPC. Any change to its
77 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
78 InputType mInputType;
79 // Time in milliseconds that this data is relevant to. This only really
80 // matters when this data is used as an event. We use uint32_t instead of
81 // TimeStamp because it is easier to convert from WidgetInputEvent. The time
82 // is platform-specific but it in the case of B2G and Fennec it is since
83 // startup.
84 uint32_t mTime;
85 // Set in parallel to mTime until we determine it is safe to drop
86 // platform-specific event times (see bug 77992).
87 TimeStamp mTimeStamp;
88 // The sequence number of the last potentially focus changing event handled
89 // by APZ. This is used to track when that event has been processed by
90 // content, and focus can be reconfirmed for async keyboard scrolling.
91 uint64_t mFocusSequenceNumber;
93 // The LayersId of the content process that the corresponding WidgetEvent
94 // should be dispatched to.
95 layers::LayersId mLayersId;
97 Modifiers modifiers;
99 INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
100 INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
101 INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
102 INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
103 INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
104 INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
105 INPUTDATA_AS_CHILD_TYPE(KeyboardInput, KEYBOARD_INPUT)
107 virtual ~InputData();
108 explicit InputData(InputType aInputType);
110 protected:
111 InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
112 Modifiers aModifiers);
116 * Data container for a single touch input. Similar to dom::Touch, but used in
117 * off-main-thread situations. This is more for just storing touch data, whereas
118 * dom::Touch is more useful for dispatching through the DOM (which can only
119 * happen on the main thread). dom::Touch also bears the problem of storing
120 * pointers to nsIWidget instances which can only be used on the main thread,
121 * so if instead we used dom::Touch and ever set these pointers
122 * off-main-thread, Bad Things Can Happen(tm).
124 * Note that this doesn't inherit from InputData because this itself is not an
125 * event. It is only a container/struct that should have any number of instances
126 * within a MultiTouchInput.
128 * fixme/bug 775746: Make dom::Touch inherit from this class.
130 class SingleTouchData {
131 public:
132 // Construct a SingleTouchData from a Screen point.
133 // mLocalScreenPoint remains (0,0) unless it's set later.
134 SingleTouchData(int32_t aIdentifier, ScreenIntPoint aScreenPoint,
135 ScreenSize aRadius, float aRotationAngle, float aForce);
137 // Construct a SingleTouchData from a ParentLayer point.
138 // mScreenPoint remains (0,0) unless it's set later.
139 // Note: if APZ starts using the radius for anything, we should add a local
140 // version of that too, and have this constructor take it as a
141 // ParentLayerSize.
142 SingleTouchData(int32_t aIdentifier, ParentLayerPoint aLocalScreenPoint,
143 ScreenSize aRadius, float aRotationAngle, float aForce);
145 SingleTouchData();
147 already_AddRefed<dom::Touch> ToNewDOMTouch() const;
149 // Warning, this class is serialized and sent over IPC. Any change to its
150 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
152 // Historical data of this touch, which was coalesced into this event.
153 // Touch event coalescing can happen at the system level when the touch
154 // screen's sampling frequency is higher than the vsync rate, or when the
155 // UI thread is busy. When multiple "samples" of touch data are coalesced into
156 // one touch event, the touch event's regular position information is the
157 // information from the last sample. And the previous, "coalesced-away"
158 // samples are stored in mHistoricalData.
160 struct HistoricalTouchData {
161 // The timestamp at which the information in this "sample" was originally
162 // sampled.
163 TimeStamp mTimeStamp;
165 // The touch data of this historical sample.
166 ScreenIntPoint mScreenPoint;
167 ParentLayerPoint mLocalScreenPoint;
168 ScreenSize mRadius;
169 float mRotationAngle = 0.0f;
170 float mForce = 0.0f;
172 CopyableTArray<HistoricalTouchData> mHistoricalData;
174 // A unique number assigned to each SingleTouchData within a MultiTouchInput
175 // so that they can be easily distinguished when handling a touch
176 // start/move/end.
177 int32_t mIdentifier;
179 // Point on the screen that the touch hit, in device pixels. They are
180 // coordinates on the screen.
181 ScreenIntPoint mScreenPoint;
183 // |mScreenPoint| transformed to the local coordinates of the APZC targeted
184 // by the hit. This is set and used by APZ.
185 ParentLayerPoint mLocalScreenPoint;
187 // Radius that the touch covers, i.e. if you're using your thumb it will
188 // probably be larger than using your pinky, even with the same force.
189 // Radius can be different along x and y. For example, if you press down with
190 // your entire finger vertically, the y radius will be much larger than the x
191 // radius.
192 ScreenSize mRadius;
194 float mRotationAngle;
196 // How hard the screen is being pressed.
197 float mForce;
201 * Similar to WidgetTouchEvent, but for use off-main-thread. Also only stores a
202 * screen touch point instead of the many different coordinate spaces
203 * WidgetTouchEvent stores its touch point in. This includes a way to initialize
204 * itself from a WidgetTouchEvent by copying all relevant data over. Note that
205 * this copying from WidgetTouchEvent functionality can only be used on the main
206 * thread.
208 * Stores an array of SingleTouchData.
210 class MultiTouchInput : public InputData {
211 public:
212 // clang-format off
213 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
214 MultiTouchType, (
215 MULTITOUCH_START,
216 MULTITOUCH_MOVE,
217 MULTITOUCH_END,
218 MULTITOUCH_CANCEL
220 // clang-format on
222 MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
223 Modifiers aModifiers);
224 MultiTouchInput();
225 MultiTouchInput(MultiTouchInput&&) = default;
226 MultiTouchInput(const MultiTouchInput& aOther);
227 explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
229 MultiTouchInput& operator=(MultiTouchInput&&) = default;
230 MultiTouchInput& operator=(const MultiTouchInput&) = default;
232 void Translate(const ScreenPoint& aTranslation);
234 WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
236 // Return the index into mTouches of the SingleTouchData with the given
237 // identifier, or -1 if there is no such SingleTouchData.
238 int32_t IndexOfTouch(int32_t aTouchIdentifier);
240 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
242 // Warning, this class is serialized and sent over IPC. Any change to its
243 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
244 MultiTouchType mType;
245 CopyableTArray<SingleTouchData> mTouches;
246 // The screen offset of the root widget. This can be changing along with
247 // the touch interaction, so we sstore it in the event.
248 ExternalPoint mScreenOffset;
249 bool mHandledByAPZ;
252 class MouseInput : public InputData {
253 protected:
254 friend mozilla::layers::APZInputBridgeChild;
255 friend mozilla::layers::PAPZInputBridgeParent;
257 MouseInput();
259 public:
260 // clang-format off
261 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
262 MouseType, (
263 MOUSE_NONE,
264 MOUSE_MOVE,
265 MOUSE_DOWN,
266 MOUSE_UP,
267 MOUSE_DRAG_START,
268 MOUSE_DRAG_END,
269 MOUSE_WIDGET_ENTER,
270 MOUSE_WIDGET_EXIT,
271 MOUSE_HITTEST
274 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
275 ButtonType, (
276 PRIMARY_BUTTON,
277 MIDDLE_BUTTON,
278 SECONDARY_BUTTON,
279 NONE
281 // clang-format on
283 MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
284 int16_t aButtons, const ScreenPoint& aPoint, uint32_t aTime,
285 TimeStamp aTimeStamp, Modifiers aModifiers);
286 explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
288 bool IsLeftButton() const;
290 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
291 WidgetMouseEvent ToWidgetEvent(nsIWidget* aWidget) const;
293 // Warning, this class is serialized and sent over IPC. Any change to its
294 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
295 MouseType mType;
296 ButtonType mButtonType;
297 uint16_t mInputSource;
298 int16_t mButtons;
299 ScreenPoint mOrigin;
300 ParentLayerPoint mLocalOrigin;
301 bool mHandledByAPZ;
303 * If click event should not be fired in the content after the "mousedown"
304 * event or following "mouseup", set to true.
306 bool mPreventClickEvent;
310 * Encapsulation class for pan events, can be used off-main-thread.
311 * These events are currently only used for scrolling on desktop.
313 class PanGestureInput : public InputData {
314 protected:
315 friend mozilla::layers::APZInputBridgeChild;
316 friend mozilla::layers::PAPZInputBridgeParent;
318 PanGestureInput();
320 public:
321 // clang-format off
322 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
323 PanGestureType, (
324 // MayStart: Dispatched before any actual panning has occurred but when a
325 // pan gesture is probably about to start, for example when the user
326 // starts touching the touchpad. Should interrupt any ongoing APZ
327 // animation and can be used to trigger scrollability indicators (e.g.
328 // flashing overlay scrollbars).
329 PANGESTURE_MAYSTART,
331 // Cancelled: Dispatched after MayStart when no pan gesture is going to
332 // happen after all, for example when the user lifts their fingers from a
333 // touchpad without having done any scrolling.
334 PANGESTURE_CANCELLED,
336 // Start: A pan gesture is starting.
337 // For devices that do not support the MayStart event type, this event can
338 // be used to interrupt ongoing APZ animations.
339 PANGESTURE_START,
341 // Pan: The actual pan motion by mPanDisplacement.
342 PANGESTURE_PAN,
344 // End: The pan gesture has ended, for example because the user has lifted
345 // their fingers from a touchpad after scrolling.
346 // Any potential momentum events fire after this event.
347 PANGESTURE_END,
349 // The following momentum event types are used in order to control the pan
350 // momentum animation. Using these instead of our own animation ensures
351 // that the animation curve is OS native and that the animation stops
352 // reliably if it is cancelled by the user.
354 // MomentumStart: Dispatched between the End event of the actual
355 // user-controlled pan, and the first MomentumPan event of the momentum
356 // animation.
357 PANGESTURE_MOMENTUMSTART,
359 // MomentumPan: The actual momentum motion by mPanDisplacement.
360 PANGESTURE_MOMENTUMPAN,
362 // MomentumEnd: The momentum animation has ended, for example because the
363 // momentum velocity has gone below the stopping threshold, or because the
364 // user has stopped the animation by putting their fingers on a touchpad.
365 PANGESTURE_MOMENTUMEND
368 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
369 PanDeltaType, (
370 // There are three kinds of scroll delta modes in Gecko: "page", "line"
371 // and "pixel". Touchpad pan gestures only support "page" and "pixel".
373 // NOTE: PANDELTA_PAGE currently replicates Gtk behavior
374 // (see AsyncPanZoomController::OnPan).
375 PANDELTA_PAGE,
376 PANDELTA_PIXEL
378 // clang-format on
380 PanGestureInput(PanGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
381 const ScreenPoint& aPanStartPoint,
382 const ScreenPoint& aPanDisplacement, Modifiers aModifiers);
384 bool IsMomentum() const;
386 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
388 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
390 ScreenPoint UserMultipliedPanDisplacement() const;
391 ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
393 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
395 // Warning, this class is serialized and sent over IPC. Any change to its
396 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
397 PanGestureType mType;
398 ScreenPoint mPanStartPoint;
400 // The delta. This can be non-zero on any type of event.
401 ScreenPoint mPanDisplacement;
403 // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
404 // coordinates of the APZC receiving the pan. These are set and used by APZ.
405 ParentLayerPoint mLocalPanStartPoint;
406 ParentLayerPoint mLocalPanDisplacement;
408 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
409 int32_t mLineOrPageDeltaX;
410 int32_t mLineOrPageDeltaY;
412 // User-set delta multipliers.
413 double mUserDeltaMultiplierX;
414 double mUserDeltaMultiplierY;
416 PanDeltaType mDeltaType = PANDELTA_PIXEL;
418 bool mHandledByAPZ : 1;
420 // true if this is a PANGESTURE_END event that will be followed by a
421 // PANGESTURE_MOMENTUMSTART event.
422 bool mFollowedByMomentum : 1;
424 // If this is true, and this event started a new input block that couldn't
425 // find a scrollable target which is scrollable in the horizontal component
426 // of the scroll start direction, then this input block needs to be put on
427 // hold until a content response has arrived, even if the block has a
428 // confirmed target.
429 // This is used by events that can result in a swipe instead of a scroll.
430 bool mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection : 1;
432 // This is used by APZ to communicate to the macOS widget code whether
433 // the overscroll-behavior of the scroll frame handling this swipe allows
434 // non-local overscroll behaviors in the horizontal direction (such as
435 // swipe navigation).
436 bool mOverscrollBehaviorAllowsSwipe : 1;
438 // true if APZ should do a fling animation after this pan ends, like
439 // it would with touchscreens. (For platforms that don't emit momentum
440 // events.)
441 bool mSimulateMomentum : 1;
443 void SetHandledByAPZ(bool aHandled) { mHandledByAPZ = aHandled; }
444 void SetFollowedByMomentum(bool aFollowed) {
445 mFollowedByMomentum = aFollowed;
447 void SetRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(
448 bool aRequires) {
449 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection =
450 aRequires;
452 void SetOverscrollBehaviorAllowsSwipe(bool aAllows) {
453 mOverscrollBehaviorAllowsSwipe = aAllows;
455 void SetSimulateMomentum(bool aSimulate) { mSimulateMomentum = aSimulate; }
459 * Encapsulation class for pinch events. In general, these will be generated by
460 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
461 * and determining whether or not the user was trying to do a gesture.
463 class PinchGestureInput : public InputData {
464 protected:
465 friend mozilla::layers::APZInputBridgeChild;
466 friend mozilla::layers::PAPZInputBridgeParent;
468 PinchGestureInput();
470 public:
471 // clang-format off
472 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
473 PinchGestureType, (
474 PINCHGESTURE_START,
475 PINCHGESTURE_SCALE,
476 // The FINGERLIFTED state is used when a touch-based pinch gesture is
477 // terminated by lifting one of the two fingers. The position of the
478 // finger that's still down is populated as the focus point.
479 PINCHGESTURE_FINGERLIFTED,
480 // The END state is used when the pinch gesture is completely terminated.
481 // In this state, the focus point should not be relied upon for having
482 // meaningful data.
483 PINCHGESTURE_END
486 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
487 PinchGestureSource, (
488 UNKNOWN, // Default initialization value. Should never actually be used.
489 TOUCH, // From two-finger pinch gesture
490 ONE_TOUCH, // From one-finger pinch gesture
491 TRACKPAD, // From trackpad pinch gesture
492 MOUSEWHEEL // Synthesized from modifier+mousewheel
494 // If adding more items here, increase n_values for the
495 // APZ_ZOOM_PINCHSOURCE Telemetry metric.
497 // clang-format on
499 // Construct a pinch gesture from a Screen point.
500 PinchGestureInput(PinchGestureType aType, PinchGestureSource aSource,
501 uint32_t aTime, TimeStamp aTimeStamp,
502 const ExternalPoint& aScreenOffset,
503 const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
504 ScreenCoord aPreviousSpan, Modifiers aModifiers);
506 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
508 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
510 double ComputeDeltaY(nsIWidget* aWidget) const;
512 // Set mLineOrPageDeltaY based on ComputeDeltaY().
513 // Return false if the caller should drop this event to ensure
514 // that preventDefault() is respected. (More specifically, this will be
515 // true for event types other than PINCHGESTURE_END if the computed
516 // mLineOrPageDeltaY is zero. In such cases, the resulting DOMMouseScroll
517 // event will not be dispatched, which is a problem if the page is relying
518 // on DOMMouseScroll to prevent browser zooming).
519 // Note that even if the function returns false, the delta from the event
520 // is accumulated and available to be sent in a later event.
521 bool SetLineOrPageDeltaY(nsIWidget* aWidget);
523 static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
525 // Warning, this class is serialized and sent over IPC. Any change to its
526 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
527 PinchGestureType mType;
529 // Some indication of the input device that generated this pinch gesture.
530 PinchGestureSource mSource;
532 // Center point of the pinch gesture. That is, if there are two fingers on the
533 // screen, it is their midpoint. In the case of more than two fingers, the
534 // point is implementation-specific, but can for example be the midpoint
535 // between the very first and very last touch. This is in device pixels and
536 // are the coordinates on the screen of this midpoint.
537 // For PINCHGESTURE_END events, this may hold the last known focus point or
538 // just be empty; in any case for END events it should not be relied upon.
539 // For PINCHGESTURE_FINGERLIFTED events, this holds the point of the finger
540 // that is still down.
541 ScreenPoint mFocusPoint;
543 // The screen offset of the root widget. This can be changing along with
544 // the touch interaction, so we sstore it in the event.
545 ExternalPoint mScreenOffset;
547 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
548 // by the hit. This is set and used by APZ.
549 ParentLayerPoint mLocalFocusPoint;
551 // The distance between the touches responsible for the pinch gesture.
552 ScreenCoord mCurrentSpan;
554 // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
555 // This is only really relevant during a PINCHGESTURE_SCALE because when it is
556 // of this type then there must have been a history of spans.
557 ScreenCoord mPreviousSpan;
559 // We accumulate (via GetIntegerDeltaForEvent) the deltaY that would be
560 // computed by ToWidgetEvent, and then whenever we get a whole integer
561 // value we put it in mLineOrPageDeltaY. Since we only ever use deltaY we
562 // don't need a mLineOrPageDeltaX. This field is used to dispatch legacy mouse
563 // events which are only dispatched when the corresponding field on
564 // WidgetWheelEvent is non-zero.
565 int32_t mLineOrPageDeltaY;
567 bool mHandledByAPZ;
571 * Encapsulation class for tap events. In general, these will be generated by
572 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances
573 * and determining whether or not the user was trying to do a gesture.
575 class TapGestureInput : public InputData {
576 protected:
577 friend mozilla::layers::APZInputBridgeChild;
578 friend mozilla::layers::PAPZInputBridgeParent;
580 TapGestureInput();
582 public:
583 // clang-format off
584 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
585 TapGestureType, (
586 TAPGESTURE_LONG,
587 TAPGESTURE_LONG_UP,
588 TAPGESTURE_UP,
589 TAPGESTURE_CONFIRMED,
590 TAPGESTURE_DOUBLE,
591 TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
592 TAPGESTURE_CANCEL
594 // clang-format on
596 // Construct a tap gesture from a Screen point.
597 // mLocalPoint remains (0,0) unless it's set later.
598 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
599 const ScreenIntPoint& aPoint, Modifiers aModifiers);
601 // Construct a tap gesture from a ParentLayer point.
602 // mPoint remains (0,0) unless it's set later.
603 TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
604 const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
606 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
608 WidgetSimpleGestureEvent ToWidgetEvent(nsIWidget* aWidget) const;
610 // Warning, this class is serialized and sent over IPC. Any change to its
611 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
612 TapGestureType mType;
614 // The location of the tap in screen pixels.
615 ScreenIntPoint mPoint;
617 // The location of the tap in the local coordinates of the APZC receiving it.
618 // This is set and used by APZ.
619 ParentLayerPoint mLocalPoint;
622 // Encapsulation class for scroll-wheel events. These are generated by mice
623 // with physical scroll wheels, and on Windows by most touchpads when using
624 // scroll gestures.
625 class ScrollWheelInput : public InputData {
626 protected:
627 friend mozilla::layers::APZInputBridgeChild;
628 friend mozilla::layers::PAPZInputBridgeParent;
630 typedef mozilla::layers::APZWheelAction APZWheelAction;
632 ScrollWheelInput();
634 public:
635 // clang-format off
636 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
637 ScrollDeltaType, (
638 // There are three kinds of scroll delta modes in Gecko: "page", "line"
639 // and "pixel".
640 SCROLLDELTA_LINE,
641 SCROLLDELTA_PAGE,
642 SCROLLDELTA_PIXEL
645 MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
646 ScrollMode, (
647 SCROLLMODE_INSTANT,
648 SCROLLMODE_SMOOTH
651 // clang-format on
653 ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers,
654 ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
655 const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
656 bool aAllowToOverrideSystemScrollSpeed,
657 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
658 explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
660 static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
661 static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
662 static mozilla::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
664 WidgetWheelEvent ToWidgetEvent(nsIWidget* aWidget) const;
665 bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
667 bool IsCustomizedByUserPrefs() const;
669 // The following two functions are for auto-dir scrolling. For detailed
670 // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
671 bool IsAutoDir() const {
672 switch (mWheelDeltaAdjustmentStrategy) {
673 case WheelDeltaAdjustmentStrategy::eAutoDir:
674 case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
675 return true;
676 default:
677 // Prevent compilation errors generated by -Werror=switch
678 break;
680 return false;
682 // Indicates which element this scroll honours if it's an auto-dir scroll.
683 // If true, honour the root element; otherwise, honour the currently scrolling
684 // target.
685 // Note that if IsAutoDir() returns false, then this function also returns
686 // false, but false in this case is meaningless as IsAutoDir() indicates it's
687 // not an auto-dir scroll.
688 // For detailed information on auto-dir,
689 // @see mozilla::WheelDeltaAdjustmentStrategy
690 bool HonoursRoot() const {
691 return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
692 mWheelDeltaAdjustmentStrategy;
695 // Warning, this class is serialized and sent over IPC. Any change to its
696 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
697 ScrollDeltaType mDeltaType;
698 ScrollMode mScrollMode;
699 ScreenPoint mOrigin;
701 bool mHandledByAPZ;
703 // Deltas are in units corresponding to the delta type. For line deltas, they
704 // are the number of line units to scroll. The number of device pixels for a
705 // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
706 // For pixel deltas, these values are in ScreenCoords.
708 // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
709 // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
710 // scrolling down.
711 double mDeltaX;
712 double mDeltaY;
714 // The location of the scroll in local coordinates. This is set and used by
715 // APZ.
716 ParentLayerPoint mLocalOrigin;
718 // See lineOrPageDeltaX/Y on WidgetWheelEvent.
719 int32_t mLineOrPageDeltaX;
720 int32_t mLineOrPageDeltaY;
722 // Indicates the order in which this event was added to a transaction. The
723 // first event is 1; if not a member of a transaction, this is 0.
724 uint32_t mScrollSeriesNumber;
726 // User-set delta multipliers.
727 double mUserDeltaMultiplierX;
728 double mUserDeltaMultiplierY;
730 bool mMayHaveMomentum;
731 bool mIsMomentum;
732 bool mAllowToOverrideSystemScrollSpeed;
734 // Sometimes a wheel event input's wheel delta should be adjusted. This member
735 // specifies how to adjust the wheel delta.
736 WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
738 APZWheelAction mAPZAction;
741 class KeyboardInput : public InputData {
742 public:
743 typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
745 // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
746 // other member, don't forget to update the minimum value in
747 // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
748 // accordingly.
749 enum KeyboardEventType {
750 KEY_DOWN,
751 KEY_PRESS,
752 KEY_UP,
753 // Any other key event such as eKeyDownOnPlugin
754 KEY_OTHER,
756 // Used as an upper bound for ContiguousEnumSerializer
757 KEY_SENTINEL,
760 explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
762 // Warning, this class is serialized and sent over IPC. Any change to its
763 // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
765 KeyboardEventType mType;
766 uint32_t mKeyCode;
767 uint32_t mCharCode;
768 CopyableTArray<ShortcutKeyCandidate> mShortcutCandidates;
770 bool mHandledByAPZ;
772 // The scroll action to perform on a layer for this keyboard input. This is
773 // only used in APZ and is NOT serialized over IPC.
774 KeyboardScrollAction mAction;
776 protected:
777 friend mozilla::layers::APZInputBridgeChild;
778 friend mozilla::layers::PAPZInputBridgeParent;
780 KeyboardInput();
783 } // namespace mozilla
785 #endif // InputData_h__