| 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 VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 5 #ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
| 6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <bitset> | 9 #include <bitset> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // Functions related to determining touch devices. | 23 // Functions related to determining touch devices. |
| 24 class VIEWS_EXPORT TouchFactory { | 24 class VIEWS_EXPORT TouchFactory { |
| 25 public: | 25 public: |
| 26 // Define the touch params following the Multi-touch Protocol. | 26 // Define the touch params following the Multi-touch Protocol. |
| 27 enum TouchParam { | 27 enum TouchParam { |
| 28 TP_TOUCH_MAJOR = 0, // Length of the touch area. | 28 TP_TOUCH_MAJOR = 0, // Length of the touch area. |
| 29 TP_TOUCH_MINOR, // Width of the touch area. | 29 TP_TOUCH_MINOR, // Width of the touch area. |
| 30 TP_ORIENTATION, // Angle between the X-axis and the major axis of the | 30 TP_ORIENTATION, // Angle between the X-axis and the major axis of the |
| 31 // touch area. | 31 // touch area. |
| 32 TP_POSITION_X, // Position X |
| 33 TP_POSITION_Y, // Position Y |
| 34 TP_TRACKING_ID, // Tracking ID |
| 32 TP_PRESSURE, // Pressure of the touch contact. | 35 TP_PRESSURE, // Pressure of the touch contact. |
| 33 | |
| 34 // NOTE: A touch event can have multiple touch points. So when we receive a | |
| 35 // touch event, we need to determine which point triggered the event. | |
| 36 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can | |
| 37 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and | |
| 38 // (X - 1), where X is the maximum touch points supported by the device. The | |
| 39 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion | |
| 40 // event that comes from a currently-unused 'Slot ID' indicates the creation | |
| 41 // of a new touch point, and any event that comes with a 0 value for | |
| 42 // 'Tracking ID' marks the removal of a touch point. During the lifetime of | |
| 43 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress | |
| 44 // and XI_ButtonRelease events are ignored. | |
| 45 TP_SLOT_ID, // ID of the finger that triggered a touch event | |
| 46 // (useful when tracking multiple simultaneous | |
| 47 // touches) | |
| 48 TP_TRACKING_ID, // ID of the touch point. | |
| 49 | |
| 50 TP_LAST_ENTRY | 36 TP_LAST_ENTRY |
| 51 }; | 37 }; |
| 52 | 38 |
| 53 // Returns the TouchFactory singleton. | 39 // Returns the TouchFactory singleton. |
| 54 static TouchFactory* GetInstance(); | 40 static TouchFactory* GetInstance(); |
| 55 | 41 |
| 56 // Updates the list of devices. | 42 // Updates the list of devices. |
| 57 void UpdateDeviceList(Display* display); | 43 void UpdateDeviceList(Display* display); |
| 58 | 44 |
| 59 // Checks whether an XI2 event should be processed or not (i.e. if the event | 45 // Checks whether an XI2 event should be processed or not (i.e. if the event |
| 60 // originated from a device we are interested in). | 46 // originated from a device we are interested in). |
| 61 bool ShouldProcessXI2Event(XEvent* xevent); | 47 bool ShouldProcessXI2Event(XEvent* xevent); |
| 62 | 48 |
| 63 // Setup an X Window for XInput2 events. | 49 // Setup an X Window for XInput2 events. |
| 64 void SetupXI2ForXWindow(::Window xid); | 50 void SetupXI2ForXWindow(::Window xid); |
| 65 | 51 |
| 66 // Keeps a list of touch devices so that it is possible to determine if a | 52 // Keeps a list of touch devices so that it is possible to determine if a |
| 67 // pointer event is a touch-event or a mouse-event. The list is reset each | 53 // pointer event is a touch-event or a mouse-event. The list is reset each |
| 68 // time this is called. | 54 // time this is called. |
| 69 void SetTouchDeviceList(const std::vector<unsigned int>& devices); | 55 void SetTouchDeviceList(const std::vector<unsigned int>& devices); |
| 70 | 56 |
| 71 // Is the device a touch-device? | 57 // Is the device a touch-device? |
| 72 bool IsTouchDevice(unsigned int deviceid) const; | 58 bool IsTouchDevice(unsigned int deviceid) const; |
| 73 | 59 |
| 74 // Is the slot ID currently used? | |
| 75 bool IsSlotUsed(int slot) const; | |
| 76 | |
| 77 // Marks a slot as being used/unused. | |
| 78 void SetSlotUsed(int slot, bool used); | |
| 79 | |
| 80 // Grabs the touch devices for the specified window on the specified display. | 60 // Grabs the touch devices for the specified window on the specified display. |
| 81 // Returns if grab was successful for all touch devices. | 61 // Returns if grab was successful for all touch devices. |
| 82 bool GrabTouchDevices(Display* display, ::Window window); | 62 bool GrabTouchDevices(Display* display, ::Window window); |
| 83 | 63 |
| 84 // Ungrabs the touch devices. Returns if ungrab was successful for all touch | 64 // Ungrabs the touch devices. Returns if ungrab was successful for all touch |
| 85 // devices. | 65 // devices. |
| 86 bool UngrabTouchDevices(Display* display); | 66 bool UngrabTouchDevices(Display* display); |
| 87 | 67 |
| 88 // Updates the root window to show (or hide) the cursor. Also indicate whether | 68 // Updates the root window to show (or hide) the cursor. Also indicate whether |
| 89 // the timer should be started to automatically hide the cursor after a | 69 // the timer should be started to automatically hide the cursor after a |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; | 158 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 179 | 159 |
| 180 // Index table to find the min & max value of the TouchParam on a specific | 160 // Index table to find the min & max value of the TouchParam on a specific |
| 181 // device. | 161 // device. |
| 182 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; | 162 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 183 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; | 163 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; |
| 184 | 164 |
| 185 // Maximum simultaneous touch points. | 165 // Maximum simultaneous touch points. |
| 186 static const int kMaxTouchPoints = 32; | 166 static const int kMaxTouchPoints = 32; |
| 187 | 167 |
| 188 // A lookup table for slots in use for a touch event. | |
| 189 std::bitset<kMaxTouchPoints> slots_used_; | |
| 190 | |
| 191 DISALLOW_COPY_AND_ASSIGN(TouchFactory); | 168 DISALLOW_COPY_AND_ASSIGN(TouchFactory); |
| 192 }; | 169 }; |
| 193 | 170 |
| 194 } // namespace views | 171 } // namespace views |
| 195 | 172 |
| 196 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 173 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
| OLD | NEW |