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

Side by Side Diff: ui/events/x/device_data_manager_x11.h

Issue 289283015: Extract touchscreen device management into a generic manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_H_ 5 #ifndef UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_
6 #define UI_EVENTS_X_DEVICE_DATA_MANAGER_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 <map> 18 #include <map>
19 #include <vector> 19 #include <vector>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "base/event_types.h" 22 #include "base/event_types.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "ui/events/device_data_manager.h"
24 #include "ui/events/event.h" 25 #include "ui/events/event.h"
25 #include "ui/events/event_constants.h" 26 #include "ui/events/event_constants.h"
26 #include "ui/events/events_base_export.h" 27 #include "ui/events/events_base_export.h"
27 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
28 #include "ui/gfx/transform.h"
29 #include "ui/gfx/x/x11_atom_cache.h" 29 #include "ui/gfx/x/x11_atom_cache.h"
30 30
31 template <typename T> struct DefaultSingletonTraits; 31 template <typename T> struct DefaultSingletonTraits;
32 32
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 class that extracts and tracks the input events data. It currently handles 43 // A class that extracts and tracks the input events data. It currently handles
44 // mouse, touchpad and touchscreen devices. 44 // mouse, touchpad and touchscreen devices.
45 class EVENTS_BASE_EXPORT DeviceDataManager { 45 class EVENTS_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager {
46 public: 46 public:
47 // 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,
48 // 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,
49 // 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
50 // and the k*Type[Start/End] constants used by IsCMTDataType and 50 // and the k*Type[Start/End] constants used by IsCMTDataType and
51 // IsTouchDataType. 51 // IsTouchDataType.
52 enum DataType { 52 enum DataType {
53 // 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
54 // touchpads. 54 // touchpads.
55 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.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 }; 99 };
100 100
101 // Data struct to store extracted data from an input event. 101 // Data struct to store extracted data from an input event.
102 typedef std::map<int, double> EventData; 102 typedef std::map<int, double> EventData;
103 103
104 // We use int because enums can be casted to ints but not vice versa. 104 // We use int because enums can be casted to ints but not vice versa.
105 static bool IsCMTDataType(const int type); 105 static bool IsCMTDataType(const int type);
106 static bool IsTouchDataType(const int type); 106 static bool IsTouchDataType(const int type);
107 107
108 // Returns the DeviceDataManager singleton. 108 // Returns the DeviceDataManager singleton.
109 static DeviceDataManager* GetInstance(); 109 static DeviceDataManagerX11* GetInstance();
110 110
111 // Returns if XInput2 is available on the system. 111 // Returns if XInput2 is available on the system.
112 bool IsXInput2Available() const; 112 bool IsXInput2Available() const;
113 113
114 // Updates the list of devices. 114 // Updates the list of devices.
115 void UpdateDeviceList(Display* display); 115 void UpdateDeviceList(Display* display);
116 116
117 // For multitouch events we use slot number to distinguish touches from 117 // For multitouch events we use slot number to distinguish touches from
118 // different fingers. This function returns true if the associated slot 118 // different fingers. This function returns true if the associated slot
119 // for |xiev| can be found and it is saved in |slot|, returns false if 119 // for |xiev| can be found and it is saved in |slot|, returns false if
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // This function is only for test purpose. It does not query the X server for 214 // This function is only for test purpose. It does not query the X server for
215 // the actual device info, but rather inits the relevant valuator structures 215 // the actual device info, but rather inits the relevant valuator structures
216 // to have safe default values for testing. 216 // to have safe default values for testing.
217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, 217 void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen,
218 const std::vector<unsigned int>& cmt_devices); 218 const std::vector<unsigned int>& cmt_devices);
219 219
220 void SetValuatorDataForTest(XIDeviceEvent* xievent, 220 void SetValuatorDataForTest(XIDeviceEvent* xievent,
221 DataType type, 221 DataType type,
222 double value); 222 double value);
223 223
224 void ClearTouchTransformerRecord();
225 void UpdateTouchInfoForDisplay(int64 display_id,
226 int touch_device_id,
227 const gfx::Transform& touch_transformer);
228 void ApplyTouchTransformer(int touch_device_id, float* x, float* y);
229 int64 GetDisplayForTouchDevice(int touch_device_id) const;
230 bool TouchEventNeedsCalibrate(int touch_device_id) const; 224 bool TouchEventNeedsCalibrate(int touch_device_id) const;
231 225
232 private: 226 private:
233 // Requirement for Singleton. 227 friend struct DefaultSingletonTraits<DeviceDataManagerX11>;
234 friend struct DefaultSingletonTraits<DeviceDataManager>;
235 228
236 DeviceDataManager(); 229 DeviceDataManagerX11();
237 ~DeviceDataManager(); 230 virtual ~DeviceDataManagerX11();
238 231
239 // Initialize the XInput related system information. 232 // Initialize the XInput related system information.
240 bool InitializeXInputInternal(); 233 bool InitializeXInputInternal();
241 234
242 // Check if an XI event contains data of the specified type. 235 // Check if an XI event contains data of the specified type.
243 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; 236 bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const;
244 237
245 void InitializeValuatorsForTest(int deviceid, 238 void InitializeValuatorsForTest(int deviceid,
246 int start_valuator, 239 int start_valuator,
247 int end_valuator, 240 int end_valuator,
248 double min_value, 241 double min_value,
249 double max_value); 242 double max_value);
250 243
251 bool IsTouchDeviceIdValid(int touch_device_id) const;
252
253 static const int kMaxDeviceNum = 128;
254 static const int kMaxXIEventType = XI_LASTEVENT + 1; 244 static const int kMaxXIEventType = XI_LASTEVENT + 1;
255 static const int kMaxSlotNum = 10; 245 static const int kMaxSlotNum = 10;
256 246
257 // Major opcode for the XInput extension. Used to identify XInput events. 247 // Major opcode for the XInput extension. Used to identify XInput events.
258 int xi_opcode_; 248 int xi_opcode_;
259 249
260 // A quick lookup table for determining if the XI event is an XIDeviceEvent. 250 // A quick lookup table for determining if the XI event is an XIDeviceEvent.
261 std::bitset<kMaxXIEventType> xi_device_event_types_; 251 std::bitset<kMaxXIEventType> xi_device_event_types_;
262 252
263 // A quick lookup table for determining if events from the pointer device 253 // A quick lookup table for determining if events from the pointer device
(...skipping 25 matching lines...) Expand all
289 // doesn't think X/device doesn't know about the valuators. We currently 279 // doesn't think X/device doesn't know about the valuators. We currently
290 // use this only on touchscreen devices. 280 // use this only on touchscreen devices.
291 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; 281 std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum];
292 282
293 // X11 atoms cache. 283 // X11 atoms cache.
294 X11AtomCache atom_cache_; 284 X11AtomCache atom_cache_;
295 285
296 unsigned char button_map_[256]; 286 unsigned char button_map_[256];
297 int button_map_count_; 287 int button_map_count_;
298 288
299 // Table to keep track of which display id is mapped to which touch device. 289 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11);
300 int64 touch_device_to_display_map_[kMaxDeviceNum];
301 // Index table to find the TouchTransformer for a touch device.
302 gfx::Transform touch_device_transformer_map_[kMaxDeviceNum];
303
304 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager);
305 }; 290 };
306 291
307 } // namespace ui 292 } // namespace ui
308 293
309 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_H_ 294 #endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698