Chromium Code Reviews| Index: ui/events/ozone/evdev/input_device_factory_evdev.cc |
| diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/input_device_factory_evdev.cc |
| similarity index 52% |
| copy from ui/events/ozone/evdev/event_factory_evdev.cc |
| copy to ui/events/ozone/evdev/input_device_factory_evdev.cc |
| index 25bed399af26cbd103932b478fc86a7e8b5c51e2..3fea5ecbf1fa283060b78b29c3d3e870364fd833 100644 |
| --- a/ui/events/ozone/evdev/event_factory_evdev.cc |
| +++ b/ui/events/ozone/evdev/input_device_factory_evdev.cc |
| @@ -1,27 +1,20 @@ |
| -// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ui/events/ozone/evdev/event_factory_evdev.h" |
| +#include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
| #include <fcntl.h> |
| #include <linux/input.h> |
| -#include "base/bind.h" |
| #include "base/debug/trace_event.h" |
| #include "base/stl_util.h" |
| -#include "base/task_runner.h" |
| -#include "base/thread_task_runner_handle.h" |
| #include "base/threading/worker_pool.h" |
| #include "base/time/time.h" |
| #include "ui/events/devices/device_data_manager.h" |
| #include "ui/events/devices/device_util_linux.h" |
| -#include "ui/events/devices/input_device.h" |
| -#include "ui/events/ozone/device/device_event.h" |
| -#include "ui/events/ozone/device/device_manager.h" |
| -#include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| -#include "ui/events/ozone/evdev/input_injector_evdev.h" |
| +#include "ui/events/ozone/evdev/event_device_info.h" |
| #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| @@ -32,7 +25,7 @@ |
| #endif |
| #ifndef EVIOCSCLOCKID |
| -#define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| +#define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| #endif |
| namespace ui { |
| @@ -163,154 +156,54 @@ void CloseInputDevice(const base::FilePath& path, |
| } // namespace |
| -EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| - DeviceManager* device_manager, |
| - KeyboardLayoutEngine* keyboard_layout) |
| - : last_device_id_(0), |
| - device_manager_(device_manager), |
| - dispatch_callback_( |
| - base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), |
| - keyboard_(&modifiers_, keyboard_layout, dispatch_callback_), |
| - cursor_(cursor), |
| +InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( |
| + DeviceEventDispatcherEvdev* dispatcher, |
| + scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, |
| #if defined(USE_EVDEV_GESTURES) |
| - gesture_property_provider_(new GesturePropertyProvider), |
| + GesturePropertyProvider* gesture_property_provider, |
| #endif |
| - input_controller_(this, |
| - &keyboard_, |
| - &button_map_ |
| + CursorDelegateEvdev* cursor) |
| + : ui_task_runner_(dispatch_runner), |
| + cursor_(cursor), |
| #if defined(USE_EVDEV_GESTURES) |
| - , |
| - gesture_property_provider_.get() |
| + gesture_property_provider_(new GesturePropertyProvider), |
|
spang
2015/01/27 20:25:21
Oops.
alexst (slow to review)
2015/01/27 20:26:18
Noted in patch 7.
|
| #endif |
| - ), |
| - initialized_(false), |
| + dispatcher_(dispatcher), |
| 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; |
| +InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
| + STLDeleteValues(&converters_); |
| } |
| -scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { |
| - return make_scoped_ptr(new InputInjectorEvdev( |
| - &modifiers_, cursor_, &keyboard_, dispatch_callback_)); |
| -} |
| +void InputDeviceFactoryEvdev::AddInputDevice(int id, |
| + const base::FilePath& path) { |
| + scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| + params->id = id; |
| + params->path = path; |
| + params->cursor = cursor_; |
| + params->dispatcher = dispatcher_; |
| -void EventFactoryEvdev::DispatchKeyEvent(int device_id, |
| - unsigned int code, |
| - bool down) { |
| - keyboard_.OnKeyChange(code, down); |
| -} |
| - |
| -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)); |
| - event->set_source_device_id(device_id); |
| - PostUiEvent(event.Pass()); |
| -} |
| - |
| -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); |
| - |
| - int modifier = EVDEV_MODIFIER_NONE; |
| - switch (button) { |
| - case BTN_LEFT: |
| - modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; |
| - break; |
| - case BTN_RIGHT: |
| - modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; |
| - break; |
| - case BTN_MIDDLE: |
| - modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; |
| - break; |
| - default: |
| - return; |
| - } |
| - |
| - int flag = modifiers_.GetEventFlagFromModifier(modifier); |
| - modifiers_.UpdateModifier(modifier, down); |
| - |
| - scoped_ptr<MouseEvent> event( |
| - new MouseEvent(down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, |
| - location, location, modifiers_.GetModifierFlags() | flag, |
| - /* changed_button_flags */ flag)); |
| - event->set_source_device_id(device_id); |
| - PostUiEvent(event.Pass()); |
| -} |
| - |
| -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 */)); |
| - event->set_source_device_id(device_id); |
| - PostUiEvent(event.Pass()); |
| -} |
| - |
| -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(), |
| - params.ordinal_delta.x(), params.ordinal_delta.y(), params.finger_count)); |
| - event->set_source_device_id(params.device_id); |
| - PostUiEvent(event.Pass()); |
| -} |
| +#if defined(USE_EVDEV_GESTURES) |
| + params->gesture_property_provider = gesture_property_provider_; |
| +#endif |
| -void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) { |
| - float x = params.location.x(); |
| - float y = params.location.y(); |
| - double radius_x = params.radii.x(); |
| - double radius_y = params.radii.y(); |
| - |
| - // Transform the event according (this is used to align touches |
| - // to the image based on display mode). |
| - DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, |
| - &y); |
| - DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, |
| - &radius_x); |
| - DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, |
| - &radius_y); |
| - |
| - scoped_ptr<TouchEvent> touch_event(new TouchEvent( |
| - params.type, gfx::PointF(x, y), |
| - /* flags */ 0, params.touch_id, params.timestamp, radius_x, radius_y, |
| - /* angle */ 0., params.pressure)); |
| - touch_event->set_source_device_id(params.device_id); |
| - PostUiEvent(touch_event.Pass()); |
| -} |
| + OpenInputDeviceReplyCallback reply_callback = |
| + base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, |
| + weak_ptr_factory_.GetWeakPtr()); |
| -void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&EventFactoryEvdev::DispatchUiEventTask, |
| - weak_ptr_factory_.GetWeakPtr(), |
| - base::Passed(&event))); |
| + // Dispatch task to open from the worker pool, since open may block. |
| + base::WorkerPool::PostTask(FROM_HERE, |
| + base::Bind(&OpenInputDevice, base::Passed(¶ms), |
| + ui_task_runner_, reply_callback), |
| + true /* task_is_slow */); |
| } |
| -void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { |
| - DispatchEvent(event.get()); |
| +void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { |
| + DetachInputDevice(path); |
| } |
| -void EventFactoryEvdev::AttachInputDevice( |
| +void InputDeviceFactoryEvdev::AttachInputDevice( |
| scoped_ptr<EventConverterEvdev> converter) { |
| const base::FilePath& path = converter->path(); |
| @@ -329,52 +222,7 @@ void EventFactoryEvdev::AttachInputDevice( |
| NotifyDeviceChange(*converters_[path]); |
| } |
| -void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
| - if (event.device_type() != DeviceEvent::INPUT) |
| - return; |
| - |
| - switch (event.action_type()) { |
| - case DeviceEvent::ADD: |
| - case DeviceEvent::CHANGE: { |
| - TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
| - |
| - scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| - params->id = NextDeviceId(); |
| - params->path = event.path(); |
| - params->cursor = cursor_; |
| - params->dispatcher = this; |
| - |
| -#if defined(USE_EVDEV_GESTURES) |
| - params->gesture_property_provider = gesture_property_provider_.get(); |
| -#endif |
| - |
| - OpenInputDeviceReplyCallback reply_callback = |
| - base::Bind(&EventFactoryEvdev::AttachInputDevice, |
| - weak_ptr_factory_.GetWeakPtr()); |
| - |
| - // Dispatch task to open from the worker pool, since open may block. |
| - base::WorkerPool::PostTask(FROM_HERE, |
| - base::Bind(&OpenInputDevice, |
| - base::Passed(¶ms), |
| - ui_task_runner_, |
| - reply_callback), |
| - true /* task_is_slow */); |
| - } |
| - break; |
| - case DeviceEvent::REMOVE: { |
| - TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); |
| - DetachInputDevice(event.path()); |
| - } |
| - break; |
| - } |
| -} |
| - |
| -void EventFactoryEvdev::OnDispatcherListChanged() { |
| - if (!initialized_) |
| - Init(); |
| -} |
| - |
| -void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| +void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
| DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| @@ -392,24 +240,11 @@ void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| // Dispatch task to close from the worker pool, since close may block. |
| base::WorkerPool::PostTask( |
| FROM_HERE, |
| - base::Bind(&CloseInputDevice, path, base::Passed(&converter)), |
| - true); |
| + base::Bind(&CloseInputDevice, path, base::Passed(&converter)), true); |
| } |
| } |
| -void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
| - const gfx::PointF& location) { |
| - if (cursor_) { |
| - cursor_->MoveCursorTo(widget, location); |
| - PostUiEvent(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, |
| - cursor_->GetLocation(), |
| - cursor_->GetLocation(), |
| - modifiers_.GetModifierFlags(), |
| - /* changed_button_flags */ 0))); |
| - } |
| -} |
| - |
| -void EventFactoryEvdev::DisableInternalTouchpad() { |
| +void InputDeviceFactoryEvdev::DisableInternalTouchpad() { |
| for (const auto& it : converters_) { |
| EventConverterEvdev* converter = it.second; |
| if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
| @@ -420,7 +255,7 @@ void EventFactoryEvdev::DisableInternalTouchpad() { |
| } |
| } |
| -void EventFactoryEvdev::EnableInternalTouchpad() { |
| +void InputDeviceFactoryEvdev::EnableInternalTouchpad() { |
| for (const auto& it : converters_) { |
| EventConverterEvdev* converter = it.second; |
| if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
| @@ -431,7 +266,7 @@ void EventFactoryEvdev::EnableInternalTouchpad() { |
| } |
| } |
| -void EventFactoryEvdev::DisableInternalKeyboardExceptKeys( |
| +void InputDeviceFactoryEvdev::DisableInternalKeyboardExceptKeys( |
| scoped_ptr<std::set<DomCode>> excepted_keys) { |
| for (const auto& it : converters_) { |
| EventConverterEvdev* converter = it.second; |
| @@ -442,7 +277,7 @@ void EventFactoryEvdev::DisableInternalKeyboardExceptKeys( |
| } |
| } |
| -void EventFactoryEvdev::EnableInternalKeyboard() { |
| +void InputDeviceFactoryEvdev::EnableInternalKeyboard() { |
| for (const auto& it : converters_) { |
| EventConverterEvdev* converter = it.second; |
| if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
| @@ -452,7 +287,7 @@ void EventFactoryEvdev::EnableInternalKeyboard() { |
| } |
| } |
| -void EventFactoryEvdev::NotifyDeviceChange( |
| +void InputDeviceFactoryEvdev::NotifyDeviceChange( |
| const EventConverterEvdev& converter) { |
| if (converter.HasTouchscreen()) |
| NotifyTouchscreensUpdated(); |
| @@ -461,7 +296,7 @@ void EventFactoryEvdev::NotifyDeviceChange( |
| NotifyKeyboardsUpdated(); |
| } |
| -void EventFactoryEvdev::NotifyTouchscreensUpdated() { |
| +void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { |
| DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| std::vector<TouchscreenDevice> touchscreens; |
| for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| @@ -478,7 +313,7 @@ void EventFactoryEvdev::NotifyTouchscreensUpdated() { |
| observer->OnTouchscreenDevicesUpdated(touchscreens); |
| } |
| -void EventFactoryEvdev::NotifyKeyboardsUpdated() { |
| +void InputDeviceFactoryEvdev::NotifyKeyboardsUpdated() { |
| DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| std::vector<KeyboardDevice> keyboards; |
| for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| @@ -491,12 +326,8 @@ void EventFactoryEvdev::NotifyKeyboardsUpdated() { |
| observer->OnKeyboardDevicesUpdated(keyboards); |
| } |
| -int EventFactoryEvdev::NextDeviceId() { |
| - return ++last_device_id_; |
| -} |
| - |
| -bool EventFactoryEvdev::GetDeviceIdsByType(const EventDeviceType type, |
| - std::vector<int>* device_ids) { |
| +bool InputDeviceFactoryEvdev::GetDeviceIdsByType(const EventDeviceType type, |
| + std::vector<int>* device_ids) { |
| if (device_ids) |
| device_ids->clear(); |
| std::vector<int> ids; |