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_X11_H_ |
6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_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" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "ui/events/device_data_manager.h" | |
24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
25 #include "ui/events/event_constants.h" | 26 #include "ui/events/event_constants.h" |
26 #include "ui/events/events_base_export.h" | 27 #include "ui/events/events_base_export.h" |
27 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
28 #include "ui/gfx/transform.h" | |
29 #include "ui/gfx/x/x11_atom_cache.h" | 29 #include "ui/gfx/x/x11_atom_cache.h" |
30 | 30 |
31 template <typename T> struct DefaultSingletonTraits; | |
32 | |
33 typedef union _XEvent XEvent; | 31 typedef union _XEvent XEvent; |
34 | 32 |
35 namespace ui { | 33 namespace ui { |
36 | 34 |
37 // CrOS touchpad metrics gesture types | 35 // CrOS touchpad metrics gesture types |
38 enum GestureMetricsType { | 36 enum GestureMetricsType { |
39 kGestureMetricsTypeNoisyGround = 0, | 37 kGestureMetricsTypeNoisyGround = 0, |
40 kGestureMetricsTypeUnknown, | 38 kGestureMetricsTypeUnknown, |
41 }; | 39 }; |
42 | 40 |
43 // A class that extracts and tracks the input events data. It currently handles | 41 // A class that extracts and tracks the input events data. It currently handles |
44 // mouse, touchpad and touchscreen devices. | 42 // mouse, touchpad and touchscreen devices. |
45 class EVENTS_BASE_EXPORT DeviceDataManager { | 43 class EVENTS_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager { |
46 public: | 44 public: |
47 // Enumerate additional data that one might be interested on an input event, | 45 // Enumerate additional data that one might be interested on an input event, |
48 // which are usually wrapped in X valuators. If you modify any of this, | 46 // which are usually wrapped in X valuators. If you modify any of this, |
49 // make sure to update the kCachedAtoms data structure in the source file | 47 // make sure to update the kCachedAtoms data structure in the source file |
50 // and the k*Type[Start/End] constants used by IsCMTDataType and | 48 // and the k*Type[Start/End] constants used by IsCMTDataType and |
51 // IsTouchDataType. | 49 // IsTouchDataType. |
52 enum DataType { | 50 enum DataType { |
53 // Define the valuators used the CrOS CMT driver. Used by mice and CrOS | 51 // Define the valuators used the CrOS CMT driver. Used by mice and CrOS |
54 // touchpads. | 52 // touchpads. |
55 DT_CMT_SCROLL_X = 0, // Scroll amount on the X (horizontal) direction. | 53 DT_CMT_SCROLL_X = 0, // Scroll amount on the X (horizontal) direction. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 DT_TOUCH_RAW_TIMESTAMP, | 92 DT_TOUCH_RAW_TIMESTAMP, |
95 | 93 |
96 // End of touch data types. | 94 // End of touch data types. |
97 | 95 |
98 DT_LAST_ENTRY // This must come last. | 96 DT_LAST_ENTRY // This must come last. |
99 }; | 97 }; |
100 | 98 |
101 // Data struct to store extracted data from an input event. | 99 // Data struct to store extracted data from an input event. |
102 typedef std::map<int, double> EventData; | 100 typedef std::map<int, double> EventData; |
103 | 101 |
102 DeviceDataManagerX11(); | |
103 virtual ~DeviceDataManagerX11(); | |
sadrul
2014/06/16 14:48:38
Make these private (because otherwise any number o
dnicoara
2014/06/16 15:13:56
The CHECK in DDM's constructor would prevent that.
sadrul
2014/06/17 20:37:08
Making them private would make this easier to unde
dnicoara
2014/06/18 14:04:29
Done
| |
104 | |
104 // We use int because enums can be casted to ints but not vice versa. | 105 // We use int because enums can be casted to ints but not vice versa. |
105 static bool IsCMTDataType(const int type); | 106 static bool IsCMTDataType(const int type); |
106 static bool IsTouchDataType(const int type); | 107 static bool IsTouchDataType(const int type); |
107 | 108 |
108 // Returns the DeviceDataManager singleton. | 109 // Returns the DeviceDataManagerX11 singleton. |
109 static DeviceDataManager* GetInstance(); | 110 static DeviceDataManagerX11* GetInstance(); |
110 | 111 |
111 // Returns if XInput2 is available on the system. | 112 // Returns if XInput2 is available on the system. |
112 bool IsXInput2Available() const; | 113 bool IsXInput2Available() const; |
113 | 114 |
114 // Updates the list of devices. | 115 // Updates the list of devices. |
115 void UpdateDeviceList(Display* display); | 116 void UpdateDeviceList(Display* display); |
116 | 117 |
117 // For multitouch events we use slot number to distinguish touches from | 118 // For multitouch events we use slot number to distinguish touches from |
118 // different fingers. This function returns true if the associated slot | 119 // different fingers. This function returns true if the associated slot |
119 // for |xiev| can be found and it is saved in |slot|, returns false if | 120 // for |xiev| can be found and it is saved in |slot|, returns false if |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 // This function is only for test purpose. It does not query the X server for | 215 // This function is only for test purpose. It does not query the X server for |
215 // the actual device info, but rather inits the relevant valuator structures | 216 // the actual device info, but rather inits the relevant valuator structures |
216 // to have safe default values for testing. | 217 // to have safe default values for testing. |
217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, | 218 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, |
218 const std::vector<unsigned int>& cmt_devices); | 219 const std::vector<unsigned int>& cmt_devices); |
219 | 220 |
220 void SetValuatorDataForTest(XIDeviceEvent* xievent, | 221 void SetValuatorDataForTest(XIDeviceEvent* xievent, |
221 DataType type, | 222 DataType type, |
222 double value); | 223 double value); |
223 | 224 |
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 bool TouchEventNeedsCalibrate(int touch_device_id) const; | 225 bool TouchEventNeedsCalibrate(int touch_device_id) const; |
231 | 226 |
232 private: | 227 private: |
233 // Requirement for Singleton. | |
234 friend struct DefaultSingletonTraits<DeviceDataManager>; | |
235 | |
236 DeviceDataManager(); | |
237 ~DeviceDataManager(); | |
238 | |
239 // Initialize the XInput related system information. | 228 // Initialize the XInput related system information. |
240 bool InitializeXInputInternal(); | 229 bool InitializeXInputInternal(); |
241 | 230 |
242 // Check if an XI event contains data of the specified type. | 231 // Check if an XI event contains data of the specified type. |
243 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; | 232 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; |
244 | 233 |
245 void InitializeValuatorsForTest(int deviceid, | 234 void InitializeValuatorsForTest(int deviceid, |
246 int start_valuator, | 235 int start_valuator, |
247 int end_valuator, | 236 int end_valuator, |
248 double min_value, | 237 double min_value, |
249 double max_value); | 238 double max_value); |
250 | 239 |
251 bool IsTouchDeviceIdValid(int touch_device_id) const; | |
252 | |
253 static const int kMaxDeviceNum = 128; | |
254 static const int kMaxXIEventType = XI_LASTEVENT + 1; | 240 static const int kMaxXIEventType = XI_LASTEVENT + 1; |
255 static const int kMaxSlotNum = 10; | 241 static const int kMaxSlotNum = 10; |
256 | 242 |
257 // Major opcode for the XInput extension. Used to identify XInput events. | 243 // Major opcode for the XInput extension. Used to identify XInput events. |
258 int xi_opcode_; | 244 int xi_opcode_; |
259 | 245 |
260 // A quick lookup table for determining if the XI event is an XIDeviceEvent. | 246 // A quick lookup table for determining if the XI event is an XIDeviceEvent. |
261 std::bitset<kMaxXIEventType> xi_device_event_types_; | 247 std::bitset<kMaxXIEventType> xi_device_event_types_; |
262 | 248 |
263 // A quick lookup table for determining if events from the pointer device | 249 // A quick lookup table for determining if events from the pointer device |
(...skipping 25 matching lines...) Expand all Loading... | |
289 // doesn't think X/device doesn't know about the valuators. We currently | 275 // doesn't think X/device doesn't know about the valuators. We currently |
290 // use this only on touchscreen devices. | 276 // use this only on touchscreen devices. |
291 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; | 277 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; |
292 | 278 |
293 // X11 atoms cache. | 279 // X11 atoms cache. |
294 X11AtomCache atom_cache_; | 280 X11AtomCache atom_cache_; |
295 | 281 |
296 unsigned char button_map_[256]; | 282 unsigned char button_map_[256]; |
297 int button_map_count_; | 283 int button_map_count_; |
298 | 284 |
299 // Table to keep track of which display id is mapped to which touch device. | 285 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); |
300 int64 touch_device_to_display_map_[kMaxDeviceNum]; | |
301 // Index table to find the TouchTransformer for a touch device. | |
302 gfx::Transform touch_device_transformer_map_[kMaxDeviceNum]; | |
303 | |
304 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager); | |
305 }; | 286 }; |
306 | 287 |
307 } // namespace ui | 288 } // namespace ui |
308 | 289 |
309 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 290 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ |
OLD | NEW |