OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 | 9 |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
11 #include "ui/events/keycodes/dom4/keycode_converter.h" | 11 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 12 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
12 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" | 13 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Values for EV_KEY. | 19 // Values for EV_KEY. |
19 const int kKeyReleaseValue = 0; | 20 const int kKeyReleaseValue = 0; |
20 const int kKeyRepeatValue = 2; | 21 const int kKeyRepeatValue = 2; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 EventConverterEvdevImpl::EventConverterEvdevImpl( | 25 EventConverterEvdevImpl::EventConverterEvdevImpl( |
25 int fd, | 26 int fd, |
26 base::FilePath path, | 27 base::FilePath path, |
27 int id, | 28 int id, |
28 InputDeviceType type, | 29 InputDeviceType type, |
29 const EventDeviceInfo& devinfo, | 30 const EventDeviceInfo& devinfo, |
30 CursorDelegateEvdev* cursor, | 31 CursorDelegateEvdev* cursor, |
31 const KeyEventDispatchCallback& key_callback, | 32 DeviceEventDispatcherEvdev* dispatcher) |
32 const MouseMoveEventDispatchCallback& mouse_move_callback, | |
33 const MouseButtonEventDispatchCallback& mouse_button_callback) | |
34 : EventConverterEvdev(fd, path, id, type), | 33 : EventConverterEvdev(fd, path, id, type), |
35 has_keyboard_(devinfo.HasKeyboard()), | 34 has_keyboard_(devinfo.HasKeyboard()), |
36 has_touchpad_(devinfo.HasTouchpad()), | 35 has_touchpad_(devinfo.HasTouchpad()), |
37 x_offset_(0), | 36 x_offset_(0), |
38 y_offset_(0), | 37 y_offset_(0), |
39 cursor_(cursor), | 38 cursor_(cursor), |
40 key_callback_(key_callback), | 39 dispatcher_(dispatcher) { |
41 mouse_move_callback_(mouse_move_callback), | |
42 mouse_button_callback_(mouse_button_callback) { | |
43 } | 40 } |
44 | 41 |
45 EventConverterEvdevImpl::~EventConverterEvdevImpl() { | 42 EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
46 Stop(); | 43 Stop(); |
47 close(fd_); | 44 close(fd_); |
48 } | 45 } |
49 | 46 |
50 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { | 47 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
51 input_event inputs[4]; | 48 input_event inputs[4]; |
52 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 49 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Mouse processing. | 110 // Mouse processing. |
114 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { | 111 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { |
115 DispatchMouseButton(input); | 112 DispatchMouseButton(input); |
116 return; | 113 return; |
117 } | 114 } |
118 | 115 |
119 // Keyboard processing. | 116 // Keyboard processing. |
120 DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( | 117 DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( |
121 EvdevCodeToNativeCode(input.code)); | 118 EvdevCodeToNativeCode(input.code)); |
122 if (!allowed_keys_ || allowed_keys_->count(key_code)) | 119 if (!allowed_keys_ || allowed_keys_->count(key_code)) |
123 key_callback_.Run(id_, input.code, input.value != kKeyReleaseValue); | 120 dispatcher_->DispatchKeyEvent(id_, input.code, |
| 121 input.value != kKeyReleaseValue); |
124 } | 122 } |
125 | 123 |
126 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { | 124 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
127 if (!cursor_) | 125 if (!cursor_) |
128 return; | 126 return; |
129 switch (input.code) { | 127 switch (input.code) { |
130 case REL_X: | 128 case REL_X: |
131 x_offset_ = input.value; | 129 x_offset_ = input.value; |
132 break; | 130 break; |
133 case REL_Y: | 131 case REL_Y: |
134 y_offset_ = input.value; | 132 y_offset_ = input.value; |
135 break; | 133 break; |
136 } | 134 } |
137 } | 135 } |
138 | 136 |
139 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { | 137 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { |
140 if (!cursor_) | 138 if (!cursor_) |
141 return; | 139 return; |
142 | 140 |
143 mouse_button_callback_.Run(id_, cursor_->GetLocation(), input.code, | 141 dispatcher_->DispatchMouseButtonEvent(id_, cursor_->GetLocation(), input.code, |
144 input.value, /* allow_remap */ true); | 142 input.value, /* allow_remap */ true); |
145 } | 143 } |
146 | 144 |
147 void EventConverterEvdevImpl::FlushEvents() { | 145 void EventConverterEvdevImpl::FlushEvents() { |
148 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) | 146 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) |
149 return; | 147 return; |
150 | 148 |
151 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); | 149 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); |
152 | 150 |
153 mouse_move_callback_.Run(id_, cursor_->GetLocation()); | 151 dispatcher_->DispatchMouseMoveEvent(id_, cursor_->GetLocation()); |
154 | 152 |
155 x_offset_ = 0; | 153 x_offset_ = 0; |
156 y_offset_ = 0; | 154 y_offset_ = 0; |
157 } | 155 } |
158 | 156 |
159 } // namespace ui | 157 } // namespace ui |
OLD | NEW |