Commit 72486d99 authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Use DeviceEventDispatcherEvdev from InputInjectorEvdev

This makes the injector use the same interface as the devices
themselves. It also allows us to remove the PostTask after ui::Event
construction from EventFactoryEvdev, because all dispatches already
start in their own task (posted by ForwardingDeviceEventDispatcher).

BUG=449710
TEST=boot link_freon & move mouse

Review URL: https://codereview.chromium.org/882503002

Cr-Commit-Position: refs/heads/master@{#313878}
parent 1a546aaf
...@@ -144,8 +144,13 @@ void EventFactoryEvdev::Init() { ...@@ -144,8 +144,13 @@ void EventFactoryEvdev::Init() {
} }
scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() {
return make_scoped_ptr(new InputInjectorEvdev( // Use forwarding dispatcher for the injector rather than dispatching
&modifiers_, cursor_, &keyboard_, dispatch_callback_)); // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch
// synchronously from the injection point.
scoped_ptr<DeviceEventDispatcherEvdev> dispatcher(
new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(),
weak_ptr_factory_.GetWeakPtr()));
return make_scoped_ptr(new InputInjectorEvdev(dispatcher.Pass(), cursor_));
} }
void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/keycodes/dom3/dom_code.h" #include "ui/events/keycodes/dom3/dom_code.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h" #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/ozone/evdev/event_modifiers_evdev.h" #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
#include "ui/events/ozone/evdev/input_injector_evdev.h" #include "ui/events/ozone/evdev/input_injector_evdev.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h" #include "ui/events/ozone/evdev/keyboard_evdev.h"
...@@ -12,69 +13,56 @@ ...@@ -12,69 +13,56 @@
namespace ui { namespace ui {
InputInjectorEvdev::InputInjectorEvdev(EventModifiersEvdev* modifiers, namespace {
CursorDelegateEvdev* cursor,
KeyboardEvdev* keyboard, const int kDeviceIdForInjection = -1;
const EventDispatchCallback& callback)
: modifiers_(modifiers), } // namespace
cursor_(cursor),
keyboard_(keyboard), InputInjectorEvdev::InputInjectorEvdev(
callback_(callback) { scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
DCHECK(modifiers_); CursorDelegateEvdev* cursor)
DCHECK(cursor_); : cursor_(cursor), dispatcher_(dispatcher.Pass()) {
DCHECK(keyboard_);
} }
InputInjectorEvdev::~InputInjectorEvdev() { InputInjectorEvdev::~InputInjectorEvdev() {
} }
void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) { void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) {
int changed_button = 0; unsigned int code;
switch (button) {
switch(button) {
case EF_LEFT_MOUSE_BUTTON: case EF_LEFT_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; code = BTN_LEFT;
break; break;
case EF_RIGHT_MOUSE_BUTTON: case EF_RIGHT_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; code = BTN_RIGHT;
break; break;
case EF_MIDDLE_MOUSE_BUTTON: case EF_MIDDLE_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; code = BTN_MIDDLE;
default: default:
LOG(WARNING) << "Invalid flag: " << button << " for the button parameter"; LOG(WARNING) << "Invalid flag: " << button << " for the button parameter";
return; return;
} }
modifiers_->UpdateModifier(changed_button, down); dispatcher_->DispatchMouseButtonEvent(
int changed_button_flag = MouseButtonEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
EventModifiersEvdev::GetEventFlagFromModifier(changed_button); code, down, false /* allow_remap */));
callback_.Run(make_scoped_ptr(new MouseEvent(
(down) ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED,
cursor_->GetLocation(),
cursor_->GetLocation(),
modifiers_->GetModifierFlags() | changed_button_flag,
changed_button_flag)));
} }
void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) { void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) {
callback_.Run(make_scoped_ptr(new MouseWheelEvent( dispatcher_->DispatchMouseWheelEvent(
gfx::Vector2d(delta_x, delta_y), MouseWheelEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
cursor_->GetLocation(), gfx::Vector2d(delta_x, delta_y)));
cursor_->GetLocation(),
modifiers_->GetModifierFlags(),
0 /* changed_button_flags */)));
} }
void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) { void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) {
if (cursor_) { if (!cursor_)
cursor_->MoveCursorTo(location); return;
callback_.Run(make_scoped_ptr(new MouseEvent(
ET_MOUSE_MOVED, cursor_->MoveCursorTo(location);
cursor_->GetLocation(),
cursor_->GetLocation(), dispatcher_->DispatchMouseMoveEvent(
modifiers_->GetModifierFlags(), MouseMoveEventParams(kDeviceIdForInjection, cursor_->GetLocation()));
0 /* changed_button_flags */)));
}
} }
void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) { void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) {
...@@ -84,7 +72,9 @@ void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) { ...@@ -84,7 +72,9 @@ void InputInjectorEvdev::InjectKeyPress(DomCode physical_key, bool down) {
int native_keycode = KeycodeConverter::DomCodeToNativeKeycode(physical_key); int native_keycode = KeycodeConverter::DomCodeToNativeKeycode(physical_key);
int evdev_code = NativeCodeToEvdevCode(native_keycode); int evdev_code = NativeCodeToEvdevCode(native_keycode);
keyboard_->OnKeyChange(evdev_code, down);
dispatcher_->DispatchKeyEvent(
KeyEventParams(kDeviceIdForInjection, evdev_code, down));
} }
} // namespace ui } // namespace ui
......
...@@ -13,16 +13,13 @@ namespace ui { ...@@ -13,16 +13,13 @@ namespace ui {
class Event; class Event;
class CursorDelegateEvdev; class CursorDelegateEvdev;
class KeyboardEvdev; class DeviceEventDispatcherEvdev;
class EventModifiersEvdev;
class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev
: public SystemInputInjector { : public SystemInputInjector {
public: public:
InputInjectorEvdev(EventModifiersEvdev* modifiers, InputInjectorEvdev(scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
CursorDelegateEvdev* cursor, CursorDelegateEvdev* cursor);
KeyboardEvdev* keyboard,
const EventDispatchCallback& callback);
~InputInjectorEvdev() override; ~InputInjectorEvdev() override;
...@@ -33,17 +30,11 @@ class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev ...@@ -33,17 +30,11 @@ class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev
void InjectKeyPress(DomCode physical_key, bool down) override; void InjectKeyPress(DomCode physical_key, bool down) override;
private: private:
// Modifier key state (shift, ctrl, etc).
EventModifiersEvdev* modifiers_;
// Shared cursor state. // Shared cursor state.
CursorDelegateEvdev* cursor_; CursorDelegateEvdev* cursor_;
// Shared keyboard state. // Interface for dispatching events.
KeyboardEvdev* keyboard_; scoped_ptr<DeviceEventDispatcherEvdev> dispatcher_;
// Callback for dispatching events.
EventDispatchCallback callback_;
DISALLOW_COPY_AND_ASSIGN(InputInjectorEvdev); DISALLOW_COPY_AND_ASSIGN(InputInjectorEvdev);
}; };
......
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h" #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/event_modifiers_evdev.h" #include "ui/events/ozone/evdev/event_converter_test_util.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h" #include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/events_ozone.h" #include "ui/events/ozone/events_ozone.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
...@@ -108,10 +109,11 @@ class InputInjectorEvdevTest : public testing::Test { ...@@ -108,10 +109,11 @@ class InputInjectorEvdevTest : public testing::Test {
void ExpectClick(int x, int y, int button, int count); void ExpectClick(int x, int y, int button, int count);
EventObserver event_observer_; EventObserver event_observer_;
EventModifiersEvdev modifiers_;
EventDispatchCallback dispatch_callback_; EventDispatchCallback dispatch_callback_;
MockCursorEvdev cursor_; MockCursorEvdev cursor_;
KeyboardEvdev keyboard_;
scoped_ptr<DeviceManager> device_manager_;
scoped_ptr<EventFactoryEvdev> event_factory_;
InputInjectorEvdev injector_; InputInjectorEvdev injector_;
...@@ -125,10 +127,14 @@ class InputInjectorEvdevTest : public testing::Test { ...@@ -125,10 +127,14 @@ class InputInjectorEvdevTest : public testing::Test {
InputInjectorEvdevTest::InputInjectorEvdevTest() InputInjectorEvdevTest::InputInjectorEvdevTest()
: dispatch_callback_(base::Bind(&EventObserver::EventDispatchCallback, : dispatch_callback_(base::Bind(&EventObserver::EventDispatchCallback,
base::Unretained(&event_observer_))), base::Unretained(&event_observer_))),
keyboard_(&modifiers_, device_manager_(CreateDeviceManagerForTest()),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), event_factory_(CreateEventFactoryEvdevForTest(
dispatch_callback_), &cursor_,
injector_(&modifiers_, &cursor_, &keyboard_, dispatch_callback_) { device_manager_.get(),
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
dispatch_callback_)),
injector_(CreateDeviceEventDispatcherEvdevForTest(event_factory_.get()),
&cursor_) {
} }
void InputInjectorEvdevTest::SimulateMouseClick(int x, void InputInjectorEvdevTest::SimulateMouseClick(int x,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment