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 "base/message_loop/message_loop.h" | |
11 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
12 #include "ui/events/keycodes/dom4/keycode_converter.h" | 11 #include "ui/events/keycodes/dom4/keycode_converter.h" |
13 #include "ui/events/ozone/evdev/keyboard_evdev.h" | 12 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
| 16 namespace { |
| 17 |
17 // Values for EV_KEY. | 18 // Values for EV_KEY. |
18 const int kKeyReleaseValue = 0; | 19 const int kKeyReleaseValue = 0; |
19 const int kKeyRepeatValue = 2; | 20 const int kKeyRepeatValue = 2; |
20 | 21 |
| 22 } // namespace |
| 23 |
21 EventConverterEvdevImpl::EventConverterEvdevImpl( | 24 EventConverterEvdevImpl::EventConverterEvdevImpl( |
22 int fd, | 25 int fd, |
23 base::FilePath path, | 26 base::FilePath path, |
24 int id, | 27 int id, |
25 InputDeviceType type, | 28 InputDeviceType type, |
26 const EventDeviceInfo& devinfo, | 29 const EventDeviceInfo& devinfo, |
27 EventModifiersEvdev* modifiers, | 30 EventModifiersEvdev* modifiers, |
28 MouseButtonMapEvdev* button_map, | 31 MouseButtonMapEvdev* button_map, |
29 CursorDelegateEvdev* cursor, | 32 CursorDelegateEvdev* cursor, |
30 KeyboardEvdev* keyboard, | 33 const KeyEventDispatchCallback& key_callback, |
31 const EventDispatchCallback& callback) | 34 const EventDispatchCallback& callback) |
32 : EventConverterEvdev(fd, path, id, type), | 35 : EventConverterEvdev(fd, path, id, type), |
33 has_keyboard_(devinfo.HasKeyboard()), | 36 has_keyboard_(devinfo.HasKeyboard()), |
34 has_touchpad_(devinfo.HasTouchpad()), | 37 has_touchpad_(devinfo.HasTouchpad()), |
35 x_offset_(0), | 38 x_offset_(0), |
36 y_offset_(0), | 39 y_offset_(0), |
37 cursor_(cursor), | 40 cursor_(cursor), |
38 keyboard_(keyboard), | |
39 modifiers_(modifiers), | 41 modifiers_(modifiers), |
40 button_map_(button_map), | 42 button_map_(button_map), |
| 43 key_callback_(key_callback), |
41 callback_(callback) { | 44 callback_(callback) { |
42 } | 45 } |
43 | 46 |
44 EventConverterEvdevImpl::~EventConverterEvdevImpl() { | 47 EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
45 Stop(); | 48 Stop(); |
46 close(fd_); | 49 close(fd_); |
47 } | 50 } |
48 | 51 |
49 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { | 52 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
50 input_event inputs[4]; | 53 input_event inputs[4]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return; | 113 return; |
111 | 114 |
112 // Mouse processing. | 115 // Mouse processing. |
113 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { | 116 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { |
114 DispatchMouseButton(input); | 117 DispatchMouseButton(input); |
115 return; | 118 return; |
116 } | 119 } |
117 | 120 |
118 // Keyboard processing. | 121 // Keyboard processing. |
119 DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( | 122 DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( |
120 KeyboardEvdev::EvdevCodeToNativeCode(input.code)); | 123 EvdevCodeToNativeCode(input.code)); |
121 if (!allowed_keys_ || allowed_keys_->count(key_code)) | 124 if (!allowed_keys_ || allowed_keys_->count(key_code)) |
122 keyboard_->OnKeyChange(input.code, input.value != kKeyReleaseValue); | 125 key_callback_.Run(id_, input.code, input.value != kKeyReleaseValue); |
123 } | 126 } |
124 | 127 |
125 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { | 128 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
126 if (!cursor_) | 129 if (!cursor_) |
127 return; | 130 return; |
128 switch (input.code) { | 131 switch (input.code) { |
129 case REL_X: | 132 case REL_X: |
130 x_offset_ = input.value; | 133 x_offset_ = input.value; |
131 break; | 134 break; |
132 case REL_Y: | 135 case REL_Y: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 new MouseEvent(ui::ET_MOUSE_MOVED, | 173 new MouseEvent(ui::ET_MOUSE_MOVED, |
171 cursor_->GetLocation(), | 174 cursor_->GetLocation(), |
172 cursor_->GetLocation(), | 175 cursor_->GetLocation(), |
173 modifiers_->GetModifierFlags(), | 176 modifiers_->GetModifierFlags(), |
174 /* changed_button_flags */ 0))); | 177 /* changed_button_flags */ 0))); |
175 x_offset_ = 0; | 178 x_offset_ = 0; |
176 y_offset_ = 0; | 179 y_offset_ = 0; |
177 } | 180 } |
178 | 181 |
179 } // namespace ui | 182 } // namespace ui |
OLD | NEW |