| 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. |
| (...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_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager { | 69 class EVENTS_BASE_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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; | 166 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; |
| 143 | 167 |
| 144 // Check if the event comes from touchpad devices. | 168 // Check if the event comes from touchpad devices. |
| 145 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; | 169 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; |
| 146 | 170 |
| 147 // Check if the event comes from devices running CMT driver or using | 171 // 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 | 172 // 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). | 173 // is a CMT event (e.g. it could be a mouse pointer move). |
| 150 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; | 174 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; |
| 151 | 175 |
| 176 // Check if the event contains information about a ScrollClass, and |
| 177 // report which scroll axes are contained in this event, defined by |
| 178 // ScrollInfo. |
| 179 int GetScrollClassEventDetail(const base::NativeEvent& native_event) const; |
| 180 |
| 181 // Check if the event comes from a device that has a ScrollClass, and |
| 182 // report which scroll axes it supports as a bit field, defined by |
| 183 // ScrollInfo. |
| 184 int GetScrollClassDeviceDetail(const base::NativeEvent& native_event) const; |
| 185 |
| 152 // Check if the event is one of the CMT gesture events (scroll, fling, | 186 // Check if the event is one of the CMT gesture events (scroll, fling, |
| 153 // metrics etc.). | 187 // metrics etc.). |
| 154 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; | 188 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; |
| 155 | 189 |
| 156 // Returns true if the event is of the specific type, false if not. | 190 // Returns true if the event is of the specific type, false if not. |
| 157 bool IsScrollEvent(const base::NativeEvent& native_event) const; | 191 bool IsScrollEvent(const base::NativeEvent& native_event) const; |
| 158 bool IsFlingEvent(const base::NativeEvent& native_event) const; | 192 bool IsFlingEvent(const base::NativeEvent& native_event) const; |
| 159 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; | 193 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; |
| 160 | 194 |
| 161 // Returns true if the event has CMT start/end timestamps. | 195 // Returns true if the event has CMT start/end timestamps. |
| 162 bool HasGestureTimes(const base::NativeEvent& native_event) const; | 196 bool HasGestureTimes(const base::NativeEvent& native_event) const; |
| 163 | 197 |
| 164 // Extract data from a scroll event (a motion event with the necessary | 198 // Extract data from a scroll event (a motion event with the necessary |
| 165 // valuators). User must first verify the event type with IsScrollEvent. | 199 // valuators). User must first verify the event type with IsScrollEvent. |
| 166 // Pointers shouldn't be NULL. | 200 // Pointers shouldn't be NULL. |
| 167 void GetScrollOffsets(const base::NativeEvent& native_event, | 201 void GetScrollOffsets(const base::NativeEvent& native_event, |
| 168 float* x_offset, | 202 float* x_offset, |
| 169 float* y_offset, | 203 float* y_offset, |
| 170 float* x_offset_ordinal, | 204 float* x_offset_ordinal, |
| 171 float* y_offset_ordinal, | 205 float* y_offset_ordinal, |
| 172 int* finger_count); | 206 int* finger_count); |
| 173 | 207 |
| 208 // Extract data from a scroll class event (smooth scrolling). User must |
| 209 // first verify the event type with GetScrollClassEventDetail. |
| 210 // Pointers shouldn't be NULL. |
| 211 void GetScrollClassOffsets(const base::NativeEvent& native_event, |
| 212 double* x_offset, |
| 213 double* y_offset); |
| 214 |
| 215 // Invalidate stored scroll class counters, since they can change when |
| 216 // pointing at other windows. |
| 217 void InvalidateScrollClasses(); |
| 218 |
| 174 // Extract data from a fling event. User must first verify the event type | 219 // Extract data from a fling event. User must first verify the event type |
| 175 // with IsFlingEvent. Pointers shouldn't be NULL. | 220 // with IsFlingEvent. Pointers shouldn't be NULL. |
| 176 void GetFlingData(const base::NativeEvent& native_event, | 221 void GetFlingData(const base::NativeEvent& native_event, |
| 177 float* vx, | 222 float* vx, |
| 178 float* vy, | 223 float* vy, |
| 179 float* vx_ordinal, | 224 float* vx_ordinal, |
| 180 float* vy_ordinal, | 225 float* vy_ordinal, |
| 181 bool* is_cancel); | 226 bool* is_cancel); |
| 182 | 227 |
| 183 // Extract data from a CrOS metrics gesture event. User must first verify | 228 // Extract data from a CrOS metrics gesture event. User must first verify |
| (...skipping 17 matching lines...) Expand all Loading... |
| 201 double* end_time); | 246 double* end_time); |
| 202 | 247 |
| 203 // Normalize the data value on deviceid to fall into [0, 1]. | 248 // 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) | 249 // *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 | 250 // Returns true and sets the normalized value in|value| if normalization is |
| 206 // successful. Returns false and |value| is unchanged otherwise. | 251 // successful. Returns false and |value| is unchanged otherwise. |
| 207 bool NormalizeData(unsigned int deviceid, | 252 bool NormalizeData(unsigned int deviceid, |
| 208 const DataType type, | 253 const DataType type, |
| 209 double* value); | 254 double* value); |
| 210 | 255 |
| 256 // Normalize the scroll amount according to the increment size. |
| 257 // *value /= increment |
| 258 // *value is expected to be 1 or -1. |
| 259 // Returns true and sets the normalized value in |value| if normalization is |
| 260 // successful. Returns false and |value| is unchanged otherwise. |
| 261 bool NormalizeScrollData(unsigned int deviceid, |
| 262 bool horizontal, |
| 263 double* value); |
| 264 |
| 211 // Extract the range of the data type. Return true if the range is available | 265 // 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. | 266 // and written into min & max, false if the range is not available. |
| 213 bool GetDataRange(unsigned int deviceid, | 267 bool GetDataRange(unsigned int deviceid, |
| 214 const DataType type, | 268 const DataType type, |
| 215 double* min, | 269 double* min, |
| 216 double* max); | 270 double* max); |
| 217 | 271 |
| 218 // Sets up relevant valuator informations for device ids in the device lists. | 272 // 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 | 273 // 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 | 274 // the actual device info, but rather inits the relevant valuator structures |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Major opcode for the XInput extension. Used to identify XInput events. | 320 // Major opcode for the XInput extension. Used to identify XInput events. |
| 267 int xi_opcode_; | 321 int xi_opcode_; |
| 268 | 322 |
| 269 // A quick lookup table for determining if the XI event is an XIDeviceEvent. | 323 // A quick lookup table for determining if the XI event is an XIDeviceEvent. |
| 270 std::bitset<kMaxXIEventType> xi_device_event_types_; | 324 std::bitset<kMaxXIEventType> xi_device_event_types_; |
| 271 | 325 |
| 272 // A quick lookup table for determining if events from the pointer device | 326 // A quick lookup table for determining if events from the pointer device |
| 273 // should be processed. | 327 // should be processed. |
| 274 std::bitset<kMaxDeviceNum> cmt_devices_; | 328 std::bitset<kMaxDeviceNum> cmt_devices_; |
| 275 std::bitset<kMaxDeviceNum> touchpads_; | 329 std::bitset<kMaxDeviceNum> touchpads_; |
| 330 std::bitset<kMaxDeviceNum> scrollclass_devices_; |
| 276 | 331 |
| 277 // A quick lookup table for determining if events from the XI device | 332 // A quick lookup table for determining if events from the XI device |
| 278 // should be blocked. | 333 // should be blocked. |
| 279 std::bitset<kMaxDeviceNum> blocked_devices_; | 334 std::bitset<kMaxDeviceNum> blocked_devices_; |
| 280 | 335 |
| 281 // The set of keys allowed while the keyboard is blocked. | 336 // The set of keys allowed while the keyboard is blocked. |
| 282 scoped_ptr<std::set<KeyboardCode> > blocked_keyboard_allowed_keys_; | 337 scoped_ptr<std::set<KeyboardCode> > blocked_keyboard_allowed_keys_; |
| 283 | 338 |
| 284 // Number of valuators on the specific device. | 339 // Number of valuators on the specific device. |
| 285 int valuator_count_[kMaxDeviceNum]; | 340 int valuator_count_[kMaxDeviceNum]; |
| 286 | 341 |
| 287 // Index table to find the valuator for DataType on the specific device | 342 // Index table to find the valuator for DataType on the specific device |
| 288 // by valuator_lookup_[device_id][data_type]. | 343 // by valuator_lookup_[device_id][data_type]. |
| 289 std::vector<int> valuator_lookup_[kMaxDeviceNum]; | 344 std::vector<int> valuator_lookup_[kMaxDeviceNum]; |
| 290 | 345 |
| 346 // Index table to find the horizontal and vertical scroll valuator |
| 347 // numbers, scroll increments and scroll position. |
| 348 ScrollInfo scroll_data_[kMaxDeviceNum]; |
| 349 |
| 291 // Index table to find the DataType for valuator on the specific device | 350 // Index table to find the DataType for valuator on the specific device |
| 292 // by data_type_lookup_[device_id][valuator]. | 351 // by data_type_lookup_[device_id][valuator]. |
| 293 std::vector<int> data_type_lookup_[kMaxDeviceNum]; | 352 std::vector<int> data_type_lookup_[kMaxDeviceNum]; |
| 294 | 353 |
| 295 // Index table to find the min & max value of the Valuator on a specific | 354 // Index table to find the min & max value of the Valuator on a specific |
| 296 // device. | 355 // device. |
| 297 std::vector<double> valuator_min_[kMaxDeviceNum]; | 356 std::vector<double> valuator_min_[kMaxDeviceNum]; |
| 298 std::vector<double> valuator_max_[kMaxDeviceNum]; | 357 std::vector<double> valuator_max_[kMaxDeviceNum]; |
| 299 | 358 |
| 300 // Table to keep track of the last seen value for the specified valuator for | 359 // Table to keep track of the last seen value for the specified valuator for |
| (...skipping 14 matching lines...) Expand all Loading... |
| 315 | 374 |
| 316 unsigned char button_map_[256]; | 375 unsigned char button_map_[256]; |
| 317 int button_map_count_; | 376 int button_map_count_; |
| 318 | 377 |
| 319 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); | 378 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); |
| 320 }; | 379 }; |
| 321 | 380 |
| 322 } // namespace ui | 381 } // namespace ui |
| 323 | 382 |
| 324 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ | 383 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ |
| OLD | NEW |