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/. */
8 #include "mozilla/dom/MouseEventBinding.h"
9 #include "mozilla/dom/Touch.h"
10 #include "mozilla/dom/WheelEventBinding.h"
11 #include "mozilla/TextEvents.h"
12 #include "nsContentUtils.h"
14 #include "nsThreadUtils.h"
15 #include "mozilla/MouseEvents.h"
16 #include "mozilla/TouchEvents.h"
17 #include "UnitTransforms.h"
23 InputData::~InputData() {}
25 InputData::InputData(InputType aInputType
)
26 : mInputType(aInputType
), mTime(0), mFocusSequenceNumber(0), modifiers(0) {}
28 InputData::InputData(InputType aInputType
, uint32_t aTime
, TimeStamp aTimeStamp
,
30 : mInputType(aInputType
),
32 mTimeStamp(aTimeStamp
),
33 mFocusSequenceNumber(0),
34 modifiers(aModifiers
) {}
36 SingleTouchData::SingleTouchData(int32_t aIdentifier
,
37 ScreenIntPoint aScreenPoint
,
38 ScreenSize aRadius
, float aRotationAngle
,
40 : mIdentifier(aIdentifier
),
41 mScreenPoint(aScreenPoint
),
43 mRotationAngle(aRotationAngle
),
46 SingleTouchData::SingleTouchData(int32_t aIdentifier
,
47 ParentLayerPoint aLocalScreenPoint
,
48 ScreenSize aRadius
, float aRotationAngle
,
50 : mIdentifier(aIdentifier
),
51 mLocalScreenPoint(aLocalScreenPoint
),
53 mRotationAngle(aRotationAngle
),
56 SingleTouchData::SingleTouchData()
57 : mIdentifier(0), mRotationAngle(0.0), mForce(0.0) {}
59 already_AddRefed
<Touch
> SingleTouchData::ToNewDOMTouch() const {
60 MOZ_ASSERT(NS_IsMainThread(),
61 "Can only create dom::Touch instances on main thread");
63 new Touch(mIdentifier
,
64 LayoutDeviceIntPoint::Truncate(mScreenPoint
.x
, mScreenPoint
.y
),
65 LayoutDeviceIntPoint::Truncate(mRadius
.width
, mRadius
.height
),
66 mRotationAngle
, mForce
);
67 return touch
.forget();
70 MultiTouchInput::MultiTouchInput(MultiTouchType aType
, uint32_t aTime
,
71 TimeStamp aTimeStamp
, Modifiers aModifiers
)
72 : InputData(MULTITOUCH_INPUT
, aTime
, aTimeStamp
, aModifiers
),
74 mHandledByAPZ(false) {}
76 MultiTouchInput::MultiTouchInput()
77 : InputData(MULTITOUCH_INPUT
),
78 mType(MULTITOUCH_START
),
79 mHandledByAPZ(false) {}
81 MultiTouchInput::MultiTouchInput(const MultiTouchInput
& aOther
)
82 : InputData(MULTITOUCH_INPUT
, aOther
.mTime
, aOther
.mTimeStamp
,
85 mHandledByAPZ(aOther
.mHandledByAPZ
) {
86 mTouches
.AppendElements(aOther
.mTouches
);
89 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent
& aTouchEvent
)
90 : InputData(MULTITOUCH_INPUT
, aTouchEvent
.mTime
, aTouchEvent
.mTimeStamp
,
91 aTouchEvent
.mModifiers
),
92 mHandledByAPZ(aTouchEvent
.mFlags
.mHandledByAPZ
) {
93 MOZ_ASSERT(NS_IsMainThread(),
94 "Can only copy from WidgetTouchEvent on main thread");
96 switch (aTouchEvent
.mMessage
) {
98 mType
= MULTITOUCH_START
;
101 mType
= MULTITOUCH_MOVE
;
104 mType
= MULTITOUCH_END
;
107 mType
= MULTITOUCH_CANCEL
;
110 MOZ_ASSERT_UNREACHABLE("Did not assign a type to a MultiTouchInput");
114 for (size_t i
= 0; i
< aTouchEvent
.mTouches
.Length(); i
++) {
115 const Touch
* domTouch
= aTouchEvent
.mTouches
[i
];
117 // Extract data from weird interfaces.
118 int32_t identifier
= domTouch
->Identifier();
119 int32_t radiusX
= domTouch
->RadiusX(CallerType::System
);
120 int32_t radiusY
= domTouch
->RadiusY(CallerType::System
);
121 float rotationAngle
= domTouch
->RotationAngle(CallerType::System
);
122 float force
= domTouch
->Force(CallerType::System
);
124 SingleTouchData
data(
128 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
),
129 ScreenSize(radiusX
, radiusY
), rotationAngle
, force
);
131 mTouches
.AppendElement(data
);
135 MultiTouchInput::MultiTouchInput(const WidgetMouseEvent
& aMouseEvent
)
136 : InputData(MULTITOUCH_INPUT
, aMouseEvent
.mTime
, aMouseEvent
.mTimeStamp
,
137 aMouseEvent
.mModifiers
),
138 mHandledByAPZ(aMouseEvent
.mFlags
.mHandledByAPZ
) {
139 MOZ_ASSERT(NS_IsMainThread(),
140 "Can only copy from WidgetMouseEvent on main thread");
141 switch (aMouseEvent
.mMessage
) {
143 mType
= MULTITOUCH_START
;
146 mType
= MULTITOUCH_MOVE
;
149 mType
= MULTITOUCH_END
;
151 // The mouse pointer has been interrupted in an implementation-specific
152 // manner, such as a synchronous event or action cancelling the touch, or a
153 // touch point leaving the document window and going into a non-document
154 // area capable of handling user interactions.
155 case eMouseExitFromWidget
:
156 mType
= MULTITOUCH_CANCEL
;
159 NS_WARNING("Did not assign a type to a MultiTouchInput");
163 mTouches
.AppendElement(SingleTouchData(
166 aMouseEvent
.mRefPoint
,
167 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
),
168 ScreenSize(1, 1), 180.0f
, 1.0f
));
171 void MultiTouchInput::Translate(const ScreenPoint
& aTranslation
) {
172 const int32_t xTranslation
= (int32_t)(aTranslation
.x
+ 0.5f
);
173 const int32_t yTranslation
= (int32_t)(aTranslation
.y
+ 0.5f
);
175 for (auto iter
= mTouches
.begin(); iter
!= mTouches
.end(); iter
++) {
176 iter
->mScreenPoint
.MoveBy(xTranslation
, yTranslation
);
180 WidgetTouchEvent
MultiTouchInput::ToWidgetTouchEvent(nsIWidget
* aWidget
) const {
181 MOZ_ASSERT(NS_IsMainThread(),
182 "Can only convert To WidgetTouchEvent on main thread");
184 EventMessage touchEventMessage
= eVoidEvent
;
186 case MULTITOUCH_START
:
187 touchEventMessage
= eTouchStart
;
189 case MULTITOUCH_MOVE
:
190 touchEventMessage
= eTouchMove
;
193 touchEventMessage
= eTouchEnd
;
195 case MULTITOUCH_CANCEL
:
196 touchEventMessage
= eTouchCancel
;
199 MOZ_ASSERT_UNREACHABLE(
200 "Did not assign a type to WidgetTouchEvent in MultiTouchInput");
204 WidgetTouchEvent
event(true, touchEventMessage
, aWidget
);
205 if (touchEventMessage
== eVoidEvent
) {
209 event
.mModifiers
= this->modifiers
;
210 event
.mTime
= this->mTime
;
211 event
.mTimeStamp
= this->mTimeStamp
;
212 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
213 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
215 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
216 *event
.mTouches
.AppendElement() = mTouches
[i
].ToNewDOMTouch();
222 WidgetMouseEvent
MultiTouchInput::ToWidgetMouseEvent(nsIWidget
* aWidget
) const {
223 MOZ_ASSERT(NS_IsMainThread(),
224 "Can only convert To WidgetMouseEvent on main thread");
226 EventMessage mouseEventMessage
= eVoidEvent
;
228 case MultiTouchInput::MULTITOUCH_START
:
229 mouseEventMessage
= eMouseDown
;
231 case MultiTouchInput::MULTITOUCH_MOVE
:
232 mouseEventMessage
= eMouseMove
;
234 case MultiTouchInput::MULTITOUCH_CANCEL
:
235 case MultiTouchInput::MULTITOUCH_END
:
236 mouseEventMessage
= eMouseUp
;
239 MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
243 WidgetMouseEvent
event(true, mouseEventMessage
, aWidget
,
244 WidgetMouseEvent::eReal
, WidgetMouseEvent::eNormal
);
246 const SingleTouchData
& firstTouch
= mTouches
[0];
247 event
.mRefPoint
.x
= firstTouch
.mScreenPoint
.x
;
248 event
.mRefPoint
.y
= firstTouch
.mScreenPoint
.y
;
251 event
.button
= WidgetMouseEvent::eLeftButton
;
252 event
.inputSource
= MouseEvent_Binding::MOZ_SOURCE_TOUCH
;
253 event
.mModifiers
= modifiers
;
254 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
255 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
257 if (mouseEventMessage
!= eMouseMove
) {
258 event
.mClickCount
= 1;
264 int32_t MultiTouchInput::IndexOfTouch(int32_t aTouchIdentifier
) {
265 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
266 if (mTouches
[i
].mIdentifier
== aTouchIdentifier
) {
273 bool MultiTouchInput::TransformToLocal(
274 const ScreenToParentLayerMatrix4x4
& aTransform
) {
275 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
276 Maybe
<ParentLayerIntPoint
> point
=
277 UntransformBy(aTransform
, mTouches
[i
].mScreenPoint
);
281 mTouches
[i
].mLocalScreenPoint
= *point
;
286 MouseInput::MouseInput()
287 : InputData(MOUSE_INPUT
),
292 mHandledByAPZ(false) {}
294 MouseInput::MouseInput(MouseType aType
, ButtonType aButtonType
,
295 uint16_t aInputSource
, int16_t aButtons
,
296 const ScreenPoint
& aPoint
, uint32_t aTime
,
297 TimeStamp aTimeStamp
, Modifiers aModifiers
)
298 : InputData(MOUSE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
300 mButtonType(aButtonType
),
301 mInputSource(aInputSource
),
304 mHandledByAPZ(false) {}
306 MouseInput::MouseInput(const WidgetMouseEventBase
& aMouseEvent
)
307 : InputData(MOUSE_INPUT
, aMouseEvent
.mTime
, aMouseEvent
.mTimeStamp
,
308 aMouseEvent
.mModifiers
),
311 mInputSource(aMouseEvent
.inputSource
),
312 mButtons(aMouseEvent
.buttons
),
313 mHandledByAPZ(aMouseEvent
.mFlags
.mHandledByAPZ
) {
314 MOZ_ASSERT(NS_IsMainThread(),
315 "Can only copy from WidgetTouchEvent on main thread");
319 switch (aMouseEvent
.button
) {
320 case WidgetMouseEventBase::eLeftButton
:
321 mButtonType
= MouseInput::LEFT_BUTTON
;
323 case WidgetMouseEventBase::eMiddleButton
:
324 mButtonType
= MouseInput::MIDDLE_BUTTON
;
326 case WidgetMouseEventBase::eRightButton
:
327 mButtonType
= MouseInput::RIGHT_BUTTON
;
331 switch (aMouseEvent
.mMessage
) {
342 mType
= MOUSE_DRAG_START
;
345 mType
= MOUSE_DRAG_END
;
347 case eMouseEnterIntoWidget
:
348 mType
= MOUSE_WIDGET_ENTER
;
350 case eMouseExitFromWidget
:
351 mType
= MOUSE_WIDGET_EXIT
;
354 mType
= MOUSE_HITTEST
;
357 MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
361 mOrigin
= ScreenPoint(ViewAs
<ScreenPixel
>(
362 aMouseEvent
.mRefPoint
,
363 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
366 bool MouseInput::IsLeftButton() const { return mButtonType
== LEFT_BUTTON
; }
368 bool MouseInput::TransformToLocal(
369 const ScreenToParentLayerMatrix4x4
& aTransform
) {
370 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mOrigin
);
374 mLocalOrigin
= *point
;
379 WidgetMouseEvent
MouseInput::ToWidgetMouseEvent(nsIWidget
* aWidget
) const {
380 MOZ_ASSERT(NS_IsMainThread(),
381 "Can only convert To WidgetTouchEvent on main thread");
383 EventMessage msg
= eVoidEvent
;
384 uint32_t clickCount
= 0;
397 case MOUSE_DRAG_START
:
403 case MOUSE_WIDGET_ENTER
:
404 msg
= eMouseEnterIntoWidget
;
406 case MOUSE_WIDGET_EXIT
:
407 msg
= eMouseExitFromWidget
;
413 MOZ_ASSERT_UNREACHABLE(
414 "Did not assign a type to WidgetMouseEvent in MouseInput");
418 WidgetMouseEvent
event(true, msg
, aWidget
, WidgetMouseEvent::eReal
,
419 WidgetMouseEvent::eNormal
);
421 if (msg
== eVoidEvent
) {
425 switch (mButtonType
) {
426 case MouseInput::LEFT_BUTTON
:
427 event
.button
= WidgetMouseEventBase::eLeftButton
;
429 case MouseInput::MIDDLE_BUTTON
:
430 event
.button
= WidgetMouseEventBase::eMiddleButton
;
432 case MouseInput::RIGHT_BUTTON
:
433 event
.button
= WidgetMouseEventBase::eRightButton
;
435 case MouseInput::NONE
:
440 event
.buttons
= mButtons
;
441 event
.mModifiers
= modifiers
;
443 event
.mTimeStamp
= mTimeStamp
;
444 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
445 event
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
447 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
448 event
.mClickCount
= clickCount
;
449 event
.inputSource
= mInputSource
;
450 event
.mIgnoreRootScrollFrame
= true;
451 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
456 PanGestureInput::PanGestureInput()
457 : InputData(PANGESTURE_INPUT
),
458 mType(PANGESTURE_MAYSTART
),
459 mLineOrPageDeltaX(0),
460 mLineOrPageDeltaY(0),
461 mUserDeltaMultiplierX(1.0),
462 mUserDeltaMultiplierY(1.0),
463 mHandledByAPZ(false),
464 mFollowedByMomentum(false),
465 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false),
466 mOverscrollBehaviorAllowsSwipe(false) {}
468 PanGestureInput::PanGestureInput(PanGestureType aType
, uint32_t aTime
,
469 TimeStamp aTimeStamp
,
470 const ScreenPoint
& aPanStartPoint
,
471 const ScreenPoint
& aPanDisplacement
,
472 Modifiers aModifiers
)
473 : InputData(PANGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
475 mPanStartPoint(aPanStartPoint
),
476 mPanDisplacement(aPanDisplacement
),
477 mLineOrPageDeltaX(0),
478 mLineOrPageDeltaY(0),
479 mUserDeltaMultiplierX(1.0),
480 mUserDeltaMultiplierY(1.0),
481 mHandledByAPZ(false),
482 mFollowedByMomentum(false),
483 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false),
484 mOverscrollBehaviorAllowsSwipe(false) {}
486 bool PanGestureInput::IsMomentum() const {
488 case PanGestureInput::PANGESTURE_MOMENTUMSTART
:
489 case PanGestureInput::PANGESTURE_MOMENTUMPAN
:
490 case PanGestureInput::PANGESTURE_MOMENTUMEND
:
497 WidgetWheelEvent
PanGestureInput::ToWidgetWheelEvent(nsIWidget
* aWidget
) const {
498 WidgetWheelEvent
wheelEvent(true, eWheel
, aWidget
);
499 wheelEvent
.mModifiers
= this->modifiers
;
500 wheelEvent
.mTime
= mTime
;
501 wheelEvent
.mTimeStamp
= mTimeStamp
;
502 wheelEvent
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
504 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
505 wheelEvent
.buttons
= 0;
506 wheelEvent
.mDeltaMode
= WheelEvent_Binding::DOM_DELTA_PIXEL
;
507 wheelEvent
.mMayHaveMomentum
= true; // pan inputs may have momentum
508 wheelEvent
.mIsMomentum
= IsMomentum();
509 wheelEvent
.mLineOrPageDeltaX
= mLineOrPageDeltaX
;
510 wheelEvent
.mLineOrPageDeltaY
= mLineOrPageDeltaY
;
511 wheelEvent
.mDeltaX
= mPanDisplacement
.x
;
512 wheelEvent
.mDeltaY
= mPanDisplacement
.y
;
513 wheelEvent
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
514 wheelEvent
.mFocusSequenceNumber
= mFocusSequenceNumber
;
518 bool PanGestureInput::TransformToLocal(
519 const ScreenToParentLayerMatrix4x4
& aTransform
) {
520 Maybe
<ParentLayerPoint
> panStartPoint
=
521 UntransformBy(aTransform
, mPanStartPoint
);
522 if (!panStartPoint
) {
525 mLocalPanStartPoint
= *panStartPoint
;
527 Maybe
<ParentLayerPoint
> panDisplacement
=
528 UntransformVector(aTransform
, mPanDisplacement
, mPanStartPoint
);
529 if (!panDisplacement
) {
532 mLocalPanDisplacement
= *panDisplacement
;
536 ScreenPoint
PanGestureInput::UserMultipliedPanDisplacement() const {
537 return ScreenPoint(mPanDisplacement
.x
* mUserDeltaMultiplierX
,
538 mPanDisplacement
.y
* mUserDeltaMultiplierY
);
541 ParentLayerPoint
PanGestureInput::UserMultipliedLocalPanDisplacement() const {
542 return ParentLayerPoint(mLocalPanDisplacement
.x
* mUserDeltaMultiplierX
,
543 mLocalPanDisplacement
.y
* mUserDeltaMultiplierY
);
546 PinchGestureInput::PinchGestureInput()
547 : InputData(PINCHGESTURE_INPUT
), mType(PINCHGESTURE_START
) {}
549 PinchGestureInput::PinchGestureInput(PinchGestureType aType
, uint32_t aTime
,
550 TimeStamp aTimeStamp
,
551 const ScreenPoint
& aFocusPoint
,
552 ParentLayerCoord aCurrentSpan
,
553 ParentLayerCoord aPreviousSpan
,
554 Modifiers aModifiers
)
555 : InputData(PINCHGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
557 mFocusPoint(aFocusPoint
),
558 mCurrentSpan(aCurrentSpan
),
559 mPreviousSpan(aPreviousSpan
) {}
561 PinchGestureInput::PinchGestureInput(PinchGestureType aType
, uint32_t aTime
,
562 TimeStamp aTimeStamp
,
563 const ParentLayerPoint
& aLocalFocusPoint
,
564 ParentLayerCoord aCurrentSpan
,
565 ParentLayerCoord aPreviousSpan
,
566 Modifiers aModifiers
)
567 : InputData(PINCHGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
569 mLocalFocusPoint(aLocalFocusPoint
),
570 mCurrentSpan(aCurrentSpan
),
571 mPreviousSpan(aPreviousSpan
) {}
573 bool PinchGestureInput::TransformToLocal(
574 const ScreenToParentLayerMatrix4x4
& aTransform
) {
575 if (mFocusPoint
== BothFingersLifted
<ScreenPixel
>()) {
576 // Special value, no transform required.
577 mLocalFocusPoint
= BothFingersLifted();
580 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mFocusPoint
);
584 mLocalFocusPoint
= *point
;
588 TapGestureInput::TapGestureInput()
589 : InputData(TAPGESTURE_INPUT
), mType(TAPGESTURE_LONG
) {}
591 TapGestureInput::TapGestureInput(TapGestureType aType
, uint32_t aTime
,
592 TimeStamp aTimeStamp
,
593 const ScreenIntPoint
& aPoint
,
594 Modifiers aModifiers
)
595 : InputData(TAPGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
599 TapGestureInput::TapGestureInput(TapGestureType aType
, uint32_t aTime
,
600 TimeStamp aTimeStamp
,
601 const ParentLayerPoint
& aLocalPoint
,
602 Modifiers aModifiers
)
603 : InputData(TAPGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
605 mLocalPoint(aLocalPoint
) {}
607 bool TapGestureInput::TransformToLocal(
608 const ScreenToParentLayerMatrix4x4
& aTransform
) {
609 Maybe
<ParentLayerIntPoint
> point
= UntransformBy(aTransform
, mPoint
);
613 mLocalPoint
= *point
;
617 ScrollWheelInput::ScrollWheelInput()
618 : InputData(SCROLLWHEEL_INPUT
),
619 mDeltaType(SCROLLDELTA_LINE
),
620 mScrollMode(SCROLLMODE_INSTANT
),
621 mHandledByAPZ(false),
624 mLineOrPageDeltaX(0),
625 mLineOrPageDeltaY(0),
626 mScrollSeriesNumber(0),
627 mUserDeltaMultiplierX(1.0),
628 mUserDeltaMultiplierY(1.0),
629 mMayHaveMomentum(false),
631 mAPZAction(APZWheelAction::Scroll
) {}
633 ScrollWheelInput::ScrollWheelInput(
634 uint32_t aTime
, TimeStamp aTimeStamp
, Modifiers aModifiers
,
635 ScrollMode aScrollMode
, ScrollDeltaType aDeltaType
,
636 const ScreenPoint
& aOrigin
, double aDeltaX
, double aDeltaY
,
637 bool aAllowToOverrideSystemScrollSpeed
,
638 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy
)
639 : InputData(SCROLLWHEEL_INPUT
, aTime
, aTimeStamp
, aModifiers
),
640 mDeltaType(aDeltaType
),
641 mScrollMode(aScrollMode
),
643 mHandledByAPZ(false),
646 mLineOrPageDeltaX(0),
647 mLineOrPageDeltaY(0),
648 mScrollSeriesNumber(0),
649 mUserDeltaMultiplierX(1.0),
650 mUserDeltaMultiplierY(1.0),
651 mMayHaveMomentum(false),
653 mAllowToOverrideSystemScrollSpeed(aAllowToOverrideSystemScrollSpeed
),
654 mWheelDeltaAdjustmentStrategy(aWheelDeltaAdjustmentStrategy
),
655 mAPZAction(APZWheelAction::Scroll
) {}
657 ScrollWheelInput::ScrollWheelInput(const WidgetWheelEvent
& aWheelEvent
)
658 : InputData(SCROLLWHEEL_INPUT
, aWheelEvent
.mTime
, aWheelEvent
.mTimeStamp
,
659 aWheelEvent
.mModifiers
),
660 mDeltaType(DeltaTypeForDeltaMode(aWheelEvent
.mDeltaMode
)),
661 mScrollMode(SCROLLMODE_INSTANT
),
662 mHandledByAPZ(aWheelEvent
.mFlags
.mHandledByAPZ
),
663 mDeltaX(aWheelEvent
.mDeltaX
),
664 mDeltaY(aWheelEvent
.mDeltaY
),
665 mLineOrPageDeltaX(aWheelEvent
.mLineOrPageDeltaX
),
666 mLineOrPageDeltaY(aWheelEvent
.mLineOrPageDeltaY
),
667 mScrollSeriesNumber(0),
668 mUserDeltaMultiplierX(1.0),
669 mUserDeltaMultiplierY(1.0),
670 mMayHaveMomentum(aWheelEvent
.mMayHaveMomentum
),
671 mIsMomentum(aWheelEvent
.mIsMomentum
),
672 mAllowToOverrideSystemScrollSpeed(
673 aWheelEvent
.mAllowToOverrideSystemScrollSpeed
),
674 mWheelDeltaAdjustmentStrategy(WheelDeltaAdjustmentStrategy::eNone
),
675 mAPZAction(APZWheelAction::Scroll
) {
676 mOrigin
= ScreenPoint(ViewAs
<ScreenPixel
>(
677 aWheelEvent
.mRefPoint
,
678 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
681 ScrollWheelInput::ScrollDeltaType
ScrollWheelInput::DeltaTypeForDeltaMode(
682 uint32_t aDeltaMode
) {
683 switch (aDeltaMode
) {
684 case WheelEvent_Binding::DOM_DELTA_LINE
:
685 return SCROLLDELTA_LINE
;
686 case WheelEvent_Binding::DOM_DELTA_PAGE
:
687 return SCROLLDELTA_PAGE
;
688 case WheelEvent_Binding::DOM_DELTA_PIXEL
:
689 return SCROLLDELTA_PIXEL
;
693 return SCROLLDELTA_LINE
;
696 uint32_t ScrollWheelInput::DeltaModeForDeltaType(ScrollDeltaType aDeltaType
) {
697 switch (aDeltaType
) {
698 case ScrollWheelInput::SCROLLDELTA_LINE
:
699 return WheelEvent_Binding::DOM_DELTA_LINE
;
700 case ScrollWheelInput::SCROLLDELTA_PAGE
:
701 return WheelEvent_Binding::DOM_DELTA_PAGE
;
702 case ScrollWheelInput::SCROLLDELTA_PIXEL
:
704 return WheelEvent_Binding::DOM_DELTA_PIXEL
;
708 nsIScrollableFrame::ScrollUnit
ScrollWheelInput::ScrollUnitForDeltaType(
709 ScrollDeltaType aDeltaType
) {
710 switch (aDeltaType
) {
711 case SCROLLDELTA_LINE
:
712 return nsIScrollableFrame::LINES
;
713 case SCROLLDELTA_PAGE
:
714 return nsIScrollableFrame::PAGES
;
715 case SCROLLDELTA_PIXEL
:
716 return nsIScrollableFrame::DEVICE_PIXELS
;
720 return nsIScrollableFrame::LINES
;
723 WidgetWheelEvent
ScrollWheelInput::ToWidgetWheelEvent(
724 nsIWidget
* aWidget
) const {
725 WidgetWheelEvent
wheelEvent(true, eWheel
, aWidget
);
726 wheelEvent
.mModifiers
= this->modifiers
;
727 wheelEvent
.mTime
= mTime
;
728 wheelEvent
.mTimeStamp
= mTimeStamp
;
729 wheelEvent
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
731 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
732 wheelEvent
.buttons
= 0;
733 wheelEvent
.mDeltaMode
= DeltaModeForDeltaType(mDeltaType
);
734 wheelEvent
.mMayHaveMomentum
= mMayHaveMomentum
;
735 wheelEvent
.mIsMomentum
= mIsMomentum
;
736 wheelEvent
.mDeltaX
= mDeltaX
;
737 wheelEvent
.mDeltaY
= mDeltaY
;
738 wheelEvent
.mLineOrPageDeltaX
= mLineOrPageDeltaX
;
739 wheelEvent
.mLineOrPageDeltaY
= mLineOrPageDeltaY
;
740 wheelEvent
.mAllowToOverrideSystemScrollSpeed
=
741 mAllowToOverrideSystemScrollSpeed
;
742 wheelEvent
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
743 wheelEvent
.mFocusSequenceNumber
= mFocusSequenceNumber
;
747 bool ScrollWheelInput::TransformToLocal(
748 const ScreenToParentLayerMatrix4x4
& aTransform
) {
749 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mOrigin
);
753 mLocalOrigin
= *point
;
757 bool ScrollWheelInput::IsCustomizedByUserPrefs() const {
758 return mUserDeltaMultiplierX
!= 1.0 || mUserDeltaMultiplierY
!= 1.0;
761 KeyboardInput::KeyboardInput(const WidgetKeyboardEvent
& aEvent
)
762 : InputData(KEYBOARD_INPUT
, aEvent
.mTime
, aEvent
.mTimeStamp
,
764 mKeyCode(aEvent
.mKeyCode
),
765 mCharCode(aEvent
.mCharCode
),
766 mHandledByAPZ(false) {
767 switch (aEvent
.mMessage
) {
769 mType
= KeyboardInput::KEY_PRESS
;
773 mType
= KeyboardInput::KEY_UP
;
777 mType
= KeyboardInput::KEY_DOWN
;
781 mType
= KeyboardInput::KEY_OTHER
;
785 aEvent
.GetShortcutKeyCandidates(mShortcutCandidates
);
788 KeyboardInput::KeyboardInput()
789 : InputData(KEYBOARD_INPUT
),
793 mHandledByAPZ(false) {}
795 } // namespace mozilla