Chromium Code Reviews| 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_DEVICES_X11_DEVICE_DATA_MANAGER_X11_H_ | 5 #ifndef UI_EVENTS_DEVICES_X11_DEVICE_DATA_MANAGER_X11_H_ |
| 6 #define UI_EVENTS_DEVICES_X11_DEVICE_DATA_MANAGER_X11_H_ | 6 #define UI_EVENTS_DEVICES_X11_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. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 typedef union _XEvent XEvent; | 33 typedef union _XEvent XEvent; |
| 34 | 34 |
| 35 namespace ui { | 35 namespace ui { |
| 36 | 36 |
| 37 // CrOS touchpad metrics gesture types | 37 // CrOS touchpad metrics gesture types |
| 38 enum GestureMetricsType { | 38 enum GestureMetricsType { |
| 39 kGestureMetricsTypeNoisyGround = 0, | 39 kGestureMetricsTypeNoisyGround = 0, |
| 40 kGestureMetricsTypeUnknown, | 40 kGestureMetricsTypeUnknown, |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Information about scroll valuators | |
| 44 struct ScrollInfo { | |
| 45 struct AxisInfo { | |
| 46 // The scroll valuator number of this scroll axis. | |
| 47 int number; | |
| 48 // The scroll increment; a value of n indicates n movement equals one | |
| 49 // traditional scroll unit. | |
| 50 double increment; | |
| 51 // Current scroll position; used to find the difference between events. | |
| 52 double position; | |
| 53 // If true then scroll has been seen in this direction. | |
| 54 bool seen; | |
| 55 }; | |
| 56 | |
| 57 AxisInfo vertical, horizontal; | |
| 58 }; | |
| 59 | |
| 60 // A bitfield describing which scroll axes are enabled for a device. | |
| 61 enum ScrollType { | |
| 62 SCROLL_TYPE_NO_SCROLL = 0, | |
| 63 SCROLL_TYPE_HORIZONTAL = 1 << 0, | |
| 64 SCROLL_TYPE_VERTICAL = 1 << 1, | |
| 65 }; | |
| 66 | |
| 43 // A class that extracts and tracks the input events data. It currently handles | 67 // A class that extracts and tracks the input events data. It currently handles |
| 44 // mouse, touchpad and touchscreen devices. | 68 // mouse, touchpad and touchscreen devices. |
| 45 class EVENTS_DEVICES_EXPORT DeviceDataManagerX11 : public DeviceDataManager { | 69 class EVENTS_DEVICES_EXPORT DeviceDataManagerX11 : public DeviceDataManager { |
| 46 public: | 70 public: |
| 47 // Enumerate additional data that one might be interested on an input event, | 71 // 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, | 72 // 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 | 73 // make sure to update the kCachedAtoms data structure in the source file |
| 50 // and the k*Type[Start/End] constants used by IsCMTDataType and | 74 // and the k*Type[Start/End] constants used by IsCMTDataType and |
| 51 // IsTouchDataType. | 75 // IsTouchDataType. |
| 52 enum DataType { | 76 enum DataType { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 136 |
| 113 // Returns the DeviceDataManagerX11 singleton. | 137 // Returns the DeviceDataManagerX11 singleton. |
| 114 static DeviceDataManagerX11* GetInstance(); | 138 static DeviceDataManagerX11* GetInstance(); |
| 115 | 139 |
| 116 // Returns if XInput2 is available on the system. | 140 // Returns if XInput2 is available on the system. |
| 117 bool IsXInput2Available() const; | 141 bool IsXInput2Available() const; |
| 118 | 142 |
| 119 // Updates the list of devices. | 143 // Updates the list of devices. |
| 120 void UpdateDeviceList(Display* display); | 144 void UpdateDeviceList(Display* display); |
| 121 | 145 |
| 146 // Updates a device based on a Valuator class info. Returns true if the | |
| 147 // device is a possible CMT device. | |
| 148 bool UpdateValuatorClassDevice(XIValuatorClassInfo* valuator_class_info, | |
| 149 Atom *atoms, | |
| 150 int deviceid); | |
|
sadrul
2015/08/18 16:57:46
This doesn't need to be public, does it?
Will Shackleton
2015/08/26 19:52:48
Acknowledged.
| |
| 151 | |
| 152 // Updates a device based on a Scroll class info. | |
| 153 void UpdateScrollClassDevice(XIScrollClassInfo* scroll_class_info, | |
| 154 int deviceid); | |
|
sadrul
2015/08/18 16:57:46
ditto
Will Shackleton
2015/08/26 19:52:48
Acknowledged.
| |
| 155 | |
| 122 // For multitouch events we use slot number to distinguish touches from | 156 // For multitouch events we use slot number to distinguish touches from |
| 123 // different fingers. This function returns true if the associated slot | 157 // different fingers. This function returns true if the associated slot |
| 124 // for |xiev| can be found and it is saved in |slot|, returns false if | 158 // for |xiev| can be found and it is saved in |slot|, returns false if |
| 125 // no slot can be found. | 159 // no slot can be found. |
| 126 bool GetSlotNumber(const XIDeviceEvent* xiev, int* slot); | 160 bool GetSlotNumber(const XIDeviceEvent* xiev, int* slot); |
| 127 | 161 |
| 128 // Get all event data in one pass. We extract only data types that we know | 162 // Get all event data in one pass. We extract only data types that we know |
| 129 // about (defined in enum DataType). The data is not processed (e.g. not | 163 // about (defined in enum DataType). The data is not processed (e.g. not |
| 130 // filled in by cached values) as in GetEventData. | 164 // filled in by cached values) as in GetEventData. |
| 131 void GetEventRawData(const XEvent& xev, EventData* data); | 165 void GetEventRawData(const XEvent& xev, EventData* data); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 142 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; | 176 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; |
| 143 | 177 |
| 144 // Check if the event comes from touchpad devices. | 178 // Check if the event comes from touchpad devices. |
| 145 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; | 179 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; |
| 146 | 180 |
| 147 // Check if the event comes from devices running CMT driver or using | 181 // Check if the event comes from devices running CMT driver or using |
| 148 // CMT valuators (e.g. mouses). Note that doesn't necessarily mean the event | 182 // CMT valuators (e.g. mouses). Note that doesn't necessarily mean the event |
| 149 // is a CMT event (e.g. it could be a mouse pointer move). | 183 // is a CMT event (e.g. it could be a mouse pointer move). |
| 150 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; | 184 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; |
| 151 | 185 |
| 186 // Check if the event contains information about a ScrollClass, and | |
| 187 // report which scroll axes are contained in this event, defined by | |
| 188 // ScrollInfo. | |
| 189 int GetScrollClassEventDetail(const base::NativeEvent& native_event) const; | |
| 190 | |
| 191 // Check if the event comes from a device that has a ScrollClass, and | |
| 192 // report which scroll axes it supports as a bit field, defined by | |
| 193 // ScrollInfo. | |
| 194 int GetScrollClassDeviceDetail(const base::NativeEvent& native_event) const; | |
| 195 | |
| 152 // Check if the event is one of the CMT gesture events (scroll, fling, | 196 // Check if the event is one of the CMT gesture events (scroll, fling, |
| 153 // metrics etc.). | 197 // metrics etc.). |
| 154 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; | 198 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; |
| 155 | 199 |
| 156 // Returns true if the event is of the specific type, false if not. | 200 // Returns true if the event is of the specific type, false if not. |
| 157 bool IsScrollEvent(const base::NativeEvent& native_event) const; | 201 bool IsScrollEvent(const base::NativeEvent& native_event) const; |
| 158 bool IsFlingEvent(const base::NativeEvent& native_event) const; | 202 bool IsFlingEvent(const base::NativeEvent& native_event) const; |
| 159 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; | 203 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; |
| 160 | 204 |
| 161 // Returns true if the event has CMT start/end timestamps. | 205 // Returns true if the event has CMT start/end timestamps. |
| 162 bool HasGestureTimes(const base::NativeEvent& native_event) const; | 206 bool HasGestureTimes(const base::NativeEvent& native_event) const; |
| 163 | 207 |
| 164 // Extract data from a scroll event (a motion event with the necessary | 208 // Extract data from a scroll event (a motion event with the necessary |
| 165 // valuators). User must first verify the event type with IsScrollEvent. | 209 // valuators). User must first verify the event type with IsScrollEvent. |
| 166 // Pointers shouldn't be NULL. | 210 // Pointers shouldn't be NULL. |
| 167 void GetScrollOffsets(const base::NativeEvent& native_event, | 211 void GetScrollOffsets(const base::NativeEvent& native_event, |
| 168 float* x_offset, | 212 float* x_offset, |
| 169 float* y_offset, | 213 float* y_offset, |
| 170 float* x_offset_ordinal, | 214 float* x_offset_ordinal, |
| 171 float* y_offset_ordinal, | 215 float* y_offset_ordinal, |
| 172 int* finger_count); | 216 int* finger_count); |
| 173 | 217 |
| 218 // Extract data from a scroll class event (smooth scrolling). User must | |
| 219 // first verify the event type with GetScrollClassEventDetail. | |
| 220 // Pointers shouldn't be NULL. | |
| 221 void GetScrollClassOffsets(const base::NativeEvent& native_event, | |
| 222 double* x_offset, | |
| 223 double* y_offset); | |
| 224 | |
| 225 // Invalidate stored scroll class counters, since they can change when | |
| 226 // pointing at other windows. | |
| 227 void InvalidateScrollClasses(); | |
| 228 | |
| 174 // Extract data from a fling event. User must first verify the event type | 229 // Extract data from a fling event. User must first verify the event type |
| 175 // with IsFlingEvent. Pointers shouldn't be NULL. | 230 // with IsFlingEvent. Pointers shouldn't be NULL. |
| 176 void GetFlingData(const base::NativeEvent& native_event, | 231 void GetFlingData(const base::NativeEvent& native_event, |
| 177 float* vx, | 232 float* vx, |
| 178 float* vy, | 233 float* vy, |
| 179 float* vx_ordinal, | 234 float* vx_ordinal, |
| 180 float* vy_ordinal, | 235 float* vy_ordinal, |
| 181 bool* is_cancel); | 236 bool* is_cancel); |
| 182 | 237 |
| 183 // Extract data from a CrOS metrics gesture event. User must first verify | 238 // Extract data from a CrOS metrics gesture event. User must first verify |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 201 double* end_time); | 256 double* end_time); |
| 202 | 257 |
| 203 // Normalize the data value on deviceid to fall into [0, 1]. | 258 // Normalize the data value on deviceid to fall into [0, 1]. |
| 204 // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp) | 259 // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp) |
| 205 // Returns true and sets the normalized value in|value| if normalization is | 260 // Returns true and sets the normalized value in|value| if normalization is |
| 206 // successful. Returns false and |value| is unchanged otherwise. | 261 // successful. Returns false and |value| is unchanged otherwise. |
| 207 bool NormalizeData(int deviceid, | 262 bool NormalizeData(int deviceid, |
| 208 const DataType type, | 263 const DataType type, |
| 209 double* value); | 264 double* value); |
| 210 | 265 |
| 266 // Normalize the scroll amount according to the increment size. | |
| 267 // *value /= increment | |
| 268 // *value is expected to be 1 or -1. | |
| 269 // Returns true and sets the normalized value in |value| if normalization is | |
| 270 // successful. Returns false and |value| is unchanged otherwise. | |
| 271 bool NormalizeScrollData(unsigned int deviceid, | |
| 272 bool horizontal, | |
| 273 double* value); | |
| 274 | |
| 211 // Extract the range of the data type. Return true if the range is available | 275 // Extract the range of the data type. Return true if the range is available |
| 212 // and written into min & max, false if the range is not available. | 276 // and written into min & max, false if the range is not available. |
| 213 bool GetDataRange(int deviceid, | 277 bool GetDataRange(int deviceid, |
| 214 const DataType type, | 278 const DataType type, |
| 215 double* min, | 279 double* min, |
| 216 double* max); | 280 double* max); |
| 217 | 281 |
| 218 // Sets up relevant valuator informations for device ids in the device lists. | 282 // Sets up relevant valuator informations for device ids in the device lists. |
| 219 // This function is only for test purpose. It does not query the X server for | 283 // This function is only for test purpose. It does not query the X server for |
| 220 // the actual device info, but rather inits the relevant valuator structures | 284 // the actual device info, but rather inits the relevant valuator structures |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 // Major opcode for the XInput extension. Used to identify XInput events. | 334 // Major opcode for the XInput extension. Used to identify XInput events. |
| 271 int xi_opcode_; | 335 int xi_opcode_; |
| 272 | 336 |
| 273 // A quick lookup table for determining if the XI event is an XIDeviceEvent. | 337 // A quick lookup table for determining if the XI event is an XIDeviceEvent. |
| 274 std::bitset<kMaxXIEventType> xi_device_event_types_; | 338 std::bitset<kMaxXIEventType> xi_device_event_types_; |
| 275 | 339 |
| 276 // A quick lookup table for determining if events from the pointer device | 340 // A quick lookup table for determining if events from the pointer device |
| 277 // should be processed. | 341 // should be processed. |
| 278 std::bitset<kMaxDeviceNum> cmt_devices_; | 342 std::bitset<kMaxDeviceNum> cmt_devices_; |
| 279 std::bitset<kMaxDeviceNum> touchpads_; | 343 std::bitset<kMaxDeviceNum> touchpads_; |
| 344 std::bitset<kMaxDeviceNum> scrollclass_devices_; | |
| 280 | 345 |
| 281 // List of the master pointer devices. | 346 // List of the master pointer devices. |
| 282 std::vector<int> master_pointers_; | 347 std::vector<int> master_pointers_; |
| 283 | 348 |
| 284 // A quick lookup table for determining if events from the XI device | 349 // A quick lookup table for determining if events from the XI device |
| 285 // should be blocked. | 350 // should be blocked. |
| 286 std::bitset<kMaxDeviceNum> blocked_devices_; | 351 std::bitset<kMaxDeviceNum> blocked_devices_; |
| 287 | 352 |
| 288 // The set of keys allowed while the keyboard is blocked. | 353 // The set of keys allowed while the keyboard is blocked. |
| 289 scoped_ptr<std::set<KeyboardCode> > blocked_keyboard_allowed_keys_; | 354 scoped_ptr<std::set<KeyboardCode> > blocked_keyboard_allowed_keys_; |
| 290 | 355 |
| 291 // Number of valuators on the specific device. | 356 // Number of valuators on the specific device. |
| 292 int valuator_count_[kMaxDeviceNum]; | 357 int valuator_count_[kMaxDeviceNum]; |
| 293 | 358 |
| 294 // Index table to find the valuator for DataType on the specific device | 359 // Index table to find the valuator for DataType on the specific device |
| 295 // by valuator_lookup_[device_id][data_type]. | 360 // by valuator_lookup_[device_id][data_type]. |
| 296 std::vector<int> valuator_lookup_[kMaxDeviceNum]; | 361 std::vector<int> valuator_lookup_[kMaxDeviceNum]; |
| 297 | 362 |
| 363 // Index table to find the horizontal and vertical scroll valuator | |
| 364 // numbers, scroll increments and scroll position. | |
| 365 ScrollInfo scroll_data_[kMaxDeviceNum]; | |
| 366 | |
| 298 // Index table to find the DataType for valuator on the specific device | 367 // Index table to find the DataType for valuator on the specific device |
| 299 // by data_type_lookup_[device_id][valuator]. | 368 // by data_type_lookup_[device_id][valuator]. |
| 300 std::vector<int> data_type_lookup_[kMaxDeviceNum]; | 369 std::vector<int> data_type_lookup_[kMaxDeviceNum]; |
| 301 | 370 |
| 302 // Index table to find the min & max value of the Valuator on a specific | 371 // Index table to find the min & max value of the Valuator on a specific |
| 303 // device. | 372 // device. |
| 304 std::vector<double> valuator_min_[kMaxDeviceNum]; | 373 std::vector<double> valuator_min_[kMaxDeviceNum]; |
| 305 std::vector<double> valuator_max_[kMaxDeviceNum]; | 374 std::vector<double> valuator_max_[kMaxDeviceNum]; |
| 306 | 375 |
| 307 // Table to keep track of the last seen value for the specified valuator for | 376 // Table to keep track of the last seen value for the specified valuator for |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 322 | 391 |
| 323 unsigned char button_map_[256]; | 392 unsigned char button_map_[256]; |
| 324 int button_map_count_; | 393 int button_map_count_; |
| 325 | 394 |
| 326 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); | 395 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); |
| 327 }; | 396 }; |
| 328 | 397 |
| 329 } // namespace ui | 398 } // namespace ui |
| 330 | 399 |
| 331 #endif // UI_EVENTS_DEVICES_X11_DEVICE_DATA_MANAGER_X11_H_ | 400 #endif // UI_EVENTS_DEVICES_X11_DEVICE_DATA_MANAGER_X11_H_ |
| OLD | NEW |