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

Side by Side Diff: ui/events/ozone/evdev/event_converter_evdev_impl.cc

Issue 677113002: ozone: evdev: Handle mouse events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adopt spang ideas Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h"
6
7 #include <errno.h>
8 #include <linux/input.h>
9
10 #include "base/message_loop/message_loop.h"
11 #include "ui/events/event.h"
12 #include "ui/events/keycodes/dom4/keycode_converter.h"
13 #include "ui/events/keycodes/keyboard_codes.h"
14 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
15
16 namespace ui {
17
18 namespace {
19
20 } // namespace
21
22 EventConverterEvdevImpl::EventConverterEvdevImpl(
23 int fd,
24 base::FilePath path,
25 int id,
26 CursorDelegateEvdev *cursor,
27 KeyboardEvdev* keyboard,
28 const EventDispatchCallback& callback)
29 : EventConverterEvdev(fd, path, id),
30 cursor_(cursor),
31 keyboard_(keyboard),
32 callback_(callback) {
33 }
34
35 EventConverterEvdevImpl::~EventConverterEvdevImpl() {
36 Stop();
37 close(fd_);
38 }
39
40 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) {
41 input_event inputs[4];
42 ssize_t read_size = read(fd, inputs, sizeof(inputs));
43 if (read_size < 0) {
44 if (errno == EINTR || errno == EAGAIN)
45 return;
46 if (errno != ENODEV)
47 PLOG(ERROR) << "error reading device " << path_.value();
48 Stop();
49 return;
50 }
51
52 DCHECK_EQ(read_size % sizeof(*inputs), 0u);
53 ProcessEvents(inputs, read_size / sizeof(*inputs));
54 }
55
56 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs,
57 int count) {
58 for (int i = 0; i < count; ++i) {
59 const input_event& input = inputs[i];
60 if (input.type == EV_KEY)
61 ConvertKeyEvent(input);
62 else if (input.type == EV_REL)
63 ConvertMouseMoveEvent(input);
64 else if (input.type == EV_SYN) {
65 // TODO(sadrul): Handle this case appropriately.
66 }
67 }
68 }
69
70 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) {
71 int x = 0, y = 0;
72 if (input.code == REL_X)
73 x = input.value;
74 else if (input.code == REL_Y)
75 y = input.value;
76 else
77 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.
78
79 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.
80
81 callback_.Run(make_scoped_ptr(
82 new MouseEvent(ui::ET_MOUSE_MOVED,
83 cursor_->location(),
84 cursor_->location(),
85 0,
86 0)));
87 }
88
89 void EventConverterEvdevImpl::ConvertKeyEvent(
90 const input_event& input) {
91 ui::EventFlags flags;
92 if (input.code == BTN_LEFT)
93 flags = ui::EF_LEFT_MOUSE_BUTTON;
94 else if (input.code == BTN_RIGHT)
95 flags = ui::EF_RIGHT_MOUSE_BUTTON;
96 else if (input.code == BTN_MIDDLE)
97 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.
98 else {
99 keyboard_->OnKeyChange(input.code, input.value != 0);
100 return;
101 }
102
103 callback_.Run(make_scoped_ptr(
104 new MouseEvent(input.value ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED,
105 cursor_->location(),
106 cursor_->location(),
107 flags,
108 flags)));
109
110 }
111
112 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_converter_evdev_impl.h ('k') | ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698