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