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

Side by Side Diff: ui/base/touch/touch_factory.h

Issue 9773024: This patch implements Chromium's Aura gesture recognizer in terms of utouch-grail and utouch-frame … (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_BASE_TOUCH_TOUCH_FACTORY_H_ 5 #ifndef UI_BASE_TOUCH_TOUCH_FACTORY_H_
6 #define UI_BASE_TOUCH_TOUCH_FACTORY_H_ 6 #define UI_BASE_TOUCH_TOUCH_FACTORY_H_
7 #pragma once 7 #pragma once
8 8
9 #if defined(USE_XI2_MT)
10 #include <utouch/frame.h>
11 #include <utouch/frame_x11.h>
12 #endif
13
9 #include <bitset> 14 #include <bitset>
10 #include <map> 15 #include <map>
11 #include <vector> 16 #include <vector>
12 17
18 #include "base/hash_tables.h"
13 #include "base/memory/singleton.h" 19 #include "base/memory/singleton.h"
14 #include "base/hash_tables.h" 20 #include "base/observer_list_threadsafe.h"
21 #include "base/synchronization/lock.h"
15 #include "base/timer.h" 22 #include "base/timer.h"
23 #if defined(USE_XI2_MT)
24 #include "ui/base/touch/multi_touch_device.h"
25 #endif
16 #include "ui/base/ui_export.h" 26 #include "ui/base/ui_export.h"
17 27
18 typedef unsigned long Cursor; 28 typedef unsigned long Cursor;
19 typedef unsigned long Window; 29 typedef unsigned long Window;
20 typedef struct _XDisplay Display; 30 typedef struct _XDisplay Display;
21 typedef union _XEvent XEvent; 31 typedef union _XEvent XEvent;
22 32
23 namespace ui { 33 namespace ui {
24 34
25 // Functions related to determining touch devices. 35 // Functions related to determining touch devices.
26 class UI_EXPORT TouchFactory { 36 class UI_EXPORT TouchFactory {
27 public: 37 public:
38 #if !defined(USE_XI2_MT)
39 typedef std::map<int, bool> TouchDeviceList;
40 #else
41 typedef std::map<int, MultiTouchDevice> TouchDeviceList;
42 #endif
43
44 struct DeviceObserver {
45 virtual ~DeviceObserver() {}
46
47 virtual void OnDevicesUpdated(TouchDeviceList deviceList) = 0;
48 };
49
28 // Define the touch params following the Multi-touch Protocol. 50 // Define the touch params following the Multi-touch Protocol.
29 enum TouchParam { 51 enum TouchParam {
30 TP_TOUCH_MAJOR = 0, // Length of the touch area. 52 TP_TOUCH_MAJOR = 0, // Length of the touch area.
31 TP_TOUCH_MINOR, // Width of the touch area. 53 TP_TOUCH_MINOR, // Width of the touch area.
32 TP_ORIENTATION, // Angle between the X-axis and the major axis of the 54 TP_ORIENTATION, // Angle between the X-axis and the major axis of the
33 // touch area. 55 // touch area.
34 TP_PRESSURE, // Pressure of the touch contact. 56 TP_PRESSURE, // Pressure of the touch contact.
35 57
36 // NOTE: A touch event can have multiple touch points. So when we receive a 58 // NOTE: A touch event can have multiple touch points. So when we receive a
37 // touch event, we need to determine which point triggered the event. 59 // touch event, we need to determine which point triggered the event.
(...skipping 16 matching lines...) Expand all
54 // is increased for each new touch. It will wrap back to 0 when reaching 76 // is increased for each new touch. It will wrap back to 0 when reaching
55 // the numerical limit. 77 // the numerical limit.
56 TP_TRACKING_ID, // ID of the touch point. 78 TP_TRACKING_ID, // ID of the touch point.
57 79
58 TP_LAST_ENTRY 80 TP_LAST_ENTRY
59 }; 81 };
60 82
61 // Returns the TouchFactory singleton. 83 // Returns the TouchFactory singleton.
62 static TouchFactory* GetInstance(); 84 static TouchFactory* GetInstance();
63 85
86 // Add a new observer.
87 // Can be called from any thread.
88 // Must not be called from within a notification callback.
89 void AddDeviceObserver(DeviceObserver * observer);
90
91 // Remove an existing observer.
92 // Can be called from any thread.
93 // Must not be called from within a notification callback.
94 void RemoveDeviceObserver(DeviceObserver * observer);
95
64 // Updates the list of devices. 96 // Updates the list of devices.
65 void UpdateDeviceList(Display* display); 97 void UpdateDeviceList(Display* display);
66 98
67 // Checks whether an XI2 event should be processed or not (i.e. if the event 99 // Checks whether an XI2 event should be processed or not (i.e. if the event
68 // originated from a device we are interested in). 100 // originated from a device we are interested in).
69 bool ShouldProcessXI2Event(XEvent* xevent); 101 bool ShouldProcessXI2Event(XEvent* xevent);
70 102
103 // Preprocesses an XI2 event and feeds it to utouch frame.
104 void ProcessXI2Event(XEvent* event);
105
71 // Setup an X Window for XInput2 events. 106 // Setup an X Window for XInput2 events.
72 void SetupXI2ForXWindow(::Window xid); 107 void SetupXI2ForXWindow(::Window xid);
73 108
74 // Keeps a list of touch devices so that it is possible to determine if a 109 // Keeps a list of touch devices so that it is possible to determine if a
75 // pointer event is a touch-event or a mouse-event. The list is reset each 110 // pointer event is a touch-event or a mouse-event. The list is reset each
76 // time this is called. 111 // time this is called.
77 void SetTouchDeviceList(const std::vector<unsigned int>& devices); 112 void SetTouchDeviceList(const std::vector<unsigned int>& devices);
78 113
79 // Is the device a touch-device? 114 // Is the device a touch-device?
80 bool IsTouchDevice(unsigned int deviceid) const; 115 bool IsTouchDevice(unsigned int deviceid) const;
81 116
82 // Is the device a real multi-touch-device? (see doc. for |touch_device_list_| 117 // Is the device a real multi-touch-device? (see doc. for |touch_device_list_|
83 // below for more explanation.) 118 // below for more explanation.)
84 bool IsMultiTouchDevice(unsigned int deviceid) const; 119 bool IsMultiTouchDevice(unsigned int deviceid) const;
85 120
86 #if defined(USE_XI2_MT) 121 #if defined(USE_XI2_MT)
87 // Tries to find an existing slot ID mapping to tracking ID. If there 122 // Tries to find an existing slot ID mapping to tracking ID. If there
88 // isn't one already, allocates a new slot ID and sets up the mapping. 123 // isn't one already, allocates a new slot ID and sets up the mapping.
89 int GetSlotForTrackingID(uint32 tracking_id); 124 int GetSlotForTrackingID(uint32 tracking_id);
90 125
91 // Releases the slot ID mapping to tracking ID. 126 // Releases the slot ID mapping to tracking ID.
92 void ReleaseSlotForTrackingID(uint32 tracking_id); 127 void ReleaseSlotForTrackingID(uint32 tracking_id);
128
129 // Provides raw access to the utouch-frame instance.
130 // TODO(tvoss): Come up with a more secure and clean
131 // pattern to provide access to the frame instance.
132 UFHandle handle() const {
133 return utouch_frame_handle_;
134 }
135
136 #if defined(USE_AURA)
137 // Provides raw access to the X handle of the Aura
138 // root window. Defaults to ui::GetX11RootWindow()
139 ::Window native_root_window_aura() const {
140 return native_root_window_aura_;
141 }
142 #endif
93 #endif 143 #endif
94 144
95 // Is the slot ID currently used? 145 // Is the slot ID currently used?
96 bool IsSlotUsed(int slot) const; 146 bool IsSlotUsed(int slot) const;
97 147
98 // Marks a slot as being used/unused. 148 // Marks a slot as being used/unused.
99 void SetSlotUsed(int slot, bool used); 149 void SetSlotUsed(int slot, bool used);
100 150
101 // Grabs the touch devices for the specified window on the specified display. 151 // Grabs the touch devices for the specified window on the specified display.
102 // Returns if grab was successful for all touch devices. 152 // Returns if grab was successful for all touch devices.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 SetCursorVisible(false, false); 193 SetCursorVisible(false, false);
144 } 194 }
145 195
146 // Setup the internal bookkeeping of the touch params valuator information for 196 // Setup the internal bookkeeping of the touch params valuator information for
147 // touch devices 197 // touch devices
148 void SetupValuator(); 198 void SetupValuator();
149 199
150 // Requirement for Signleton 200 // Requirement for Signleton
151 friend struct DefaultSingletonTraits<TouchFactory>; 201 friend struct DefaultSingletonTraits<TouchFactory>;
152 202
203 // Observer management
204 ObserverListThreadSafe<DeviceObserver>* device_observer_list_;
205
153 // The default cursor is hidden after startup, and when the mouse pointer is 206 // The default cursor is hidden after startup, and when the mouse pointer is
154 // idle for a while. Once there is some event from a mouse device, the cursor 207 // idle for a while. Once there is some event from a mouse device, the cursor
155 // is immediately displayed. 208 // is immediately displayed.
156 bool is_cursor_visible_; 209 bool is_cursor_visible_;
157 210
158 // The cursor is hidden if it is idle for a certain amount time. This timer 211 // The cursor is hidden if it is idle for a certain amount time. This timer
159 // is used to keep track of the idleness. 212 // is used to keep track of the idleness.
160 base::OneShotTimer<TouchFactory> cursor_timer_; 213 base::OneShotTimer<TouchFactory> cursor_timer_;
161 214
162 // The default cursor. 215 // The default cursor.
(...skipping 19 matching lines...) Expand all
182 std::bitset<kMaxDeviceNum> touch_device_lookup_; 235 std::bitset<kMaxDeviceNum> touch_device_lookup_;
183 236
184 // Indicates whether a touch device is currently available or not. 237 // Indicates whether a touch device is currently available or not.
185 bool touch_device_available_; 238 bool touch_device_available_;
186 239
187 // The list of touch devices. For testing/debugging purposes, a single-pointer 240 // The list of touch devices. For testing/debugging purposes, a single-pointer
188 // device (mouse or touch screen without sufficient X/driver support for MT) 241 // device (mouse or touch screen without sufficient X/driver support for MT)
189 // can sometimes be treated as a touch device. The key in the map represents 242 // can sometimes be treated as a touch device. The key in the map represents
190 // the device id, and the value represents if the device is multi-touch 243 // the device id, and the value represents if the device is multi-touch
191 // capable. 244 // capable.
192 std::map<int, bool> touch_device_list_; 245 base::Lock touch_device_list_lock_;
246 TouchDeviceList touch_device_list_;
193 247
194 // Index table to find the valuator for the TouchParam on the specific device 248 // Index table to find the valuator for the TouchParam on the specific device
195 // by valuator_lookup_[device_id][touch_params]. Use 2-D array to get fast 249 // by valuator_lookup_[device_id][touch_params]. Use 2-D array to get fast
196 // index at the expense of space. If the kMaxDeviceNum grows larger that the 250 // index at the expense of space. If the kMaxDeviceNum grows larger that the
197 // space waste becomes a concern, the 2D lookup table can be replaced by a 251 // space waste becomes a concern, the 2D lookup table can be replaced by a
198 // hash map. 252 // hash map.
199 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; 253 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY];
200 254
201 // Index table to find the min & max value of the TouchParam on a specific 255 // Index table to find the min & max value of the TouchParam on a specific
202 // device. 256 // device.
203 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; 257 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY];
204 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; 258 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY];
205 259
206 // Maximum simultaneous touch points. 260 // Maximum simultaneous touch points.
207 static const int kMaxTouchPoints = 32; 261 static const int kMaxTouchPoints = 32;
208 262
209 #if defined(USE_XI2_MT) 263 #if defined(USE_XI2_MT)
264 #if defined(USE_AURA)
265 // The X handle of the aura root window
266 ::Window native_root_window_aura_;
267 #endif
268
269 UFHandle utouch_frame_handle_;
270
210 // Stores the minimum available slot ID which helps get slot ID from 271 // Stores the minimum available slot ID which helps get slot ID from
211 // tracking ID. When it equals to kMaxTouchPoints, there is no available 272 // tracking ID. When it equals to kMaxTouchPoints, there is no available
212 // slot. 273 // slot.
213 int min_available_slot_; 274 int min_available_slot_;
214 275
215 // A hash table to map tracking ID to slot. 276 // A hash table to map tracking ID to slot.
216 typedef base::hash_map<uint32, int> TrackingIdMap; 277 typedef base::hash_map<uint32, int> TrackingIdMap;
217 TrackingIdMap tracking_id_map_; 278 TrackingIdMap tracking_id_map_;
218 #endif 279 #endif
219 280
220 // A lookup table for slots in use for a touch event. 281 // A lookup table for slots in use for a touch event.
221 std::bitset<kMaxTouchPoints> slots_used_; 282 std::bitset<kMaxTouchPoints> slots_used_;
222 283
223 DISALLOW_COPY_AND_ASSIGN(TouchFactory); 284 DISALLOW_COPY_AND_ASSIGN(TouchFactory);
224 }; 285 };
225 286
226 } // namespace ui 287 } // namespace ui
227 288
228 #endif // UI_BASE_TOUCH_TOUCH_FACTORY_H_ 289 #endif // UI_BASE_TOUCH_TOUCH_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698