| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_X11_H_ | 5 #ifndef UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ |
| 6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_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 <functional> |
| 18 #include <map> | 19 #include <map> |
| 19 #include <set> | 20 #include <set> |
| 20 #include <vector> | 21 #include <vector> |
| 21 | 22 |
| 22 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 23 #include "base/event_types.h" | 24 #include "base/event_types.h" |
| 24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 25 #include "ui/events/device_data_manager.h" | 26 #include "ui/events/device_data_manager.h" |
| 26 #include "ui/events/event_constants.h" | 27 #include "ui/events/event_constants.h" |
| 27 #include "ui/events/events_base_export.h" | 28 #include "ui/events/events_base_export.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 class EVENTS_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager { | 45 class EVENTS_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager { |
| 45 public: | 46 public: |
| 46 // Enumerate additional data that one might be interested on an input event, | 47 // Enumerate additional data that one might be interested on an input event, |
| 47 // which are usually wrapped in X valuators. If you modify any of this, | 48 // which are usually wrapped in X valuators. If you modify any of this, |
| 48 // make sure to update the kCachedAtoms data structure in the source file | 49 // make sure to update the kCachedAtoms data structure in the source file |
| 49 // and the k*Type[Start/End] constants used by IsCMTDataType and | 50 // and the k*Type[Start/End] constants used by IsCMTDataType and |
| 50 // IsTouchDataType. | 51 // IsTouchDataType. |
| 51 enum DataType { | 52 enum DataType { |
| 52 // Define the valuators used the CrOS CMT driver. Used by mice and CrOS | 53 // Define the valuators used the CrOS CMT driver. Used by mice and CrOS |
| 53 // touchpads. | 54 // touchpads. |
| 54 DT_CMT_SCROLL_X = 0, // Scroll amount on the X (horizontal) direction. | 55 DT_CMT_SCROLL_X = 0, // Scroll amount on the X (horizontal) direction. |
| 55 DT_CMT_SCROLL_Y, // Scroll amount on the Y (vertical) direction. | 56 DT_CMT_SCROLL_Y, // Scroll amount on the Y (vertical) direction. |
| 56 DT_CMT_ORDINAL_X, // Original (unaccelerated) value on the X direction. | 57 DT_CMT_ORDINAL_X, // Original (unaccelerated) value on the X direction. |
| 57 // Can be used both for scrolls and flings. | 58 // Can be used both for scrolls and flings. |
| 58 DT_CMT_ORDINAL_Y, // Original (unaccelerated) value on the Y direction. | 59 DT_CMT_ORDINAL_Y, // Original (unaccelerated) value on the Y direction. |
| 59 // Can be used both for scrolls and flings. | 60 // Can be used both for scrolls and flings. |
| 60 DT_CMT_START_TIME, // Gesture start time. | 61 DT_CMT_START_TIME, // Gesture start time. |
| 61 DT_CMT_END_TIME, // Gesture end time. | 62 DT_CMT_END_TIME, // Gesture end time. |
| 62 DT_CMT_FLING_X, // Fling amount on the X (horizontal) direction. | 63 DT_CMT_FLING_X, // Fling amount on the X (horizontal) direction. |
| 63 DT_CMT_FLING_Y, // Fling amount on the Y (vertical) direction. | 64 DT_CMT_FLING_Y, // Fling amount on the Y (vertical) direction. |
| 64 DT_CMT_FLING_STATE, // The state of fling gesture (whether the user just | 65 DT_CMT_FLING_STATE, // The state of fling gesture (whether the user just |
| 65 // start flinging or that he/she taps down). | 66 // start flinging or that he/she taps down). |
| 66 DT_CMT_METRICS_TYPE, // Metrics type of the metrics gesture, which are | 67 DT_CMT_METRICS_TYPE, // Metrics type of the metrics gesture, which are |
| 67 // used to wrap interesting patterns that we would | 68 // used to wrap interesting patterns that we would |
| 68 // like to track via the UMA system. | 69 // like to track via the UMA system. |
| 69 DT_CMT_METRICS_DATA1, // Complementary data 1 of the metrics gesture. | 70 DT_CMT_METRICS_DATA1, // Complementary data 1 of the metrics gesture. |
| 70 DT_CMT_METRICS_DATA2, // Complementary data 2 of the metrics gesture. | 71 DT_CMT_METRICS_DATA2, // Complementary data 2 of the metrics gesture. |
| 71 DT_CMT_FINGER_COUNT, // Finger counts in the current gesture. A same type | 72 DT_CMT_FINGER_COUNT, // Finger counts in the current gesture. A same type |
| 72 // of gesture can have very different meanings based | 73 // of gesture can have very different meanings based |
| 73 // on that (e.g. 2f scroll v.s. 3f swipe). | 74 // on that (e.g. 2f scroll v.s. 3f swipe). |
| 74 | 75 |
| 75 // End of CMT data types. | 76 // End of CMT data types. |
| 76 // Beginning of touch data types. | 77 // Beginning of touch data types. |
| 77 | 78 |
| 78 // Define the valuators following the Multi-touch Protocol. Used by | 79 // Define the valuators following the Multi-touch Protocol. Used by |
| 79 // touchscreen devices. | 80 // touchscreen devices. |
| 80 DT_TOUCH_MAJOR, // Length of the touch area. | 81 DT_TOUCH_MAJOR, // Length of the touch area. |
| 81 DT_TOUCH_MINOR, // Width of the touch area. | 82 DT_TOUCH_MINOR, // Width of the touch area. |
| 82 DT_TOUCH_ORIENTATION, // Angle between the X-axis and the major axis of the | 83 DT_TOUCH_ORIENTATION, // Angle between the X-axis and the major axis of the |
| 83 // touch area. | 84 // touch area. |
| 84 DT_TOUCH_PRESSURE, // Pressure of the touch contact. | 85 DT_TOUCH_PRESSURE, // Pressure of the touch contact. |
| 85 | 86 |
| 86 DT_TOUCH_POSITION_X, // Touch X position. | 87 DT_TOUCH_POSITION_X, // Touch X position. |
| 87 DT_TOUCH_POSITION_Y, // Touch Y position. | 88 DT_TOUCH_POSITION_Y, // Touch Y position. |
| 88 | 89 |
| 89 // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to | 90 // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to |
| 90 // track individual touch. 'Tracking ID' is an unsigned 32-bit value and | 91 // track individual touch. 'Tracking ID' is an unsigned 32-bit value and |
| 91 // is increased for each new touch. It will wrap back to 0 when reaching | 92 // is increased for each new touch. It will wrap back to 0 when reaching |
| 92 // the numerical limit. | 93 // the numerical limit. |
| 93 DT_TOUCH_TRACKING_ID, // ID of the touch point. | 94 DT_TOUCH_TRACKING_ID, // ID of the touch point. |
| 94 | 95 |
| 95 // Kernel timestamp from touch screen (if available). | 96 // Kernel timestamp from touch screen (if available). |
| 96 DT_TOUCH_RAW_TIMESTAMP, | 97 DT_TOUCH_RAW_TIMESTAMP, |
| 97 | 98 |
| 98 // End of touch data types. | 99 // End of touch data types. |
| 99 | 100 |
| 100 DT_LAST_ENTRY // This must come last. | 101 DT_LAST_ENTRY // This must come last. |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 // Data struct to store extracted data from an input event. | 104 // Data struct to store extracted data from an input event. |
| 104 typedef std::map<int, double> EventData; | 105 typedef std::map<int, double> EventData; |
| 105 | 106 |
| 106 static void CreateInstance(); | 107 static void CreateInstance(); |
| 107 | 108 |
| 108 // We use int because enums can be casted to ints but not vice versa. | 109 // We use int because enums can be casted to ints but not vice versa. |
| 109 static bool IsCMTDataType(const int type); | 110 static bool IsCMTDataType(const int type); |
| 110 static bool IsTouchDataType(const int type); | 111 static bool IsTouchDataType(const int type); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // This function is only for test purpose. It does not query the X server for | 219 // This function is only for test purpose. It does not query the X server for |
| 219 // the actual device info, but rather inits the relevant valuator structures | 220 // the actual device info, but rather inits the relevant valuator structures |
| 220 // to have safe default values for testing. | 221 // to have safe default values for testing. |
| 221 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, | 222 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, |
| 222 const std::vector<unsigned int>& cmt_devices); | 223 const std::vector<unsigned int>& cmt_devices); |
| 223 | 224 |
| 224 void SetValuatorDataForTest(XIDeviceEvent* xievent, | 225 void SetValuatorDataForTest(XIDeviceEvent* xievent, |
| 225 DataType type, | 226 DataType type, |
| 226 double value); | 227 double value); |
| 227 | 228 |
| 228 bool TouchEventNeedsCalibrate(int touch_device_id) const; | 229 bool TouchEventNeedsCalibrate(unsigned int touch_device_id) const; |
| 229 | 230 |
| 230 // Sets the keys which are still allowed on a disabled keyboard device. | 231 // Sets the keys which are still allowed on a disabled keyboard device. |
| 231 void SetDisabledKeyboardAllowedKeys( | 232 void SetDisabledKeyboardAllowedKeys( |
| 232 scoped_ptr<std::set<KeyboardCode> > excepted_keys); | 233 scoped_ptr<std::set<KeyboardCode> > excepted_keys); |
| 233 | 234 |
| 234 // Disables and enables events from devices by device id. | 235 // Disables and enables events from devices by device id. |
| 235 void DisableDevice(unsigned int deviceid); | 236 void DisableDevice(unsigned int deviceid); |
| 236 void EnableDevice(unsigned int deviceid); | 237 void EnableDevice(unsigned int deviceid); |
| 237 | 238 |
| 238 // Returns true if |native_event| should be blocked. | 239 // Returns true if |native_event| should be blocked. |
| 239 bool IsEventBlocked(const base::NativeEvent& native_event); | 240 bool IsEventBlocked(const base::NativeEvent& native_event); |
| 240 | 241 |
| 242 protected: |
| 243 // DeviceHotplugEventObserver: |
| 244 virtual void OnKeyboardDevicesUpdated( |
| 245 const std::vector<KeyboardDevice>& devices) override; |
| 246 |
| 241 private: | 247 private: |
| 242 DeviceDataManagerX11(); | 248 DeviceDataManagerX11(); |
| 243 virtual ~DeviceDataManagerX11(); | 249 virtual ~DeviceDataManagerX11(); |
| 244 | 250 |
| 245 // Initialize the XInput related system information. | 251 // Initialize the XInput related system information. |
| 246 bool InitializeXInputInternal(); | 252 bool InitializeXInputInternal(); |
| 247 | 253 |
| 248 // Check if an XI event contains data of the specified type. | 254 // Check if an XI event contains data of the specified type. |
| 249 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; | 255 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; |
| 250 | 256 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 299 |
| 294 // Table to keep track of the last seen value for the specified valuator for | 300 // Table to keep track of the last seen value for the specified valuator for |
| 295 // a specified slot of a device. Defaults to 0 if the valuator for that slot | 301 // a specified slot of a device. Defaults to 0 if the valuator for that slot |
| 296 // was not specified in an earlier event. With MT-B/XI2.2, valuators in an | 302 // was not specified in an earlier event. With MT-B/XI2.2, valuators in an |
| 297 // XEvent are not reported if the values haven't changed from the previous | 303 // XEvent are not reported if the values haven't changed from the previous |
| 298 // event. So it is necessary to remember these valuators so that chrome | 304 // event. So it is necessary to remember these valuators so that chrome |
| 299 // doesn't think X/device doesn't know about the valuators. We currently | 305 // doesn't think X/device doesn't know about the valuators. We currently |
| 300 // use this only on touchscreen devices. | 306 // use this only on touchscreen devices. |
| 301 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; | 307 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; |
| 302 | 308 |
| 309 // Map that stores meta-data for blocked keyboards. This is needed to restore |
| 310 // devices when they are re-enabled. |
| 311 std::map<unsigned int, ui::KeyboardDevice> blocked_keyboards_; |
| 312 |
| 303 // X11 atoms cache. | 313 // X11 atoms cache. |
| 304 X11AtomCache atom_cache_; | 314 X11AtomCache atom_cache_; |
| 305 | 315 |
| 306 unsigned char button_map_[256]; | 316 unsigned char button_map_[256]; |
| 307 int button_map_count_; | 317 int button_map_count_; |
| 308 | 318 |
| 309 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); | 319 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); |
| 310 }; | 320 }; |
| 311 | 321 |
| 312 } // namespace ui | 322 } // namespace ui |
| 313 | 323 |
| 314 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ | 324 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ |
| OLD | NEW |