Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: ui/events/devices/x11/device_data_manager_x11.h

Issue 688253002: Implemented smooth scrolling using xinput2 in X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Applied comments, moved zoom handling to issue 1554253004 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // A bitfield describing which scroll axes are enabled for a device.
44 enum ScrollType {
45 SCROLL_TYPE_NO_SCROLL = 0,
46 SCROLL_TYPE_HORIZONTAL = 1 << 0,
47 SCROLL_TYPE_VERTICAL = 1 << 1,
48 };
49
43 // A class that extracts and tracks the input events data. It currently handles 50 // A class that extracts and tracks the input events data. It currently handles
44 // mouse, touchpad and touchscreen devices. 51 // mouse, touchpad and touchscreen devices.
45 class EVENTS_DEVICES_EXPORT DeviceDataManagerX11 : public DeviceDataManager { 52 class EVENTS_DEVICES_EXPORT DeviceDataManagerX11 : public DeviceDataManager {
46 public: 53 public:
47 // Enumerate additional data that one might be interested on an input event, 54 // 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, 55 // 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 56 // make sure to update the kCachedAtoms data structure in the source file
50 // and the k*Type[Start/End] constants used by IsCMTDataType and 57 // and the k*Type[Start/End] constants used by IsCMTDataType and
51 // IsTouchDataType. 58 // IsTouchDataType.
52 enum DataType { 59 enum DataType {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; 152 bool IsXIDeviceEvent(const base::NativeEvent& native_event) const;
146 153
147 // Check if the event comes from touchpad devices. 154 // Check if the event comes from touchpad devices.
148 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; 155 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const;
149 156
150 // Check if the event comes from devices running CMT driver or using 157 // 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 158 // 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). 159 // is a CMT event (e.g. it could be a mouse pointer move).
153 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; 160 bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const;
154 161
162 // Check if the event contains information about a ScrollClass, and
163 // report which scroll axes are contained in this event, defined by
164 // ScrollType.
165 int GetScrollClassEventDetail(const base::NativeEvent& native_event) const;
166
167 // Check if the event comes from a device that has a ScrollClass, and
168 // report which scroll axes it supports as a bit field, defined by
169 // ScrollType.
170 int GetScrollClassDeviceDetail(const base::NativeEvent& native_event) const;
171
155 // Check if the event is one of the CMT gesture events (scroll, fling, 172 // Check if the event is one of the CMT gesture events (scroll, fling,
156 // metrics etc.). 173 // metrics etc.).
157 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; 174 bool IsCMTGestureEvent(const base::NativeEvent& native_event) const;
158 175
159 // Returns true if the event is of the specific type, false if not. 176 // Returns true if the event is of the specific type, false if not.
160 bool IsScrollEvent(const base::NativeEvent& native_event) const; 177 bool IsScrollEvent(const base::NativeEvent& native_event) const;
161 bool IsFlingEvent(const base::NativeEvent& native_event) const; 178 bool IsFlingEvent(const base::NativeEvent& native_event) const;
162 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; 179 bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const;
163 180
164 // Returns true if the event has CMT start/end timestamps. 181 // Returns true if the event has CMT start/end timestamps.
165 bool HasGestureTimes(const base::NativeEvent& native_event) const; 182 bool HasGestureTimes(const base::NativeEvent& native_event) const;
166 183
167 // Extract data from a scroll event (a motion event with the necessary 184 // Extract data from a scroll event (a motion event with the necessary
168 // valuators). User must first verify the event type with IsScrollEvent. 185 // valuators). User must first verify the event type with IsScrollEvent.
169 // Pointers shouldn't be NULL. 186 // Pointers shouldn't be NULL.
170 void GetScrollOffsets(const base::NativeEvent& native_event, 187 void GetScrollOffsets(const base::NativeEvent& native_event,
171 float* x_offset, 188 float* x_offset,
172 float* y_offset, 189 float* y_offset,
173 float* x_offset_ordinal, 190 float* x_offset_ordinal,
174 float* y_offset_ordinal, 191 float* y_offset_ordinal,
175 int* finger_count); 192 int* finger_count);
176 193
194 // Extract data from a scroll class event (smooth scrolling). User must
195 // first verify the event type with GetScrollClassEventDetail.
196 // Pointers shouldn't be NULL.
197 void GetScrollClassOffsets(const base::NativeEvent& native_event,
198 double* x_offset,
199 double* y_offset);
200
201 // Invalidate stored scroll class counters, since they can change when
202 // pointing at other windows.
203 void InvalidateScrollClasses();
204
177 // Extract data from a fling event. User must first verify the event type 205 // Extract data from a fling event. User must first verify the event type
178 // with IsFlingEvent. Pointers shouldn't be NULL. 206 // with IsFlingEvent. Pointers shouldn't be NULL.
179 void GetFlingData(const base::NativeEvent& native_event, 207 void GetFlingData(const base::NativeEvent& native_event,
180 float* vx, 208 float* vx,
181 float* vy, 209 float* vy,
182 float* vx_ordinal, 210 float* vx_ordinal,
183 float* vy_ordinal, 211 float* vy_ordinal,
184 bool* is_cancel); 212 bool* is_cancel);
185 213
186 // Extract data from a CrOS metrics gesture event. User must first verify 214 // Extract data from a CrOS metrics gesture event. User must first verify
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const std::vector<int>& master_pointers() const { 276 const std::vector<int>& master_pointers() const {
249 return master_pointers_; 277 return master_pointers_;
250 } 278 }
251 279
252 protected: 280 protected:
253 // DeviceHotplugEventObserver: 281 // DeviceHotplugEventObserver:
254 void OnKeyboardDevicesUpdated( 282 void OnKeyboardDevicesUpdated(
255 const std::vector<KeyboardDevice>& devices) override; 283 const std::vector<KeyboardDevice>& devices) override;
256 284
257 private: 285 private:
286 // Information about scroll valuators
287 struct ScrollInfo {
288 struct AxisInfo {
289 // The scroll valuator number of this scroll axis.
290 int number;
291 // The scroll increment; a value of n indicates n movement equals one
292 // traditional scroll unit.
293 double increment;
294 // Current scroll position; used to find the difference between events.
295 double position;
296 // If true then scroll has been seen in this direction.
297 bool seen;
298 };
299
300 AxisInfo vertical, horizontal;
301 };
302
258 DeviceDataManagerX11(); 303 DeviceDataManagerX11();
259 ~DeviceDataManagerX11() override; 304 ~DeviceDataManagerX11() override;
260 305
261 // Initialize the XInput related system information. 306 // Initialize the XInput related system information.
262 bool InitializeXInputInternal(); 307 bool InitializeXInputInternal();
263 308
264 void InitializeValuatorsForTest(int deviceid, 309 void InitializeValuatorsForTest(int deviceid,
265 int start_valuator, 310 int start_valuator,
266 int end_valuator, 311 int end_valuator,
267 double min_value, 312 double min_value,
268 double max_value); 313 double max_value);
269 314
315 // Updates a device based on a Valuator class info. Returns true if the
316 // device is a possible CMT device.
317 bool UpdateValuatorClassDevice(XIValuatorClassInfo* valuator_class_info,
318 Atom* atoms,
319 int deviceid);
320
321 // Updates a device based on a Scroll class info.
322 void UpdateScrollClassDevice(XIScrollClassInfo* scroll_class_info,
323 int deviceid);
324
325 // Normalize the scroll amount according to the increment size.
326 // *value /= increment
327 // *value is expected to be 1 or -1.
328 // Returns true and sets the normalized value in |value| if normalization is
329 // successful. Returns false and |value| is unchanged otherwise.
330 double ExtractAndUpdateScrollOffset(
sadrul 2016/01/05 16:46:23 single space after double
Will Shackleton 2016/01/05 21:27:02 Done.
331 DeviceDataManagerX11::ScrollInfo::AxisInfo* axis,
332 double valuator) const;
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698