Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Unified Diff: ui/events/ozone/evdev/keyboard_evdev.cc

Issue 641113004: ozone: evdev: Factor keyboard into KeyboardEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::bitset Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/ozone/evdev/keyboard_evdev.h ('k') | ui/events/ozone/events_ozone.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/ozone/evdev/keyboard_evdev.cc
diff --git a/ui/events/ozone/evdev/key_event_converter_evdev.cc b/ui/events/ozone/evdev/keyboard_evdev.cc
similarity index 78%
copy from ui/events/ozone/evdev/key_event_converter_evdev.cc
copy to ui/events/ozone/evdev/keyboard_evdev.cc
index 195b5142d453bc81decd88f884cca2250ee54371..6e5266f16c1510a6ab07ea4e139aaa6fe9e9057f 100644
--- a/ui/events/ozone/evdev/key_event_converter_evdev.cc
+++ b/ui/events/ozone/evdev/keyboard_evdev.cc
@@ -2,15 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/events/ozone/evdev/key_event_converter_evdev.h"
+#include "ui/events/ozone/evdev/keyboard_evdev.h"
-#include <errno.h>
-#include <linux/input.h>
-
-#include "base/message_loop/message_loop.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom4/keycode_converter.h"
-#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/ozone/evdev/event_modifiers_evdev.h"
namespace ui {
@@ -19,7 +14,7 @@ namespace {
const int kXkbKeycodeOffset = 8;
-ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) {
+ui::KeyboardCode KeyboardCodeFromEvdevKey(unsigned int code) {
static const ui::KeyboardCode kLinuxBaseKeyMap[] = {
ui::VKEY_UNKNOWN, // KEY_RESERVED
ui::VKEY_ESCAPE, // KEY_ESC
@@ -158,7 +153,7 @@ ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) {
return ui::VKEY_UNKNOWN;
}
-int ModifierFromButton(unsigned int code) {
+int ModifierFromEvdevKey(unsigned int code) {
switch (code) {
case KEY_CAPSLOCK:
return EVDEV_MODIFIER_CAPS_LOCK;
@@ -185,71 +180,52 @@ int ModifierFromButton(unsigned int code) {
}
}
-bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; }
+bool IsModifierLockKeyFromEvdevKey(unsigned int code) {
+ return code == KEY_CAPSLOCK;
+}
} // namespace
-KeyEventConverterEvdev::KeyEventConverterEvdev(
- int fd,
- base::FilePath path,
- int id,
- EventModifiersEvdev* modifiers,
- const EventDispatchCallback& callback)
- : EventConverterEvdev(fd, path, id),
- callback_(callback),
- modifiers_(modifiers) {
- // TODO(spang): Initialize modifiers using EVIOCGKEY.
+KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers,
+ const EventDispatchCallback& callback)
+ : callback_(callback), modifiers_(modifiers) {
}
-KeyEventConverterEvdev::~KeyEventConverterEvdev() {
- Stop();
- close(fd_);
+KeyboardEvdev::~KeyboardEvdev() {
}
-void KeyEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
- input_event inputs[4];
- ssize_t read_size = read(fd, inputs, sizeof(inputs));
- if (read_size < 0) {
- if (errno == EINTR || errno == EAGAIN)
- return;
- if (errno != ENODEV)
- PLOG(ERROR) << "error reading device " << path_.value();
- Stop();
+void KeyboardEvdev::OnKeyChange(unsigned int key, bool down) {
+ if (key > KEY_MAX)
return;
- }
- DCHECK_EQ(read_size % sizeof(*inputs), 0u);
- ProcessEvents(inputs, read_size / sizeof(*inputs));
-}
+ if (down != key_state_.test(key)) {
+ // State transition: !(down) -> (down)
+ if (down)
+ key_state_.set(key);
+ else
+ key_state_.reset(key);
-void KeyEventConverterEvdev::ProcessEvents(const input_event* inputs,
- int count) {
- for (int i = 0; i < count; ++i) {
- const input_event& input = inputs[i];
- if (input.type == EV_KEY) {
- ConvertKeyEvent(input.code, input.value);
- } else if (input.type == EV_SYN) {
- // TODO(sadrul): Handle this case appropriately.
- }
+ UpdateModifier(key, down);
}
+
+ DispatchKey(key, down);
}
-void KeyEventConverterEvdev::ConvertKeyEvent(int key, int value) {
- int down = (value != 0);
- int repeat = (value == 2);
- int modifier = ModifierFromButton(key);
- ui::KeyboardCode code = KeyboardCodeFromButton(key);
+void KeyboardEvdev::UpdateModifier(unsigned int key, bool down) {
+ int modifier = ModifierFromEvdevKey(key);
+ int locking = IsModifierLockKeyFromEvdevKey(key);
- if (!repeat && (modifier != EVDEV_MODIFIER_NONE)) {
- if (IsLockButton(key)) {
- // Locking modifier keys: CapsLock.
- modifiers_->UpdateModifierLock(modifier, down);
- } else {
- // Regular modifier keys: Shift, Ctrl, Alt, etc.
- modifiers_->UpdateModifier(modifier, down);
- }
- }
+ if (modifier == EVDEV_MODIFIER_NONE)
+ return;
+
+ if (locking)
+ modifiers_->UpdateModifierLock(modifier, down);
+ else
+ modifiers_->UpdateModifier(modifier, down);
+}
+void KeyboardEvdev::DispatchKey(unsigned int key, bool down) {
+ ui::KeyboardCode code = KeyboardCodeFromEvdevKey(key);
int flags = modifiers_->GetModifierFlags();
KeyEvent key_event(
« no previous file with comments | « ui/events/ozone/evdev/keyboard_evdev.h ('k') | ui/events/ozone/events_ozone.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698