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 #include "views/events/event.h" | 5 #include "views/events/event.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
15 #include "ui/base/touch/touch_factory.h" | 15 #include "ui/base/touch/touch_factory.h" |
16 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
17 | 17 |
18 namespace views { | 18 namespace views { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 int GetTouchIDFromXEvent(XEvent* xev) { | 22 int GetTouchIDFromXEvent(XEvent* xev) { |
23 float id = 0; | 23 float slot = 0; |
| 24 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
24 #if defined(USE_XI2_MT) | 25 #if defined(USE_XI2_MT) |
25 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new | 26 float tracking_id; |
26 // touch-sequence when TRACKING_ID is used to extract the touch id. | 27 if (!factory->ExtractTouchParam( |
27 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_TRACKING_ID; | 28 *xev, ui::TouchFactory::TP_TRACKING_ID, &tracking_id)) |
| 29 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
| 30 else |
| 31 slot = factory->GetSlotForTrackingID(tracking_id); |
28 #else | 32 #else |
29 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_SLOT_ID; | 33 if (!factory->ExtractTouchParam( |
| 34 *xev, ui::TouchFactory::TP_SLOT_ID, &slot)) |
| 35 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
30 #endif | 36 #endif |
31 if (!ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &id)) | 37 return slot; |
32 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; | |
33 return id; | |
34 } | 38 } |
35 | 39 |
36 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { | 40 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { |
37 char buf[6]; | 41 char buf[6]; |
38 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); | 42 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); |
39 DCHECK_LE(bytes_written, 6); | 43 DCHECK_LE(bytes_written, 6); |
40 | 44 |
41 string16 result; | 45 string16 result; |
42 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && | 46 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && |
43 result.length() == 1) ? result[0] : 0; | 47 result.length() == 1) ? result[0] : 0; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 radius_x_(GetTouchParamFromXEvent(native_event, | 168 radius_x_(GetTouchParamFromXEvent(native_event, |
165 ui::TouchFactory::TP_TOUCH_MAJOR, | 169 ui::TouchFactory::TP_TOUCH_MAJOR, |
166 2.0) / 2.0), | 170 2.0) / 2.0), |
167 radius_y_(GetTouchParamFromXEvent(native_event, | 171 radius_y_(GetTouchParamFromXEvent(native_event, |
168 ui::TouchFactory::TP_TOUCH_MINOR, | 172 ui::TouchFactory::TP_TOUCH_MINOR, |
169 2.0) / 2.0), | 173 2.0) / 2.0), |
170 rotation_angle_(GetTouchParamFromXEvent(native_event, | 174 rotation_angle_(GetTouchParamFromXEvent(native_event, |
171 ui::TouchFactory::TP_ORIENTATION, | 175 ui::TouchFactory::TP_ORIENTATION, |
172 0.0)), | 176 0.0)), |
173 force_(GetTouchForceFromXEvent(native_event)) { | 177 force_(GetTouchForceFromXEvent(native_event)) { |
174 #if !defined(USE_XI2_MT) | 178 #if defined(USE_XI2_MT) |
| 179 if (type() == ui::ET_TOUCH_RELEASED) { |
| 180 // NOTE: The slot is allocated by TouchFactory for each XI_TouchBegin |
| 181 // event, which carries a new tracking ID to identify a new touch |
| 182 // sequence. |
| 183 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| 184 float tracking_id; |
| 185 if (factory->ExtractTouchParam(*native_event, |
| 186 ui::TouchFactory::TP_TRACKING_ID, |
| 187 &tracking_id)) { |
| 188 factory->ReleaseSlotForTrackingID(tracking_id); |
| 189 } |
| 190 } |
| 191 #else |
175 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 192 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
176 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 193 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
177 float slot; | 194 float slot; |
178 if (factory->ExtractTouchParam(*native_event, | 195 if (factory->ExtractTouchParam(*native_event, |
179 ui::TouchFactory::TP_SLOT_ID, &slot)) { | 196 ui::TouchFactory::TP_SLOT_ID, &slot)) { |
180 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 197 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
181 } | 198 } |
182 } | 199 } |
183 #endif | 200 #endif |
184 } | 201 } |
185 | 202 |
186 } // namespace views | 203 } // namespace views |
OLD | NEW |