| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { | 70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { |
| 71 if (XIMaskIsSet(xievent->buttons.mask, i)) { | 71 if (XIMaskIsSet(xievent->buttons.mask, i)) { |
| 72 buttonflags |= GetEventFlagsForButton(i); | 72 buttonflags |= GetEventFlagsForButton(i); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 return buttonflags; | 76 return buttonflags; |
| 77 } | 77 } |
| 78 | 78 |
| 79 ui::EventType GetTouchEventType(XEvent* xev) { | 79 ui::EventType GetTouchEventType(XEvent* xev) { |
| 80 #if defined(USE_XI2_MT) |
| 81 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |
| 82 switch(event->evtype) { |
| 83 case XI_TouchBegin: |
| 84 return ui::ET_TOUCH_PRESSED; |
| 85 case XI_TouchUpdate: |
| 86 return ui::ET_TOUCH_MOVED; |
| 87 case XI_TouchEnd: |
| 88 return ui::ET_TOUCH_RELEASED; |
| 89 } |
| 90 |
| 91 return ui::ET_UNKNOWN; |
| 92 #else |
| 80 XGenericEventCookie* cookie = &xev->xcookie; | 93 XGenericEventCookie* cookie = &xev->xcookie; |
| 81 DCHECK_EQ(cookie->evtype, XI_Motion); | 94 DCHECK_EQ(cookie->evtype, XI_Motion); |
| 82 | 95 |
| 83 // Note: We will not generate a _STATIONARY event here. It will be created, | 96 // Note: We will not generate a _STATIONARY event here. It will be created, |
| 84 // when necessary, by a RWHVV. | 97 // when necessary, by a RWHVV. |
| 85 // TODO(sad): When should _CANCELLED be generated? | 98 // TODO(sad): When should _CANCELLED be generated? |
| 86 | 99 |
| 87 TouchFactory* factory = TouchFactory::GetInstance(); | 100 TouchFactory* factory = TouchFactory::GetInstance(); |
| 88 float slot; | 101 float slot; |
| 89 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) | 102 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) |
| 90 return ui::ET_UNKNOWN; | 103 return ui::ET_UNKNOWN; |
| 91 | 104 |
| 92 if (!factory->IsSlotUsed(slot)) { | 105 if (!factory->IsSlotUsed(slot)) { |
| 93 // This is a new touch point. | 106 // This is a new touch point. |
| 94 return ui::ET_TOUCH_PRESSED; | 107 return ui::ET_TOUCH_PRESSED; |
| 95 } | 108 } |
| 96 | 109 |
| 97 float tracking; | 110 float tracking; |
| 98 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, | 111 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, |
| 99 &tracking)) | 112 &tracking)) |
| 100 return ui::ET_UNKNOWN; | 113 return ui::ET_UNKNOWN; |
| 101 | 114 |
| 102 if (tracking == 0l) { | 115 if (tracking == 0l) { |
| 103 // The touch point has been released. | 116 // The touch point has been released. |
| 104 return ui::ET_TOUCH_RELEASED; | 117 return ui::ET_TOUCH_RELEASED; |
| 105 } | 118 } |
| 106 | 119 |
| 107 return ui::ET_TOUCH_MOVED; | 120 return ui::ET_TOUCH_MOVED; |
| 121 #endif // defined(USE_XI2_MT) |
| 108 } | 122 } |
| 109 | 123 |
| 110 int GetTouchIDFromXEvent(XEvent* xev) { | 124 int GetTouchIDFromXEvent(XEvent* xev) { |
| 111 float slot = 0; | 125 float id = 0; |
| 126 #if defined(USE_XI2_MT) |
| 127 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new |
| 128 // touch-sequence when TRACKING_ID is used to extract the touch id. |
| 129 TouchFactory::TouchParam tp = TouchFactory::TP_TRACKING_ID; |
| 130 #else |
| 131 TouchFactory::TouchParam tp = TouchFactory::TP_SLOT_ID; |
| 132 #endif |
| 112 if (!TouchFactory::GetInstance()->ExtractTouchParam( | 133 if (!TouchFactory::GetInstance()->ExtractTouchParam( |
| 113 *xev, TouchFactory::TP_SLOT_ID, &slot)) | 134 *xev, tp, &id)) |
| 114 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; | 135 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; |
| 115 return slot; | 136 return id; |
| 116 } | 137 } |
| 117 | 138 |
| 118 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { | 139 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { |
| 119 switch (native_event->type) { | 140 switch (native_event->type) { |
| 120 case KeyPress: | 141 case KeyPress: |
| 121 return ui::ET_KEY_PRESSED; | 142 return ui::ET_KEY_PRESSED; |
| 122 case KeyRelease: | 143 case KeyRelease: |
| 123 return ui::ET_KEY_RELEASED; | 144 return ui::ET_KEY_RELEASED; |
| 124 case ButtonPress: | 145 case ButtonPress: |
| 125 if (native_event->xbutton.button == 4 || | 146 if (native_event->xbutton.button == 4 || |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 radius_x_(GetTouchParamFromXEvent(native_event_2, | 417 radius_x_(GetTouchParamFromXEvent(native_event_2, |
| 397 TouchFactory::TP_TOUCH_MAJOR, | 418 TouchFactory::TP_TOUCH_MAJOR, |
| 398 2.0) / 2.0), | 419 2.0) / 2.0), |
| 399 radius_y_(GetTouchParamFromXEvent(native_event_2, | 420 radius_y_(GetTouchParamFromXEvent(native_event_2, |
| 400 TouchFactory::TP_TOUCH_MINOR, | 421 TouchFactory::TP_TOUCH_MINOR, |
| 401 2.0) / 2.0), | 422 2.0) / 2.0), |
| 402 rotation_angle_(GetTouchParamFromXEvent(native_event_2, | 423 rotation_angle_(GetTouchParamFromXEvent(native_event_2, |
| 403 TouchFactory::TP_ORIENTATION, | 424 TouchFactory::TP_ORIENTATION, |
| 404 0.0)), | 425 0.0)), |
| 405 force_(GetTouchForceFromXEvent(native_event_2)) { | 426 force_(GetTouchForceFromXEvent(native_event_2)) { |
| 427 #if !defined(USE_XI2_MT) |
| 406 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 428 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
| 407 TouchFactory* factory = TouchFactory::GetInstance(); | 429 TouchFactory* factory = TouchFactory::GetInstance(); |
| 408 float slot; | 430 float slot; |
| 409 if (factory->ExtractTouchParam(*native_event_2, | 431 if (factory->ExtractTouchParam(*native_event_2, |
| 410 TouchFactory::TP_SLOT_ID, &slot)) { | 432 TouchFactory::TP_SLOT_ID, &slot)) { |
| 411 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 433 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
| 412 } | 434 } |
| 413 } | 435 } |
| 436 #endif |
| 414 } | 437 } |
| 415 | 438 |
| 416 } // namespace views | 439 } // namespace views |
| OLD | NEW |