| 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 13 matching lines...) Expand all Loading... |
| 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 EventModifiersEvdev* modifiers, |
| 83 CursorDelegateEvdev* cursor, | 86 CursorDelegateEvdev* cursor, |
| 87 GesturePropertyProvider* prop_provider, |
| 84 const EventDispatchCallback& callback) | 88 const EventDispatchCallback& callback) |
| 85 : modifiers_(modifiers), | 89 : modifiers_(modifiers), |
| 86 cursor_(cursor), | 90 cursor_(cursor), |
| 91 prop_provider_(prop_provider), |
| 87 dispatch_callback_(callback), | 92 dispatch_callback_(callback), |
| 88 interpreter_(NULL) {} | 93 interpreter_(NULL), |
| 94 dev_(NULL), |
| 95 device_props_(new GestureDeviceProperties) {} |
| 89 | 96 |
| 90 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { | 97 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { |
| 91 if (interpreter_) { | 98 if (interpreter_) { |
| 92 DeleteGestureInterpreter(interpreter_); | 99 DeleteGestureInterpreter(interpreter_); |
| 93 interpreter_ = NULL; | 100 interpreter_ = NULL; |
| 94 } | 101 } |
| 95 } | 102 } |
| 96 | 103 |
| 97 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( | 104 void GestureInterpreterLibevdevCros::OnLibEvdevCrosOpen( |
| 98 Evdev* evdev, | 105 Evdev* evdev, |
| 99 EventStateRec* evstate) { | 106 EventStateRec* evstate) { |
| 100 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; | 107 DCHECK(evdev->info.is_monotonic) << "libevdev must use monotonic timestamps"; |
| 101 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; | 108 VLOG(9) << "HACK DO NOT REMOVE OR LINK WILL FAIL" << (void*)gestures_log; |
| 102 | 109 |
| 103 HardwareProperties hwprops = GestureHardwareProperties(evdev); | 110 // Set device pointer and initialize properties. |
| 111 dev_ = evdev; |
| 112 GesturesPropFunctionsWrapper::InitializeDeviceProperties(this, |
| 113 device_props_.get()); |
| 114 HardwareProperties hwprops = |
| 115 GestureHardwareProperties(evdev, device_props_.get()); |
| 104 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); | 116 GestureInterpreterDeviceClass devclass = GestureDeviceClass(evdev); |
| 105 | 117 |
| 106 // Create & initialize GestureInterpreter. | 118 // Create & initialize GestureInterpreter. |
| 107 DCHECK(!interpreter_); | 119 DCHECK(!interpreter_); |
| 108 interpreter_ = NewGestureInterpreter(); | 120 interpreter_ = NewGestureInterpreter(); |
| 121 GestureInterpreterSetPropProvider( |
| 122 interpreter_, |
| 123 const_cast<GesturesPropProvider*>(&kGesturePropProvider), |
| 124 this); |
| 109 GestureInterpreterInitialize(interpreter_, devclass); | 125 GestureInterpreterInitialize(interpreter_, devclass); |
| 110 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); | 126 GestureInterpreterSetHardwareProperties(interpreter_, &hwprops); |
| 111 GestureInterpreterSetTimerProvider( | 127 GestureInterpreterSetTimerProvider( |
| 112 interpreter_, | 128 interpreter_, |
| 113 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), | 129 const_cast<GesturesTimerProvider*>(&kGestureTimerProvider), |
| 114 this); | 130 this); |
| 115 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); | 131 GestureInterpreterSetCallback(interpreter_, OnGestureReadyHelper, this); |
| 116 } | 132 } |
| 117 | 133 |
| 118 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, | 134 void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 bool down) { | 405 bool down) { |
| 390 const gfx::PointF& loc = cursor_->location(); | 406 const gfx::PointF& loc = cursor_->location(); |
| 391 int flag = modifiers_->GetEventFlagFromModifier(modifier); | 407 int flag = modifiers_->GetEventFlagFromModifier(modifier); |
| 392 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); | 408 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); |
| 393 modifiers_->UpdateModifier(modifier, down); | 409 modifiers_->UpdateModifier(modifier, down); |
| 394 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); | 410 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); |
| 395 Dispatch(&event); | 411 Dispatch(&event); |
| 396 } | 412 } |
| 397 | 413 |
| 398 } // namespace ui | 414 } // namespace ui |
| OLD | NEW |