OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 5 #ifndef UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ |
6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ |
7 | 7 |
8 // Generically-named #defines from Xlib is conflicting with symbols in GTest. | 8 // Generically-named #defines from Xlib is conflicting with symbols in GTest. |
9 // So many tests .cc file #undef Bool before including device_data_manager.h, | 9 // So many tests .cc file #undef Bool before including device_data_manager.h, |
10 // which makes Bool unrecognized in XInput2.h. | 10 // which makes Bool unrecognized in XInput2.h. |
11 #ifndef Bool | 11 #ifndef Bool |
12 #define Bool int | 12 #define Bool int |
13 #endif | 13 #endif |
14 | 14 |
15 #include <X11/extensions/XInput2.h> | 15 #include <X11/extensions/XInput2.h> |
16 | 16 |
17 #include <bitset> | 17 #include <bitset> |
18 #include <map> | 18 #include <map> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
22 #include "base/event_types.h" | 22 #include "base/event_types.h" |
| 23 #include "base/memory/scoped_ptr.h" |
| 24 #include "ui/events/event.h" |
23 #include "ui/events/event_constants.h" | 25 #include "ui/events/event_constants.h" |
24 #include "ui/events/events_base_export.h" | 26 #include "ui/events/events_base_export.h" |
| 27 #include "ui/gfx/geometry/rect.h" |
| 28 #include "ui/gfx/transform.h" |
25 #include "ui/gfx/x/x11_atom_cache.h" | 29 #include "ui/gfx/x/x11_atom_cache.h" |
26 | 30 |
27 template <typename T> struct DefaultSingletonTraits; | 31 template <typename T> struct DefaultSingletonTraits; |
28 | 32 |
29 typedef union _XEvent XEvent; | 33 typedef union _XEvent XEvent; |
30 | 34 |
31 namespace ui { | 35 namespace ui { |
32 | 36 |
33 // CrOS touchpad metrics gesture types | 37 // CrOS touchpad metrics gesture types |
34 enum GestureMetricsType { | 38 enum GestureMetricsType { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // This function is only for test purpose. It does not query the X server for | 214 // This function is only for test purpose. It does not query the X server for |
211 // the actual device info, but rather inits the relevant valuator structures | 215 // the actual device info, but rather inits the relevant valuator structures |
212 // to have safe default values for testing. | 216 // to have safe default values for testing. |
213 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, | 217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, |
214 const std::vector<unsigned int>& cmt_devices); | 218 const std::vector<unsigned int>& cmt_devices); |
215 | 219 |
216 void SetValuatorDataForTest(XIDeviceEvent* xievent, | 220 void SetValuatorDataForTest(XIDeviceEvent* xievent, |
217 DataType type, | 221 DataType type, |
218 double value); | 222 double value); |
219 | 223 |
| 224 void ClearTouchTransformerRecord(); |
| 225 void UpdateTouchInfoForDisplay(int64 display_id, |
| 226 int touch_device_id, |
| 227 const gfx::Transform& touch_transformer); |
| 228 void ApplyTouchTransformer(int touch_device_id, float* x, float* y); |
| 229 int64 GetDisplayForTouchDevice(int touch_device_id) const; |
| 230 void CalibrateTouchEvent(TouchEvent* event, |
| 231 int touch_device_id, |
| 232 const gfx::Rect& bounds); |
| 233 |
220 private: | 234 private: |
221 // Requirement for Singleton. | 235 // Requirement for Singleton. |
222 friend struct DefaultSingletonTraits<DeviceDataManager>; | 236 friend struct DefaultSingletonTraits<DeviceDataManager>; |
223 | 237 |
224 DeviceDataManager(); | 238 DeviceDataManager(); |
225 ~DeviceDataManager(); | 239 ~DeviceDataManager(); |
226 | 240 |
227 // Initialize the XInput related system information. | 241 // Initialize the XInput related system information. |
228 bool InitializeXInputInternal(); | 242 bool InitializeXInputInternal(); |
229 | 243 |
230 // Check if an XI event contains data of the specified type. | 244 // Check if an XI event contains data of the specified type. |
231 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; | 245 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; |
232 | 246 |
233 void InitializeValuatorsForTest(int deviceid, | 247 void InitializeValuatorsForTest(int deviceid, |
234 int start_valuator, | 248 int start_valuator, |
235 int end_valuator, | 249 int end_valuator, |
236 double min_value, | 250 double min_value, |
237 double max_value); | 251 double max_value); |
238 | 252 |
| 253 bool IsTouchDeviceIdValid(int touch_device_id) const; |
| 254 |
239 static const int kMaxDeviceNum = 128; | 255 static const int kMaxDeviceNum = 128; |
240 static const int kMaxXIEventType = XI_LASTEVENT + 1; | 256 static const int kMaxXIEventType = XI_LASTEVENT + 1; |
241 static const int kMaxSlotNum = 10; | 257 static const int kMaxSlotNum = 10; |
242 | 258 |
243 // Major opcode for the XInput extension. Used to identify XInput events. | 259 // Major opcode for the XInput extension. Used to identify XInput events. |
244 int xi_opcode_; | 260 int xi_opcode_; |
245 | 261 |
246 // A quick lookup table for determining if the XI event is an XIDeviceEvent. | 262 // A quick lookup table for determining if the XI event is an XIDeviceEvent. |
247 std::bitset<kMaxXIEventType> xi_device_event_types_; | 263 std::bitset<kMaxXIEventType> xi_device_event_types_; |
248 | 264 |
(...skipping 26 matching lines...) Expand all Loading... |
275 // doesn't think X/device doesn't know about the valuators. We currently | 291 // doesn't think X/device doesn't know about the valuators. We currently |
276 // use this only on touchscreen devices. | 292 // use this only on touchscreen devices. |
277 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; | 293 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; |
278 | 294 |
279 // X11 atoms cache. | 295 // X11 atoms cache. |
280 X11AtomCache atom_cache_; | 296 X11AtomCache atom_cache_; |
281 | 297 |
282 unsigned char button_map_[256]; | 298 unsigned char button_map_[256]; |
283 int button_map_count_; | 299 int button_map_count_; |
284 | 300 |
| 301 class TouchEventCalibrate; |
| 302 scoped_ptr<TouchEventCalibrate> touch_calibrate_; |
| 303 |
| 304 // Table to keep track of which display id is mapped to which touch device. |
| 305 int64 touch_device_to_display_map_[kMaxDeviceNum]; |
| 306 // Index table to find the TouchTransformer for a touch device. |
| 307 gfx::Transform touch_device_transformer_map_[kMaxDeviceNum]; |
| 308 |
285 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager); | 309 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager); |
286 }; | 310 }; |
287 | 311 |
288 } // namespace ui | 312 } // namespace ui |
289 | 313 |
290 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 314 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ |
OLD | NEW |