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