| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/key_event_converter.h" | 5 #include "ui/events/ozone/evdev/key_event_converter.h" |
| 6 | 6 |
| 7 #include <linux/input.h> | 7 #include <linux/input.h> |
| 8 | 8 |
| 9 #include "base/message_loop/message_pump_ozone.h" |
| 9 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 11 #include "ui/events/ozone/evdev/event_modifiers.h" | 12 #include "ui/events/ozone/evdev/event_modifiers.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) { | 18 ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) { |
| 18 static const ui::KeyboardCode kLinuxBaseKeyMap[] = { | 19 static const ui::KeyboardCode kLinuxBaseKeyMap[] = { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; } | 184 bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; } |
| 184 | 185 |
| 185 } // namespace | 186 } // namespace |
| 186 | 187 |
| 187 KeyEventConverterEvdev::KeyEventConverterEvdev(int fd, | 188 KeyEventConverterEvdev::KeyEventConverterEvdev(int fd, |
| 188 base::FilePath path, | 189 base::FilePath path, |
| 189 EventModifiersEvdev* modifiers) | 190 EventModifiersEvdev* modifiers) |
| 190 : fd_(fd), path_(path), modifiers_(modifiers) { | 191 : fd_(fd), path_(path), modifiers_(modifiers) { |
| 191 // TODO(spang): Initialize modifiers using EVIOCGKEY. | 192 // TODO(spang): Initialize modifiers using EVIOCGKEY. |
| 193 Start(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 KeyEventConverterEvdev::~KeyEventConverterEvdev() { | 196 KeyEventConverterEvdev::~KeyEventConverterEvdev() { |
| 195 if (fd_ >= 0 && close(fd_) < 0) | 197 Stop(); |
| 196 DLOG(WARNING) << "failed close on " << path_.value(); | 198 close(fd_); |
| 199 } |
| 200 |
| 201 void KeyEventConverterEvdev::Start() { |
| 202 base::MessagePumpOzone::Current()->WatchFileDescriptor( |
| 203 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); |
| 204 } |
| 205 |
| 206 void KeyEventConverterEvdev::Stop() { |
| 207 controller_.StopWatchingFileDescriptor(); |
| 197 } | 208 } |
| 198 | 209 |
| 199 void KeyEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 210 void KeyEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |
| 200 input_event inputs[4]; | 211 input_event inputs[4]; |
| 201 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 212 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| 202 if (read_size <= 0) | 213 if (read_size <= 0) |
| 203 return; | 214 return; |
| 204 | 215 |
| 205 CHECK_EQ(read_size % sizeof(*inputs), 0u); | 216 CHECK_EQ(read_size % sizeof(*inputs), 0u); |
| 206 ProcessEvents(inputs, read_size / sizeof(*inputs)); | 217 ProcessEvents(inputs, read_size / sizeof(*inputs)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 250 } |
| 240 | 251 |
| 241 int flags = modifiers_->GetModifierFlags(); | 252 int flags = modifiers_->GetModifierFlags(); |
| 242 | 253 |
| 243 scoped_ptr<KeyEvent> key_event( | 254 scoped_ptr<KeyEvent> key_event( |
| 244 new KeyEvent(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, code, flags, true)); | 255 new KeyEvent(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, code, flags, true)); |
| 245 DispatchEvent(key_event.PassAs<ui::Event>()); | 256 DispatchEvent(key_event.PassAs<ui::Event>()); |
| 246 } | 257 } |
| 247 | 258 |
| 248 } // namespace ui | 259 } // namespace ui |
| OLD | NEW |