| 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 static void CreateInstance(); |
| 103 |
| 104 // We use int because enums can be casted to ints but not vice versa. | 104 // We use int because enums can be casted to ints but not vice versa. |
| 105 static bool IsCMTDataType(const int type); | 105 static bool IsCMTDataType(const int type); |
| 106 static bool IsTouchDataType(const int type); | 106 static bool IsTouchDataType(const int type); |
| 107 | 107 |
| 108 // Returns the DeviceDataManager singleton. | 108 // Returns the DeviceDataManagerX11 singleton. |
| 109 static DeviceDataManager* GetInstance(); | 109 static DeviceDataManagerX11* GetInstance(); |
| 110 | 110 |
| 111 // Returns if XInput2 is available on the system. | 111 // Returns if XInput2 is available on the system. |
| 112 bool IsXInput2Available() const; | 112 bool IsXInput2Available() const; |
| 113 | 113 |
| 114 // Updates the list of devices. | 114 // Updates the list of devices. |
| 115 void UpdateDeviceList(Display* display); | 115 void UpdateDeviceList(Display* display); |
| 116 | 116 |
| 117 // For multitouch events we use slot number to distinguish touches from | 117 // For multitouch events we use slot number to distinguish touches from |
| 118 // different fingers. This function returns true if the associated slot | 118 // 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 | 119 // 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 | 214 // 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 | 215 // the actual device info, but rather inits the relevant valuator structures |
| 216 // to have safe default values for testing. | 216 // to have safe default values for testing. |
| 217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, | 217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, |
| 218 const std::vector<unsigned int>& cmt_devices); | 218 const std::vector<unsigned int>& cmt_devices); |
| 219 | 219 |
| 220 void SetValuatorDataForTest(XIDeviceEvent* xievent, | 220 void SetValuatorDataForTest(XIDeviceEvent* xievent, |
| 221 DataType type, | 221 DataType type, |
| 222 double value); | 222 double value); |
| 223 | 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 bool TouchEventNeedsCalibrate(int touch_device_id) const; | 224 bool TouchEventNeedsCalibrate(int touch_device_id) const; |
| 231 | 225 |
| 232 private: | 226 private: |
| 233 // Requirement for Singleton. | 227 DeviceDataManagerX11(); |
| 234 friend struct DefaultSingletonTraits<DeviceDataManager>; | 228 virtual ~DeviceDataManagerX11(); |
| 235 | |
| 236 DeviceDataManager(); | |
| 237 ~DeviceDataManager(); | |
| 238 | 229 |
| 239 // Initialize the XInput related system information. | 230 // Initialize the XInput related system information. |
| 240 bool InitializeXInputInternal(); | 231 bool InitializeXInputInternal(); |
| 241 | 232 |
| 242 // Check if an XI event contains data of the specified type. | 233 // Check if an XI event contains data of the specified type. |
| 243 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; | 234 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; |
| 244 | 235 |
| 245 void InitializeValuatorsForTest(int deviceid, | 236 void InitializeValuatorsForTest(int deviceid, |
| 246 int start_valuator, | 237 int start_valuator, |
| 247 int end_valuator, | 238 int end_valuator, |
| 248 double min_value, | 239 double min_value, |
| 249 double max_value); | 240 double max_value); |
| 250 | 241 |
| 251 bool IsTouchDeviceIdValid(int touch_device_id) const; | |
| 252 | |
| 253 static const int kMaxDeviceNum = 128; | |
| 254 static const int kMaxXIEventType = XI_LASTEVENT + 1; | 242 static const int kMaxXIEventType = XI_LASTEVENT + 1; |
| 255 static const int kMaxSlotNum = 10; | 243 static const int kMaxSlotNum = 10; |
| 256 | 244 |
| 257 // Major opcode for the XInput extension. Used to identify XInput events. | 245 // Major opcode for the XInput extension. Used to identify XInput events. |
| 258 int xi_opcode_; | 246 int xi_opcode_; |
| 259 | 247 |
| 260 // A quick lookup table for determining if the XI event is an XIDeviceEvent. | 248 // A quick lookup table for determining if the XI event is an XIDeviceEvent. |
| 261 std::bitset<kMaxXIEventType> xi_device_event_types_; | 249 std::bitset<kMaxXIEventType> xi_device_event_types_; |
| 262 | 250 |
| 263 // A quick lookup table for determining if events from the pointer device | 251 // 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 | 277 // doesn't think X/device doesn't know about the valuators. We currently |
| 290 // use this only on touchscreen devices. | 278 // use this only on touchscreen devices. |
| 291 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; | 279 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; |
| 292 | 280 |
| 293 // X11 atoms cache. | 281 // X11 atoms cache. |
| 294 X11AtomCache atom_cache_; | 282 X11AtomCache atom_cache_; |
| 295 | 283 |
| 296 unsigned char button_map_[256]; | 284 unsigned char button_map_[256]; |
| 297 int button_map_count_; | 285 int button_map_count_; |
| 298 | 286 |
| 299 // Table to keep track of which display id is mapped to which touch device. | 287 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 }; | 288 }; |
| 306 | 289 |
| 307 } // namespace ui | 290 } // namespace ui |
| 308 | 291 |
| 309 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ | 292 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ |
| OLD | NEW |