Chromium Code Reviews| 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/keycodes/keyboard_codes.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 | 16 |
| 17 EventConverterEvdevImpl::EventConverterEvdevImpl( | 17 EventConverterEvdevImpl::EventConverterEvdevImpl( |
| 18 int fd, | 18 int fd, |
| 19 base::FilePath path, | 19 base::FilePath path, |
| 20 int id, | 20 int id, |
| 21 InputDeviceType type, | 21 InputDeviceType type, |
| 22 const EventDeviceInfo& devinfo, | 22 const EventDeviceInfo& devinfo, |
| 23 EventModifiersEvdev* modifiers, | 23 EventModifiersEvdev* modifiers, |
| 24 MouseButtonMapEvdev* button_map, | 24 MouseButtonMapEvdev* button_map, |
| 25 CursorDelegateEvdev* cursor, | 25 CursorDelegateEvdev* cursor, |
| 26 KeyboardEvdev* keyboard, | 26 KeyboardEvdev* keyboard, |
| 27 const EventDispatchCallback& callback) | 27 const EventDispatchCallback& callback) |
| 28 : EventConverterEvdev(fd, path, id, type), | 28 : EventConverterEvdev(fd, path, id, type), |
| 29 has_keyboard_(devinfo.HasKeyboard()), | 29 has_keyboard_(devinfo.HasKeyboard()), |
| 30 has_touchpad_(devinfo.HasTouchpad()), | |
| 30 x_offset_(0), | 31 x_offset_(0), |
| 31 y_offset_(0), | 32 y_offset_(0), |
| 32 cursor_(cursor), | 33 cursor_(cursor), |
| 33 keyboard_(keyboard), | 34 keyboard_(keyboard), |
| 34 modifiers_(modifiers), | 35 modifiers_(modifiers), |
| 35 button_map_(button_map), | 36 button_map_(button_map), |
| 36 callback_(callback) { | 37 callback_(callback) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 EventConverterEvdevImpl::~EventConverterEvdevImpl() { | 40 EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
| 40 Stop(); | 41 Stop(); |
| 41 close(fd_); | 42 close(fd_); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { | 45 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
| 45 input_event inputs[4]; | 46 input_event inputs[4]; |
| 46 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 47 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| 47 if (read_size < 0) { | 48 if (read_size < 0) { |
| 48 if (errno == EINTR || errno == EAGAIN) | 49 if (errno == EINTR || errno == EAGAIN) |
| 49 return; | 50 return; |
| 50 if (errno != ENODEV) | 51 if (errno != ENODEV) |
| 51 PLOG(ERROR) << "error reading device " << path_.value(); | 52 PLOG(ERROR) << "error reading device " << path_.value(); |
| 52 Stop(); | 53 Stop(); |
| 53 return; | 54 return; |
| 54 } | 55 } |
| 55 | 56 |
| 57 if (ignore_events_) | |
| 58 return; | |
| 59 | |
| 56 DCHECK_EQ(read_size % sizeof(*inputs), 0u); | 60 DCHECK_EQ(read_size % sizeof(*inputs), 0u); |
| 57 ProcessEvents(inputs, read_size / sizeof(*inputs)); | 61 ProcessEvents(inputs, read_size / sizeof(*inputs)); |
| 58 } | 62 } |
| 59 | 63 |
| 64 void EventConverterEvdevImpl::SetAllowedKeys( | |
| 65 scoped_ptr<std::set<KeyboardCode> > allowed_keys) { | |
| 66 DCHECK(HasKeyboard()); | |
| 67 allowed_keys_ = allowed_keys.Pass(); | |
| 68 } | |
| 69 | |
| 70 void EventConverterEvdevImpl::AllowAllKeys() { | |
| 71 DCHECK(HasKeyboard()); | |
| 72 allowed_keys_.reset(); | |
| 73 } | |
| 74 | |
| 60 bool EventConverterEvdevImpl::HasKeyboard() const { | 75 bool EventConverterEvdevImpl::HasKeyboard() const { |
| 61 return has_keyboard_; | 76 return has_keyboard_; |
| 62 } | 77 } |
| 63 | 78 |
| 79 bool EventConverterEvdevImpl::HasTouchpad() const { | |
| 80 return has_touchpad_; | |
| 81 } | |
| 82 | |
| 64 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, | 83 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, |
| 65 int count) { | 84 int count) { |
| 66 for (int i = 0; i < count; ++i) { | 85 for (int i = 0; i < count; ++i) { |
| 67 const input_event& input = inputs[i]; | 86 const input_event& input = inputs[i]; |
| 68 switch (input.type) { | 87 switch (input.type) { |
| 69 case EV_KEY: | 88 case EV_KEY: |
| 70 ConvertKeyEvent(input); | 89 ConvertKeyEvent(input); |
| 71 break; | 90 break; |
| 72 case EV_REL: | 91 case EV_REL: |
| 73 ConvertMouseMoveEvent(input); | 92 ConvertMouseMoveEvent(input); |
| 74 break; | 93 break; |
| 75 case EV_SYN: | 94 case EV_SYN: |
| 76 FlushEvents(); | 95 FlushEvents(); |
| 77 break; | 96 break; |
| 78 } | 97 } |
| 79 } | 98 } |
| 80 } | 99 } |
| 81 | 100 |
| 82 void EventConverterEvdevImpl::ConvertKeyEvent(const input_event& input) { | 101 void EventConverterEvdevImpl::ConvertKeyEvent(const input_event& input) { |
| 83 // Mouse processing. | 102 // Mouse processing. |
| 84 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { | 103 if (input.code >= BTN_MOUSE && input.code < BTN_JOYSTICK) { |
| 85 DispatchMouseButton(input); | 104 DispatchMouseButton(input); |
| 86 return; | 105 return; |
| 87 } | 106 } |
| 88 // Keyboard processing. | 107 // Keyboard processing. |
| 89 keyboard_->OnKeyChange(input.code, input.value != 0); | 108 KeyboardCode key_code = KeyboardEvdev::KeyboardCodeFromEvdevKey(input.code); |
|
spang
2014/12/22 18:56:16
I think this the key filter should probably use Do
kpschoedel
2014/12/22 19:17:56
Yes, assuming the comment in
scoped_disable_inter
| |
| 109 if (!allowed_keys_ || allowed_keys_->count(key_code)) | |
| 110 keyboard_->OnKeyChange(input.code, input.value != 0); | |
| 90 } | 111 } |
| 91 | 112 |
| 92 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { | 113 void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { |
| 93 if (!cursor_) | 114 if (!cursor_) |
| 94 return; | 115 return; |
| 95 switch (input.code) { | 116 switch (input.code) { |
| 96 case REL_X: | 117 case REL_X: |
| 97 x_offset_ = input.value; | 118 x_offset_ = input.value; |
| 98 break; | 119 break; |
| 99 case REL_Y: | 120 case REL_Y: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 new MouseEvent(ui::ET_MOUSE_MOVED, | 158 new MouseEvent(ui::ET_MOUSE_MOVED, |
| 138 cursor_->GetLocation(), | 159 cursor_->GetLocation(), |
| 139 cursor_->GetLocation(), | 160 cursor_->GetLocation(), |
| 140 modifiers_->GetModifierFlags(), | 161 modifiers_->GetModifierFlags(), |
| 141 /* changed_button_flags */ 0))); | 162 /* changed_button_flags */ 0))); |
| 142 x_offset_ = 0; | 163 x_offset_ = 0; |
| 143 y_offset_ = 0; | 164 y_offset_ = 0; |
| 144 } | 165 } |
| 145 | 166 |
| 146 } // namespace ui | 167 } // namespace ui |
| OLD | NEW |