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

Unified Diff: chrome/browser/chromeos/input_method/input_method_engine.cc

Issue 324903002: Remoes X11 dependency in InputMethodEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits. Created 6 years, 6 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 | « no previous file | chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/input_method/input_method_engine.cc
diff --git a/chrome/browser/chromeos/input_method/input_method_engine.cc b/chrome/browser/chromeos/input_method/input_method_engine.cc
index 4f7c33741b21e44f215b4182e377ed245a76e7c9..adac10d1df323926024f928b737d4e4405b2467e 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine.cc
@@ -4,11 +4,6 @@
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
-#define XK_MISCELLANY
-#include <X11/keysymdef.h>
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
#undef FocusIn
#undef FocusOut
#undef RootWindow
@@ -34,8 +29,6 @@
#include "ui/base/ime/chromeos/ime_keymap.h"
#include "ui/events/event.h"
#include "ui/events/event_processor.h"
-#include "ui/events/keycodes/dom4/keycode_converter.h"
-#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
@@ -70,6 +63,35 @@ size_t GetUtf8StringLength(const char* s) {
return ret;
}
+std::string GetKeyFromEvent(const ui::KeyEvent& event) {
+ const std::string& code = event.code();
+ if (StartsWithASCII(code, "Control", true))
+ return "Ctrl";
+ if (StartsWithASCII(code, "Shift", true))
+ return "Shift";
+ if (StartsWithASCII(code, "Alt", true))
+ return "Alt";
+ if (StartsWithASCII(code, "Arrow", true))
+ return code.substr(5);
+ if (code == "Escape")
+ return "Esc";
+ if (code == "Backspace" || code == "Tab" ||
+ code == "Enter" || code == "CapsLock")
+ return code;
+ uint16 ch = 0;
+ // Ctrl+? cases, gets key value for Ctrl is not down.
+ if (event.flags() & ui::EF_CONTROL_DOWN) {
+ ui::KeyEvent event_no_ctrl(event.type(),
+ event.key_code(),
+ event.flags() ^ ui::EF_CONTROL_DOWN,
+ false);
+ ch = event_no_ctrl.GetCharacter();
+ } else {
+ ch = event.GetCharacter();
+ }
+ return base::UTF16ToUTF8(base::string16(1, ch));
+}
+
} // namespace
InputMethodEngine::InputMethodEngine()
@@ -266,24 +288,19 @@ bool InputMethodEngine::SendKeyEvents(
const ui::EventType type =
(event.type == "keyup") ? ui::ET_KEY_RELEASED : ui::ET_KEY_PRESSED;
- // KeyboardCodeFromXKyeSym assumes US keyboard layout.
- ui::KeycodeConverter* conv = ui::KeycodeConverter::GetInstance();
- DCHECK(conv);
-
- // DOM code (KeyA) -> XKB -> XKeySym (XK_A) -> KeyboardCode (VKEY_A)
- const uint16 native_keycode =
- conv->CodeToNativeKeycode(event.code.c_str());
- const uint xkeysym = ui::DefaultXKeysymFromHardwareKeycode(native_keycode);
- const ui::KeyboardCode key_code = ui::KeyboardCodeFromXKeysym(xkeysym);
-
- const std::string code = event.code;
int flags = ui::EF_NONE;
flags |= event.alt_key ? ui::EF_ALT_DOWN : ui::EF_NONE;
flags |= event.ctrl_key ? ui::EF_CONTROL_DOWN : ui::EF_NONE;
flags |= event.shift_key ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
flags |= event.caps_lock ? ui::EF_CAPS_LOCK_DOWN : ui::EF_NONE;
- ui::KeyEvent ui_event(type, key_code, code, flags, false /* is_char */);
+ ui::KeyEvent ui_event(type,
+ ui::DomKeycodeToKeyboardCode(event.code),
+ event.code,
+ flags,
+ false /* is_char */);
+ if (!event.key.empty())
+ ui_event.set_character(base::UTF8ToUTF16(event.key)[0]);
base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_,
&ui_event);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event);
@@ -584,6 +601,7 @@ void InputMethodEngine::Reset() {
}
namespace {
+
void GetExtensionKeyboardEventFromKeyEvent(
const ui::KeyEvent& event,
InputMethodEngine::KeyboardEvent* ext_event) {
@@ -597,28 +615,9 @@ void GetExtensionKeyboardEventFromKeyEvent(
ext_event->ctrl_key = event.IsControlDown();
ext_event->shift_key = event.IsShiftDown();
ext_event->caps_lock = event.IsCapsLockDown();
-
- uint32 x11_keysym = 0;
- if (event.HasNativeEvent()) {
- const base::NativeEvent& native_event = event.native_event();
- DCHECK(native_event);
-
- XKeyEvent* x_key = &(static_cast<XEvent*>(native_event)->xkey);
- KeySym keysym = NoSymbol;
- ::XLookupString(x_key, NULL, 0, &keysym, NULL);
- x11_keysym = keysym;
- } else {
- // Convert ui::KeyEvent.key_code to DOM UIEvent key.
- // XKeysymForWindowsKeyCode converts key_code to XKeySym, but it
- // assumes US layout and does not care about CapLock state.
- //
- // TODO(komatsu): Support CapsLock states.
- // TODO(komatsu): Support non-us keyboard layouts.
- x11_keysym = ui::XKeysymForWindowsKeyCode(event.key_code(),
- event.IsShiftDown());
- }
- ext_event->key = ui::FromXKeycodeToKeyValue(x11_keysym);
+ ext_event->key = GetKeyFromEvent(event);
}
+
} // namespace
void InputMethodEngine::ProcessKeyEvent(
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698