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" | 10 #include "base/message_loop/message_loop.h" |
11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
12 #include "ui/events/keycodes/dom4/keycode_converter.h" | 12 #include "ui/events/keycodes/dom4/keycode_converter.h" |
13 #include "ui/events/keycodes/keyboard_codes.h" | 13 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 // Values for EV_KEY. | 17 // Values for EV_KEY. |
18 const int kKeyReleaseValue = 0; | 18 const int kKeyReleaseValue = 0; |
19 const int kKeyRepeatValue = 2; | 19 const int kKeyRepeatValue = 2; |
20 | 20 |
21 EventConverterEvdevImpl::EventConverterEvdevImpl( | 21 EventConverterEvdevImpl::EventConverterEvdevImpl( |
22 int fd, | 22 int fd, |
23 base::FilePath path, | 23 base::FilePath path, |
24 int id, | 24 int id, |
25 InputDeviceType type, | 25 InputDeviceType type, |
26 const EventDeviceInfo& devinfo, | 26 const EventDeviceInfo& devinfo, |
27 EventModifiersEvdev* modifiers, | 27 EventModifiersEvdev* modifiers, |
28 MouseButtonMapEvdev* button_map, | 28 MouseButtonMapEvdev* button_map, |
29 CursorDelegateEvdev* cursor, | 29 CursorDelegateEvdev* cursor, |
30 KeyboardEvdev* keyboard, | 30 KeyboardEvdev* keyboard, |
31 const EventDispatchCallback& callback) | 31 const EventDispatchCallback& callback) |
32 : EventConverterEvdev(fd, path, id, type), | 32 : EventConverterEvdev(fd, path, id, type), |
33 has_keyboard_(devinfo.HasKeyboard()), | 33 has_keyboard_(devinfo.HasKeyboard()), |
34 has_touchpad_(devinfo.HasTouchpad()), | |
34 x_offset_(0), | 35 x_offset_(0), |
35 y_offset_(0), | 36 y_offset_(0), |
36 cursor_(cursor), | 37 cursor_(cursor), |
37 keyboard_(keyboard), | 38 keyboard_(keyboard), |
38 modifiers_(modifiers), | 39 modifiers_(modifiers), |
39 button_map_(button_map), | 40 button_map_(button_map), |
40 callback_(callback) { | 41 callback_(callback) { |
41 } | 42 } |
42 | 43 |
43 EventConverterEvdevImpl::~EventConverterEvdevImpl() { | 44 EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
44 Stop(); | 45 Stop(); |
45 close(fd_); | 46 close(fd_); |
46 } | 47 } |
47 | 48 |
48 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { | 49 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
49 input_event inputs[4]; | 50 input_event inputs[4]; |
50 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 51 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
51 if (read_size < 0) { | 52 if (read_size < 0) { |
52 if (errno == EINTR || errno == EAGAIN) | 53 if (errno == EINTR || errno == EAGAIN) |
53 return; | 54 return; |
54 if (errno != ENODEV) | 55 if (errno != ENODEV) |
55 PLOG(ERROR) << "error reading device " << path_.value(); | 56 PLOG(ERROR) << "error reading device " << path_.value(); |
56 Stop(); | 57 Stop(); |
57 return; | 58 return; |
58 } | 59 } |
59 | 60 |
61 if (ignore_events_) | |
spang
2015/01/02 22:49:57
Add a TODO(spang): Re-implement this by releasing
| |
62 return; | |
63 | |
60 DCHECK_EQ(read_size % sizeof(*inputs), 0u); | 64 DCHECK_EQ(read_size % sizeof(*inputs), 0u); |
61 ProcessEvents(inputs, read_size / sizeof(*inputs)); | 65 ProcessEvents(inputs, read_size / sizeof(*inputs)); |
62 } | 66 } |
63 | 67 |
64 bool EventConverterEvdevImpl::HasKeyboard() const { | 68 bool EventConverterEvdevImpl::HasKeyboard() const { |
65 return has_keyboard_; | 69 return has_keyboard_; |
66 } | 70 } |
67 | 71 |
72 bool EventConverterEvdevImpl::HasTouchpad() const { | |
73 return has_touchpad_; | |
74 } | |
75 | |
76 void EventConverterEvdevImpl::SetAllowedKeys( | |
77 scoped_ptr<std::set<DomCode>> allowed_keys) { | |
78 DCHECK(HasKeyboard()); | |
79 allowed_keys_ = allowed_keys.Pass(); | |
80 } | |
81 | |
82 void EventConverterEvdevImpl::AllowAllKeys() { | |
83 DCHECK(HasKeyboard()); | |
84 allowed_keys_.reset(); | |
85 } | |
86 | |
68 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, | 87 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, |
69 int count) { | 88 int count) { |
70 for (int i = 0; i < count; ++i) { | 89 for (int i = 0; i < count; ++i) { |
71 const input_event& input = inputs[i]; | 90 const input_event& input = inputs[i]; |
72 switch (input.type) { | 91 switch (input.type) { |
73 case EV_KEY: | 92 case EV_KEY: |
74 ConvertKeyEvent(input); | 93 ConvertKeyEvent(input); |
75 break; | 94 break; |
76 case EV_REL: | 95 case EV_REL: |
77 ConvertMouseMoveEvent(input); | 96 ConvertMouseMoveEvent(input); |
(...skipping 10 matching lines...) Expand all Loading... | |
88 if (input.value == kKeyRepeatValue) | 107 if (input.value == kKeyRepeatValue) |
89 return; | 108 return; |
90 | 109 |
91 // Mouse processing. | 110 // Mouse processing. |
92 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { | 111 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { |
93 DispatchMouseButton(input); | 112 DispatchMouseButton(input); |
94 return; | 113 return; |
95 } | 114 } |
96 | 115 |
97 // Keyboard processing. | 116 // Keyboard processing. |
98 keyboard_->OnKeyChange(input.code, input.value != kKeyReleaseValue); | 117 DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( |
118 KeyboardEvdev::EvdevCodeToNativeCode(input.code)); | |
kpschoedel
2014/12/25 18:14:17
NativeKeycodeToDomCode() is a slow operation; sinc
| |
119 if (!allowed_keys_ || allowed_keys_->count(key_code)) | |
120 keyboard_->OnKeyChange(input.code, input.value != kKeyReleaseValue); | |
99 } | 121 } |
100 | 122 |
101 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { | 123 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
102 if (!cursor_) | 124 if (!cursor_) |
103 return; | 125 return; |
104 switch (input.code) { | 126 switch (input.code) { |
105 case REL_X: | 127 case REL_X: |
106 x_offset_ = input.value; | 128 x_offset_ = input.value; |
107 break; | 129 break; |
108 case REL_Y: | 130 case REL_Y: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 new MouseEvent(ui::ET_MOUSE_MOVED, | 168 new MouseEvent(ui::ET_MOUSE_MOVED, |
147 cursor_->GetLocation(), | 169 cursor_->GetLocation(), |
148 cursor_->GetLocation(), | 170 cursor_->GetLocation(), |
149 modifiers_->GetModifierFlags(), | 171 modifiers_->GetModifierFlags(), |
150 /* changed_button_flags */ 0))); | 172 /* changed_button_flags */ 0))); |
151 x_offset_ = 0; | 173 x_offset_ = 0; |
152 y_offset_ = 0; | 174 y_offset_ = 0; |
153 } | 175 } |
154 | 176 |
155 } // namespace ui | 177 } // namespace ui |
OLD | NEW |