Line data Source code
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 : #include "InputData.h"
7 :
8 : #include "mozilla/dom/Touch.h"
9 : #include "nsDebug.h"
10 : #include "nsThreadUtils.h"
11 : #include "mozilla/MouseEvents.h"
12 : #include "mozilla/TouchEvents.h"
13 : #include "UnitTransforms.h"
14 :
15 : namespace mozilla {
16 :
17 : using namespace dom;
18 :
19 4 : InputData::~InputData()
20 : {
21 4 : }
22 :
23 0 : InputData::InputData(InputType aInputType)
24 : : mInputType(aInputType)
25 : , mTime(0)
26 : , mFocusSequenceNumber(0)
27 0 : , modifiers(0)
28 : {
29 0 : }
30 :
31 8 : InputData::InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
32 8 : Modifiers aModifiers)
33 : : mInputType(aInputType)
34 : , mTime(aTime)
35 : , mTimeStamp(aTimeStamp)
36 : , mFocusSequenceNumber(0)
37 8 : , modifiers(aModifiers)
38 : {
39 8 : }
40 :
41 0 : SingleTouchData::SingleTouchData(int32_t aIdentifier, ScreenIntPoint aScreenPoint,
42 : ScreenSize aRadius, float aRotationAngle,
43 0 : float aForce)
44 : : mIdentifier(aIdentifier)
45 : , mScreenPoint(aScreenPoint)
46 : , mRadius(aRadius)
47 : , mRotationAngle(aRotationAngle)
48 0 : , mForce(aForce)
49 : {
50 0 : }
51 :
52 0 : SingleTouchData::SingleTouchData(int32_t aIdentifier,
53 : ParentLayerPoint aLocalScreenPoint,
54 : ScreenSize aRadius, float aRotationAngle,
55 0 : float aForce)
56 : : mIdentifier(aIdentifier)
57 : , mLocalScreenPoint(aLocalScreenPoint)
58 : , mRadius(aRadius)
59 : , mRotationAngle(aRotationAngle)
60 0 : , mForce(aForce)
61 : {
62 0 : }
63 :
64 0 : SingleTouchData::SingleTouchData()
65 : {
66 0 : }
67 :
68 0 : already_AddRefed<Touch> SingleTouchData::ToNewDOMTouch() const
69 : {
70 0 : MOZ_ASSERT(NS_IsMainThread(),
71 : "Can only create dom::Touch instances on main thread");
72 0 : RefPtr<Touch> touch = new Touch(mIdentifier,
73 0 : LayoutDeviceIntPoint::Truncate(mScreenPoint.x, mScreenPoint.y),
74 0 : LayoutDeviceIntPoint::Truncate(mRadius.width, mRadius.height),
75 0 : mRotationAngle,
76 0 : mForce);
77 0 : return touch.forget();
78 : }
79 :
80 4 : MultiTouchInput::MultiTouchInput(MultiTouchType aType, uint32_t aTime,
81 4 : TimeStamp aTimeStamp, Modifiers aModifiers)
82 : : InputData(MULTITOUCH_INPUT, aTime, aTimeStamp, aModifiers)
83 : , mType(aType)
84 4 : , mHandledByAPZ(false)
85 : {
86 4 : }
87 :
88 0 : MultiTouchInput::MultiTouchInput()
89 : : InputData(MULTITOUCH_INPUT)
90 0 : , mHandledByAPZ(false)
91 : {
92 0 : }
93 :
94 0 : MultiTouchInput::MultiTouchInput(const MultiTouchInput& aOther)
95 0 : : InputData(MULTITOUCH_INPUT, aOther.mTime, aOther.mTimeStamp, aOther.modifiers)
96 0 : , mType(aOther.mType)
97 0 : , mHandledByAPZ(aOther.mHandledByAPZ)
98 : {
99 0 : mTouches.AppendElements(aOther.mTouches);
100 0 : }
101 :
102 0 : MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
103 0 : : InputData(MULTITOUCH_INPUT, aTouchEvent.mTime, aTouchEvent.mTimeStamp,
104 0 : aTouchEvent.mModifiers)
105 0 : , mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ)
106 : {
107 0 : MOZ_ASSERT(NS_IsMainThread(),
108 : "Can only copy from WidgetTouchEvent on main thread");
109 :
110 0 : switch (aTouchEvent.mMessage) {
111 : case eTouchStart:
112 0 : mType = MULTITOUCH_START;
113 0 : break;
114 : case eTouchMove:
115 0 : mType = MULTITOUCH_MOVE;
116 0 : break;
117 : case eTouchEnd:
118 0 : mType = MULTITOUCH_END;
119 0 : break;
120 : case eTouchCancel:
121 0 : mType = MULTITOUCH_CANCEL;
122 0 : break;
123 : default:
124 0 : MOZ_ASSERT_UNREACHABLE("Did not assign a type to a MultiTouchInput");
125 : break;
126 : }
127 :
128 0 : for (size_t i = 0; i < aTouchEvent.mTouches.Length(); i++) {
129 0 : const Touch* domTouch = aTouchEvent.mTouches[i];
130 :
131 : // Extract data from weird interfaces.
132 0 : int32_t identifier = domTouch->Identifier();
133 0 : int32_t radiusX = domTouch->RadiusX();
134 0 : int32_t radiusY = domTouch->RadiusY();
135 0 : float rotationAngle = domTouch->RotationAngle();
136 0 : float force = domTouch->Force();
137 :
138 : SingleTouchData data(identifier,
139 : ViewAs<ScreenPixel>(domTouch->mRefPoint,
140 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
141 : ScreenSize(radiusX, radiusY),
142 : rotationAngle,
143 0 : force);
144 :
145 0 : mTouches.AppendElement(data);
146 : }
147 0 : }
148 :
149 0 : MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent)
150 0 : : InputData(MULTITOUCH_INPUT, aMouseEvent.mTime, aMouseEvent.mTimeStamp,
151 0 : aMouseEvent.mModifiers)
152 0 : , mHandledByAPZ(aMouseEvent.mFlags.mHandledByAPZ)
153 : {
154 0 : MOZ_ASSERT(NS_IsMainThread(),
155 : "Can only copy from WidgetMouseEvent on main thread");
156 0 : switch (aMouseEvent.mMessage) {
157 : case eMouseDown:
158 0 : mType = MULTITOUCH_START;
159 0 : break;
160 : case eMouseMove:
161 0 : mType = MULTITOUCH_MOVE;
162 0 : break;
163 : case eMouseUp:
164 0 : mType = MULTITOUCH_END;
165 0 : break;
166 : // The mouse pointer has been interrupted in an implementation-specific
167 : // manner, such as a synchronous event or action cancelling the touch, or a
168 : // touch point leaving the document window and going into a non-document
169 : // area capable of handling user interactions.
170 : case eMouseExitFromWidget:
171 0 : mType = MULTITOUCH_CANCEL;
172 0 : break;
173 : default:
174 0 : NS_WARNING("Did not assign a type to a MultiTouchInput");
175 0 : break;
176 : }
177 :
178 0 : mTouches.AppendElement(SingleTouchData(0,
179 : ViewAs<ScreenPixel>(aMouseEvent.mRefPoint,
180 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
181 : ScreenSize(1, 1),
182 : 180.0f,
183 0 : 1.0f));
184 0 : }
185 :
186 : void
187 0 : MultiTouchInput::Translate(const ScreenPoint& aTranslation)
188 : {
189 0 : const int32_t xTranslation = (int32_t)(aTranslation.x + 0.5f);
190 0 : const int32_t yTranslation = (int32_t)(aTranslation.y + 0.5f);
191 :
192 0 : for (auto iter = mTouches.begin(); iter != mTouches.end(); iter++) {
193 0 : iter->mScreenPoint.MoveBy(xTranslation, yTranslation);
194 : }
195 0 : }
196 :
197 : WidgetTouchEvent
198 0 : MultiTouchInput::ToWidgetTouchEvent(nsIWidget* aWidget) const
199 : {
200 0 : MOZ_ASSERT(NS_IsMainThread(),
201 : "Can only convert To WidgetTouchEvent on main thread");
202 :
203 0 : EventMessage touchEventMessage = eVoidEvent;
204 0 : switch (mType) {
205 : case MULTITOUCH_START:
206 0 : touchEventMessage = eTouchStart;
207 0 : break;
208 : case MULTITOUCH_MOVE:
209 0 : touchEventMessage = eTouchMove;
210 0 : break;
211 : case MULTITOUCH_END:
212 0 : touchEventMessage = eTouchEnd;
213 0 : break;
214 : case MULTITOUCH_CANCEL:
215 0 : touchEventMessage = eTouchCancel;
216 0 : break;
217 : default:
218 0 : MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetTouchEvent in MultiTouchInput");
219 : break;
220 : }
221 :
222 0 : WidgetTouchEvent event(true, touchEventMessage, aWidget);
223 0 : if (touchEventMessage == eVoidEvent) {
224 0 : return event;
225 : }
226 :
227 0 : event.mModifiers = this->modifiers;
228 0 : event.mTime = this->mTime;
229 0 : event.mTimeStamp = this->mTimeStamp;
230 0 : event.mFlags.mHandledByAPZ = mHandledByAPZ;
231 0 : event.mFocusSequenceNumber = mFocusSequenceNumber;
232 :
233 0 : for (size_t i = 0; i < mTouches.Length(); i++) {
234 0 : *event.mTouches.AppendElement() = mTouches[i].ToNewDOMTouch();
235 : }
236 :
237 0 : return event;
238 : }
239 :
240 : WidgetMouseEvent
241 0 : MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const
242 : {
243 0 : MOZ_ASSERT(NS_IsMainThread(),
244 : "Can only convert To WidgetMouseEvent on main thread");
245 :
246 0 : EventMessage mouseEventMessage = eVoidEvent;
247 0 : switch (mType) {
248 : case MultiTouchInput::MULTITOUCH_START:
249 0 : mouseEventMessage = eMouseDown;
250 0 : break;
251 : case MultiTouchInput::MULTITOUCH_MOVE:
252 0 : mouseEventMessage = eMouseMove;
253 0 : break;
254 : case MultiTouchInput::MULTITOUCH_CANCEL:
255 : case MultiTouchInput::MULTITOUCH_END:
256 0 : mouseEventMessage = eMouseUp;
257 0 : break;
258 : default:
259 0 : MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent");
260 : break;
261 : }
262 :
263 : WidgetMouseEvent event(true, mouseEventMessage, aWidget,
264 0 : WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
265 :
266 0 : const SingleTouchData& firstTouch = mTouches[0];
267 0 : event.mRefPoint.x = firstTouch.mScreenPoint.x;
268 0 : event.mRefPoint.y = firstTouch.mScreenPoint.y;
269 :
270 0 : event.mTime = mTime;
271 0 : event.button = WidgetMouseEvent::eLeftButton;
272 0 : event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
273 0 : event.mModifiers = modifiers;
274 0 : event.mFlags.mHandledByAPZ = mHandledByAPZ;
275 0 : event.mFocusSequenceNumber = mFocusSequenceNumber;
276 :
277 0 : if (mouseEventMessage != eMouseMove) {
278 0 : event.mClickCount = 1;
279 : }
280 :
281 0 : return event;
282 : }
283 :
284 : int32_t
285 0 : MultiTouchInput::IndexOfTouch(int32_t aTouchIdentifier)
286 : {
287 0 : for (size_t i = 0; i < mTouches.Length(); i++) {
288 0 : if (mTouches[i].mIdentifier == aTouchIdentifier) {
289 0 : return (int32_t)i;
290 : }
291 : }
292 0 : return -1;
293 : }
294 :
295 : bool
296 0 : MultiTouchInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
297 : {
298 0 : for (size_t i = 0; i < mTouches.Length(); i++) {
299 0 : Maybe<ParentLayerIntPoint> point = UntransformBy(aTransform, mTouches[i].mScreenPoint);
300 0 : if (!point) {
301 0 : return false;
302 : }
303 0 : mTouches[i].mLocalScreenPoint = *point;
304 : }
305 0 : return true;
306 : }
307 :
308 0 : MouseInput::MouseInput()
309 : : InputData(MOUSE_INPUT)
310 : , mType(MOUSE_NONE)
311 : , mButtonType(NONE)
312 : , mInputSource(0)
313 : , mButtons(0)
314 0 : , mHandledByAPZ(false)
315 : {
316 0 : }
317 :
318 0 : MouseInput::MouseInput(MouseType aType, ButtonType aButtonType,
319 : uint16_t aInputSource, int16_t aButtons,
320 : const ScreenPoint& aPoint, uint32_t aTime,
321 0 : TimeStamp aTimeStamp, Modifiers aModifiers)
322 : : InputData(MOUSE_INPUT, aTime, aTimeStamp, aModifiers)
323 : , mType(aType)
324 : , mButtonType(aButtonType)
325 : , mInputSource(aInputSource)
326 : , mButtons(aButtons)
327 : , mOrigin(aPoint)
328 0 : , mHandledByAPZ(false)
329 : {
330 0 : }
331 :
332 4 : MouseInput::MouseInput(const WidgetMouseEventBase& aMouseEvent)
333 4 : : InputData(MOUSE_INPUT, aMouseEvent.mTime, aMouseEvent.mTimeStamp,
334 4 : aMouseEvent.mModifiers)
335 : , mType(MOUSE_NONE)
336 : , mButtonType(NONE)
337 4 : , mInputSource(aMouseEvent.inputSource)
338 4 : , mButtons(aMouseEvent.buttons)
339 16 : , mHandledByAPZ(aMouseEvent.mFlags.mHandledByAPZ)
340 : {
341 4 : MOZ_ASSERT(NS_IsMainThread(),
342 : "Can only copy from WidgetTouchEvent on main thread");
343 :
344 4 : mButtonType = NONE;
345 :
346 4 : switch (aMouseEvent.button) {
347 : case WidgetMouseEventBase::eLeftButton:
348 4 : mButtonType = MouseInput::LEFT_BUTTON;
349 4 : break;
350 : case WidgetMouseEventBase::eMiddleButton:
351 0 : mButtonType = MouseInput::MIDDLE_BUTTON;
352 0 : break;
353 : case WidgetMouseEventBase::eRightButton:
354 0 : mButtonType = MouseInput::RIGHT_BUTTON;
355 0 : break;
356 : }
357 :
358 4 : switch (aMouseEvent.mMessage) {
359 : case eMouseMove:
360 4 : mType = MOUSE_MOVE;
361 4 : break;
362 : case eMouseUp:
363 0 : mType = MOUSE_UP;
364 0 : break;
365 : case eMouseDown:
366 0 : mType = MOUSE_DOWN;
367 0 : break;
368 : case eDragStart:
369 0 : mType = MOUSE_DRAG_START;
370 0 : break;
371 : case eDragEnd:
372 0 : mType = MOUSE_DRAG_END;
373 0 : break;
374 : case eMouseEnterIntoWidget:
375 0 : mType = MOUSE_WIDGET_ENTER;
376 0 : break;
377 : case eMouseExitFromWidget:
378 0 : mType = MOUSE_WIDGET_EXIT;
379 0 : break;
380 : default:
381 0 : MOZ_ASSERT_UNREACHABLE("Mouse event type not supported");
382 : break;
383 : }
384 :
385 4 : mOrigin =
386 8 : ScreenPoint(ViewAs<ScreenPixel>(aMouseEvent.mRefPoint,
387 4 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
388 4 : }
389 :
390 : bool
391 16 : MouseInput::IsLeftButton() const
392 : {
393 16 : return mButtonType == LEFT_BUTTON;
394 : }
395 :
396 : bool
397 0 : MouseInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
398 : {
399 0 : Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mOrigin);
400 0 : if (!point) {
401 0 : return false;
402 : }
403 0 : mLocalOrigin = *point;
404 :
405 0 : return true;
406 : }
407 :
408 : WidgetMouseEvent
409 0 : MouseInput::ToWidgetMouseEvent(nsIWidget* aWidget) const
410 : {
411 0 : MOZ_ASSERT(NS_IsMainThread(),
412 : "Can only convert To WidgetTouchEvent on main thread");
413 :
414 0 : EventMessage msg = eVoidEvent;
415 0 : uint32_t clickCount = 0;
416 0 : switch (mType) {
417 : case MOUSE_MOVE:
418 0 : msg = eMouseMove;
419 0 : break;
420 : case MOUSE_UP:
421 0 : msg = eMouseUp;
422 0 : clickCount = 1;
423 0 : break;
424 : case MOUSE_DOWN:
425 0 : msg = eMouseDown;
426 0 : clickCount = 1;
427 0 : break;
428 : case MOUSE_DRAG_START:
429 0 : msg = eDragStart;
430 0 : break;
431 : case MOUSE_DRAG_END:
432 0 : msg = eDragEnd;
433 0 : break;
434 : case MOUSE_WIDGET_ENTER:
435 0 : msg = eMouseEnterIntoWidget;
436 0 : break;
437 : case MOUSE_WIDGET_EXIT:
438 0 : msg = eMouseExitFromWidget;
439 0 : break;
440 : default:
441 0 : MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent in MouseInput");
442 : break;
443 : }
444 :
445 0 : WidgetMouseEvent event(true, msg, aWidget, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
446 :
447 0 : if (msg == eVoidEvent) {
448 0 : return event;
449 : }
450 :
451 0 : switch (mButtonType) {
452 : case MouseInput::LEFT_BUTTON:
453 0 : event.button = WidgetMouseEventBase::eLeftButton;
454 0 : break;
455 : case MouseInput::MIDDLE_BUTTON:
456 0 : event.button = WidgetMouseEventBase::eMiddleButton;
457 0 : break;
458 : case MouseInput::RIGHT_BUTTON:
459 0 : event.button = WidgetMouseEventBase::eRightButton;
460 0 : break;
461 : case MouseInput::NONE:
462 : default:
463 0 : break;
464 : }
465 :
466 0 : event.buttons = mButtons;
467 0 : event.mModifiers = modifiers;
468 0 : event.mTime = mTime;
469 0 : event.mTimeStamp = mTimeStamp;
470 0 : event.mFlags.mHandledByAPZ = mHandledByAPZ;
471 : event.mRefPoint =
472 0 : RoundedToInt(ViewAs<LayoutDevicePixel>(mOrigin,
473 0 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
474 0 : event.mClickCount = clickCount;
475 0 : event.inputSource = mInputSource;
476 0 : event.mIgnoreRootScrollFrame = true;
477 0 : event.mFocusSequenceNumber = mFocusSequenceNumber;
478 :
479 0 : return event;
480 : }
481 :
482 0 : PanGestureInput::PanGestureInput()
483 : : InputData(PANGESTURE_INPUT)
484 : , mLineOrPageDeltaX(0)
485 : , mLineOrPageDeltaY(0)
486 : , mUserDeltaMultiplierX(1.0)
487 : , mUserDeltaMultiplierY(1.0)
488 : , mHandledByAPZ(false)
489 : , mFollowedByMomentum(false)
490 0 : , mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false)
491 : {
492 0 : }
493 :
494 0 : PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime,
495 : TimeStamp aTimeStamp,
496 : const ScreenPoint& aPanStartPoint,
497 : const ScreenPoint& aPanDisplacement,
498 0 : Modifiers aModifiers)
499 : : InputData(PANGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
500 : , mType(aType)
501 : , mPanStartPoint(aPanStartPoint)
502 : , mPanDisplacement(aPanDisplacement)
503 : , mLineOrPageDeltaX(0)
504 : , mLineOrPageDeltaY(0)
505 : , mUserDeltaMultiplierX(1.0)
506 : , mUserDeltaMultiplierY(1.0)
507 : , mHandledByAPZ(false)
508 : , mFollowedByMomentum(false)
509 0 : , mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection(false)
510 : {
511 0 : }
512 :
513 : bool
514 0 : PanGestureInput::IsMomentum() const
515 : {
516 0 : switch (mType) {
517 : case PanGestureInput::PANGESTURE_MOMENTUMSTART:
518 : case PanGestureInput::PANGESTURE_MOMENTUMPAN:
519 : case PanGestureInput::PANGESTURE_MOMENTUMEND:
520 0 : return true;
521 : default:
522 0 : return false;
523 : }
524 : }
525 :
526 : WidgetWheelEvent
527 0 : PanGestureInput::ToWidgetWheelEvent(nsIWidget* aWidget) const
528 : {
529 0 : WidgetWheelEvent wheelEvent(true, eWheel, aWidget);
530 0 : wheelEvent.mModifiers = this->modifiers;
531 0 : wheelEvent.mTime = mTime;
532 0 : wheelEvent.mTimeStamp = mTimeStamp;
533 : wheelEvent.mRefPoint =
534 0 : RoundedToInt(ViewAs<LayoutDevicePixel>(mPanStartPoint,
535 0 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
536 0 : wheelEvent.buttons = 0;
537 0 : wheelEvent.mDeltaMode = nsIDOMWheelEvent::DOM_DELTA_PIXEL;
538 0 : wheelEvent.mMayHaveMomentum = true; // pan inputs may have momentum
539 0 : wheelEvent.mIsMomentum = IsMomentum();
540 0 : wheelEvent.mLineOrPageDeltaX = mLineOrPageDeltaX;
541 0 : wheelEvent.mLineOrPageDeltaY = mLineOrPageDeltaY;
542 0 : wheelEvent.mDeltaX = mPanDisplacement.x;
543 0 : wheelEvent.mDeltaY = mPanDisplacement.y;
544 0 : wheelEvent.mFlags.mHandledByAPZ = mHandledByAPZ;
545 0 : wheelEvent.mFocusSequenceNumber = mFocusSequenceNumber;
546 0 : return wheelEvent;
547 : }
548 :
549 : bool
550 0 : PanGestureInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
551 : {
552 0 : Maybe<ParentLayerPoint> panStartPoint = UntransformBy(aTransform, mPanStartPoint);
553 0 : if (!panStartPoint) {
554 0 : return false;
555 : }
556 0 : mLocalPanStartPoint = *panStartPoint;
557 :
558 0 : Maybe<ParentLayerPoint> panDisplacement = UntransformVector(aTransform, mPanDisplacement, mPanStartPoint);
559 0 : if (!panDisplacement) {
560 0 : return false;
561 : }
562 0 : mLocalPanDisplacement = *panDisplacement;
563 0 : return true;
564 : }
565 :
566 : ScreenPoint
567 0 : PanGestureInput::UserMultipliedPanDisplacement() const
568 : {
569 0 : return ScreenPoint(mPanDisplacement.x * mUserDeltaMultiplierX,
570 0 : mPanDisplacement.y * mUserDeltaMultiplierY);
571 : }
572 :
573 : ParentLayerPoint
574 0 : PanGestureInput::UserMultipliedLocalPanDisplacement() const
575 : {
576 0 : return ParentLayerPoint(mLocalPanDisplacement.x * mUserDeltaMultiplierX,
577 0 : mLocalPanDisplacement.y * mUserDeltaMultiplierY);
578 : }
579 :
580 0 : PinchGestureInput::PinchGestureInput()
581 0 : : InputData(PINCHGESTURE_INPUT)
582 : {
583 0 : }
584 :
585 0 : PinchGestureInput::PinchGestureInput(PinchGestureType aType, uint32_t aTime,
586 : TimeStamp aTimeStamp,
587 : const ParentLayerPoint& aLocalFocusPoint,
588 : ParentLayerCoord aCurrentSpan,
589 : ParentLayerCoord aPreviousSpan,
590 0 : Modifiers aModifiers)
591 : : InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
592 : , mType(aType)
593 : , mLocalFocusPoint(aLocalFocusPoint)
594 : , mCurrentSpan(aCurrentSpan)
595 0 : , mPreviousSpan(aPreviousSpan)
596 : {
597 0 : }
598 :
599 : bool
600 0 : PinchGestureInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
601 : {
602 0 : Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mFocusPoint);
603 0 : if (!point) {
604 0 : return false;
605 : }
606 0 : mLocalFocusPoint = *point;
607 0 : return true;
608 : }
609 :
610 0 : TapGestureInput::TapGestureInput()
611 0 : : InputData(TAPGESTURE_INPUT)
612 : {
613 0 : }
614 :
615 0 : TapGestureInput::TapGestureInput(TapGestureType aType, uint32_t aTime,
616 : TimeStamp aTimeStamp,
617 : const ScreenIntPoint& aPoint,
618 0 : Modifiers aModifiers)
619 : : InputData(TAPGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
620 : , mType(aType)
621 0 : , mPoint(aPoint)
622 : {
623 0 : }
624 :
625 0 : TapGestureInput::TapGestureInput(TapGestureType aType, uint32_t aTime,
626 : TimeStamp aTimeStamp,
627 : const ParentLayerPoint& aLocalPoint,
628 0 : Modifiers aModifiers)
629 : : InputData(TAPGESTURE_INPUT, aTime, aTimeStamp, aModifiers)
630 : , mType(aType)
631 0 : , mLocalPoint(aLocalPoint)
632 : {
633 0 : }
634 :
635 : bool
636 0 : TapGestureInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
637 : {
638 0 : Maybe<ParentLayerIntPoint> point = UntransformBy(aTransform, mPoint);
639 0 : if (!point) {
640 0 : return false;
641 : }
642 0 : mLocalPoint = *point;
643 0 : return true;
644 : }
645 :
646 0 : ScrollWheelInput::ScrollWheelInput()
647 : : InputData(SCROLLWHEEL_INPUT)
648 : , mHandledByAPZ(false)
649 : , mLineOrPageDeltaX(0)
650 : , mLineOrPageDeltaY(0)
651 : , mScrollSeriesNumber(0)
652 : , mUserDeltaMultiplierX(1.0)
653 : , mUserDeltaMultiplierY(1.0)
654 : , mMayHaveMomentum(false)
655 0 : , mIsMomentum(false)
656 : {
657 0 : }
658 :
659 0 : ScrollWheelInput::ScrollWheelInput(uint32_t aTime, TimeStamp aTimeStamp,
660 : Modifiers aModifiers, ScrollMode aScrollMode,
661 : ScrollDeltaType aDeltaType,
662 : const ScreenPoint& aOrigin, double aDeltaX,
663 : double aDeltaY,
664 0 : bool aAllowToOverrideSystemScrollSpeed)
665 : : InputData(SCROLLWHEEL_INPUT, aTime, aTimeStamp, aModifiers)
666 : , mDeltaType(aDeltaType)
667 : , mScrollMode(aScrollMode)
668 : , mOrigin(aOrigin)
669 : , mHandledByAPZ(false)
670 : , mDeltaX(aDeltaX)
671 : , mDeltaY(aDeltaY)
672 : , mLineOrPageDeltaX(0)
673 : , mLineOrPageDeltaY(0)
674 : , mScrollSeriesNumber(0)
675 : , mUserDeltaMultiplierX(1.0)
676 : , mUserDeltaMultiplierY(1.0)
677 : , mMayHaveMomentum(false)
678 : , mIsMomentum(false)
679 0 : , mAllowToOverrideSystemScrollSpeed(aAllowToOverrideSystemScrollSpeed)
680 : {
681 0 : }
682 :
683 0 : ScrollWheelInput::ScrollWheelInput(const WidgetWheelEvent& aWheelEvent)
684 0 : : InputData(SCROLLWHEEL_INPUT, aWheelEvent.mTime, aWheelEvent.mTimeStamp,
685 0 : aWheelEvent.mModifiers)
686 0 : , mDeltaType(DeltaTypeForDeltaMode(aWheelEvent.mDeltaMode))
687 : , mScrollMode(SCROLLMODE_INSTANT)
688 0 : , mHandledByAPZ(aWheelEvent.mFlags.mHandledByAPZ)
689 0 : , mDeltaX(aWheelEvent.mDeltaX)
690 0 : , mDeltaY(aWheelEvent.mDeltaY)
691 0 : , mLineOrPageDeltaX(aWheelEvent.mLineOrPageDeltaX)
692 0 : , mLineOrPageDeltaY(aWheelEvent.mLineOrPageDeltaY)
693 : , mScrollSeriesNumber(0)
694 : , mUserDeltaMultiplierX(1.0)
695 : , mUserDeltaMultiplierY(1.0)
696 0 : , mMayHaveMomentum(aWheelEvent.mMayHaveMomentum)
697 0 : , mIsMomentum(aWheelEvent.mIsMomentum)
698 : , mAllowToOverrideSystemScrollSpeed(
699 0 : aWheelEvent.mAllowToOverrideSystemScrollSpeed)
700 : {
701 0 : mOrigin =
702 0 : ScreenPoint(ViewAs<ScreenPixel>(aWheelEvent.mRefPoint,
703 0 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
704 0 : }
705 :
706 : ScrollWheelInput::ScrollDeltaType
707 0 : ScrollWheelInput::DeltaTypeForDeltaMode(uint32_t aDeltaMode)
708 : {
709 0 : switch (aDeltaMode) {
710 : case nsIDOMWheelEvent::DOM_DELTA_LINE:
711 0 : return SCROLLDELTA_LINE;
712 : case nsIDOMWheelEvent::DOM_DELTA_PAGE:
713 0 : return SCROLLDELTA_PAGE;
714 : case nsIDOMWheelEvent::DOM_DELTA_PIXEL:
715 0 : return SCROLLDELTA_PIXEL;
716 : default:
717 0 : MOZ_CRASH();
718 : }
719 : return SCROLLDELTA_LINE;
720 : }
721 :
722 : uint32_t
723 0 : ScrollWheelInput::DeltaModeForDeltaType(ScrollDeltaType aDeltaType)
724 : {
725 0 : switch (aDeltaType) {
726 : case ScrollWheelInput::SCROLLDELTA_LINE:
727 0 : return nsIDOMWheelEvent::DOM_DELTA_LINE;
728 : case ScrollWheelInput::SCROLLDELTA_PAGE:
729 0 : return nsIDOMWheelEvent::DOM_DELTA_PAGE;
730 : case ScrollWheelInput::SCROLLDELTA_PIXEL:
731 : default:
732 0 : return nsIDOMWheelEvent::DOM_DELTA_PIXEL;
733 : }
734 : }
735 :
736 : nsIScrollableFrame::ScrollUnit
737 0 : ScrollWheelInput::ScrollUnitForDeltaType(ScrollDeltaType aDeltaType)
738 : {
739 0 : switch (aDeltaType) {
740 : case SCROLLDELTA_LINE:
741 0 : return nsIScrollableFrame::LINES;
742 : case SCROLLDELTA_PAGE:
743 0 : return nsIScrollableFrame::PAGES;
744 : case SCROLLDELTA_PIXEL:
745 0 : return nsIScrollableFrame::DEVICE_PIXELS;
746 : default:
747 0 : MOZ_CRASH();
748 : }
749 : return nsIScrollableFrame::LINES;
750 : }
751 :
752 : WidgetWheelEvent
753 0 : ScrollWheelInput::ToWidgetWheelEvent(nsIWidget* aWidget) const
754 : {
755 0 : WidgetWheelEvent wheelEvent(true, eWheel, aWidget);
756 0 : wheelEvent.mModifiers = this->modifiers;
757 0 : wheelEvent.mTime = mTime;
758 0 : wheelEvent.mTimeStamp = mTimeStamp;
759 : wheelEvent.mRefPoint =
760 0 : RoundedToInt(ViewAs<LayoutDevicePixel>(mOrigin,
761 0 : PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
762 0 : wheelEvent.buttons = 0;
763 0 : wheelEvent.mDeltaMode = DeltaModeForDeltaType(mDeltaType);
764 0 : wheelEvent.mMayHaveMomentum = mMayHaveMomentum;
765 0 : wheelEvent.mIsMomentum = mIsMomentum;
766 0 : wheelEvent.mDeltaX = mDeltaX;
767 0 : wheelEvent.mDeltaY = mDeltaY;
768 0 : wheelEvent.mLineOrPageDeltaX = mLineOrPageDeltaX;
769 0 : wheelEvent.mLineOrPageDeltaY = mLineOrPageDeltaY;
770 0 : wheelEvent.mAllowToOverrideSystemScrollSpeed =
771 0 : mAllowToOverrideSystemScrollSpeed;
772 0 : wheelEvent.mFlags.mHandledByAPZ = mHandledByAPZ;
773 0 : wheelEvent.mFocusSequenceNumber = mFocusSequenceNumber;
774 0 : return wheelEvent;
775 : }
776 :
777 : bool
778 0 : ScrollWheelInput::TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform)
779 : {
780 0 : Maybe<ParentLayerPoint> point = UntransformBy(aTransform, mOrigin);
781 0 : if (!point) {
782 0 : return false;
783 : }
784 0 : mLocalOrigin = *point;
785 0 : return true;
786 : }
787 :
788 : bool
789 0 : ScrollWheelInput::IsCustomizedByUserPrefs() const
790 : {
791 0 : return mUserDeltaMultiplierX != 1.0 ||
792 0 : mUserDeltaMultiplierY != 1.0;
793 : }
794 :
795 0 : KeyboardInput::KeyboardInput(const WidgetKeyboardEvent& aEvent)
796 : : InputData(KEYBOARD_INPUT,
797 0 : aEvent.mTime,
798 : aEvent.mTimeStamp,
799 0 : aEvent.mModifiers)
800 0 : , mKeyCode(aEvent.mKeyCode)
801 0 : , mCharCode(aEvent.mCharCode)
802 0 : , mHandledByAPZ(false)
803 : {
804 0 : switch (aEvent.mMessage) {
805 : case eKeyPress: {
806 0 : mType = KeyboardInput::KEY_PRESS;
807 0 : break;
808 : }
809 : case eKeyUp: {
810 0 : mType = KeyboardInput::KEY_UP;
811 0 : break;
812 : }
813 : case eKeyDown: {
814 0 : mType = KeyboardInput::KEY_DOWN;
815 0 : break;
816 : }
817 : default:
818 0 : mType = KeyboardInput::KEY_OTHER;
819 0 : break;
820 : }
821 :
822 0 : aEvent.GetShortcutKeyCandidates(mShortcutCandidates);
823 0 : }
824 :
825 0 : KeyboardInput::KeyboardInput()
826 : : InputData(KEYBOARD_INPUT)
827 : , mKeyCode(0)
828 : , mCharCode(0)
829 0 : , mHandledByAPZ(false)
830 : {
831 0 : }
832 :
833 : } // namespace mozilla
|