Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/InputData.h
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#ifndef InputData_h__
7
#define InputData_h__
8
9
#include "nsDebug.h"
10
#include "nsIScrollableFrame.h"
11
#include "nsPoint.h"
12
#include "nsTArray.h"
13
#include "Units.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
22
template<class E> struct already_AddRefed;
23
class nsIWidget;
24
25
namespace mozilla {
26
27
namespace layers {
28
class APZInputBridgeChild;
29
class PAPZInputBridgeParent;
30
}
31
32
namespace dom {
33
class Touch;
34
} // namespace dom
35
36
MOZ_DEFINE_ENUM(
37
  InputType, (
38
    MULTITOUCH_INPUT,
39
    MOUSE_INPUT,
40
    PANGESTURE_INPUT,
41
    PINCHGESTURE_INPUT,
42
    TAPGESTURE_INPUT,
43
    SCROLLWHEEL_INPUT,
44
    KEYBOARD_INPUT
45
));
46
47
class MultiTouchInput;
48
class MouseInput;
49
class PanGestureInput;
50
class PinchGestureInput;
51
class TapGestureInput;
52
class ScrollWheelInput;
53
class KeyboardInput;
54
55
// This looks unnecessary now, but as we add more and more classes that derive
56
// from InputType (eventually probably almost as many as *Events.h has), it
57
// will be more and more clear what's going on with a macro that shortens the
58
// definition of the RTTI functions.
59
#define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
60
  const type& As##type() const \
61
0
  { \
62
0
    MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
63
0
    return (const type&) *this; \
64
0
  } \
Unexecuted instantiation: mozilla::InputData::AsMultiTouchInput() const
Unexecuted instantiation: mozilla::InputData::AsMouseInput() const
Unexecuted instantiation: mozilla::InputData::AsPanGestureInput() const
Unexecuted instantiation: mozilla::InputData::AsPinchGestureInput() const
Unexecuted instantiation: mozilla::InputData::AsTapGestureInput() const
Unexecuted instantiation: mozilla::InputData::AsScrollWheelInput() const
Unexecuted instantiation: mozilla::InputData::AsKeyboardInput() const
65
  type& As##type() \
66
0
  { \
67
0
    MOZ_ASSERT(mInputType == enumID, "Invalid cast of InputData."); \
68
0
    return (type&) *this; \
69
0
  }
Unexecuted instantiation: mozilla::InputData::AsMultiTouchInput()
Unexecuted instantiation: mozilla::InputData::AsMouseInput()
Unexecuted instantiation: mozilla::InputData::AsPanGestureInput()
Unexecuted instantiation: mozilla::InputData::AsPinchGestureInput()
Unexecuted instantiation: mozilla::InputData::AsTapGestureInput()
Unexecuted instantiation: mozilla::InputData::AsScrollWheelInput()
Unexecuted instantiation: mozilla::InputData::AsKeyboardInput()
70
71
/** Base input data class. Should never be instantiated. */
72
class InputData
73
{
74
public:
75
  // Warning, this class is serialized and sent over IPC. Any change to its
76
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
77
  InputType mInputType;
78
  // Time in milliseconds that this data is relevant to. This only really
79
  // matters when this data is used as an event. We use uint32_t instead of
80
  // TimeStamp because it is easier to convert from WidgetInputEvent. The time
81
  // is platform-specific but it in the case of B2G and Fennec it is since
82
  // startup.
83
  uint32_t mTime;
84
  // Set in parallel to mTime until we determine it is safe to drop
85
  // platform-specific event times (see bug 77992).
86
  TimeStamp mTimeStamp;
87
  // The sequence number of the last potentially focus changing event handled
88
  // by APZ. This is used to track when that event has been processed by content,
89
  // and focus can be reconfirmed for async keyboard scrolling.
90
  uint64_t mFocusSequenceNumber;
91
92
  Modifiers modifiers;
93
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)
101
102
  virtual ~InputData();
103
  explicit InputData(InputType aInputType);
104
105
protected:
106
  InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
107
            Modifiers aModifiers);
108
};
109
110
/**
111
 * Data container for a single touch input. Similar to dom::Touch, but used in
112
 * off-main-thread situations. This is more for just storing touch data, whereas
113
 * dom::Touch is more useful for dispatching through the DOM (which can only
114
 * happen on the main thread). dom::Touch also bears the problem of storing
115
 * pointers to nsIWidget instances which can only be used on the main thread,
116
 * so if instead we used dom::Touch and ever set these pointers
117
 * off-main-thread, Bad Things Can Happen(tm).
118
 *
119
 * Note that this doesn't inherit from InputData because this itself is not an
120
 * event. It is only a container/struct that should have any number of instances
121
 * within a MultiTouchInput.
122
 *
123
 * fixme/bug 775746: Make dom::Touch inherit from this class.
124
 */
125
class SingleTouchData
126
{
127
public:
128
  // Construct a SingleTouchData from a Screen point.
129
  // mLocalScreenPoint remains (0,0) unless it's set later.
130
  SingleTouchData(int32_t aIdentifier,
131
                  ScreenIntPoint aScreenPoint,
132
                  ScreenSize aRadius,
133
                  float aRotationAngle,
134
                  float aForce);
135
136
  // Construct a SingleTouchData from a ParentLayer point.
137
  // mScreenPoint remains (0,0) unless it's set later.
138
  // Note: if APZ starts using the radius for anything, we should add a local
139
  // version of that too, and have this constructor take it as a ParentLayerSize.
140
  SingleTouchData(int32_t aIdentifier,
141
                  ParentLayerPoint aLocalScreenPoint,
142
                  ScreenSize aRadius,
143
                  float aRotationAngle,
144
                  float aForce);
145
146
  SingleTouchData();
147
148
  already_AddRefed<dom::Touch> ToNewDOMTouch() const;
149
150
  // Warning, this class is serialized and sent over IPC. Any change to its
151
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
152
153
  // A unique number assigned to each SingleTouchData within a MultiTouchInput so
154
  // that they can be easily distinguished when handling a touch start/move/end.
155
  int32_t mIdentifier;
156
157
  // Point on the screen that the touch hit, in device pixels. They are
158
  // coordinates on the screen.
159
  ScreenIntPoint mScreenPoint;
160
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;
164
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;
171
172
  float mRotationAngle;
173
174
  // How hard the screen is being pressed.
175
  float mForce;
176
};
177
178
/**
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.
185
 *
186
 * Stores an array of SingleTouchData.
187
 */
188
class MultiTouchInput : public InputData
189
{
190
public:
191
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
192
    MultiTouchType, (
193
      MULTITOUCH_START,
194
      MULTITOUCH_MOVE,
195
      MULTITOUCH_END,
196
      MULTITOUCH_CANCEL
197
  ));
198
199
  MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
200
                  Modifiers aModifiers);
201
  MultiTouchInput();
202
  MultiTouchInput(const MultiTouchInput& aOther);
203
  explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
204
  // This conversion from WidgetMouseEvent to MultiTouchInput is needed because
205
  // on the B2G emulator we can only receive mouse events, but we need to be
206
  // able to pan correctly. To do this, we convert the events into a format that
207
  // the panning code can handle. This code is very limited and only supports
208
  // SingleTouchData. It also sends garbage for the identifier, radius, force
209
  // and rotation angle.
210
  explicit MultiTouchInput(const WidgetMouseEvent& aMouseEvent);
211
  void Translate(const ScreenPoint& aTranslation);
212
213
  WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
214
  WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
215
216
  // Return the index into mTouches of the SingleTouchData with the given
217
  // identifier, or -1 if there is no such SingleTouchData.
218
  int32_t IndexOfTouch(int32_t aTouchIdentifier);
219
220
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
221
222
  // Warning, this class is serialized and sent over IPC. Any change to its
223
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
224
  MultiTouchType mType;
225
  nsTArray<SingleTouchData> mTouches;
226
  bool mHandledByAPZ;
227
};
228
229
class MouseInput : public InputData
230
{
231
protected:
232
  friend mozilla::layers::APZInputBridgeChild;
233
  friend mozilla::layers::PAPZInputBridgeParent;
234
235
  MouseInput();
236
237
public:
238
239
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
240
    MouseType, (
241
      MOUSE_NONE,
242
      MOUSE_MOVE,
243
      MOUSE_DOWN,
244
      MOUSE_UP,
245
      MOUSE_DRAG_START,
246
      MOUSE_DRAG_END,
247
      MOUSE_WIDGET_ENTER,
248
      MOUSE_WIDGET_EXIT,
249
      MOUSE_HITTEST
250
  ));
251
252
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
253
    ButtonType, (
254
      LEFT_BUTTON,
255
      MIDDLE_BUTTON,
256
      RIGHT_BUTTON,
257
      NONE
258
  ));
259
260
  MouseInput(MouseType aType, ButtonType aButtonType, uint16_t aInputSource,
261
             int16_t aButtons, const ScreenPoint& aPoint, uint32_t aTime,
262
             TimeStamp aTimeStamp, Modifiers aModifiers);
263
  explicit MouseInput(const WidgetMouseEventBase& aMouseEvent);
264
265
  bool IsLeftButton() const;
266
267
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
268
  WidgetMouseEvent ToWidgetMouseEvent(nsIWidget* aWidget) const;
269
270
  // Warning, this class is serialized and sent over IPC. Any change to its
271
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
272
  MouseType mType;
273
  ButtonType mButtonType;
274
  uint16_t mInputSource;
275
  int16_t mButtons;
276
  ScreenPoint mOrigin;
277
  ParentLayerPoint mLocalOrigin;
278
  bool mHandledByAPZ;
279
};
280
281
/**
282
 * Encapsulation class for pan events, can be used off-main-thread.
283
 * These events are currently only used for scrolling on desktop.
284
 */
285
class PanGestureInput : public InputData
286
{
287
protected:
288
  friend mozilla::layers::APZInputBridgeChild;
289
  friend mozilla::layers::PAPZInputBridgeParent;
290
291
  PanGestureInput();
292
293
public:
294
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
295
    PanGestureType, (
296
      // MayStart: Dispatched before any actual panning has occurred but when a
297
      // pan gesture is probably about to start, for example when the user
298
      // starts touching the touchpad. Should interrupt any ongoing APZ
299
      // animation and can be used to trigger scrollability indicators (e.g.
300
      // flashing overlay scrollbars).
301
      PANGESTURE_MAYSTART,
302
303
      // Cancelled: Dispatched after MayStart when no pan gesture is going to
304
      // happen after all, for example when the user lifts their fingers from a
305
      // touchpad without having done any scrolling.
306
      PANGESTURE_CANCELLED,
307
308
      // Start: A pan gesture is starting.
309
      // For devices that do not support the MayStart event type, this event can
310
      // be used to interrupt ongoing APZ animations.
311
      PANGESTURE_START,
312
313
      // Pan: The actual pan motion by mPanDisplacement.
314
      PANGESTURE_PAN,
315
316
      // End: The pan gesture has ended, for example because the user has lifted
317
      // their fingers from a touchpad after scrolling.
318
      // Any potential momentum events fire after this event.
319
      PANGESTURE_END,
320
321
      // The following momentum event types are used in order to control the pan
322
      // momentum animation. Using these instead of our own animation ensures
323
      // that the animation curve is OS native and that the animation stops
324
      // reliably if it is cancelled by the user.
325
326
      // MomentumStart: Dispatched between the End event of the actual
327
      // user-controlled pan, and the first MomentumPan event of the momentum
328
      // animation.
329
      PANGESTURE_MOMENTUMSTART,
330
331
      // MomentumPan: The actual momentum motion by mPanDisplacement.
332
      PANGESTURE_MOMENTUMPAN,
333
334
      // MomentumEnd: The momentum animation has ended, for example because the
335
      // momentum velocity has gone below the stopping threshold, or because the
336
      // user has stopped the animation by putting their fingers on a touchpad.
337
      PANGESTURE_MOMENTUMEND
338
  ));
339
340
  PanGestureInput(PanGestureType aType,
341
                  uint32_t aTime,
342
                  TimeStamp aTimeStamp,
343
                  const ScreenPoint& aPanStartPoint,
344
                  const ScreenPoint& aPanDisplacement,
345
                  Modifiers aModifiers);
346
347
  bool IsMomentum() const;
348
349
  WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
350
351
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
352
353
  ScreenPoint UserMultipliedPanDisplacement() const;
354
  ParentLayerPoint UserMultipliedLocalPanDisplacement() const;
355
356
  // Warning, this class is serialized and sent over IPC. Any change to its
357
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
358
  PanGestureType mType;
359
  ScreenPoint mPanStartPoint;
360
361
  // The delta. This can be non-zero on any type of event.
362
  ScreenPoint mPanDisplacement;
363
364
  // Versions of |mPanStartPoint| and |mPanDisplacement| in the local
365
  // coordinates of the APZC receiving the pan. These are set and used by APZ.
366
  ParentLayerPoint mLocalPanStartPoint;
367
  ParentLayerPoint mLocalPanDisplacement;
368
369
  // See lineOrPageDeltaX/Y on WidgetWheelEvent.
370
  int32_t mLineOrPageDeltaX;
371
  int32_t mLineOrPageDeltaY;
372
373
  // User-set delta multipliers.
374
  double mUserDeltaMultiplierX;
375
  double mUserDeltaMultiplierY;
376
377
  bool mHandledByAPZ;
378
379
  // true if this is a PANGESTURE_END event that will be followed by a
380
  // PANGESTURE_MOMENTUMSTART event.
381
  bool mFollowedByMomentum;
382
383
  // If this is true, and this event started a new input block that couldn't
384
  // find a scrollable target which is scrollable in the horizontal component
385
  // of the scroll start direction, then this input block needs to be put on
386
  // hold until a content response has arrived, even if the block has a
387
  // confirmed target.
388
  // This is used by events that can result in a swipe instead of a scroll.
389
  bool mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection;
390
391
  // This is used by APZ to communicate to the macOS widget code whether
392
  // the overscroll-behavior of the scroll frame handling this swipe allows
393
  // non-local overscroll behaviors in the horizontal direction (such as
394
  // swipe navigation).
395
  bool mOverscrollBehaviorAllowsSwipe;
396
397
  // XXX: If adding any more bools, switch to using bitfields instead.
398
};
399
400
/**
401
 * Encapsulation class for pinch events. In general, these will be generated by
402
 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
403
 * determining whether or not the user was trying to do a gesture.
404
 */
405
class PinchGestureInput : public InputData
406
{
407
protected:
408
  friend mozilla::layers::APZInputBridgeChild;
409
  friend mozilla::layers::PAPZInputBridgeParent;
410
411
  PinchGestureInput();
412
413
public:
414
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
415
    PinchGestureType, (
416
      PINCHGESTURE_START,
417
      PINCHGESTURE_SCALE,
418
      PINCHGESTURE_END
419
  ));
420
421
  // Construct a pinch gesture from a Screen point.
422
  // (Technically, we should take the span values in Screen pixels as well,
423
  // but that would require also storing them in Screen pixels and then
424
  // converting them in TransformToLocal() like the focus point. Since pinch
425
  // gesture events are processed by the root content APZC, the only transform
426
  // between Screen and ParentLayer pixels should be a translation, which is
427
  // irrelevant to span values, so we don't bother.)
428
  PinchGestureInput(PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
429
                    const ScreenPoint& aFocusPoint,
430
                    ParentLayerCoord aCurrentSpan,
431
                    ParentLayerCoord aPreviousSpan, Modifiers aModifiers);
432
433
  // Construct a pinch gesture from a ParentLayer point.
434
  // mFocusPoint remains (0,0) unless it's set later.
435
  PinchGestureInput(PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
436
                    const ParentLayerPoint& aLocalFocusPoint,
437
                    ParentLayerCoord aCurrentSpan,
438
                    ParentLayerCoord aPreviousSpan, Modifiers aModifiers);
439
440
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
441
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
  PinchGestureType mType;
445
446
  // Center point of the pinch gesture. That is, if there are two fingers on the
447
  // screen, it is their midpoint. In the case of more than two fingers, the
448
  // point is implementation-specific, but can for example be the midpoint
449
  // between the very first and very last touch. This is in device pixels and
450
  // are the coordinates on the screen of this midpoint.
451
  // For PINCHGESTURE_END events, this instead will hold the coordinates of
452
  // the remaining finger, if there is one. If there isn't one then it will
453
  // store |BothFingersLifted()|.
454
  ScreenPoint mFocusPoint;
455
456
  // |mFocusPoint| transformed to the local coordinates of the APZC targeted
457
  // by the hit. This is set and used by APZ.
458
  ParentLayerPoint mLocalFocusPoint;
459
460
  // The distance between the touches responsible for the pinch gesture.
461
  ParentLayerCoord mCurrentSpan;
462
463
  // The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
464
  // This is only really relevant during a PINCHGESTURE_SCALE because when it is
465
  // of this type then there must have been a history of spans.
466
  ParentLayerCoord mPreviousSpan;
467
468
  // A special value for mFocusPoint used in PINCHGESTURE_END events to
469
  // indicate that both fingers have been lifted. If only one finger has
470
  // been lifted, the coordinates of the remaining finger are expected to
471
  // be stored in mFocusPoint.
472
  // For pinch events that were not triggered by touch gestures, the
473
  // value of mFocusPoint in a PINCHGESTURE_END event is always expected
474
  // to be this value.
475
  // For convenience, we allow retrieving this value in any coordinate system.
476
  // Since it's a special value, no conversion is needed.
477
  template <typename Units = ParentLayerPixel>
478
0
  static gfx::PointTyped<Units> BothFingersLifted() {
479
0
    return gfx::PointTyped<Units>{-1, -1};
480
0
  }
Unexecuted instantiation: mozilla::gfx::PointTyped<mozilla::ScreenPixel, float> mozilla::PinchGestureInput::BothFingersLifted<mozilla::ScreenPixel>()
Unexecuted instantiation: mozilla::gfx::PointTyped<mozilla::ParentLayerPixel, float> mozilla::PinchGestureInput::BothFingersLifted<mozilla::ParentLayerPixel>()
481
};
482
483
/**
484
 * Encapsulation class for tap events. In general, these will be generated by
485
 * a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
486
 * determining whether or not the user was trying to do a gesture.
487
 */
488
class TapGestureInput : public InputData
489
{
490
protected:
491
  friend mozilla::layers::APZInputBridgeChild;
492
  friend mozilla::layers::PAPZInputBridgeParent;
493
494
  TapGestureInput();
495
496
public:
497
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
498
    TapGestureType, (
499
      TAPGESTURE_LONG,
500
      TAPGESTURE_LONG_UP,
501
      TAPGESTURE_UP,
502
      TAPGESTURE_CONFIRMED,
503
      TAPGESTURE_DOUBLE,
504
      TAPGESTURE_SECOND, // See GeckoContentController::TapType::eSecondTap
505
      TAPGESTURE_CANCEL
506
  ));
507
508
  // Construct a tap gesture from a Screen point.
509
  // mLocalPoint remains (0,0) unless it's set later.
510
  TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
511
                  const ScreenIntPoint& aPoint, Modifiers aModifiers);
512
513
  // Construct a tap gesture from a ParentLayer point.
514
  // mPoint remains (0,0) unless it's set later.
515
  TapGestureInput(TapGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
516
                  const ParentLayerPoint& aLocalPoint, Modifiers aModifiers);
517
518
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
519
520
  // Warning, this class is serialized and sent over IPC. Any change to its
521
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
522
  TapGestureType mType;
523
524
  // The location of the tap in screen pixels.
525
  ScreenIntPoint mPoint;
526
527
  // The location of the tap in the local coordinates of the APZC receiving it.
528
  // This is set and used by APZ.
529
  ParentLayerPoint mLocalPoint;
530
};
531
532
// Encapsulation class for scroll-wheel events. These are generated by mice
533
// with physical scroll wheels, and on Windows by most touchpads when using
534
// scroll gestures.
535
class ScrollWheelInput : public InputData
536
{
537
protected:
538
  friend mozilla::layers::APZInputBridgeChild;
539
  friend mozilla::layers::PAPZInputBridgeParent;
540
541
  typedef mozilla::layers::APZWheelAction APZWheelAction;
542
543
  ScrollWheelInput();
544
545
public:
546
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
547
    ScrollDeltaType, (
548
      // There are three kinds of scroll delta modes in Gecko: "page", "line" and
549
      // "pixel".
550
      SCROLLDELTA_LINE,
551
      SCROLLDELTA_PAGE,
552
      SCROLLDELTA_PIXEL
553
  ));
554
555
  MOZ_DEFINE_ENUM_AT_CLASS_SCOPE(
556
    ScrollMode, (
557
      SCROLLMODE_INSTANT,
558
      SCROLLMODE_SMOOTH
559
    )
560
  );
561
562
  ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp, Modifiers aModifiers,
563
                   ScrollMode aScrollMode, ScrollDeltaType aDeltaType,
564
                   const ScreenPoint& aOrigin, double aDeltaX, double aDeltaY,
565
                   bool aAllowToOverrideSystemScrollSpeed,
566
                   WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy);
567
  explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
568
569
  static ScrollDeltaType DeltaTypeForDeltaMode(uint32_t aDeltaMode);
570
  static uint32_t DeltaModeForDeltaType(ScrollDeltaType aDeltaType);
571
  static nsIScrollableFrame::ScrollUnit ScrollUnitForDeltaType(ScrollDeltaType aDeltaType);
572
573
  WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
574
  bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
575
576
  bool IsCustomizedByUserPrefs() const;
577
578
  // The following two functions are for auto-dir scrolling. For detailed
579
  // information on auto-dir, @see mozilla::WheelDeltaAdjustmentStrategy
580
  bool IsAutoDir() const
581
0
  {
582
0
    switch (mWheelDeltaAdjustmentStrategy) {
583
0
      case WheelDeltaAdjustmentStrategy::eAutoDir:
584
0
      case WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour:
585
0
        return true;
586
0
      default:
587
0
        // Prevent compilation errors generated by -Werror=switch
588
0
        break;
589
0
    }
590
0
    return false;
591
0
  }
592
  // Indicates which element this scroll honours if it's an auto-dir scroll.
593
  // If true, honour the root element; otherwise, honour the currently scrolling
594
  // target.
595
  // Note that if IsAutoDir() returns false, then this function also returns
596
  // false, but false in this case is meaningless as IsAutoDir() indicates it's
597
  // not an auto-dir scroll.
598
  // For detailed information on auto-dir,
599
  // @see mozilla::WheelDeltaAdjustmentStrategy
600
  bool HonoursRoot() const
601
0
  {
602
0
    return WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour ==
603
0
             mWheelDeltaAdjustmentStrategy;
604
0
  }
605
606
  // Warning, this class is serialized and sent over IPC. Any change to its
607
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
608
  ScrollDeltaType mDeltaType;
609
  ScrollMode mScrollMode;
610
  ScreenPoint mOrigin;
611
612
  bool mHandledByAPZ;
613
614
  // Deltas are in units corresponding to the delta type. For line deltas, they
615
  // are the number of line units to scroll. The number of device pixels for a
616
  // horizontal and vertical line unit are in FrameMetrics::mLineScrollAmount.
617
  // For pixel deltas, these values are in ScreenCoords.
618
  //
619
  // The horizontal (X) delta is > 0 for scrolling right and < 0 for scrolling
620
  // left. The vertical (Y) delta is < 0 for scrolling up and > 0 for
621
  // scrolling down.
622
  double mDeltaX;
623
  double mDeltaY;
624
625
  // The location of the scroll in local coordinates. This is set and used by
626
  // APZ.
627
  ParentLayerPoint mLocalOrigin;
628
629
  // See lineOrPageDeltaX/Y on WidgetWheelEvent.
630
  int32_t mLineOrPageDeltaX;
631
  int32_t mLineOrPageDeltaY;
632
633
  // Indicates the order in which this event was added to a transaction. The
634
  // first event is 1; if not a member of a transaction, this is 0.
635
  uint32_t mScrollSeriesNumber;
636
637
  // User-set delta multipliers.
638
  double mUserDeltaMultiplierX;
639
  double mUserDeltaMultiplierY;
640
641
  bool mMayHaveMomentum;
642
  bool mIsMomentum;
643
  bool mAllowToOverrideSystemScrollSpeed;
644
645
  // Sometimes a wheel event input's wheel delta should be adjusted. This member
646
  // specifies how to adjust the wheel delta.
647
  WheelDeltaAdjustmentStrategy mWheelDeltaAdjustmentStrategy;
648
649
  APZWheelAction mAPZAction;
650
};
651
652
class KeyboardInput : public InputData
653
{
654
public:
655
  typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
656
657
  // Note that if you change the first member in this enum(I.e. KEY_DOWN) to one
658
  // other member, don't forget to update the minimum value in
659
  // ContiguousEnumSerializer for KeyboardEventType in widget/nsGUIEventIPC
660
  // accordingly.
661
  enum KeyboardEventType
662
  {
663
    KEY_DOWN,
664
    KEY_PRESS,
665
    KEY_UP,
666
    // Any other key event such as eKeyDownOnPlugin
667
    KEY_OTHER,
668
669
    // Used as an upper bound for ContiguousEnumSerializer
670
    KEY_SENTINEL,
671
  };
672
673
  explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
674
675
  // Warning, this class is serialized and sent over IPC. Any change to its
676
  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
677
678
  KeyboardEventType mType;
679
  uint32_t mKeyCode;
680
  uint32_t mCharCode;
681
  nsTArray<ShortcutKeyCandidate> mShortcutCandidates;
682
683
  bool mHandledByAPZ;
684
685
  // The scroll action to perform on a layer for this keyboard input. This is
686
  // only used in APZ and is NOT serialized over IPC.
687
  KeyboardScrollAction mAction;
688
689
protected:
690
  friend mozilla::layers::APZInputBridgeChild;
691
  friend mozilla::layers::PAPZInputBridgeParent;
692
693
  KeyboardInput();
694
};
695
696
} // namespace mozilla
697
698
#endif // InputData_h__