Bug 1527719 [wpt PR 15359] - KV storage: make backingStore return the same frozen...
[gecko.git] / widget / InputData.cpp
blobc111aa63d19254824ba555de62149942f4230e31
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 #include "InputData.h"
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"
13 #include "nsDebug.h"
14 #include "nsThreadUtils.h"
15 #include "mozilla/MouseEvents.h"
16 #include "mozilla/TouchEvents.h"
17 #include "UnitTransforms.h"
19 namespace mozilla {
21 using namespace dom;
23 InputData::~InputData() {}
25 InputData::InputData(InputType aInputType)
26 : mInputType(aInputType),
27 mTime(0),
28 mFocusSequenceNumber(0),
29 mLayersId{0},
30 modifiers(0) {}
32 InputData::InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
33 Modifiers aModifiers)
34 : mInputType(aInputType),
35 mTime(aTime),
36 mTimeStamp(aTimeStamp),
37 mFocusSequenceNumber(0),
38 mLayersId{0},
39 modifiers(aModifiers) {}
41 SingleTouchData::SingleTouchData(int32_t aIdentifier,
42 ScreenIntPoint aScreenPoint,
43 ScreenSize aRadius, float aRotationAngle,
44 float aForce)
45 : mIdentifier(aIdentifier),
46 mScreenPoint(aScreenPoint),
47 mRadius(aRadius),
48 mRotationAngle(aRotationAngle),
49 mForce(aForce) {}
51 SingleTouchData::SingleTouchData(int32_t aIdentifier,
52 ParentLayerPoint aLocalScreenPoint,
53 ScreenSize aRadius, float aRotationAngle,
54 float aForce)
55 : mIdentifier(aIdentifier),
56 mLocalScreenPoint(aLocalScreenPoint),
57 mRadius(aRadius),
58 mRotationAngle(aRotationAngle),
59 mForce(aForce) {}
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");
67 RefPtr<Touch> touch =
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),
78 mType(aType),
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,
88 aOther.modifiers),
89 mType(aOther.mType),
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) {
103 case eTouchStart:
104 mType = MULTITOUCH_START;
105 break;
106 case eTouchMove:
107 mType = MULTITOUCH_MOVE;
108 break;
109 case eTouchEnd:
110 mType = MULTITOUCH_END;
111 break;
112 case eTouchCancel:
113 mType = MULTITOUCH_CANCEL;
114 break;
115 default:
116 MOZ_ASSERT_UNREACHABLE("Did not assign a type to a MultiTouchInput");
117 break;
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(
135 identifier,
136 ViewAs<ScreenPixel>(
137 domTouch->mRefPoint,
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;
159 switch (mType) {
160 case MULTITOUCH_START:
161 touchEventMessage = eTouchStart;
162 break;
163 case MULTITOUCH_MOVE:
164 touchEventMessage = eTouchMove;
165 break;
166 case MULTITOUCH_END:
167 touchEventMessage = eTouchEnd;
168 break;
169 case MULTITOUCH_CANCEL:
170 touchEventMessage = eTouchCancel;
171 break;
172 default:
173 MOZ_ASSERT_UNREACHABLE(
174 "Did not assign a type to WidgetTouchEvent in MultiTouchInput");
175 break;
178 WidgetTouchEvent event(true, touchEventMessage, aWidget);
179 if (touchEventMessage == eVoidEvent) {
180 return event;
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();
193 return event;
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;
201 switch (mType) {
202 case MultiTouchInput::MULTITOUCH_START:
203 mouseEventMessage = eMouseDown;
204 break;
205 case MultiTouchInput::MULTITOUCH_MOVE:
206 mouseEventMessage = eMouseMove;
207 break;
208 case MultiTouchInput::MULTITOUCH_CANCEL:
209 case MultiTouchInput::MULTITOUCH_END:
210 mouseEventMessage = eMouseUp;
211 break;
212 default:
213 MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
214 break;
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;
224 event.mTime = mTime;
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;
235 return event;
238 int32_t MultiTouchInput::IndexOfTouch(int32_t aTouchIdentifier) {
239 for (size_t i = 0; i < mTouches.Length(); i++) {
240 if (mTouches[i].mIdentifier == aTouchIdentifier) {
241 return (int32_t)i;
244 return -1;
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);
252 if (!point) {
253 return false;
255 mTouches[i].mLocalScreenPoint = *point;
257 return true;
260 MouseInput::MouseInput()
261 : InputData(MOUSE_INPUT),
262 mType(MOUSE_NONE),
263 mButtonType(NONE),
264 mInputSource(0),
265 mButtons(0),
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),
273 mType(aType),
274 mButtonType(aButtonType),
275 mInputSource(aInputSource),
276 mButtons(aButtons),
277 mOrigin(aPoint),
278 mHandledByAPZ(false) {}
280 MouseInput::MouseInput(const WidgetMouseEventBase& aMouseEvent)
281 : InputData(MOUSE_INPUT, aMouseEvent.mTime, aMouseEvent.mTimeStamp,
282 aMouseEvent.mModifiers),
283 mType(MOUSE_NONE),
284 mButtonType(NONE),
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");
291 mButtonType = NONE;
293 switch (aMouseEvent.button) {
294 case WidgetMouseEventBase::eLeftButton:
295 mButtonType = MouseInput::LEFT_BUTTON;
296 break;
297 case WidgetMouseEventBase::eMiddleButton:
298 mButtonType = MouseInput::MIDDLE_BUTTON;
299 break;
300 case WidgetMouseEventBase::eRightButton:
301 mButtonType = MouseInput::RIGHT_BUTTON;
302 break;
305 switch (aMouseEvent.mMessage) {
306 case eMouseMove:
307 mType = MOUSE_MOVE;
308 break;
309 case eMouseUp:
310 mType = MOUSE_UP;
311 break;
312 case eMouseDown:
313 mType = MOUSE_DOWN;
314 break;
315 case eDragStart:
316 mType = MOUSE_DRAG_START;
317 break;
318 case eDragEnd:
319 mType = MOUSE_DRAG_END;
320 break;
321 case eMouseEnterIntoWidget:
322 mType = MOUSE_WIDGET_ENTER;
323 break;
324 case eMouseExitFromWidget:
325 mType = MOUSE_WIDGET_EXIT;
326 break;
327 case eMouseHitTest:
328 mType = MOUSE_HITTEST;
329 break;
330 default:
331 MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
332 break;
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);
345 if (!point) {
346 return false;
348 mLocalOrigin = *point;
350 return true;
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;
359 switch (mType) {
360 case MOUSE_MOVE:
361 msg = eMouseMove;
362 break;
363 case MOUSE_UP:
364 msg = eMouseUp;
365 clickCount = 1;
366 break;
367 case MOUSE_DOWN:
368 msg = eMouseDown;
369 clickCount = 1;
370 break;
371 case MOUSE_DRAG_START:
372 msg = eDragStart;
373 break;
374 case MOUSE_DRAG_END:
375 msg = eDragEnd;
376 break;
377 case MOUSE_WIDGET_ENTER:
378 msg = eMouseEnterIntoWidget;
379 break;
380 case MOUSE_WIDGET_EXIT:
381 msg = eMouseExitFromWidget;
382 break;
383 case MOUSE_HITTEST:
384 msg = eMouseHitTest;
385 break;
386 default:
387 MOZ_ASSERT_UNREACHABLE(
388 "Did not assign a type to WidgetMouseEvent in MouseInput");
389 break;
392 WidgetMouseEvent event(true, msg, aWidget, WidgetMouseEvent::eReal,
393 WidgetMouseEvent::eNormal);
395 if (msg == eVoidEvent) {
396 return event;
399 switch (mButtonType) {
400 case MouseInput::LEFT_BUTTON:
401 event.button = WidgetMouseEventBase::eLeftButton;
402 break;
403 case MouseInput::MIDDLE_BUTTON:
404 event.button = WidgetMouseEventBase::eMiddleButton;
405 break;
406 case MouseInput::RIGHT_BUTTON:
407 event.button = WidgetMouseEventBase::eRightButton;
408 break;
409 case MouseInput::NONE:
410 default:
411 break;
414 event.buttons = mButtons;
415 event.mModifiers = modifiers;
416 event.mTime = mTime;
417 event.mTimeStamp = mTimeStamp;
418 event.mFlags.mHandledByAPZ = mHandledByAPZ;
419 event.mRefPoint = RoundedToInt(ViewAs<LayoutDevicePixel>(
420 mOrigin,
421 PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
422 event.mClickCount = clickCount;
423 event.inputSource = mInputSource;
424 event.mIgnoreRootScrollFrame = true;
425 event.mFocusSequenceNumber = mFocusSequenceNumber;
427 return event;
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),
448 mType(aType),
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 {
461 switch (mType) {
462 case PanGestureInput::PANGESTURE_MOMENTUMSTART:
463 case PanGestureInput::PANGESTURE_MOMENTUMPAN:
464 case PanGestureInput::PANGESTURE_MOMENTUMEND:
465 return true;
466 default:
467 return false;
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>(
477 mPanStartPoint,
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;
489 return wheelEvent;
492 bool PanGestureInput::TransformToLocal(
493 const ScreenToParentLayerMatrix4x4& aTransform) {
494 Maybe<ParentLayerPoint> panStartPoint =
495 UntransformBy(aTransform, mPanStartPoint);
496 if (!panStartPoint) {
497 return false;
499 mLocalPanStartPoint = *panStartPoint;
501 Maybe<ParentLayerPoint> panDisplacement =
502 UntransformVector(aTransform, mPanDisplacement, mPanStartPoint);
503 if (!panDisplacement) {
504 return false;
506 mLocalPanDisplacement = *panDisplacement;
507 return true;
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),
528 mType(aType),
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();
539 return true;
541 Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mFocusPoint);
542 if (!point) {
543 return false;
545 mLocalFocusPoint = *point;
546 return true;
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),
557 mType(aType),
558 mPoint(aPoint) {}
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),
565 mType(aType),
566 mLocalPoint(aLocalPoint) {}
568 bool TapGestureInput::TransformToLocal(
569 const ScreenToParentLayerMatrix4x4& aTransform) {
570 Maybe<ParentLayerIntPoint> point = UntransformBy(aTransform, mPoint);
571 if (!point) {
572 return false;
574 mLocalPoint = *point;
575 return true;
578 ScrollWheelInput::ScrollWheelInput()
579 : InputData(SCROLLWHEEL_INPUT),
580 mDeltaType(SCROLLDELTA_LINE),
581 mScrollMode(SCROLLMODE_INSTANT),
582 mHandledByAPZ(false),
583 mDeltaX(0.0),
584 mDeltaY(0.0),
585 mLineOrPageDeltaX(0),
586 mLineOrPageDeltaY(0),
587 mScrollSeriesNumber(0),
588 mUserDeltaMultiplierX(1.0),
589 mUserDeltaMultiplierY(1.0),
590 mMayHaveMomentum(false),
591 mIsMomentum(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),
603 mOrigin(aOrigin),
604 mHandledByAPZ(false),
605 mDeltaX(aDeltaX),
606 mDeltaY(aDeltaY),
607 mLineOrPageDeltaX(0),
608 mLineOrPageDeltaY(0),
609 mScrollSeriesNumber(0),
610 mUserDeltaMultiplierX(1.0),
611 mUserDeltaMultiplierY(1.0),
612 mMayHaveMomentum(false),
613 mIsMomentum(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;
651 default:
652 MOZ_CRASH();
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:
664 default:
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;
678 default:
679 MOZ_CRASH();
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>(
691 mOrigin,
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;
705 return wheelEvent;
708 bool ScrollWheelInput::TransformToLocal(
709 const ScreenToParentLayerMatrix4x4& aTransform) {
710 Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mOrigin);
711 if (!point) {
712 return false;
714 mLocalOrigin = *point;
715 return true;
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,
724 aEvent.mModifiers),
725 mKeyCode(aEvent.mKeyCode),
726 mCharCode(aEvent.mCharCode),
727 mHandledByAPZ(false) {
728 switch (aEvent.mMessage) {
729 case eKeyPress: {
730 mType = KeyboardInput::KEY_PRESS;
731 break;
733 case eKeyUp: {
734 mType = KeyboardInput::KEY_UP;
735 break;
737 case eKeyDown: {
738 mType = KeyboardInput::KEY_DOWN;
739 break;
741 default:
742 mType = KeyboardInput::KEY_OTHER;
743 break;
746 aEvent.GetShortcutKeyCandidates(mShortcutCandidates);
749 KeyboardInput::KeyboardInput()
750 : InputData(KEYBOARD_INPUT),
751 mType(KEY_DOWN),
752 mKeyCode(0),
753 mCharCode(0),
754 mHandledByAPZ(false) {}
756 } // namespace mozilla