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
),
28 mFocusSequenceNumber(0),
32 InputData::InputData(InputType aInputType
, uint32_t aTime
, TimeStamp aTimeStamp
,
34 : mInputType(aInputType
),
36 mTimeStamp(aTimeStamp
),
37 mFocusSequenceNumber(0),
39 modifiers(aModifiers
) {}
41 SingleTouchData::SingleTouchData(int32_t aIdentifier
,
42 ScreenIntPoint aScreenPoint
,
43 ScreenSize aRadius
, float aRotationAngle
,
45 : mIdentifier(aIdentifier
),
46 mScreenPoint(aScreenPoint
),
48 mRotationAngle(aRotationAngle
),
51 SingleTouchData::SingleTouchData(int32_t aIdentifier
,
52 ParentLayerPoint aLocalScreenPoint
,
53 ScreenSize aRadius
, float aRotationAngle
,
55 : mIdentifier(aIdentifier
),
56 mLocalScreenPoint(aLocalScreenPoint
),
58 mRotationAngle(aRotationAngle
),
61 SingleTouchData::SingleTouchData()
62 : mIdentifier(0), mRotationAngle(0.0), mForce(0.0) {}
64 already_AddRefed
<Touch
> SingleTouchData::ToNewDOMTouch() const {
65 MOZ_ASSERT(NS_IsMainThread(),
66 "Can only create dom::Touch instances on main thread");
68 new Touch(mIdentifier
,
69 LayoutDeviceIntPoint::Truncate(mScreenPoint
.x
, mScreenPoint
.y
),
70 LayoutDeviceIntPoint::Truncate(mRadius
.width
, mRadius
.height
),
71 mRotationAngle
, mForce
);
72 return touch
.forget();
75 MultiTouchInput::MultiTouchInput(MultiTouchType aType
, uint32_t aTime
,
76 TimeStamp aTimeStamp
, Modifiers aModifiers
)
77 : InputData(MULTITOUCH_INPUT
, aTime
, aTimeStamp
, aModifiers
),
79 mHandledByAPZ(false) {}
81 MultiTouchInput::MultiTouchInput()
82 : InputData(MULTITOUCH_INPUT
),
83 mType(MULTITOUCH_START
),
84 mHandledByAPZ(false) {}
86 MultiTouchInput::MultiTouchInput(const MultiTouchInput
& aOther
)
87 : InputData(MULTITOUCH_INPUT
, aOther
.mTime
, aOther
.mTimeStamp
,
90 mScreenOffset(aOther
.mScreenOffset
),
91 mHandledByAPZ(aOther
.mHandledByAPZ
) {
92 mTouches
.AppendElements(aOther
.mTouches
);
95 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent
& aTouchEvent
)
96 : InputData(MULTITOUCH_INPUT
, aTouchEvent
.mTime
, aTouchEvent
.mTimeStamp
,
97 aTouchEvent
.mModifiers
),
98 mHandledByAPZ(aTouchEvent
.mFlags
.mHandledByAPZ
) {
99 MOZ_ASSERT(NS_IsMainThread(),
100 "Can only copy from WidgetTouchEvent on main thread");
102 switch (aTouchEvent
.mMessage
) {
104 mType
= MULTITOUCH_START
;
107 mType
= MULTITOUCH_MOVE
;
110 mType
= MULTITOUCH_END
;
113 mType
= MULTITOUCH_CANCEL
;
116 MOZ_ASSERT_UNREACHABLE("Did not assign a type to a MultiTouchInput");
120 mScreenOffset
= ViewAs
<ExternalPixel
>(
121 aTouchEvent
.mWidget
->WidgetToScreenOffset(),
122 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
);
124 for (size_t i
= 0; i
< aTouchEvent
.mTouches
.Length(); i
++) {
125 const Touch
* domTouch
= aTouchEvent
.mTouches
[i
];
127 // Extract data from weird interfaces.
128 int32_t identifier
= domTouch
->Identifier();
129 int32_t radiusX
= domTouch
->RadiusX(CallerType::System
);
130 int32_t radiusY
= domTouch
->RadiusY(CallerType::System
);
131 float rotationAngle
= domTouch
->RotationAngle(CallerType::System
);
132 float force
= domTouch
->Force(CallerType::System
);
134 SingleTouchData
data(
138 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
),
139 ScreenSize(radiusX
, radiusY
), rotationAngle
, force
);
141 mTouches
.AppendElement(data
);
145 void MultiTouchInput::Translate(const ScreenPoint
& aTranslation
) {
146 const int32_t xTranslation
= (int32_t)(aTranslation
.x
+ 0.5f
);
147 const int32_t yTranslation
= (int32_t)(aTranslation
.y
+ 0.5f
);
149 for (auto iter
= mTouches
.begin(); iter
!= mTouches
.end(); iter
++) {
150 iter
->mScreenPoint
.MoveBy(xTranslation
, yTranslation
);
154 WidgetTouchEvent
MultiTouchInput::ToWidgetTouchEvent(nsIWidget
* aWidget
) const {
155 MOZ_ASSERT(NS_IsMainThread(),
156 "Can only convert To WidgetTouchEvent on main thread");
158 EventMessage touchEventMessage
= eVoidEvent
;
160 case MULTITOUCH_START
:
161 touchEventMessage
= eTouchStart
;
163 case MULTITOUCH_MOVE
:
164 touchEventMessage
= eTouchMove
;
167 touchEventMessage
= eTouchEnd
;
169 case MULTITOUCH_CANCEL
:
170 touchEventMessage
= eTouchCancel
;
173 MOZ_ASSERT_UNREACHABLE(
174 "Did not assign a type to WidgetTouchEvent in MultiTouchInput");
178 WidgetTouchEvent
event(true, touchEventMessage
, aWidget
);
179 if (touchEventMessage
== eVoidEvent
) {
183 event
.mModifiers
= this->modifiers
;
184 event
.mTime
= this->mTime
;
185 event
.mTimeStamp
= this->mTimeStamp
;
186 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
187 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
189 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
190 *event
.mTouches
.AppendElement() = mTouches
[i
].ToNewDOMTouch();
196 WidgetMouseEvent
MultiTouchInput::ToWidgetMouseEvent(nsIWidget
* aWidget
) const {
197 MOZ_ASSERT(NS_IsMainThread(),
198 "Can only convert To WidgetMouseEvent on main thread");
200 EventMessage mouseEventMessage
= eVoidEvent
;
202 case MultiTouchInput::MULTITOUCH_START
:
203 mouseEventMessage
= eMouseDown
;
205 case MultiTouchInput::MULTITOUCH_MOVE
:
206 mouseEventMessage
= eMouseMove
;
208 case MultiTouchInput::MULTITOUCH_CANCEL
:
209 case MultiTouchInput::MULTITOUCH_END
:
210 mouseEventMessage
= eMouseUp
;
213 MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
217 WidgetMouseEvent
event(true, mouseEventMessage
, aWidget
,
218 WidgetMouseEvent::eReal
, WidgetMouseEvent::eNormal
);
220 const SingleTouchData
& firstTouch
= mTouches
[0];
221 event
.mRefPoint
.x
= firstTouch
.mScreenPoint
.x
;
222 event
.mRefPoint
.y
= firstTouch
.mScreenPoint
.y
;
225 event
.button
= WidgetMouseEvent::eLeftButton
;
226 event
.inputSource
= MouseEvent_Binding::MOZ_SOURCE_TOUCH
;
227 event
.mModifiers
= modifiers
;
228 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
229 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
231 if (mouseEventMessage
!= eMouseMove
) {
232 event
.mClickCount
= 1;
238 int32_t MultiTouchInput::IndexOfTouch(int32_t aTouchIdentifier
) {
239 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
240 if (mTouches
[i
].mIdentifier
== aTouchIdentifier
) {
247 bool MultiTouchInput::TransformToLocal(
248 const ScreenToParentLayerMatrix4x4
& aTransform
) {
249 for (size_t i
= 0; i
< mTouches
.Length(); i
++) {
250 Maybe
<ParentLayerIntPoint
> point
=
251 UntransformBy(aTransform
, mTouches
[i
].mScreenPoint
);
255 mTouches
[i
].mLocalScreenPoint
= *point
;
260 MouseInput::MouseInput()
261 : InputData(MOUSE_INPUT
),
266 mHandledByAPZ(false) {}
268 MouseInput::MouseInput(MouseType aType
, ButtonType aButtonType
,
269 uint16_t aInputSource
, int16_t aButtons
,
270 const ScreenPoint
& aPoint
, uint32_t aTime
,
271 TimeStamp aTimeStamp
, Modifiers aModifiers
)
272 : InputData(MOUSE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
274 mButtonType(aButtonType
),
275 mInputSource(aInputSource
),
278 mHandledByAPZ(false) {}
280 MouseInput::MouseInput(const WidgetMouseEventBase
& aMouseEvent
)
281 : InputData(MOUSE_INPUT
, aMouseEvent
.mTime
, aMouseEvent
.mTimeStamp
,
282 aMouseEvent
.mModifiers
),
285 mInputSource(aMouseEvent
.inputSource
),
286 mButtons(aMouseEvent
.buttons
),
287 mHandledByAPZ(aMouseEvent
.mFlags
.mHandledByAPZ
) {
288 MOZ_ASSERT(NS_IsMainThread(),
289 "Can only copy from WidgetTouchEvent on main thread");
293 switch (aMouseEvent
.button
) {
294 case WidgetMouseEventBase::eLeftButton
:
295 mButtonType
= MouseInput::LEFT_BUTTON
;
297 case WidgetMouseEventBase::eMiddleButton
:
298 mButtonType
= MouseInput::MIDDLE_BUTTON
;
300 case WidgetMouseEventBase::eRightButton
:
301 mButtonType
= MouseInput::RIGHT_BUTTON
;
305 switch (aMouseEvent
.mMessage
) {
316 mType
= MOUSE_DRAG_START
;
319 mType
= MOUSE_DRAG_END
;
321 case eMouseEnterIntoWidget
:
322 mType
= MOUSE_WIDGET_ENTER
;
324 case eMouseExitFromWidget
:
325 mType
= MOUSE_WIDGET_EXIT
;
328 mType
= MOUSE_HITTEST
;
331 MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
335 mOrigin
= ScreenPoint(ViewAs
<ScreenPixel
>(
336 aMouseEvent
.mRefPoint
,
337 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
340 bool MouseInput::IsLeftButton() const { return mButtonType
== LEFT_BUTTON
; }
342 bool MouseInput::TransformToLocal(
343 const ScreenToParentLayerMatrix4x4
& aTransform
) {
344 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mOrigin
);
348 mLocalOrigin
= *point
;
353 WidgetMouseEvent
MouseInput::ToWidgetMouseEvent(nsIWidget
* aWidget
) const {
354 MOZ_ASSERT(NS_IsMainThread(),
355 "Can only convert To WidgetTouchEvent on main thread");
357 EventMessage msg
= eVoidEvent
;
358 uint32_t clickCount
= 0;
371 case MOUSE_DRAG_START
:
377 case MOUSE_WIDGET_ENTER
:
378 msg
= eMouseEnterIntoWidget
;
380 case MOUSE_WIDGET_EXIT
:
381 msg
= eMouseExitFromWidget
;
387 MOZ_ASSERT_UNREACHABLE(
388 "Did not assign a type to WidgetMouseEvent in MouseInput");
392 WidgetMouseEvent
event(true, msg
, aWidget
, WidgetMouseEvent::eReal
,
393 WidgetMouseEvent::eNormal
);
395 if (msg
== eVoidEvent
) {
399 switch (mButtonType
) {
400 case MouseInput::LEFT_BUTTON
:
401 event
.button
= WidgetMouseEventBase::eLeftButton
;
403 case MouseInput::MIDDLE_BUTTON
:
404 event
.button
= WidgetMouseEventBase::eMiddleButton
;
406 case MouseInput::RIGHT_BUTTON
:
407 event
.button
= WidgetMouseEventBase::eRightButton
;
409 case MouseInput::NONE
:
414 event
.buttons
= mButtons
;
415 event
.mModifiers
= modifiers
;
417 event
.mTimeStamp
= mTimeStamp
;
418 event
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
419 event
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
421 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
422 event
.mClickCount
= clickCount
;
423 event
.inputSource
= mInputSource
;
424 event
.mIgnoreRootScrollFrame
= true;
425 event
.mFocusSequenceNumber
= mFocusSequenceNumber
;
430 PanGestureInput::PanGestureInput()
431 : InputData(PANGESTURE_INPUT
),
432 mType(PANGESTURE_MAYSTART
),
433 mLineOrPageDeltaX(0),
434 mLineOrPageDeltaY(0),
435 mUserDeltaMultiplierX(1.0),
436 mUserDeltaMultiplierY(1.0),
437 mHandledByAPZ(false),
438 mFollowedByMomentum(false),
439 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false),
440 mOverscrollBehaviorAllowsSwipe(false) {}
442 PanGestureInput::PanGestureInput(PanGestureType aType
, uint32_t aTime
,
443 TimeStamp aTimeStamp
,
444 const ScreenPoint
& aPanStartPoint
,
445 const ScreenPoint
& aPanDisplacement
,
446 Modifiers aModifiers
)
447 : InputData(PANGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
449 mPanStartPoint(aPanStartPoint
),
450 mPanDisplacement(aPanDisplacement
),
451 mLineOrPageDeltaX(0),
452 mLineOrPageDeltaY(0),
453 mUserDeltaMultiplierX(1.0),
454 mUserDeltaMultiplierY(1.0),
455 mHandledByAPZ(false),
456 mFollowedByMomentum(false),
457 mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false),
458 mOverscrollBehaviorAllowsSwipe(false) {}
460 bool PanGestureInput::IsMomentum() const {
462 case PanGestureInput::PANGESTURE_MOMENTUMSTART
:
463 case PanGestureInput::PANGESTURE_MOMENTUMPAN
:
464 case PanGestureInput::PANGESTURE_MOMENTUMEND
:
471 WidgetWheelEvent
PanGestureInput::ToWidgetWheelEvent(nsIWidget
* aWidget
) const {
472 WidgetWheelEvent
wheelEvent(true, eWheel
, aWidget
);
473 wheelEvent
.mModifiers
= this->modifiers
;
474 wheelEvent
.mTime
= mTime
;
475 wheelEvent
.mTimeStamp
= mTimeStamp
;
476 wheelEvent
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
478 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
479 wheelEvent
.buttons
= 0;
480 wheelEvent
.mDeltaMode
= WheelEvent_Binding::DOM_DELTA_PIXEL
;
481 wheelEvent
.mMayHaveMomentum
= true; // pan inputs may have momentum
482 wheelEvent
.mIsMomentum
= IsMomentum();
483 wheelEvent
.mLineOrPageDeltaX
= mLineOrPageDeltaX
;
484 wheelEvent
.mLineOrPageDeltaY
= mLineOrPageDeltaY
;
485 wheelEvent
.mDeltaX
= mPanDisplacement
.x
;
486 wheelEvent
.mDeltaY
= mPanDisplacement
.y
;
487 wheelEvent
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
488 wheelEvent
.mFocusSequenceNumber
= mFocusSequenceNumber
;
492 bool PanGestureInput::TransformToLocal(
493 const ScreenToParentLayerMatrix4x4
& aTransform
) {
494 Maybe
<ParentLayerPoint
> panStartPoint
=
495 UntransformBy(aTransform
, mPanStartPoint
);
496 if (!panStartPoint
) {
499 mLocalPanStartPoint
= *panStartPoint
;
501 Maybe
<ParentLayerPoint
> panDisplacement
=
502 UntransformVector(aTransform
, mPanDisplacement
, mPanStartPoint
);
503 if (!panDisplacement
) {
506 mLocalPanDisplacement
= *panDisplacement
;
510 ScreenPoint
PanGestureInput::UserMultipliedPanDisplacement() const {
511 return ScreenPoint(mPanDisplacement
.x
* mUserDeltaMultiplierX
,
512 mPanDisplacement
.y
* mUserDeltaMultiplierY
);
515 ParentLayerPoint
PanGestureInput::UserMultipliedLocalPanDisplacement() const {
516 return ParentLayerPoint(mLocalPanDisplacement
.x
* mUserDeltaMultiplierX
,
517 mLocalPanDisplacement
.y
* mUserDeltaMultiplierY
);
520 PinchGestureInput::PinchGestureInput()
521 : InputData(PINCHGESTURE_INPUT
), mType(PINCHGESTURE_START
) {}
523 PinchGestureInput::PinchGestureInput(
524 PinchGestureType aType
, uint32_t aTime
, TimeStamp aTimeStamp
,
525 const ExternalPoint
& aScreenOffset
, const ScreenPoint
& aFocusPoint
,
526 ScreenCoord aCurrentSpan
, ScreenCoord aPreviousSpan
, Modifiers aModifiers
)
527 : InputData(PINCHGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
529 mFocusPoint(aFocusPoint
),
530 mScreenOffset(aScreenOffset
),
531 mCurrentSpan(aCurrentSpan
),
532 mPreviousSpan(aPreviousSpan
) {}
534 bool PinchGestureInput::TransformToLocal(
535 const ScreenToParentLayerMatrix4x4
& aTransform
) {
536 if (mFocusPoint
== BothFingersLifted
<ScreenPixel
>()) {
537 // Special value, no transform required.
538 mLocalFocusPoint
= BothFingersLifted();
541 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mFocusPoint
);
545 mLocalFocusPoint
= *point
;
549 TapGestureInput::TapGestureInput()
550 : InputData(TAPGESTURE_INPUT
), mType(TAPGESTURE_LONG
) {}
552 TapGestureInput::TapGestureInput(TapGestureType aType
, uint32_t aTime
,
553 TimeStamp aTimeStamp
,
554 const ScreenIntPoint
& aPoint
,
555 Modifiers aModifiers
)
556 : InputData(TAPGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
560 TapGestureInput::TapGestureInput(TapGestureType aType
, uint32_t aTime
,
561 TimeStamp aTimeStamp
,
562 const ParentLayerPoint
& aLocalPoint
,
563 Modifiers aModifiers
)
564 : InputData(TAPGESTURE_INPUT
, aTime
, aTimeStamp
, aModifiers
),
566 mLocalPoint(aLocalPoint
) {}
568 bool TapGestureInput::TransformToLocal(
569 const ScreenToParentLayerMatrix4x4
& aTransform
) {
570 Maybe
<ParentLayerIntPoint
> point
= UntransformBy(aTransform
, mPoint
);
574 mLocalPoint
= *point
;
578 ScrollWheelInput::ScrollWheelInput()
579 : InputData(SCROLLWHEEL_INPUT
),
580 mDeltaType(SCROLLDELTA_LINE
),
581 mScrollMode(SCROLLMODE_INSTANT
),
582 mHandledByAPZ(false),
585 mLineOrPageDeltaX(0),
586 mLineOrPageDeltaY(0),
587 mScrollSeriesNumber(0),
588 mUserDeltaMultiplierX(1.0),
589 mUserDeltaMultiplierY(1.0),
590 mMayHaveMomentum(false),
592 mAPZAction(APZWheelAction::Scroll
) {}
594 ScrollWheelInput::ScrollWheelInput(
595 uint32_t aTime
, TimeStamp aTimeStamp
, Modifiers aModifiers
,
596 ScrollMode aScrollMode
, ScrollDeltaType aDeltaType
,
597 const ScreenPoint
& aOrigin
, double aDeltaX
, double aDeltaY
,
598 bool aAllowToOverrideSystemScrollSpeed
,
599 WheelDeltaAdjustmentStrategy aWheelDeltaAdjustmentStrategy
)
600 : InputData(SCROLLWHEEL_INPUT
, aTime
, aTimeStamp
, aModifiers
),
601 mDeltaType(aDeltaType
),
602 mScrollMode(aScrollMode
),
604 mHandledByAPZ(false),
607 mLineOrPageDeltaX(0),
608 mLineOrPageDeltaY(0),
609 mScrollSeriesNumber(0),
610 mUserDeltaMultiplierX(1.0),
611 mUserDeltaMultiplierY(1.0),
612 mMayHaveMomentum(false),
614 mAllowToOverrideSystemScrollSpeed(aAllowToOverrideSystemScrollSpeed
),
615 mWheelDeltaAdjustmentStrategy(aWheelDeltaAdjustmentStrategy
),
616 mAPZAction(APZWheelAction::Scroll
) {}
618 ScrollWheelInput::ScrollWheelInput(const WidgetWheelEvent
& aWheelEvent
)
619 : InputData(SCROLLWHEEL_INPUT
, aWheelEvent
.mTime
, aWheelEvent
.mTimeStamp
,
620 aWheelEvent
.mModifiers
),
621 mDeltaType(DeltaTypeForDeltaMode(aWheelEvent
.mDeltaMode
)),
622 mScrollMode(SCROLLMODE_INSTANT
),
623 mHandledByAPZ(aWheelEvent
.mFlags
.mHandledByAPZ
),
624 mDeltaX(aWheelEvent
.mDeltaX
),
625 mDeltaY(aWheelEvent
.mDeltaY
),
626 mLineOrPageDeltaX(aWheelEvent
.mLineOrPageDeltaX
),
627 mLineOrPageDeltaY(aWheelEvent
.mLineOrPageDeltaY
),
628 mScrollSeriesNumber(0),
629 mUserDeltaMultiplierX(1.0),
630 mUserDeltaMultiplierY(1.0),
631 mMayHaveMomentum(aWheelEvent
.mMayHaveMomentum
),
632 mIsMomentum(aWheelEvent
.mIsMomentum
),
633 mAllowToOverrideSystemScrollSpeed(
634 aWheelEvent
.mAllowToOverrideSystemScrollSpeed
),
635 mWheelDeltaAdjustmentStrategy(WheelDeltaAdjustmentStrategy::eNone
),
636 mAPZAction(APZWheelAction::Scroll
) {
637 mOrigin
= ScreenPoint(ViewAs
<ScreenPixel
>(
638 aWheelEvent
.mRefPoint
,
639 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
642 ScrollWheelInput::ScrollDeltaType
ScrollWheelInput::DeltaTypeForDeltaMode(
643 uint32_t aDeltaMode
) {
644 switch (aDeltaMode
) {
645 case WheelEvent_Binding::DOM_DELTA_LINE
:
646 return SCROLLDELTA_LINE
;
647 case WheelEvent_Binding::DOM_DELTA_PAGE
:
648 return SCROLLDELTA_PAGE
;
649 case WheelEvent_Binding::DOM_DELTA_PIXEL
:
650 return SCROLLDELTA_PIXEL
;
654 return SCROLLDELTA_LINE
;
657 uint32_t ScrollWheelInput::DeltaModeForDeltaType(ScrollDeltaType aDeltaType
) {
658 switch (aDeltaType
) {
659 case ScrollWheelInput::SCROLLDELTA_LINE
:
660 return WheelEvent_Binding::DOM_DELTA_LINE
;
661 case ScrollWheelInput::SCROLLDELTA_PAGE
:
662 return WheelEvent_Binding::DOM_DELTA_PAGE
;
663 case ScrollWheelInput::SCROLLDELTA_PIXEL
:
665 return WheelEvent_Binding::DOM_DELTA_PIXEL
;
669 nsIScrollableFrame::ScrollUnit
ScrollWheelInput::ScrollUnitForDeltaType(
670 ScrollDeltaType aDeltaType
) {
671 switch (aDeltaType
) {
672 case SCROLLDELTA_LINE
:
673 return nsIScrollableFrame::LINES
;
674 case SCROLLDELTA_PAGE
:
675 return nsIScrollableFrame::PAGES
;
676 case SCROLLDELTA_PIXEL
:
677 return nsIScrollableFrame::DEVICE_PIXELS
;
681 return nsIScrollableFrame::LINES
;
684 WidgetWheelEvent
ScrollWheelInput::ToWidgetWheelEvent(
685 nsIWidget
* aWidget
) const {
686 WidgetWheelEvent
wheelEvent(true, eWheel
, aWidget
);
687 wheelEvent
.mModifiers
= this->modifiers
;
688 wheelEvent
.mTime
= mTime
;
689 wheelEvent
.mTimeStamp
= mTimeStamp
;
690 wheelEvent
.mRefPoint
= RoundedToInt(ViewAs
<LayoutDevicePixel
>(
692 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent
));
693 wheelEvent
.buttons
= 0;
694 wheelEvent
.mDeltaMode
= DeltaModeForDeltaType(mDeltaType
);
695 wheelEvent
.mMayHaveMomentum
= mMayHaveMomentum
;
696 wheelEvent
.mIsMomentum
= mIsMomentum
;
697 wheelEvent
.mDeltaX
= mDeltaX
;
698 wheelEvent
.mDeltaY
= mDeltaY
;
699 wheelEvent
.mLineOrPageDeltaX
= mLineOrPageDeltaX
;
700 wheelEvent
.mLineOrPageDeltaY
= mLineOrPageDeltaY
;
701 wheelEvent
.mAllowToOverrideSystemScrollSpeed
=
702 mAllowToOverrideSystemScrollSpeed
;
703 wheelEvent
.mFlags
.mHandledByAPZ
= mHandledByAPZ
;
704 wheelEvent
.mFocusSequenceNumber
= mFocusSequenceNumber
;
708 bool ScrollWheelInput::TransformToLocal(
709 const ScreenToParentLayerMatrix4x4
& aTransform
) {
710 Maybe
<ParentLayerPoint
> point
= UntransformBy(aTransform
, mOrigin
);
714 mLocalOrigin
= *point
;
718 bool ScrollWheelInput::IsCustomizedByUserPrefs() const {
719 return mUserDeltaMultiplierX
!= 1.0 || mUserDeltaMultiplierY
!= 1.0;
722 KeyboardInput::KeyboardInput(const WidgetKeyboardEvent
& aEvent
)
723 : InputData(KEYBOARD_INPUT
, aEvent
.mTime
, aEvent
.mTimeStamp
,
725 mKeyCode(aEvent
.mKeyCode
),
726 mCharCode(aEvent
.mCharCode
),
727 mHandledByAPZ(false) {
728 switch (aEvent
.mMessage
) {
730 mType
= KeyboardInput::KEY_PRESS
;
734 mType
= KeyboardInput::KEY_UP
;
738 mType
= KeyboardInput::KEY_DOWN
;
742 mType
= KeyboardInput::KEY_OTHER
;
746 aEvent
.GetShortcutKeyCandidates(mShortcutCandidates
);
749 KeyboardInput::KeyboardInput()
750 : InputData(KEYBOARD_INPUT
),
754 mHandledByAPZ(false) {}
756 } // namespace mozilla