OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 5 #ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 #include <vector> | 10 #include <vector> |
(...skipping 24 matching lines...) Expand all Loading... | |
35 // touch event, we need to determine which point triggered the event. | 35 // touch event, we need to determine which point triggered the event. |
36 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can | 36 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can |
37 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and | 37 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and |
38 // (X - 1), where X is the maximum touch points supported by the device. The | 38 // (X - 1), where X is the maximum touch points supported by the device. The |
39 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion | 39 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion |
40 // event that comes from a currently-unused 'Slot ID' indicates the creation | 40 // event that comes from a currently-unused 'Slot ID' indicates the creation |
41 // of a new touch point, and any event that comes with a 0 value for | 41 // of a new touch point, and any event that comes with a 0 value for |
42 // 'Tracking ID' marks the removal of a touch point. During the lifetime of | 42 // 'Tracking ID' marks the removal of a touch point. During the lifetime of |
43 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress | 43 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress |
44 // and XI_ButtonRelease events are ignored. | 44 // and XI_ButtonRelease events are ignored. |
45 #if !defined(USE_XI2_1) | |
45 TP_SLOT_ID, // ID of the finger that triggered a touch event | 46 TP_SLOT_ID, // ID of the finger that triggered a touch event |
46 // (useful when tracking multiple simultaneous | 47 // (useful when tracking multiple simultaneous |
47 // touches) | 48 // touches) |
49 #endif | |
50 // NOTE for XInput 2.1: 'Tracking ID' is provided in every touch event to | |
51 // track individual touch. 'Tracking ID' is a unsigned 32-bit value and | |
Daniel Kurtz
2011/09/08 23:09:58
is an unsigned
ningxin.hu
2011/09/09 05:08:54
Thanks. Will correct.
| |
52 // is increased for each new touch. It will wrap back to 0 when reaching | |
53 // the numerical limit. | |
48 TP_TRACKING_ID, // ID of the touch point. | 54 TP_TRACKING_ID, // ID of the touch point. |
49 | 55 |
50 TP_LAST_ENTRY | 56 TP_LAST_ENTRY |
51 }; | 57 }; |
52 | 58 |
53 // Returns the TouchFactory singleton. | 59 // Returns the TouchFactory singleton. |
54 static TouchFactory* GetInstance(); | 60 static TouchFactory* GetInstance(); |
55 | 61 |
56 // Updates the list of devices. | 62 // Updates the list of devices. |
57 void UpdateDeviceList(Display* display); | 63 void UpdateDeviceList(Display* display); |
58 | 64 |
59 // Checks whether an XI2 event should be processed or not (i.e. if the event | 65 // Checks whether an XI2 event should be processed or not (i.e. if the event |
60 // originated from a device we are interested in). | 66 // originated from a device we are interested in). |
61 bool ShouldProcessXI2Event(XEvent* xevent); | 67 bool ShouldProcessXI2Event(XEvent* xevent); |
62 | 68 |
63 // Setup an X Window for XInput2 events. | 69 // Setup an X Window for XInput2 events. |
64 void SetupXI2ForXWindow(::Window xid); | 70 void SetupXI2ForXWindow(::Window xid); |
65 | 71 |
66 // Keeps a list of touch devices so that it is possible to determine if a | 72 // Keeps a list of touch devices so that it is possible to determine if a |
67 // pointer event is a touch-event or a mouse-event. The list is reset each | 73 // pointer event is a touch-event or a mouse-event. The list is reset each |
68 // time this is called. | 74 // time this is called. |
69 void SetTouchDeviceList(const std::vector<unsigned int>& devices); | 75 void SetTouchDeviceList(const std::vector<unsigned int>& devices); |
70 | 76 |
71 // Is the device a touch-device? | 77 // Is the device a touch-device? |
72 bool IsTouchDevice(unsigned int deviceid) const; | 78 bool IsTouchDevice(unsigned int deviceid) const; |
73 | 79 |
80 #if !defined(USE_XI2_1) | |
74 // Is the slot ID currently used? | 81 // Is the slot ID currently used? |
75 bool IsSlotUsed(int slot) const; | 82 bool IsSlotUsed(int slot) const; |
76 | 83 |
77 // Marks a slot as being used/unused. | 84 // Marks a slot as being used/unused. |
78 void SetSlotUsed(int slot, bool used); | 85 void SetSlotUsed(int slot, bool used); |
86 #endif | |
79 | 87 |
80 // Grabs the touch devices for the specified window on the specified display. | 88 // Grabs the touch devices for the specified window on the specified display. |
81 // Returns if grab was successful for all touch devices. | 89 // Returns if grab was successful for all touch devices. |
82 bool GrabTouchDevices(Display* display, ::Window window); | 90 bool GrabTouchDevices(Display* display, ::Window window); |
83 | 91 |
84 // Ungrabs the touch devices. Returns if ungrab was successful for all touch | 92 // Ungrabs the touch devices. Returns if ungrab was successful for all touch |
85 // devices. | 93 // devices. |
86 bool UngrabTouchDevices(Display* display); | 94 bool UngrabTouchDevices(Display* display); |
87 | 95 |
88 // Updates the root window to show (or hide) the cursor. Also indicate whether | 96 // Updates the root window to show (or hide) the cursor. Also indicate whether |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // The cursor is hidden if it is idle for a certain amount time. This timer | 152 // The cursor is hidden if it is idle for a certain amount time. This timer |
145 // is used to keep track of the idleness. | 153 // is used to keep track of the idleness. |
146 base::OneShotTimer<TouchFactory> cursor_timer_; | 154 base::OneShotTimer<TouchFactory> cursor_timer_; |
147 | 155 |
148 // The default cursor. | 156 // The default cursor. |
149 Cursor arrow_cursor_; | 157 Cursor arrow_cursor_; |
150 | 158 |
151 // The invisible cursor. | 159 // The invisible cursor. |
152 Cursor invisible_cursor_; | 160 Cursor invisible_cursor_; |
153 | 161 |
162 #if !defined(USE_XI2_1) | |
Daniel Kurtz
2011/09/08 23:09:58
Was there a reason to move this up?
ningxin.hu
2011/09/09 05:08:54
The reason is member initialization sequence when
| |
163 // Maximum simultaneous touch points. | |
164 static const int kMaxTouchPoints = 32; | |
165 | |
166 // A lookup table for slots in use for a touch event. | |
167 std::bitset<kMaxTouchPoints> slots_used_; | |
168 #endif | |
169 | |
154 // NOTE: To keep track of touch devices, we currently maintain a lookup table | 170 // NOTE: To keep track of touch devices, we currently maintain a lookup table |
155 // to quickly decide if a device is a touch device or not. We also maintain a | 171 // to quickly decide if a device is a touch device or not. We also maintain a |
156 // list of the touch devices. Ideally, there will be only one touch device, | 172 // list of the touch devices. Ideally, there will be only one touch device, |
157 // and instead of having the lookup table and the list, there will be a single | 173 // and instead of having the lookup table and the list, there will be a single |
158 // identifier for the touch device. This can be completed after enough testing | 174 // identifier for the touch device. This can be completed after enough testing |
159 // on real touch devices. | 175 // on real touch devices. |
160 | 176 |
161 static const int kMaxDeviceNum = 128; | 177 static const int kMaxDeviceNum = 128; |
162 | 178 |
163 // A quick lookup table for determining if events from the pointer device | 179 // A quick lookup table for determining if events from the pointer device |
(...skipping 11 matching lines...) Expand all Loading... | |
175 // index at the expense of space. If the kMaxDeviceNum grows larger that the | 191 // index at the expense of space. If the kMaxDeviceNum grows larger that the |
176 // space waste becomes a concern, the 2D lookup table can be replaced by a | 192 // space waste becomes a concern, the 2D lookup table can be replaced by a |
177 // hash map. | 193 // hash map. |
178 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; | 194 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; |
179 | 195 |
180 // Index table to find the min & max value of the TouchParam on a specific | 196 // Index table to find the min & max value of the TouchParam on a specific |
181 // device. | 197 // device. |
182 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; | 198 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; |
183 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; | 199 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; |
184 | 200 |
185 // Maximum simultaneous touch points. | |
186 static const int kMaxTouchPoints = 32; | |
187 | |
188 // A lookup table for slots in use for a touch event. | |
189 std::bitset<kMaxTouchPoints> slots_used_; | |
190 | |
191 DISALLOW_COPY_AND_ASSIGN(TouchFactory); | 201 DISALLOW_COPY_AND_ASSIGN(TouchFactory); |
192 }; | 202 }; |
193 | 203 |
194 } // namespace views | 204 } // namespace views |
195 | 205 |
196 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 206 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
OLD | NEW |