| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
| 6 | 6 |
| 7 #include <gestures/gestures.h> | 7 #include <gestures/gestures.h> |
| 8 #include <libevdev/libevdev.h> | 8 #include <libevdev/libevdev.h> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 13 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 14 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" | 14 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
| 15 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 15 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" | 16 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" |
| 16 #include "ui/gfx/geometry/point_f.h" | 17 #include "ui/gfx/geometry/point_f.h" |
| 17 | 18 |
| 18 namespace ui { | 19 namespace ui { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Convert libevdev device class to libgestures device class. | 23 // Convert libevdev device class to libgestures device class. |
| 23 GestureInterpreterDeviceClass GestureDeviceClass(Evdev* evdev) { | 24 GestureInterpreterDeviceClass GestureDeviceClass(Evdev* evdev) { |
| 24 switch (evdev->info.evdev_class) { | 25 switch (evdev->info.evdev_class) { |
| 25 case EvdevClassMouse: | 26 case EvdevClassMouse: |
| 26 return GESTURES_DEVCLASS_MOUSE; | 27 return GESTURES_DEVCLASS_MOUSE; |
| 27 case EvdevClassMultitouchMouse: | 28 case EvdevClassMultitouchMouse: |
| 28 return GESTURES_DEVCLASS_MULTITOUCH_MOUSE; | 29 return GESTURES_DEVCLASS_MULTITOUCH_MOUSE; |
| 29 case EvdevClassTouchpad: | 30 case EvdevClassTouchpad: |
| 30 return GESTURES_DEVCLASS_TOUCHPAD; | 31 return GESTURES_DEVCLASS_TOUCHPAD; |
| 31 case EvdevClassTouchscreen: | 32 case EvdevClassTouchscreen: |
| 32 return GESTURES_DEVCLASS_TOUCHSCREEN; | 33 return GESTURES_DEVCLASS_TOUCHSCREEN; |
| 33 default: | 34 default: |
| 34 return GESTURES_DEVCLASS_UNKNOWN; | 35 return GESTURES_DEVCLASS_UNKNOWN; |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 // Convert libevdev state to libgestures hardware properties. | 39 // Convert libevdev state to libgestures hardware properties. |
| 39 HardwareProperties GestureHardwareProperties(Evdev* evdev) { | 40 HardwareProperties GestureHardwareProperties( |
| 41 Evdev* evdev, |
| 42 const GestureDeviceProperties* props) { |
| 40 HardwareProperties hwprops; | 43 HardwareProperties hwprops; |
| 41 hwprops.left = Event_Get_Left(evdev); | 44 hwprops.left = props->area_left; |
| 42 hwprops.top = Event_Get_Top(evdev); | 45 hwprops.top = props->area_top; |
| 43 hwprops.right = Event_Get_Right(evdev); | 46 hwprops.right = props->area_right; |
| 44 hwprops.bottom = Event_Get_Bottom(evdev); | 47 hwprops.bottom = props->area_bottom; |
| 45 hwprops.res_x = Event_Get_Res_X(evdev); | 48 hwprops.res_x = props->res_x; |
| 46 hwprops.res_y = Event_Get_Res_Y(evdev); | 49 hwprops.res_y = props->res_y; |
| 47 hwprops.screen_x_dpi = 133; | 50 hwprops.screen_x_dpi = 133; |
| 48 hwprops.screen_y_dpi = 133; | 51 hwprops.screen_y_dpi = 133; |
| 49 hwprops.orientation_minimum = Event_Get_Orientation_Minimum(evdev); | 52 hwprops.orientation_minimum = props->orientation_minimum; |
| 50 hwprops.orientation_maximum = Event_Get_Orientation_Maximum(evdev); | 53 hwprops.orientation_maximum = props->orientation_maximum; |
| 51 hwprops.max_finger_cnt = Event_Get_Slot_Count(evdev); | 54 hwprops.max_finger_cnt = Event_Get_Slot_Count(evdev); |
| 52 hwprops.max_touch_cnt = Event_Get_Touch_Count_Max(evdev); | 55 hwprops.max_touch_cnt = Event_Get_Touch_Count_Max(evdev); |
| 53 hwprops.supports_t5r2 = Event_Get_T5R2(evdev); | 56 hwprops.supports_t5r2 = Event_Get_T5R2(evdev); |
| 54 hwprops.support_semi_mt = Event_Get_Semi_MT(evdev); | 57 hwprops.support_semi_mt = Event_Get_Semi_MT(evdev); |
| 55 /* buttonpad means a physical button under the touch surface */ | 58 /* buttonpad means a physical button under the touch surface */ |
| 56 hwprops.is_button_pad = Event_Get_Button_Pad(evdev); | 59 hwprops.is_button_pad = Event_Get_Button_Pad(evdev); |
| 57 return hwprops; | 60 return hwprops; |
| 58 } | 61 } |
| 59 | 62 |
| 60 // Callback from libgestures when a gesture is ready. | 63 // Callback from libgestures when a gesture is ready. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 | 75 |
| 73 // Number of fingers for scroll gestures. | 76 // Number of fingers for scroll gestures. |
| 74 const int kGestureScrollFingerCount = 2; | 77 const int kGestureScrollFingerCount = 2; |
| 75 | 78 |
| 76 // Number of fingers for swipe gestures. | 79 // Number of fingers for swipe gestures. |
| 77 const int kGestureSwipeFingerCount = 3; | 80 const int kGestureSwipeFingerCount = 3; |
| 78 | 81 |
| 79 } // namespace | 82 } // namespace |
| 80 | 83 |
| 81 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( | 84 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( |
| 82 EventModifiersEvdev* modifiers, | 85 int id, EventModifiersEvdev* modifiers, CursorDelegateEvdev* cursor, |
| 83 CursorDelegateEvdev* cursor, | 86 GesturePropertyProvider* property_provider, |
| 84 const EventDispatchCallback& callback) | 87 const EventDispatchCallback& callback) |
| 85 : modifiers_(modifiers), | 88 : id_(id), |
| 89 modifiers_(modifiers), |
| 86 cursor_(cursor), | 90 cursor_(cursor), |
| 91 property_provider_(property_provider), |
| 87 dispatch_callback_(callback), | 92 dispatch_callback_(callback), |
| 88 interpreter_(NULL) {} | 93 interpreter_(NULL), |
| 94 evdev_(NULL), |
| 95 device_properties_(new GestureDeviceProperties) {} |
| 89 | 96 |
| 90 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { | 97 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { |
| 98 // Note that this destructor got called after the evdev device node has been |
| 99 // closed. Therefore, all clean-up codes here shouldn't depend on the device |
| 100 // information (except for the pointer address itself). |
| 101 |
| 102 // Clean-up if the gesture interpreter has been successfully created. |
| 91 if (interpreter_) { | 103 if (interpreter_) { |
| 104 // Unset callbacks. |
| 105 GestureInterpreterSetCallback(interpreter_, NULL, NULL); |
| 106 GestureInterpreterSetPropProvider(interpreter_, NULL, NULL); |
| 107 GestureInterpreterSetTimerProvider(interpreter_, NULL, NULL); |
| 92 DeleteGestureInterpreter(interpreter_); | 108 DeleteGestureInterpreter(interpreter_); |
| 93 interpreter_ = NULL; | 109 interpreter_ = NULL; |
| 94 } | 110 } |
| 111 |
| 112 // Unregister device from the gesture property provider. |
| 113 GesturesPropFunctionsWrapper::UnregisterDevice(this); |
| 95 } | 114 } |
| 96 | 115 |
| 97 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( | 116 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( |
| 98 Evdev* evdev, | 117 Evdev* evdev, |
| 99 EventStateRec* evstate) { | 118 EventStateRec* evstate) { |
| 100 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; | 119 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; |
| 101 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; | 120 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; |
| 102 | 121 |
| 103 HardwareProperties hwprops = GestureHardwareProperties(evdev); | 122 // Set device pointer and initialize properties. |
| 123 evdev_ = evdev; |
| 124 GesturesPropFunctionsWrapper::InitializeDeviceProperties(this, |
| 125 device_properties_.get()); |
| 126 HardwareProperties hwprops = |
| 127 GestureHardwareProperties(evdev, device_properties_.get()); |
| 104 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); | 128 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); |
| 105 | 129 |
| 106 // Create & initialize GestureInterpreter. | 130 // Create & initialize GestureInterpreter. |
| 107 DCHECK(!interpreter_); | 131 DCHECK(!interpreter_); |
| 108 interpreter_ = NewGestureInterpreter(); | 132 interpreter_ = NewGestureInterpreter(); |
| 133 GestureInterpreterSetPropProvider( |
| 134 interpreter_, |
| 135 const_cast<GesturesPropProvider*>(&kGesturePropProvider), |
| 136 this); |
| 109 GestureInterpreterInitialize(interpreter_, devclass); | 137 GestureInterpreterInitialize(interpreter_, devclass); |
| 110 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); | 138 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); |
| 111 GestureInterpreterSetTimerProvider( | 139 GestureInterpreterSetTimerProvider( |
| 112 interpreter_, | 140 interpreter_, |
| 113 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), | 141 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), |
| 114 this); | 142 this); |
| 115 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); | 143 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); |
| 116 } | 144 } |
| 117 | 145 |
| 118 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, | 146 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 bool down) { | 417 bool down) { |
| 390 const gfx::PointF& loc = cursor_->location(); | 418 const gfx::PointF& loc = cursor_->location(); |
| 391 int flag = modifiers_->GetEventFlagFromModifier(modifier); | 419 int flag = modifiers_->GetEventFlagFromModifier(modifier); |
| 392 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); | 420 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); |
| 393 modifiers_->UpdateModifier(modifier, down); | 421 modifiers_->UpdateModifier(modifier, down); |
| 394 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); | 422 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); |
| 395 Dispatch(&event); | 423 Dispatch(&event); |
| 396 } | 424 } |
| 397 | 425 |
| 398 } // namespace ui | 426 } // namespace ui |
| OLD | NEW |