|
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 |
|
14 namespace mozilla { |
|
15 |
|
16 using namespace dom; |
|
17 |
|
18 MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent) |
|
19 : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.modifiers) |
|
20 { |
|
21 NS_ABORT_IF_FALSE(NS_IsMainThread(), |
|
22 "Can only copy from WidgetTouchEvent on main thread"); |
|
23 |
|
24 switch (aTouchEvent.message) { |
|
25 case NS_TOUCH_START: |
|
26 mType = MULTITOUCH_START; |
|
27 break; |
|
28 case NS_TOUCH_MOVE: |
|
29 mType = MULTITOUCH_MOVE; |
|
30 break; |
|
31 case NS_TOUCH_END: |
|
32 mType = MULTITOUCH_END; |
|
33 break; |
|
34 case NS_TOUCH_ENTER: |
|
35 mType = MULTITOUCH_ENTER; |
|
36 break; |
|
37 case NS_TOUCH_LEAVE: |
|
38 mType = MULTITOUCH_LEAVE; |
|
39 break; |
|
40 case NS_TOUCH_CANCEL: |
|
41 mType = MULTITOUCH_CANCEL; |
|
42 break; |
|
43 default: |
|
44 NS_WARNING("Did not assign a type to a MultiTouchInput"); |
|
45 break; |
|
46 } |
|
47 |
|
48 for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) { |
|
49 const Touch* domTouch = aTouchEvent.touches[i]; |
|
50 |
|
51 // Extract data from weird interfaces. |
|
52 int32_t identifier = domTouch->Identifier(); |
|
53 int32_t radiusX = domTouch->RadiusX(); |
|
54 int32_t radiusY = domTouch->RadiusY(); |
|
55 float rotationAngle = domTouch->RotationAngle(); |
|
56 float force = domTouch->Force(); |
|
57 |
|
58 SingleTouchData data(identifier, |
|
59 ScreenIntPoint::FromUnknownPoint( |
|
60 gfx::IntPoint(domTouch->mRefPoint.x, |
|
61 domTouch->mRefPoint.y)), |
|
62 ScreenSize(radiusX, radiusY), |
|
63 rotationAngle, |
|
64 force); |
|
65 |
|
66 mTouches.AppendElement(data); |
|
67 } |
|
68 } |
|
69 |
|
70 // This conversion from WidgetMouseEvent to MultiTouchInput is needed because on |
|
71 // the B2G emulator we can only receive mouse events, but we need to be able |
|
72 // to pan correctly. To do this, we convert the events into a format that the |
|
73 // panning code can handle. This code is very limited and only supports |
|
74 // SingleTouchData. It also sends garbage for the identifier, radius, force |
|
75 // and rotation angle. |
|
76 MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent) |
|
77 : InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.modifiers) |
|
78 { |
|
79 NS_ABORT_IF_FALSE(NS_IsMainThread(), |
|
80 "Can only copy from WidgetMouseEvent on main thread"); |
|
81 switch (aMouseEvent.message) { |
|
82 case NS_MOUSE_BUTTON_DOWN: |
|
83 mType = MULTITOUCH_START; |
|
84 break; |
|
85 case NS_MOUSE_MOVE: |
|
86 mType = MULTITOUCH_MOVE; |
|
87 break; |
|
88 case NS_MOUSE_BUTTON_UP: |
|
89 mType = MULTITOUCH_END; |
|
90 break; |
|
91 // The mouse pointer has been interrupted in an implementation-specific |
|
92 // manner, such as a synchronous event or action cancelling the touch, or a |
|
93 // touch point leaving the document window and going into a non-document |
|
94 // area capable of handling user interactions. |
|
95 case NS_MOUSE_EXIT: |
|
96 mType = MULTITOUCH_CANCEL; |
|
97 break; |
|
98 default: |
|
99 NS_WARNING("Did not assign a type to a MultiTouchInput"); |
|
100 break; |
|
101 } |
|
102 |
|
103 mTouches.AppendElement(SingleTouchData(0, |
|
104 ScreenIntPoint::FromUnknownPoint( |
|
105 gfx::IntPoint(aMouseEvent.refPoint.x, |
|
106 aMouseEvent.refPoint.y)), |
|
107 ScreenSize(1, 1), |
|
108 180.0f, |
|
109 1.0f)); |
|
110 } |
|
111 } |