Chromium Code Reviews| Index: ui/events/ozone/evdev/event_converter_evdev_impl.cc |
| diff --git a/ui/events/ozone/evdev/event_converter_evdev_impl.cc b/ui/events/ozone/evdev/event_converter_evdev_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb9c1d1ee8ff09cd5e470dec8db626359917e058 |
| --- /dev/null |
| +++ b/ui/events/ozone/evdev/event_converter_evdev_impl.cc |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2014 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_converter_evdev_impl.h" |
| + |
| +#include <errno.h> |
| +#include <linux/input.h> |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "ui/events/event.h" |
| +#include "ui/events/keycodes/dom4/keycode_converter.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| +#include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +} // namespace |
| + |
| +EventConverterEvdevImpl::EventConverterEvdevImpl( |
| + int fd, |
| + base::FilePath path, |
| + int id, |
| + CursorDelegateEvdev *cursor, |
| + KeyboardEvdev* keyboard, |
| + const EventDispatchCallback& callback) |
| + : EventConverterEvdev(fd, path, id), |
| + cursor_(cursor), |
| + keyboard_(keyboard), |
| + callback_(callback) { |
| +} |
| + |
| +EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
| + Stop(); |
| + close(fd_); |
| +} |
| + |
| +void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
| + input_event inputs[4]; |
| + ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| + if (read_size < 0) { |
| + if (errno == EINTR || errno == EAGAIN) |
| + return; |
| + if (errno != ENODEV) |
| + PLOG(ERROR) << "error reading device " << path_.value(); |
| + Stop(); |
| + return; |
| + } |
| + |
| + DCHECK_EQ(read_size % sizeof(*inputs), 0u); |
| + ProcessEvents(inputs, read_size / sizeof(*inputs)); |
| +} |
| + |
| +void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, |
| + int count) { |
| + for (int i = 0; i < count; ++i) { |
| + const input_event& input = inputs[i]; |
| + if (input.type == EV_KEY) |
| + ConvertKeyEvent(input); |
| + else if (input.type == EV_REL) |
| + ConvertMouseMoveEvent(input); |
| + else if (input.type == EV_SYN) { |
| + // TODO(sadrul): Handle this case appropriately. |
| + } |
| + } |
| +} |
| + |
| +void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
| + int x = 0, y = 0; |
| + if (input.code == REL_X) |
| + x = input.value; |
| + else if (input.code == REL_Y) |
| + y = input.value; |
| + else |
| + return; |
|
spang
2014/10/24 20:44:04
please handle non-axis-aligned movement properly.
vignatti (out of this project)
2014/10/27 17:57:08
Done.
|
| + |
| + cursor_->MoveCursor(gfx::Vector2dF(x, y)); |
|
spang
2014/10/24 20:44:03
cursor can be NULL in which case all mouse events
vignatti (out of this project)
2014/10/27 17:57:07
Done.
|
| + |
| + callback_.Run(make_scoped_ptr( |
| + new MouseEvent(ui::ET_MOUSE_MOVED, |
| + cursor_->location(), |
| + cursor_->location(), |
| + 0, |
| + 0))); |
| +} |
| + |
| +void EventConverterEvdevImpl::ConvertKeyEvent( |
| + const input_event& input) { |
| + ui::EventFlags flags; |
| + if (input.code == BTN_LEFT) |
| + flags = ui::EF_LEFT_MOUSE_BUTTON; |
| + else if (input.code == BTN_RIGHT) |
| + flags = ui::EF_RIGHT_MOUSE_BUTTON; |
| + else if (input.code == BTN_MIDDLE) |
| + flags = ui::EF_MIDDLE_MOUSE_BUTTON; |
|
spang
2014/10/24 20:44:04
Please handle modifiers properly; they are shared
vignatti (out of this project)
2014/10/27 17:57:08
Done.
|
| + else { |
| + keyboard_->OnKeyChange(input.code, input.value != 0); |
| + return; |
| + } |
| + |
| + callback_.Run(make_scoped_ptr( |
| + new MouseEvent(input.value ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, |
| + cursor_->location(), |
| + cursor_->location(), |
| + flags, |
| + flags))); |
| + |
| +} |
| + |
| +} // namespace ui |