Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_UTOUCH) | |
| 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 // Allow components interested in multi-touch hierarch events | |
| 45 // to be notified if a device has been added or removed. | |
| 46 struct DeviceObserver { | |
| 47 virtual ~DeviceObserver() {} | |
| 48 | |
| 49 // Called when the list of known devices changes. | |
| 50 virtual void OnDevicesUpdated(TouchDeviceList deviceList) = 0; | |
| 51 }; | |
| 52 | |
| 28 // Define the touch params following the Multi-touch Protocol. | 53 // Define the touch params following the Multi-touch Protocol. |
| 29 enum TouchParam { | 54 enum TouchParam { |
| 30 TP_TOUCH_MAJOR = 0, // Length of the touch area. | 55 TP_TOUCH_MAJOR = 0, // Length of the touch area. |
| 31 TP_TOUCH_MINOR, // Width of the touch area. | 56 TP_TOUCH_MINOR, // Width of the touch area. |
| 32 TP_ORIENTATION, // Angle between the X-axis and the major axis of the | 57 TP_ORIENTATION, // Angle between the X-axis and the major axis of the |
| 33 // touch area. | 58 // touch area. |
| 34 TP_PRESSURE, // Pressure of the touch contact. | 59 TP_PRESSURE, // Pressure of the touch contact. |
| 35 | 60 |
| 36 // NOTE: A touch event can have multiple touch points. So when we receive a | 61 // 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. | 62 // touch event, we need to determine which point triggered the event. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 54 // is increased for each new touch. It will wrap back to 0 when reaching | 79 // is increased for each new touch. It will wrap back to 0 when reaching |
| 55 // the numerical limit. | 80 // the numerical limit. |
| 56 TP_TRACKING_ID, // ID of the touch point. | 81 TP_TRACKING_ID, // ID of the touch point. |
| 57 | 82 |
| 58 TP_LAST_ENTRY | 83 TP_LAST_ENTRY |
| 59 }; | 84 }; |
| 60 | 85 |
| 61 // Returns the TouchFactory singleton. | 86 // Returns the TouchFactory singleton. |
| 62 static TouchFactory* GetInstance(); | 87 static TouchFactory* GetInstance(); |
| 63 | 88 |
| 89 // Add a new observer. | |
| 90 // Can be called from any thread. | |
| 91 // Must not be called from within a notification callback. | |
| 92 void AddDeviceObserver(DeviceObserver * observer); | |
| 93 | |
| 94 // Remove an existing observer. | |
| 95 // Can be called from any thread. | |
| 96 // Must not be called from within a notification callback. | |
| 97 void RemoveDeviceObserver(DeviceObserver * observer); | |
| 98 | |
| 64 // Updates the list of devices. | 99 // Updates the list of devices. |
| 65 void UpdateDeviceList(Display* display); | 100 void UpdateDeviceList(Display* display); |
| 66 | 101 |
| 67 // Checks whether an XI2 event should be processed or not (i.e. if the event | 102 // Checks whether an XI2 event should be processed or not (i.e. if the event |
| 68 // originated from a device we are interested in). | 103 // originated from a device we are interested in). |
| 69 bool ShouldProcessXI2Event(XEvent* xevent); | 104 bool ShouldProcessXI2Event(XEvent* xevent); |
| 70 | 105 |
| 106 #if defined(USE_UTOUCH) | |
| 107 // Preprocesses an XI2 event and feeds it to utouch frame. | |
| 108 void ProcessXI2Event(XEvent* event); | |
| 109 #endif // USE_UTOUCH | |
| 110 | |
| 71 // Setup an X Window for XInput2 events. | 111 // Setup an X Window for XInput2 events. |
| 72 void SetupXI2ForXWindow(::Window xid); | 112 void SetupXI2ForXWindow(::Window xid); |
| 73 | 113 |
| 74 // Keeps a list of touch devices so that it is possible to determine if a | 114 // 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 | 115 // pointer event is a touch-event or a mouse-event. The list is reset each |
| 76 // time this is called. | 116 // time this is called. |
| 77 void SetTouchDeviceList(const std::vector<unsigned int>& devices); | 117 void SetTouchDeviceList(const std::vector<unsigned int>& devices); |
| 78 | 118 |
| 79 // Is the device a touch-device? | 119 // Is the device a touch-device? |
| 80 bool IsTouchDevice(unsigned int deviceid) const; | 120 bool IsTouchDevice(unsigned int deviceid) const; |
| 81 | 121 |
| 82 // Is the device a real multi-touch-device? (see doc. for |touch_device_list_| | 122 // Is the device a real multi-touch-device? (see doc. for |touch_device_list_| |
| 83 // below for more explanation.) | 123 // below for more explanation.) |
| 84 bool IsMultiTouchDevice(unsigned int deviceid) const; | 124 bool IsMultiTouchDevice(unsigned int deviceid) const; |
| 85 | 125 |
| 86 #if defined(USE_XI2_MT) | 126 #if defined(USE_XI2_MT) |
| 87 // Tries to find an existing slot ID mapping to tracking ID. If there | 127 // 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. | 128 // isn't one already, allocates a new slot ID and sets up the mapping. |
| 89 int GetSlotForTrackingID(uint32 tracking_id); | 129 int GetSlotForTrackingID(uint32 tracking_id); |
| 90 | 130 |
| 91 // Releases the slot ID mapping to tracking ID. | 131 // Releases the slot ID mapping to tracking ID. |
| 92 void ReleaseSlotForTrackingID(uint32 tracking_id); | 132 void ReleaseSlotForTrackingID(uint32 tracking_id); |
| 133 | |
| 134 #if defined(USE_UTOUCH) | |
| 135 // Provides raw access to the utouch-frame instance. | |
| 136 // TODO(tvoss): Come up with a more secure and clean | |
| 137 // pattern to provide access to the frame instance. | |
| 138 UFHandle handle() const { | |
| 139 return utouch_frame_handle_; | |
| 140 } | |
| 141 #endif // USE_UTOUCH | |
| 142 | |
| 143 #if defined(USE_AURA) | |
| 144 // Provides raw access to the X handle of the Aura | |
| 145 // root window. Defaults to ui::GetX11RootWindow() | |
| 146 ::Window native_root_window_aura() const { | |
|
sadrul
2012/04/03 19:52:01
This belongs in ui/aura/, either in root_window or
| |
| 147 return native_root_window_aura_; | |
| 148 } | |
| 149 #endif | |
| 93 #endif | 150 #endif |
| 94 | 151 |
| 95 // Is the slot ID currently used? | 152 // Is the slot ID currently used? |
| 96 bool IsSlotUsed(int slot) const; | 153 bool IsSlotUsed(int slot) const; |
| 97 | 154 |
| 98 // Marks a slot as being used/unused. | 155 // Marks a slot as being used/unused. |
| 99 void SetSlotUsed(int slot, bool used); | 156 void SetSlotUsed(int slot, bool used); |
| 100 | 157 |
| 101 // Grabs the touch devices for the specified window on the specified display. | 158 // Grabs the touch devices for the specified window on the specified display. |
| 102 // Returns if grab was successful for all touch devices. | 159 // Returns if grab was successful for all touch devices. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 SetCursorVisible(false, false); | 200 SetCursorVisible(false, false); |
| 144 } | 201 } |
| 145 | 202 |
| 146 // Setup the internal bookkeeping of the touch params valuator information for | 203 // Setup the internal bookkeeping of the touch params valuator information for |
| 147 // touch devices | 204 // touch devices |
| 148 void SetupValuator(); | 205 void SetupValuator(); |
| 149 | 206 |
| 150 // Requirement for Signleton | 207 // Requirement for Signleton |
| 151 friend struct DefaultSingletonTraits<TouchFactory>; | 208 friend struct DefaultSingletonTraits<TouchFactory>; |
| 152 | 209 |
| 210 // Observer management | |
| 211 ObserverListThreadSafe<DeviceObserver>* device_observer_list_; | |
| 212 | |
| 153 // The default cursor is hidden after startup, and when the mouse pointer is | 213 // 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 | 214 // idle for a while. Once there is some event from a mouse device, the cursor |
| 155 // is immediately displayed. | 215 // is immediately displayed. |
| 156 bool is_cursor_visible_; | 216 bool is_cursor_visible_; |
| 157 | 217 |
| 158 // The cursor is hidden if it is idle for a certain amount time. This timer | 218 // The cursor is hidden if it is idle for a certain amount time. This timer |
| 159 // is used to keep track of the idleness. | 219 // is used to keep track of the idleness. |
| 160 base::OneShotTimer<TouchFactory> cursor_timer_; | 220 base::OneShotTimer<TouchFactory> cursor_timer_; |
| 161 | 221 |
| 162 // The default cursor. | 222 // The default cursor. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 182 std::bitset<kMaxDeviceNum> touch_device_lookup_; | 242 std::bitset<kMaxDeviceNum> touch_device_lookup_; |
| 183 | 243 |
| 184 // Indicates whether a touch device is currently available or not. | 244 // Indicates whether a touch device is currently available or not. |
| 185 bool touch_device_available_; | 245 bool touch_device_available_; |
| 186 | 246 |
| 187 // The list of touch devices. For testing/debugging purposes, a single-pointer | 247 // 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) | 248 // 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 | 249 // 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 | 250 // the device id, and the value represents if the device is multi-touch |
| 191 // capable. | 251 // capable. |
| 192 std::map<int, bool> touch_device_list_; | 252 base::Lock touch_device_list_lock_; |
| 253 TouchDeviceList touch_device_list_; | |
|
sadrul
2012/04/03 19:52:01
Update the comment to explain the change for USE_X
| |
| 193 | 254 |
| 194 // Index table to find the valuator for the TouchParam on the specific device | 255 // 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 | 256 // 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 | 257 // 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 | 258 // space waste becomes a concern, the 2D lookup table can be replaced by a |
| 198 // hash map. | 259 // hash map. |
| 199 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; | 260 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 200 | 261 |
| 201 // Index table to find the min & max value of the TouchParam on a specific | 262 // Index table to find the min & max value of the TouchParam on a specific |
| 202 // device. | 263 // device. |
| 203 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; | 264 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 204 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; | 265 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 205 | 266 |
| 206 // Maximum simultaneous touch points. | 267 // Maximum simultaneous touch points. |
| 207 static const int kMaxTouchPoints = 32; | 268 static const int kMaxTouchPoints = 32; |
| 208 | 269 |
| 209 #if defined(USE_XI2_MT) | 270 #if defined(USE_XI2_MT) |
| 271 #if defined(USE_AURA) | |
| 272 // The X handle of the aura root window | |
| 273 ::Window native_root_window_aura_; | |
| 274 #endif | |
| 275 | |
| 276 #if defined(USE_UTOUCH) | |
| 277 UFHandle utouch_frame_handle_; | |
| 278 #endif // USE_UTOUCH | |
| 279 | |
| 210 // Stores the minimum available slot ID which helps get slot ID from | 280 // Stores the minimum available slot ID which helps get slot ID from |
| 211 // tracking ID. When it equals to kMaxTouchPoints, there is no available | 281 // tracking ID. When it equals to kMaxTouchPoints, there is no available |
| 212 // slot. | 282 // slot. |
| 213 int min_available_slot_; | 283 int min_available_slot_; |
| 214 | 284 |
| 215 // A hash table to map tracking ID to slot. | 285 // A hash table to map tracking ID to slot. |
| 216 typedef base::hash_map<uint32, int> TrackingIdMap; | 286 typedef base::hash_map<uint32, int> TrackingIdMap; |
| 217 TrackingIdMap tracking_id_map_; | 287 TrackingIdMap tracking_id_map_; |
| 218 #endif | 288 #endif |
| 219 | 289 |
| 220 // A lookup table for slots in use for a touch event. | 290 // A lookup table for slots in use for a touch event. |
| 221 std::bitset<kMaxTouchPoints> slots_used_; | 291 std::bitset<kMaxTouchPoints> slots_used_; |
| 222 | 292 |
| 223 DISALLOW_COPY_AND_ASSIGN(TouchFactory); | 293 DISALLOW_COPY_AND_ASSIGN(TouchFactory); |
| 224 }; | 294 }; |
| 225 | 295 |
| 226 } // namespace ui | 296 } // namespace ui |
| 227 | 297 |
| 228 #endif // UI_BASE_TOUCH_TOUCH_FACTORY_H_ | 298 #endif // UI_BASE_TOUCH_TOUCH_FACTORY_H_ |
| OLD | NEW |