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> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (tracking == 0l) { | 115 if (tracking == 0l) { |
116 // The touch point has been released. | 116 // The touch point has been released. |
117 return ui::ET_TOUCH_RELEASED; | 117 return ui::ET_TOUCH_RELEASED; |
118 } | 118 } |
119 | 119 |
120 return ui::ET_TOUCH_MOVED; | 120 return ui::ET_TOUCH_MOVED; |
121 #endif // defined(USE_XI2_MT) | 121 #endif // defined(USE_XI2_MT) |
122 } | 122 } |
123 | 123 |
124 int GetTouchIDFromXEvent(XEvent* xev) { | 124 int GetTouchIDFromXEvent(XEvent* xev) { |
125 float id = 0; | 125 float slot = 0; |
| 126 TouchFactory* factory = TouchFactory::GetInstance(); |
126 #if defined(USE_XI2_MT) | 127 #if defined(USE_XI2_MT) |
127 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new | 128 float tracking_id; |
128 // touch-sequence when TRACKING_ID is used to extract the touch id. | 129 if (!factory->ExtractTouchParam( |
129 TouchFactory::TouchParam tp = TouchFactory::TP_TRACKING_ID; | 130 *xev, TouchFactory::TP_TRACKING_ID, &tracking_id)) |
| 131 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
| 132 else |
| 133 slot = factory->GetSlotForTrackingID(tracking_id); |
130 #else | 134 #else |
131 TouchFactory::TouchParam tp = TouchFactory::TP_SLOT_ID; | 135 if (!factory->ExtractTouchParam( |
| 136 *xev, TouchFactory::TP_SLOT_ID, &slot)) |
| 137 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
132 #endif | 138 #endif |
133 if (!TouchFactory::GetInstance()->ExtractTouchParam( | 139 return slot; |
134 *xev, tp, &id)) | |
135 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; | |
136 return id; | |
137 } | 140 } |
138 | 141 |
139 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { | 142 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { |
140 switch (native_event->type) { | 143 switch (native_event->type) { |
141 case KeyPress: | 144 case KeyPress: |
142 return ui::ET_KEY_PRESSED; | 145 return ui::ET_KEY_PRESSED; |
143 case KeyRelease: | 146 case KeyRelease: |
144 return ui::ET_KEY_RELEASED; | 147 return ui::ET_KEY_RELEASED; |
145 case ButtonPress: | 148 case ButtonPress: |
146 if (native_event->xbutton.button == 4 || | 149 if (native_event->xbutton.button == 4 || |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 radius_x_(GetTouchParamFromXEvent(native_event_2, | 420 radius_x_(GetTouchParamFromXEvent(native_event_2, |
418 TouchFactory::TP_TOUCH_MAJOR, | 421 TouchFactory::TP_TOUCH_MAJOR, |
419 2.0) / 2.0), | 422 2.0) / 2.0), |
420 radius_y_(GetTouchParamFromXEvent(native_event_2, | 423 radius_y_(GetTouchParamFromXEvent(native_event_2, |
421 TouchFactory::TP_TOUCH_MINOR, | 424 TouchFactory::TP_TOUCH_MINOR, |
422 2.0) / 2.0), | 425 2.0) / 2.0), |
423 rotation_angle_(GetTouchParamFromXEvent(native_event_2, | 426 rotation_angle_(GetTouchParamFromXEvent(native_event_2, |
424 TouchFactory::TP_ORIENTATION, | 427 TouchFactory::TP_ORIENTATION, |
425 0.0)), | 428 0.0)), |
426 force_(GetTouchForceFromXEvent(native_event_2)) { | 429 force_(GetTouchForceFromXEvent(native_event_2)) { |
427 #if !defined(USE_XI2_MT) | 430 #if defined(USE_XI2_MT) |
| 431 if (type() == ui::ET_TOUCH_RELEASED) { |
| 432 // NOTE: The slot is allocated by TouchFactory for each XI_TouchBegin |
| 433 // event, which carries a new tracking ID to identify a new touch |
| 434 // sequence. |
| 435 TouchFactory* factory = TouchFactory::GetInstance(); |
| 436 float tracking_id; |
| 437 if (factory->ExtractTouchParam(*native_event_2, |
| 438 TouchFactory::TP_TRACKING_ID, |
| 439 &tracking_id)) { |
| 440 factory->ReleaseSlotForTrackingID(tracking_id); |
| 441 } |
| 442 } |
| 443 #else |
428 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 444 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
429 TouchFactory* factory = TouchFactory::GetInstance(); | 445 TouchFactory* factory = TouchFactory::GetInstance(); |
430 float slot; | 446 float slot; |
431 if (factory->ExtractTouchParam(*native_event_2, | 447 if (factory->ExtractTouchParam(*native_event_2, |
432 TouchFactory::TP_SLOT_ID, &slot)) { | 448 TouchFactory::TP_SLOT_ID, &slot)) { |
433 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 449 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
434 } | 450 } |
435 } | 451 } |
436 #endif | 452 #endif |
437 } | 453 } |
438 | 454 |
439 } // namespace views | 455 } // namespace views |
OLD | NEW |