| 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( |
| 85 int id, |
| 82 EventModifiersEvdev* modifiers, | 86 EventModifiersEvdev* modifiers, |
| 83 CursorDelegateEvdev* cursor, | 87 CursorDelegateEvdev* cursor, |
| 88 GesturePropertyProvider* property_provider, |
| 84 const EventDispatchCallback& callback) | 89 const EventDispatchCallback& callback) |
| 85 : modifiers_(modifiers), | 90 : id_(id), |
| 91 modifiers_(modifiers), |
| 86 cursor_(cursor), | 92 cursor_(cursor), |
| 93 property_provider_(property_provider), |
| 87 dispatch_callback_(callback), | 94 dispatch_callback_(callback), |
| 88 interpreter_(NULL) {} | 95 interpreter_(NULL), |
| 96 evdev_(NULL), |
| 97 device_properties_(new GestureDeviceProperties) { |
| 98 } |
| 89 | 99 |
| 90 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { | 100 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { |
| 101 // Note that this destructor got called after the evdev device node has been |
| 102 // closed. Therefore, all clean-up codes here shouldn't depend on the device |
| 103 // information (except for the pointer address itself). |
| 104 |
| 105 // Clean-up if the gesture interpreter has been successfully created. |
| 91 if (interpreter_) { | 106 if (interpreter_) { |
| 107 // Unset callbacks. |
| 108 GestureInterpreterSetCallback(interpreter_, NULL, NULL); |
| 109 GestureInterpreterSetPropProvider(interpreter_, NULL, NULL); |
| 110 GestureInterpreterSetTimerProvider(interpreter_, NULL, NULL); |
| 92 DeleteGestureInterpreter(interpreter_); | 111 DeleteGestureInterpreter(interpreter_); |
| 93 interpreter_ = NULL; | 112 interpreter_ = NULL; |
| 94 } | 113 } |
| 114 |
| 115 // Unregister device from the gesture property provider. |
| 116 GesturesPropFunctionsWrapper::UnregisterDevice(this); |
| 95 } | 117 } |
| 96 | 118 |
| 97 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( | 119 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( |
| 98 Evdev* evdev, | 120 Evdev* evdev, |
| 99 EventStateRec* evstate) { | 121 EventStateRec* evstate) { |
| 100 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; | 122 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; |
| 101 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; | 123 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; |
| 102 | 124 |
| 103 HardwareProperties hwprops = GestureHardwareProperties(evdev); | 125 // Set device pointer and initialize properties. |
| 126 evdev_ = evdev; |
| 127 GesturesPropFunctionsWrapper::InitializeDeviceProperties( |
| 128 this, device_properties_.get()); |
| 129 HardwareProperties hwprops = |
| 130 GestureHardwareProperties(evdev, device_properties_.get()); |
| 104 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); | 131 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); |
| 105 | 132 |
| 106 // Create & initialize GestureInterpreter. | 133 // Create & initialize GestureInterpreter. |
| 107 DCHECK(!interpreter_); | 134 DCHECK(!interpreter_); |
| 108 interpreter_ = NewGestureInterpreter(); | 135 interpreter_ = NewGestureInterpreter(); |
| 136 GestureInterpreterSetPropProvider( |
| 137 interpreter_, |
| 138 const_cast<GesturesPropProvider*>(&kGesturePropProvider), |
| 139 this); |
| 109 GestureInterpreterInitialize(interpreter_, devclass); | 140 GestureInterpreterInitialize(interpreter_, devclass); |
| 110 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); | 141 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); |
| 111 GestureInterpreterSetTimerProvider( | 142 GestureInterpreterSetTimerProvider( |
| 112 interpreter_, | 143 interpreter_, |
| 113 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), | 144 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), |
| 114 this); | 145 this); |
| 115 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); | 146 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); |
| 116 } | 147 } |
| 117 | 148 |
| 118 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, | 149 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 bool down) { | 420 bool down) { |
| 390 const gfx::PointF& loc = cursor_->location(); | 421 const gfx::PointF& loc = cursor_->location(); |
| 391 int flag = modifiers_->GetEventFlagFromModifier(modifier); | 422 int flag = modifiers_->GetEventFlagFromModifier(modifier); |
| 392 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); | 423 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); |
| 393 modifiers_->UpdateModifier(modifier, down); | 424 modifiers_->UpdateModifier(modifier, down); |
| 394 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); | 425 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); |
| 395 Dispatch(&event); | 426 Dispatch(&event); |
| 396 } | 427 } |
| 397 | 428 |
| 398 } // namespace ui | 429 } // namespace ui |
| OLD | NEW |