Commit c21dfe90 authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Move EventModifiersEvdev usage to EventFactoryEvdev

This is part of a series moving IO on evdev devices to a fast thread,
since UI thread is too slow for the cursor.

EventModifiersEvdev is a UI thread object, so move all remaining
ui::Event construction outside of the device-specific objects. Devices
no longer get a EventModifiersEvdev* since they will execute on a
different thread.

This completes the series moving ui::Event construction out of device
objects and into EventFactoryEvdev.

BUG=449710
TEST=boot link_freon & click mouse

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

Cr-Commit-Position: refs/heads/master@{#313464}
parent e6117333
......@@ -27,7 +27,6 @@ EventConverterEvdevImpl::EventConverterEvdevImpl(
int id,
InputDeviceType type,
const EventDeviceInfo& devinfo,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const KeyEventDispatchCallback& key_callback,
const MouseMoveEventDispatchCallback& mouse_move_callback,
......@@ -38,7 +37,6 @@ EventConverterEvdevImpl::EventConverterEvdevImpl(
x_offset_(0),
y_offset_(0),
cursor_(cursor),
modifiers_(modifiers),
key_callback_(key_callback),
mouse_move_callback_(mouse_move_callback),
mouse_button_callback_(mouse_button_callback) {
......
......@@ -32,7 +32,6 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl
int id,
InputDeviceType type,
const EventDeviceInfo& info,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const KeyEventDispatchCallback& key_callback,
const MouseMoveEventDispatchCallback& mouse_move_callback,
......@@ -79,9 +78,6 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl
// Shared cursor state.
CursorDelegateEvdev* cursor_;
// Modifier key state (shift, ctrl, etc).
EventModifiersEvdev* modifiers_;
// Callbacks for dispatching events.
KeyEventDispatchCallback key_callback_;
MouseMoveEventDispatchCallback mouse_move_callback_;
......
......@@ -26,7 +26,6 @@ class MockEventConverterEvdevImpl : public EventConverterEvdevImpl {
public:
MockEventConverterEvdevImpl(
int fd,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const KeyEventDispatchCallback& key_callback,
const MouseMoveEventDispatchCallback& mouse_move_callback,
......@@ -36,7 +35,6 @@ class MockEventConverterEvdevImpl : public EventConverterEvdevImpl {
1,
INPUT_DEVICE_UNKNOWN,
EventDeviceInfo(),
modifiers,
cursor,
key_callback,
mouse_move_callback,
......@@ -133,7 +131,7 @@ class EventConverterEvdevImplTest : public testing::Test {
base::Unretained(this))));
device_.reset(new ui::MockEventConverterEvdevImpl(
events_in_, event_factory_->modifiers(), cursor_.get(),
events_in_, cursor_.get(),
base::Bind(&ui::EventFactoryEvdev::PostKeyEvent,
base::Unretained(event_factory_.get())),
base::Bind(&ui::EventFactoryEvdev::PostMouseMoveEvent,
......
......@@ -44,6 +44,39 @@ MouseButtonEventParams::MouseButtonEventParams(
MouseButtonEventParams::~MouseButtonEventParams() {
}
MouseWheelEventParams::MouseWheelEventParams(int device_id,
const gfx::PointF& location,
const gfx::Vector2d& delta)
: device_id(device_id), location(location), delta(delta) {
}
MouseWheelEventParams::MouseWheelEventParams(
const MouseWheelEventParams& other) = default;
MouseWheelEventParams::~MouseWheelEventParams() {
}
ScrollEventParams::ScrollEventParams(int device_id,
EventType type,
const gfx::PointF location,
const gfx::Vector2dF delta,
const gfx::Vector2dF ordinal_delta,
int finger_count,
const base::TimeDelta timestamp)
: device_id(device_id),
type(type),
location(location),
delta(delta),
ordinal_delta(ordinal_delta),
finger_count(finger_count),
timestamp(timestamp) {
}
ScrollEventParams::ScrollEventParams(const ScrollEventParams& other) = default;
ScrollEventParams::~ScrollEventParams() {
}
TouchEventParams::TouchEventParams(int device_id,
int touch_id,
EventType type,
......
......@@ -10,6 +10,7 @@
#include "ui/events/event_constants.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace base {
......@@ -18,6 +19,7 @@ class TimeDelta;
namespace gfx {
class PointF;
class Vector2d;
class Vector2dF;
}
......@@ -71,6 +73,44 @@ struct EVENTS_OZONE_EVDEV_EXPORT MouseButtonEventParams {
typedef base::Callback<void(const MouseButtonEventParams& params)>
MouseButtonEventDispatchCallback;
struct EVENTS_OZONE_EVDEV_EXPORT MouseWheelEventParams {
MouseWheelEventParams(int device_id,
const gfx::PointF& location,
const gfx::Vector2d& delta);
MouseWheelEventParams(const MouseWheelEventParams& other);
~MouseWheelEventParams();
int device_id;
gfx::PointF location;
gfx::Vector2d delta;
};
typedef base::Callback<void(const MouseWheelEventParams& params)>
MouseWheelEventDispatchCallback;
struct EVENTS_OZONE_EVDEV_EXPORT ScrollEventParams {
ScrollEventParams(int device_id,
EventType type,
const gfx::PointF location,
const gfx::Vector2dF delta,
const gfx::Vector2dF ordinal_delta,
int finger_count,
const base::TimeDelta timestamp);
ScrollEventParams(const ScrollEventParams& other);
~ScrollEventParams();
int device_id;
EventType type;
const gfx::PointF location;
const gfx::Vector2dF delta;
const gfx::Vector2dF ordinal_delta;
int finger_count;
const base::TimeDelta timestamp;
};
typedef base::Callback<void(const ScrollEventParams& params)>
ScrollEventDispatchCallback;
struct EVENTS_OZONE_EVDEV_EXPORT TouchEventParams {
TouchEventParams(int device_id,
int touch_id,
......
......@@ -50,14 +50,14 @@ struct OpenInputDeviceParams {
base::FilePath path;
// Callback for dispatching events. Call on UI thread only.
EventDispatchCallback dispatch_callback;
KeyEventDispatchCallback key_callback;
MouseMoveEventDispatchCallback mouse_move_callback;
MouseButtonEventDispatchCallback mouse_button_callback;
MouseWheelEventDispatchCallback mouse_wheel_callback;
ScrollEventDispatchCallback scroll_callback;
TouchEventDispatchCallback touch_callback;
// State shared between devices. Must not be dereferenced on worker thread.
EventModifiersEvdev* modifiers;
CursorDelegateEvdev* cursor;
#if defined(USE_EVDEV_GESTURES)
GesturePropertyProvider* gesture_property_provider;
......@@ -87,10 +87,10 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
if (UseGesturesLibraryForDevice(devinfo)) {
scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp =
make_scoped_ptr(new GestureInterpreterLibevdevCros(
params.id, params.modifiers, params.cursor,
params.gesture_property_provider, params.key_callback,
params.mouse_move_callback, params.mouse_button_callback,
params.dispatch_callback));
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));
return make_scoped_ptr(new EventReaderLibevdevCros(
fd, params.path, params.id, type, devinfo, gesture_interp.Pass()));
}
......@@ -107,13 +107,13 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
// Graphics tablet
if (devinfo.HasAbsXY())
return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev(
fd, params.path, params.id, type, params.modifiers, params.cursor,
devinfo, params.dispatch_callback));
fd, params.path, params.id, type, params.cursor, devinfo,
params.mouse_move_callback, params.mouse_button_callback));
// Everything else: use EventConverterEvdevImpl.
return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl(
fd, params.path, params.id, type, devinfo, params.modifiers,
params.cursor, params.key_callback, params.mouse_move_callback,
fd, params.path, params.id, type, devinfo, params.cursor,
params.key_callback, params.mouse_move_callback,
params.mouse_button_callback));
}
......@@ -248,6 +248,24 @@ void EventFactoryEvdev::PostMouseButtonEvent(
PostUiEvent(event.Pass());
}
void EventFactoryEvdev::PostMouseWheelEvent(
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 EventFactoryEvdev::PostScrollEvent(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());
}
void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) {
float x = params.location.x();
float y = params.location.y();
......@@ -313,8 +331,6 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams);
params->id = NextDeviceId();
params->path = event.path();
params->dispatch_callback = dispatch_callback_;
params->modifiers = &modifiers_;
params->cursor = cursor_;
params->key_callback = base::Bind(&EventFactoryEvdev::PostKeyEvent,
weak_ptr_factory_.GetWeakPtr());
......@@ -324,6 +340,11 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
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());
......
......@@ -78,13 +78,12 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
InputController* input_controller() { return &input_controller_; }
// Transitional accessors for testing.
EventModifiersEvdev* modifiers() { return &modifiers_; }
// Post events to UI.
void PostKeyEvent(const KeyEventParams& params);
void PostMouseMoveEvent(const MouseMoveEventParams& params);
void PostMouseButtonEvent(const MouseButtonEventParams& params);
void PostMouseWheelEvent(const MouseWheelEventParams& parms);
void PostScrollEvent(const ScrollEventParams& params);
void PostTouchEvent(const TouchEventParams& params);
protected:
......
......@@ -15,7 +15,6 @@
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/event_device_util.h"
#include "ui/events/ozone/evdev/event_modifiers_evdev.h"
#include "ui/events/ozone/evdev/keyboard_util_evdev.h"
#include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
#include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
......@@ -88,22 +87,22 @@ const int kGestureSwipeFingerCount = 3;
GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros(
int id,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
GesturePropertyProvider* property_provider,
const KeyEventDispatchCallback& key_callback,
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback,
const EventDispatchCallback& callback)
const MouseWheelEventDispatchCallback& mouse_wheel_callback,
const ScrollEventDispatchCallback& scroll_callback)
: id_(id),
is_mouse_(false),
modifiers_(modifiers),
cursor_(cursor),
property_provider_(property_provider),
key_callback_(key_callback),
mouse_move_callback_(mouse_move_callback),
mouse_button_callback_(mouse_button_callback),
dispatch_callback_(callback),
mouse_wheel_callback_(mouse_wheel_callback),
scroll_callback_(scroll_callback),
interpreter_(NULL),
evdev_(NULL),
device_properties_(new GestureDeviceProperties) {
......@@ -294,23 +293,14 @@ void GestureInterpreterLibevdevCros::OnGestureScroll(
// TODO(spang): Use scroll->start_time
if (is_mouse_) {
Dispatch(make_scoped_ptr(new MouseWheelEvent(
gfx::Vector2d(scroll->dx, scroll->dy),
cursor_->GetLocation(),
cursor_->GetLocation(),
modifiers_->GetModifierFlags(),
0)));
mouse_wheel_callback_.Run(MouseWheelEventParams(
id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy)));
} else {
Dispatch(make_scoped_ptr(new ScrollEvent(
ET_SCROLL,
cursor_->GetLocation(),
StimeToTimedelta(gesture->end_time),
modifiers_->GetModifierFlags(),
scroll->dx,
scroll->dy,
scroll->ordinal_dx,
scroll->ordinal_dy,
kGestureScrollFingerCount)));
scroll_callback_.Run(ScrollEventParams(
id_, ET_SCROLL, cursor_->GetLocation(),
gfx::Vector2dF(scroll->dx, scroll->dy),
gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy),
kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
}
}
......@@ -362,15 +352,10 @@ void GestureInterpreterLibevdevCros::OnGestureFling(const Gesture* gesture,
: ET_SCROLL_FLING_CANCEL);
// Fling is like 2-finger scrolling but with velocity instead of displacement.
Dispatch(make_scoped_ptr(new ScrollEvent(type,
cursor_->GetLocation(),
StimeToTimedelta(gesture->end_time),
modifiers_->GetModifierFlags(),
fling->vx,
fling->vy,
fling->ordinal_vx,
fling->ordinal_vy,
kGestureScrollFingerCount)));
scroll_callback_.Run(ScrollEventParams(
id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy),
gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy),
kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
}
void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture,
......@@ -385,15 +370,11 @@ void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture,
return; // No cursor!
// Swipe is 3-finger scrolling.
Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL,
cursor_->GetLocation(),
StimeToTimedelta(gesture->end_time),
modifiers_->GetModifierFlags(),
swipe->dx,
swipe->dy,
swipe->ordinal_dx,
swipe->ordinal_dy,
kGestureSwipeFingerCount)));
scroll_callback_.Run(ScrollEventParams(
id_, ET_SCROLL, cursor_->GetLocation(),
gfx::Vector2dF(swipe->dx, swipe->dy),
gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy),
kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time)));
}
void GestureInterpreterLibevdevCros::OnGestureSwipeLift(
......@@ -407,15 +388,10 @@ void GestureInterpreterLibevdevCros::OnGestureSwipeLift(
// Turn a swipe lift into a fling start.
// TODO(spang): Figure out why and put it in this comment.
Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL_FLING_START,
cursor_->GetLocation(),
StimeToTimedelta(gesture->end_time),
modifiers_->GetModifierFlags(),
/* x_offset */ 0,
/* y_offset */ 0,
/* x_offset_ordinal */ 0,
/* y_offset_ordinal */ 0,
kGestureScrollFingerCount)));
scroll_callback_.Run(ScrollEventParams(
id_, ET_SCROLL_FLING_START, cursor_->GetLocation(),
gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */,
kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
}
void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture,
......@@ -439,10 +415,6 @@ void GestureInterpreterLibevdevCros::OnGestureMetrics(
NOTIMPLEMENTED();
}
void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) {
dispatch_callback_.Run(event.Pass());
}
void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button,
bool down) {
bool allow_remap = is_mouse_;
......
......@@ -19,7 +19,6 @@
namespace ui {
class EventDeviceInfo;
class EventModifiersEvdev;
class CursorDelegateEvdev;
struct GestureDeviceProperties;
class GesturePropertyProvider;
......@@ -42,13 +41,13 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
public:
GestureInterpreterLibevdevCros(
int id,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
GesturePropertyProvider* property_provider,
const KeyEventDispatchCallback& key_callback,
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback,
const EventDispatchCallback& callback);
const MouseWheelEventDispatchCallback& mouse_wheel_callback,
const ScrollEventDispatchCallback& scroll_callback);
~GestureInterpreterLibevdevCros() override;
// Overriden from ui::EventReaderLibevdevCros::Delegate
......@@ -81,7 +80,6 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
void OnGesturePinch(const Gesture* gesture, const GesturePinch* pinch);
void OnGestureMetrics(const Gesture* gesture, const GestureMetrics* metrics);
void Dispatch(scoped_ptr<Event> event);
void DispatchMouseButton(unsigned int modifier, bool down);
void DispatchChangedKeys(Evdev* evdev, const timeval& time);
......@@ -96,9 +94,6 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
// should be processed.
scoped_ptr<std::set<int>> allowed_keys_;
// Shared modifier state.
EventModifiersEvdev* modifiers_;
// Shared cursor state.
CursorDelegateEvdev* cursor_;
......@@ -109,7 +104,8 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
KeyEventDispatchCallback key_callback_;
MouseMoveEventDispatchCallback mouse_move_callback_;
MouseButtonEventDispatchCallback mouse_button_callback_;
EventDispatchCallback dispatch_callback_;
MouseWheelEventDispatchCallback mouse_wheel_callback_;
ScrollEventDispatchCallback scroll_callback_;
// Gestures interpretation state.
gestures::GestureInterpreter* interpreter_;
......
......@@ -17,14 +17,14 @@ TabletEventConverterEvdev::TabletEventConverterEvdev(
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const EventDeviceInfo& info,
const EventDispatchCallback& callback)
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback)
: EventConverterEvdev(fd, path, id, type),
cursor_(cursor),
modifiers_(modifiers),
callback_(callback),
mouse_move_callback_(mouse_move_callback),
mouse_button_callback_(mouse_button_callback),
stylus_(0),
abs_value_dirty_(false) {
x_abs_min_ = info.GetAbsMinimum(ABS_X);
......@@ -127,14 +127,14 @@ void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) {
if (!cursor_)
return;
unsigned int modifier;
unsigned int button;
// These are the same as X11 behaviour
if (input.code == BTN_TOUCH)
modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON;
button = BTN_LEFT;
else if (input.code == BTN_STYLUS2)
modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON;
button = BTN_RIGHT;
else if (input.code == BTN_STYLUS)
modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON;
button = BTN_MIDDLE;
else
return;
......@@ -143,12 +143,10 @@ void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) {
abs_value_dirty_ = false;
}
int flag = modifiers_->GetEventFlagFromModifier(modifier);
modifiers_->UpdateModifier(modifier, input.value);
callback_.Run(make_scoped_ptr(
new MouseEvent(input.value ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED,
cursor_->GetLocation(), cursor_->GetLocation(),
modifiers_->GetModifierFlags() | flag, flag)));
bool down = input.value;
mouse_button_callback_.Run(MouseButtonEventParams(
id_, cursor_->GetLocation(), button, down, false /* allow_remap */));
}
void TabletEventConverterEvdev::FlushEvents() {
......@@ -166,10 +164,7 @@ void TabletEventConverterEvdev::FlushEvents() {
UpdateCursor();
callback_.Run(make_scoped_ptr(
new MouseEvent(ui::ET_MOUSE_MOVED, cursor_->GetLocation(),
cursor_->GetLocation(), modifiers_->GetModifierFlags(),
/* changed_button_flags */ 0)));
mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation()));
abs_value_dirty_ = false;
}
......
......@@ -21,14 +21,15 @@ namespace ui {
class EVENTS_OZONE_EVDEV_EXPORT TabletEventConverterEvdev
: public EventConverterEvdev {
public:
TabletEventConverterEvdev(int fd,
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const EventDeviceInfo& info,
const EventDispatchCallback& callback);
TabletEventConverterEvdev(
int fd,
base::FilePath path,
int id,
InputDeviceType type,
CursorDelegateEvdev* cursor,
const EventDeviceInfo& info,
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback);
~TabletEventConverterEvdev() override;
// EventConverterEvdev:
......@@ -53,11 +54,9 @@ class EVENTS_OZONE_EVDEV_EXPORT TabletEventConverterEvdev
// Shared cursor state.
CursorDelegateEvdev* cursor_;
// Modifier key state (shift, ctrl, etc).
EventModifiersEvdev* modifiers_;
// Callback for dispatching events.
EventDispatchCallback callback_;
// Callbacks for dispatching events.
MouseMoveEventDispatchCallback mouse_move_callback_;
MouseButtonEventDispatchCallback mouse_button_callback_;
int y_abs_location_;
int x_abs_location_;
......
......@@ -17,7 +17,10 @@
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/evdev/tablet_event_converter_evdev.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h"
......@@ -38,34 +41,24 @@ namespace ui {
class MockTabletEventConverterEvdev : public TabletEventConverterEvdev {
public:
MockTabletEventConverterEvdev(int fd,
base::FilePath path,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor);
MockTabletEventConverterEvdev(
int fd,
base::FilePath path,
CursorDelegateEvdev* cursor,
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback);
~MockTabletEventConverterEvdev() override {};
void ConfigureReadMock(struct input_event* queue,
long read_this_many,
long queue_index);
unsigned size() { return dispatched_events_.size(); }
MouseEvent* event(unsigned index) {
DCHECK_GT(dispatched_events_.size(), index);
Event* ev = dispatched_events_[index];
DCHECK(ev->IsMouseEvent());
return static_cast<MouseEvent*>(ev);
}
// Actually dispatch the event reader code.
void ReadNow() {
OnFileCanReadWithoutBlocking(read_pipe_);
base::RunLoop().RunUntilIdle();
}
void DispatchCallback(scoped_ptr<Event> event) {
dispatched_events_.push_back(event.release());
}
private:
int read_pipe_;
int write_pipe_;
......@@ -104,18 +97,17 @@ class MockTabletCursorEvdev : public CursorDelegateEvdev {
MockTabletEventConverterEvdev::MockTabletEventConverterEvdev(
int fd,
base::FilePath path,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor)
: TabletEventConverterEvdev(
fd,
path,
1,
INPUT_DEVICE_UNKNOWN,
modifiers,
cursor,
EventDeviceInfo(),
base::Bind(&MockTabletEventConverterEvdev::DispatchCallback,
base::Unretained(this))) {
CursorDelegateEvdev* cursor,
const MouseMoveEventDispatchCallback& mouse_move_callback,
const MouseButtonEventDispatchCallback& mouse_button_callback)
: TabletEventConverterEvdev(fd,
path,
1,
INPUT_DEVICE_UNKNOWN,
cursor,
EventDeviceInfo(),
mouse_move_callback,
mouse_button_callback) {
// Real values taken from Wacom Intuos 4
x_abs_min_ = 0;
x_abs_range_ = 65024;
......@@ -145,6 +137,35 @@ void MockTabletEventConverterEvdev::ConfigureReadMock(struct input_event* queue,
<< "write() failed, errno: " << errno;
}
class MockDeviceManager : public ui::DeviceManager {
public:
MockDeviceManager() {}
~MockDeviceManager() override {}
// DeviceManager:
void ScanDevices(DeviceEventObserver* observer) override {}
void AddObserver(DeviceEventObserver* observer) override {}
void RemoveObserver(DeviceEventObserver* observer) override {}
};
class TestEventFactoryEvdev : public EventFactoryEvdev {
public:
TestEventFactoryEvdev(CursorDelegateEvdev* cursor,
DeviceManager* device_manager,
KeyboardLayoutEngine* keyboard_layout_engine,
const EventDispatchCallback& callback)
: EventFactoryEvdev(cursor, device_manager, keyboard_layout_engine),
callback_(callback) {}
~TestEventFactoryEvdev() override {}
private:
void PostUiEvent(scoped_ptr<Event> event) override {
callback_.Run(event.Pass());
}
EventDispatchCallback callback_;
};
} // namespace ui
// Test fixture.
......@@ -162,26 +183,47 @@ class TabletEventConverterEvdevTest : public testing::Test {
events_out_ = evdev_io[1];
cursor_.reset(new ui::MockTabletCursorEvdev());
modifiers_.reset(new ui::EventModifiersEvdev());
device_manager_.reset(new ui::MockDeviceManager);
event_factory_.reset(new ui::TestEventFactoryEvdev(
cursor_.get(), device_manager_.get(),
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
base::Bind(&TabletEventConverterEvdevTest::DispatchEventForTest,
base::Unretained(this))));
device_.reset(new ui::MockTabletEventConverterEvdev(
events_in_, base::FilePath(kTestDevicePath), modifiers_.get(),
cursor_.get()));
events_in_, base::FilePath(kTestDevicePath), cursor_.get(),
base::Bind(&ui::EventFactoryEvdev::PostMouseMoveEvent,
base::Unretained(event_factory_.get())),
base::Bind(&ui::EventFactoryEvdev::PostMouseButtonEvent,
base::Unretained(event_factory_.get()))));
}
void TearDown() override {
modifiers_.reset();
cursor_.reset();
device_.reset();
}
ui::MockTabletEventConverterEvdev* device() { return device_.get(); }
ui::CursorDelegateEvdev* cursor() { return cursor_.get(); }
ui::EventModifiersEvdev* modifiers() { return modifiers_.get(); }
unsigned size() { return dispatched_events_.size(); }
ui::MouseEvent* dispatched_event(unsigned index) {
DCHECK_GT(dispatched_events_.size(), index);
ui::Event* ev = dispatched_events_[index];
DCHECK(ev->IsMouseEvent());
return static_cast<ui::MouseEvent*>(ev);
}
void DispatchEventForTest(scoped_ptr<ui::Event> event) {
dispatched_events_.push_back(event.release());
}
private:
scoped_ptr<ui::MockTabletEventConverterEvdev> device_;
scoped_ptr<ui::MockTabletCursorEvdev> cursor_;
scoped_ptr<ui::EventModifiersEvdev> modifiers_;
scoped_ptr<ui::DeviceManager> device_manager_;
scoped_ptr<ui::EventFactoryEvdev> event_factory_;
scoped_ptr<ui::MockTabletEventConverterEvdev> device_;
ScopedVector<ui::Event> dispatched_events_;
int events_out_;
int events_in_;
......@@ -214,9 +256,9 @@ TEST_F(TabletEventConverterEvdevTest, MoveTopLeft) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(1u, dev->size());
EXPECT_EQ(1u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_LT(cursor()->GetLocation().x(), EPSILON);
......@@ -247,9 +289,9 @@ TEST_F(TabletEventConverterEvdevTest, MoveTopRight) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(1u, dev->size());
EXPECT_EQ(1u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_GT(cursor()->GetLocation().x(),
......@@ -280,9 +322,9 @@ TEST_F(TabletEventConverterEvdevTest, MoveBottomLeft) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(1u, dev->size());
EXPECT_EQ(1u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_LT(cursor()->GetLocation().x(), EPSILON);
......@@ -315,9 +357,9 @@ TEST_F(TabletEventConverterEvdevTest, MoveBottomRight) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(1u, dev->size());
EXPECT_EQ(1u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_GT(cursor()->GetLocation().x(),
......@@ -365,14 +407,14 @@ TEST_F(TabletEventConverterEvdevTest, Tap) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(3u, dev->size());
EXPECT_EQ(3u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
event = dev->event(1);
event = dispatched_event(1);
EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type());
EXPECT_EQ(true, event->IsLeftMouseButton());
event = dev->event(2);
event = dispatched_event(2);
EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type());
EXPECT_EQ(true, event->IsLeftMouseButton());
}
......@@ -412,14 +454,14 @@ TEST_F(TabletEventConverterEvdevTest, StylusButtonPress) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(3u, dev->size());
EXPECT_EQ(3u, size());
ui::MouseEvent* event = dev->event(0);
ui::MouseEvent* event = dispatched_event(0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
event = dev->event(1);
event = dispatched_event(1);
EXPECT_EQ(ui::ET_MOUSE_PRESSED, event->type());
EXPECT_EQ(true, event->IsRightMouseButton());
event = dev->event(2);
event = dispatched_event(2);
EXPECT_EQ(ui::ET_MOUSE_RELEASED, event->type());
EXPECT_EQ(true, event->IsRightMouseButton());
}
......@@ -435,5 +477,5 @@ TEST_F(TabletEventConverterEvdevTest, CheckStylusFiltering) {
};
dev->ProcessEvents(mock_kernel_queue, arraysize(mock_kernel_queue));
EXPECT_EQ(0u, dev->size());
EXPECT_EQ(0u, size());
}
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