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() {
}
scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() {
return make_scoped_ptr(new InputInjectorEvdev(
&modifiers_, cursor_, &keyboard_, dispatch_callback_));
// Use forwarding dispatcher for the injector rather than dispatching
// 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) {
......
......@@ -5,6 +5,7 @@
#include "ui/events/event.h"
#include "ui/events/keycodes/dom3/dom_code.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/input_injector_evdev.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h"
......@@ -12,69 +13,56 @@
namespace ui {
InputInjectorEvdev::InputInjectorEvdev(EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
KeyboardEvdev* keyboard,
const EventDispatchCallback& callback)
: modifiers_(modifiers),
cursor_(cursor),
keyboard_(keyboard),
callback_(callback) {
DCHECK(modifiers_);
DCHECK(cursor_);
DCHECK(keyboard_);
namespace {
const int kDeviceIdForInjection = -1;
} // namespace
InputInjectorEvdev::InputInjectorEvdev(
scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
CursorDelegateEvdev* cursor)
: cursor_(cursor), dispatcher_(dispatcher.Pass()) {
}
InputInjectorEvdev::~InputInjectorEvdev() {
}
void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) {
int changed_button = 0;
switch(button) {
unsigned int code;
switch (button) {
case EF_LEFT_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON;
code = BTN_LEFT;
break;
case EF_RIGHT_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON;
code = BTN_RIGHT;
break;
case EF_MIDDLE_MOUSE_BUTTON:
changed_button = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON;
code = BTN_MIDDLE;
default:
LOG(WARNING) << "Invalid flag: " << button << " for the button parameter";
return;
}
modifiers_->UpdateModifier(changed_button, down);
int changed_button_flag =
EventModifiersEvdev::GetEventFlagFromModifier(changed_button);
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)));
dispatcher_->DispatchMouseButtonEvent(
MouseButtonEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
code, down, false /* allow_remap */));
}
void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) {
callback_.Run(make_scoped_ptr(new MouseWheelEvent(
gfx::Vector2d(delta_x, delta_y),
cursor_->GetLocation(),
cursor_->GetLocation(),
modifiers_->GetModifierFlags(),
0 /* changed_button_flags */)));
dispatcher_->DispatchMouseWheelEvent(
MouseWheelEventParams(kDeviceIdForInjection, cursor_->GetLocation(),
gfx::Vector2d(delta_x, delta_y)));
}
void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) {
if (cursor_) {
cursor_->MoveCursorTo(location);
callback_.Run(make_scoped_ptr(new MouseEvent(
ET_MOUSE_MOVED,
cursor_->GetLocation(),
cursor_->GetLocation(),
modifiers_->GetModifierFlags(),
0 /* changed_button_flags */)));
}
if (!cursor_)
return;
cursor_->MoveCursorTo(location);
dispatcher_->DispatchMouseMoveEvent(
MouseMoveEventParams(kDeviceIdForInjection, cursor_->GetLocation()));
}
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 evdev_code = NativeCodeToEvdevCode(native_keycode);
keyboard_->OnKeyChange(evdev_code, down);
dispatcher_->DispatchKeyEvent(
KeyEventParams(kDeviceIdForInjection, evdev_code, down));
}
} // namespace ui
......
......@@ -13,16 +13,13 @@ namespace ui {
class Event;
class CursorDelegateEvdev;
class KeyboardEvdev;
class EventModifiersEvdev;
class DeviceEventDispatcherEvdev;
class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev
: public SystemInputInjector {
public:
InputInjectorEvdev(EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
KeyboardEvdev* keyboard,
const EventDispatchCallback& callback);
InputInjectorEvdev(scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
CursorDelegateEvdev* cursor);
~InputInjectorEvdev() override;
......@@ -33,17 +30,11 @@ class EVENTS_OZONE_EVDEV_EXPORT InputInjectorEvdev
void InjectKeyPress(DomCode physical_key, bool down) override;
private:
// Modifier key state (shift, ctrl, etc).
EventModifiersEvdev* modifiers_;
// Shared cursor state.
CursorDelegateEvdev* cursor_;
// Shared keyboard state.
KeyboardEvdev* keyboard_;
// Callback for dispatching events.
EventDispatchCallback callback_;
// Interface for dispatching events.
scoped_ptr<DeviceEventDispatcherEvdev> dispatcher_;
DISALLOW_COPY_AND_ASSIGN(InputInjectorEvdev);
};
......
......@@ -8,9 +8,10 @@
#include "base/run_loop.h"
#include "testing/gmock/include/gmock/gmock.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/event_modifiers_evdev.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h"
#include "ui/events/ozone/evdev/event_converter_test_util.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/events_ozone.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
......@@ -108,10 +109,11 @@ class InputInjectorEvdevTest : public testing::Test {
void ExpectClick(int x, int y, int button, int count);
EventObserver event_observer_;
EventModifiersEvdev modifiers_;
EventDispatchCallback dispatch_callback_;
MockCursorEvdev cursor_;
KeyboardEvdev keyboard_;
scoped_ptr<DeviceManager> device_manager_;
scoped_ptr<EventFactoryEvdev> event_factory_;
InputInjectorEvdev injector_;
......@@ -125,10 +127,14 @@ class InputInjectorEvdevTest : public testing::Test {
InputInjectorEvdevTest::InputInjectorEvdevTest()
: dispatch_callback_(base::Bind(&EventObserver::EventDispatchCallback,
base::Unretained(&event_observer_))),
keyboard_(&modifiers_,
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
dispatch_callback_),
injector_(&modifiers_, &cursor_, &keyboard_, dispatch_callback_) {
device_manager_(CreateDeviceManagerForTest()),
event_factory_(CreateEventFactoryEvdevForTest(
&cursor_,
device_manager_.get(),
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
dispatch_callback_)),
injector_(CreateDeviceEventDispatcherEvdevForTest(event_factory_.get()),
&cursor_) {
}
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