| Index: ui/events/ozone/evdev/event_factory_evdev.cc
|
| diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc
|
| index 3a446f3619a98af7798f01374deba83421398073..25bed399af26cbd103932b478fc86a7e8b5c51e2 100644
|
| --- a/ui/events/ozone/evdev/event_factory_evdev.cc
|
| +++ b/ui/events/ozone/evdev/event_factory_evdev.cc
|
| @@ -49,13 +49,8 @@ struct OpenInputDeviceParams {
|
| // Device path to open.
|
| base::FilePath path;
|
|
|
| - // Callback for dispatching events. Call on UI thread only.
|
| - KeyEventDispatchCallback key_callback;
|
| - MouseMoveEventDispatchCallback mouse_move_callback;
|
| - MouseButtonEventDispatchCallback mouse_button_callback;
|
| - MouseWheelEventDispatchCallback mouse_wheel_callback;
|
| - ScrollEventDispatchCallback scroll_callback;
|
| - TouchEventDispatchCallback touch_callback;
|
| + // Dispatcher for events. Call on UI thread only.
|
| + DeviceEventDispatcherEvdev* dispatcher;
|
|
|
| // State shared between devices. Must not be dereferenced on worker thread.
|
| CursorDelegateEvdev* cursor;
|
| @@ -88,9 +83,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
|
| scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp =
|
| make_scoped_ptr(new GestureInterpreterLibevdevCros(
|
| params.id, params.cursor, params.gesture_property_provider,
|
| - params.key_callback, params.mouse_move_callback,
|
| - params.mouse_button_callback, params.mouse_wheel_callback,
|
| - params.scroll_callback));
|
| + params.dispatcher));
|
| return make_scoped_ptr(new EventReaderLibevdevCros(
|
| fd, params.path, params.id, type, devinfo, gesture_interp.Pass()));
|
| }
|
| @@ -99,7 +92,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
|
| // Touchscreen: use TouchEventConverterEvdev.
|
| if (devinfo.HasMTAbsXY()) {
|
| scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev(
|
| - fd, params.path, params.id, type, params.touch_callback));
|
| + fd, params.path, params.id, type, params.dispatcher));
|
| converter->Initialize(devinfo);
|
| return converter.Pass();
|
| }
|
| @@ -108,13 +101,12 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
|
| if (devinfo.HasAbsXY())
|
| return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev(
|
| fd, params.path, params.id, type, params.cursor, devinfo,
|
| - params.mouse_move_callback, params.mouse_button_callback));
|
| + params.dispatcher));
|
|
|
| // Everything else: use EventConverterEvdevImpl.
|
| - return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl(
|
| - fd, params.path, params.id, type, devinfo, params.cursor,
|
| - params.key_callback, params.mouse_move_callback,
|
| - params.mouse_button_callback));
|
| + return make_scoped_ptr<EventConverterEvdevImpl>(
|
| + new EventConverterEvdevImpl(fd, params.path, params.id, type, devinfo,
|
| + params.cursor, params.dispatcher));
|
| }
|
|
|
| // Open an input device. Opening may put the calling thread to sleep, and
|
| @@ -191,25 +183,37 @@ EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor,
|
| gesture_property_provider_.get()
|
| #endif
|
| ),
|
| + initialized_(false),
|
| weak_ptr_factory_(this) {
|
| DCHECK(device_manager_);
|
| }
|
|
|
| EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); }
|
|
|
| +void EventFactoryEvdev::Init() {
|
| + DCHECK(!initialized_);
|
| + ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| +
|
| + // Scan & monitor devices.
|
| + device_manager_->AddObserver(this);
|
| + device_manager_->ScanDevices(this);
|
| +
|
| + initialized_ = true;
|
| +}
|
| +
|
| scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() {
|
| return make_scoped_ptr(new InputInjectorEvdev(
|
| &modifiers_, cursor_, &keyboard_, dispatch_callback_));
|
| }
|
|
|
| -void EventFactoryEvdev::PostKeyEvent(int device_id,
|
| - unsigned int code,
|
| - bool down) {
|
| +void EventFactoryEvdev::DispatchKeyEvent(int device_id,
|
| + unsigned int code,
|
| + bool down) {
|
| keyboard_.OnKeyChange(code, down);
|
| }
|
|
|
| -void EventFactoryEvdev::PostMouseMoveEvent(int device_id,
|
| - const gfx::PointF& location) {
|
| +void EventFactoryEvdev::DispatchMouseMoveEvent(int device_id,
|
| + const gfx::PointF& location) {
|
| scoped_ptr<MouseEvent> event(new MouseEvent(
|
| ui::ET_MOUSE_MOVED, location, location, modifiers_.GetModifierFlags(),
|
| /* changed_button_flags */ 0));
|
| @@ -217,11 +221,11 @@ void EventFactoryEvdev::PostMouseMoveEvent(int device_id,
|
| PostUiEvent(event.Pass());
|
| }
|
|
|
| -void EventFactoryEvdev::PostMouseButtonEvent(int device_id,
|
| - const gfx::PointF& location,
|
| - unsigned int button,
|
| - bool down,
|
| - bool allow_remap) {
|
| +void EventFactoryEvdev::DispatchMouseButtonEvent(int device_id,
|
| + const gfx::PointF& location,
|
| + unsigned int button,
|
| + bool down,
|
| + bool allow_remap) {
|
| // Mouse buttons can be remapped, touchpad taps & clicks cannot.
|
| if (allow_remap)
|
| button = button_map_.GetMappedButton(button);
|
| @@ -252,9 +256,9 @@ void EventFactoryEvdev::PostMouseButtonEvent(int device_id,
|
| PostUiEvent(event.Pass());
|
| }
|
|
|
| -void EventFactoryEvdev::PostMouseWheelEvent(int device_id,
|
| - const gfx::PointF& location,
|
| - const gfx::Vector2d& delta) {
|
| +void EventFactoryEvdev::DispatchMouseWheelEvent(int device_id,
|
| + const gfx::PointF& location,
|
| + const gfx::Vector2d& delta) {
|
| scoped_ptr<MouseWheelEvent> event(new MouseWheelEvent(
|
| delta, location, location, modifiers_.GetModifierFlags(),
|
| 0 /* changed_button_flags */));
|
| @@ -262,7 +266,7 @@ void EventFactoryEvdev::PostMouseWheelEvent(int device_id,
|
| PostUiEvent(event.Pass());
|
| }
|
|
|
| -void EventFactoryEvdev::PostScrollEvent(const ScrollEventParams& params) {
|
| +void EventFactoryEvdev::DispatchScrollEvent(const ScrollEventParams& params) {
|
| scoped_ptr<ScrollEvent> event(new ScrollEvent(
|
| params.type, params.location, params.timestamp,
|
| modifiers_.GetModifierFlags(), params.delta.x(), params.delta.y(),
|
| @@ -271,7 +275,7 @@ void EventFactoryEvdev::PostScrollEvent(const ScrollEventParams& params) {
|
| PostUiEvent(event.Pass());
|
| }
|
|
|
| -void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) {
|
| +void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) {
|
| float x = params.location.x();
|
| float y = params.location.y();
|
| double radius_x = params.radii.x();
|
| @@ -338,21 +342,7 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
|
| params->id = NextDeviceId();
|
| params->path = event.path();
|
| params->cursor = cursor_;
|
| - params->key_callback = base::Bind(&EventFactoryEvdev::PostKeyEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| - params->mouse_move_callback =
|
| - base::Bind(&EventFactoryEvdev::PostMouseMoveEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| - params->mouse_button_callback =
|
| - base::Bind(&EventFactoryEvdev::PostMouseButtonEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| - params->mouse_wheel_callback =
|
| - base::Bind(&EventFactoryEvdev::PostMouseWheelEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| - params->scroll_callback = base::Bind(&EventFactoryEvdev::PostScrollEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| - params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent,
|
| - weak_ptr_factory_.GetWeakPtr());
|
| + params->dispatcher = this;
|
|
|
| #if defined(USE_EVDEV_GESTURES)
|
| params->gesture_property_provider = gesture_property_provider_.get();
|
| @@ -380,12 +370,8 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
|
| }
|
|
|
| void EventFactoryEvdev::OnDispatcherListChanged() {
|
| - if (!ui_task_runner_.get()) {
|
| - ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| - // Scan & monitor devices.
|
| - device_manager_->AddObserver(this);
|
| - device_manager_->ScanDevices(this);
|
| - }
|
| + if (!initialized_)
|
| + Init();
|
| }
|
|
|
| void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) {
|
|
|