Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: ui/events/ozone/evdev/input_device_factory_evdev.cc

Issue 863353003: [PATCH 6/11] ozone: evdev: Factor device I/O out of EventFactoryOzone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile with USE_EVDEV_GESTURES Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/ozone/evdev/input_device_factory_evdev.h ('k') | ui/events/ozone/events_ozone.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63508d35c85dca789007f2a4f7a2986818264895..63427fa058b5f53d64fb7728f3f885c19223079e 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 "base/trace_event/trace_event.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,149 +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_(gesture_property_provider),
#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;
-}
-
-scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() {
- return make_scoped_ptr(new InputInjectorEvdev(
- &modifiers_, cursor_, &keyboard_, dispatch_callback_));
-}
-
-void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) {
- keyboard_.OnKeyChange(params.code, params.down);
-}
-
-void EventFactoryEvdev::DispatchMouseMoveEvent(
- const MouseMoveEventParams& params) {
- scoped_ptr<MouseEvent> event(new MouseEvent(ui::ET_MOUSE_MOVED,
- params.location, params.location,
- modifiers_.GetModifierFlags(),
- /* changed_button_flags */ 0));
- event->set_source_device_id(params.device_id);
- PostUiEvent(event.Pass());
}
-void EventFactoryEvdev::DispatchMouseButtonEvent(
- const MouseButtonEventParams& params) {
- // Mouse buttons can be remapped, touchpad taps & clicks cannot.
- unsigned int button = params.button;
- if (params.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, params.down);
-
- scoped_ptr<MouseEvent> event(new MouseEvent(
- params.down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED,
- params.location, params.location, modifiers_.GetModifierFlags() | flag,
- /* changed_button_flags */ flag));
- event->set_source_device_id(params.device_id);
- PostUiEvent(event.Pass());
+InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() {
+ STLDeleteValues(&converters_);
}
-void EventFactoryEvdev::DispatchMouseWheelEvent(
- const MouseWheelEventParams& params) {
- scoped_ptr<MouseWheelEvent> event(new MouseWheelEvent(
- params.delta, params.location, params.location,
- modifiers_.GetModifierFlags(), 0 /* changed_button_flags */));
- event->set_source_device_id(params.device_id);
- PostUiEvent(event.Pass());
-}
+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::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 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(&params),
+ 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();
@@ -324,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(&params),
- 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());
@@ -387,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 &&
@@ -415,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 &&
@@ -426,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;
@@ -437,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 &&
@@ -447,7 +287,7 @@ void EventFactoryEvdev::EnableInternalKeyboard() {
}
}
-void EventFactoryEvdev::NotifyDeviceChange(
+void InputDeviceFactoryEvdev::NotifyDeviceChange(
const EventConverterEvdev& converter) {
if (converter.HasTouchscreen())
NotifyTouchscreensUpdated();
@@ -456,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) {
@@ -473,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) {
@@ -486,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;
« no previous file with comments | « ui/events/ozone/evdev/input_device_factory_evdev.h ('k') | ui/events/ozone/events_ozone.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698