| 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 "ui/events/event.h" | 9 #include "ui/events/event.h" | 
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" | 
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 180   } | 180   } | 
| 181 } | 181 } | 
| 182 | 182 | 
| 183 bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; } | 183 bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; } | 
| 184 | 184 | 
| 185 }  // namespace | 185 }  // namespace | 
| 186 | 186 | 
| 187 KeyEventConverterEvdev::KeyEventConverterEvdev(int fd, | 187 KeyEventConverterEvdev::KeyEventConverterEvdev(int fd, | 
| 188                                                base::FilePath path, | 188                                                base::FilePath path, | 
| 189                                                EventModifiersEvdev* modifiers) | 189                                                EventModifiersEvdev* modifiers) | 
| 190     : fd_(fd), path_(path), modifiers_(modifiers) { | 190     : EventConverterEvdev(fd, path, modifiers) { | 
| 191   // TODO(spang): Initialize modifiers using EVIOCGKEY. | 191   // TODO(spang): Initialize modifiers using EVIOCGKEY. | 
| 192 } | 192 } | 
| 193 | 193 | 
| 194 KeyEventConverterEvdev::~KeyEventConverterEvdev() { | 194 KeyEventConverterEvdev::~KeyEventConverterEvdev() {} | 
| 195   if (fd_ >= 0 && close(fd_) < 0) |  | 
| 196     DLOG(WARNING) << "failed close on " << path_.value(); |  | 
| 197 } |  | 
| 198 |  | 
| 199 void KeyEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |  | 
| 200   input_event inputs[4]; |  | 
| 201   ssize_t read_size = read(fd, inputs, sizeof(inputs)); |  | 
| 202   if (read_size <= 0) |  | 
| 203     return; |  | 
| 204 |  | 
| 205   CHECK_EQ(read_size % sizeof(*inputs), 0u); |  | 
| 206   ProcessEvents(inputs, read_size / sizeof(*inputs)); |  | 
| 207 } |  | 
| 208 |  | 
| 209 void KeyEventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) { |  | 
| 210   NOTREACHED(); |  | 
| 211 } |  | 
| 212 | 195 | 
| 213 void KeyEventConverterEvdev::ProcessEvents(const input_event* inputs, | 196 void KeyEventConverterEvdev::ProcessEvents(const input_event* inputs, | 
| 214                                            int count) { | 197                                            int count) { | 
| 215   for (int i = 0; i < count; ++i) { | 198   for (int i = 0; i < count; ++i) { | 
| 216     const input_event& input = inputs[i]; | 199     const input_event& input = inputs[i]; | 
| 217     if (input.type == EV_KEY) { | 200     if (input.type == EV_KEY) { | 
| 218       ConvertKeyEvent(input.code, input.value); | 201       ConvertKeyEvent(input.code, input.value); | 
| 219     } else if (input.type == EV_SYN) { | 202     } else if (input.type == EV_SYN) { | 
| 220       // TODO(sadrul): Handle this case appropriately. | 203       // TODO(sadrul): Handle this case appropriately. | 
| 221     } | 204     } | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 239   } | 222   } | 
| 240 | 223 | 
| 241   int flags = modifiers_->GetModifierFlags(); | 224   int flags = modifiers_->GetModifierFlags(); | 
| 242 | 225 | 
| 243   scoped_ptr<KeyEvent> key_event( | 226   scoped_ptr<KeyEvent> key_event( | 
| 244       new KeyEvent(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, code, flags, true)); | 227       new KeyEvent(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, code, flags, true)); | 
| 245   DispatchEvent(key_event.PassAs<ui::Event>()); | 228   DispatchEvent(key_event.PassAs<ui::Event>()); | 
| 246 } | 229 } | 
| 247 | 230 | 
| 248 }  // namespace ui | 231 }  // namespace ui | 
| OLD | NEW | 
|---|