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( | 120 dispatcher_->DispatchKeyEvent( |
124 KeyEventParams(id_, input.code, input.value != kKeyReleaseValue)); | 121 KeyEventParams(id_, input.code, input.value != kKeyReleaseValue)); |
125 } | 122 } |
126 } | 123 } |
127 | 124 |
128 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { | 125 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
129 if (!cursor_) | 126 if (!cursor_) |
130 return; | 127 return; |
131 switch (input.code) { | 128 switch (input.code) { |
132 case REL_X: | 129 case REL_X: |
133 x_offset_ = input.value; | 130 x_offset_ = input.value; |
134 break; | 131 break; |
135 case REL_Y: | 132 case REL_Y: |
136 y_offset_ = input.value; | 133 y_offset_ = input.value; |
137 break; | 134 break; |
138 } | 135 } |
139 } | 136 } |
140 | 137 |
141 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { | 138 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { |
142 if (!cursor_) | 139 if (!cursor_) |
143 return; | 140 return; |
144 | 141 |
145 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(), | 142 dispatcher_->DispatchMouseButtonEvent( |
146 input.code, input.value, | 143 MouseButtonEventParams(id_, cursor_->GetLocation(), input.code, |
147 /* allow_remap */ true)); | 144 input.value, /* allow_remap */ true)); |
148 } | 145 } |
149 | 146 |
150 void EventConverterEvdevImpl::FlushEvents() { | 147 void EventConverterEvdevImpl::FlushEvents() { |
151 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) | 148 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) |
152 return; | 149 return; |
153 | 150 |
154 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); | 151 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); |
155 | 152 |
156 mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation())); | 153 dispatcher_->DispatchMouseMoveEvent( |
| 154 MouseMoveEventParams(id_, cursor_->GetLocation())); |
157 | 155 |
158 x_offset_ = 0; | 156 x_offset_ = 0; |
159 y_offset_ = 0; | 157 y_offset_ = 0; |
160 } | 158 } |
161 | 159 |
162 } // namespace ui | 160 } // namespace ui |
OLD | NEW |