diff options
author | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:21:50 +0000 |
---|---|---|
committer | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:21:50 +0000 |
commit | 5e4e9c5aa38f82dc64efa2740df8081a6d06caea (patch) | |
tree | 4f8a99b63d56f4275b10a409c72d7033ebeb3364 /ui/base | |
parent | e503a12601fee9e142e37a630f3db9b758499c82 (diff) | |
download | chromium_src-5e4e9c5aa38f82dc64efa2740df8081a6d06caea.zip chromium_src-5e4e9c5aa38f82dc64efa2740df8081a6d06caea.tar.gz chromium_src-5e4e9c5aa38f82dc64efa2740df8081a6d06caea.tar.bz2 |
[cros] Fix accelerator keys when using non-US/Latin keyboard layouts.
BUG=chromium-os:10120
TEST=Switch to Russian keyboard layout, try accelerators like ctrl-t, ctrl-w, etc.
Review URL: http://codereview.chromium.org/6674052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/keycodes/keyboard_code_conversion_gtk.cc | 19 | ||||
-rw-r--r-- | ui/base/keycodes/keyboard_code_conversion_gtk.h | 4 | ||||
-rw-r--r-- | ui/base/keycodes/keyboard_code_conversion_x.cc | 98 | ||||
-rw-r--r-- | ui/base/keycodes/keyboard_code_conversion_x.h | 5 |
4 files changed, 126 insertions, 0 deletions
diff --git a/ui/base/keycodes/keyboard_code_conversion_gtk.cc b/ui/base/keycodes/keyboard_code_conversion_gtk.cc index 6545d7e..4425b88 100644 --- a/ui/base/keycodes/keyboard_code_conversion_gtk.cc +++ b/ui/base/keycodes/keyboard_code_conversion_gtk.cc @@ -35,10 +35,16 @@ #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" +#include <gdk/gdk.h> #include <gdk/gdkkeysyms.h> +#include "build/build_config.h" #include "ui/base/keycodes/keyboard_codes_posix.h" +#ifdef USE_X11 +#include "ui/base/keycodes/keyboard_code_conversion_x.h" +#endif + namespace ui { KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) { @@ -615,4 +621,17 @@ int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) { } } +KeyboardCode KeyboardCodeFromGdkEventKey(GdkEventKey* event) { + KeyboardCode keycode = WindowsKeyCodeForGdkKeyCode(event->keyval); +#ifdef USE_X11 + // Gtk's key values are same as X11's keysyms. + if (keycode == VKEY_UNKNOWN) { + unsigned int keyval = + DefaultXKeysymFromHardwareKeycode(event->hardware_keycode); + keycode = WindowsKeyCodeForGdkKeyCode(keyval); + } +#endif + return keycode; +} + } // namespace ui diff --git a/ui/base/keycodes/keyboard_code_conversion_gtk.h b/ui/base/keycodes/keyboard_code_conversion_gtk.h index e30d8d9..3221da5 100644 --- a/ui/base/keycodes/keyboard_code_conversion_gtk.h +++ b/ui/base/keycodes/keyboard_code_conversion_gtk.h @@ -39,12 +39,16 @@ #include "ui/base/keycodes/keyboard_codes_posix.h" +typedef struct _GdkEventKey GdkEventKey; + namespace ui { KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode); int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift); +KeyboardCode KeyboardCodeFromGdkEventKey(GdkEventKey* event); + } // namespace ui #endif // UI_BASE_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_ diff --git a/ui/base/keycodes/keyboard_code_conversion_x.cc b/ui/base/keycodes/keyboard_code_conversion_x.cc index 47ce830..4235fca 100644 --- a/ui/base/keycodes/keyboard_code_conversion_x.cc +++ b/ui/base/keycodes/keyboard_code_conversion_x.cc @@ -7,6 +7,7 @@ #include <X11/keysym.h> #include <X11/Xlib.h> +#include "base/basictypes.h" #include "base/logging.h" namespace ui { @@ -15,6 +16,16 @@ namespace ui { KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { KeySym keysym = XLookupKeysym(&xev->xkey, 0); + KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); + if (keycode == VKEY_UNKNOWN) { + keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); + keycode = KeyboardCodeFromXKeysym(keysym); + } + + return keycode; +} + +KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { // Consult GDK key translation (in WindowsKeyCodeForGdkKeyCode) for details // about the following translations. @@ -278,4 +289,91 @@ KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { return VKEY_UNKNOWN; } +unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { + static const unsigned int kHardwareKeycodeMap[] = { + 0, // 0x00: + 0, // 0x01: + 0, // 0x02: + 0, // 0x03: + 0, // 0x04: + 0, // 0x05: + 0, // 0x06: + 0, // 0x07: + 0, // 0x08: + XK_Escape, // 0x09: XK_Escape + XK_1, // 0x0A: XK_1 + XK_2, // 0x0B: XK_2 + XK_3, // 0x0C: XK_3 + XK_4, // 0x0D: XK_4 + XK_5, // 0x0E: XK_5 + XK_6, // 0x0F: XK_6 + XK_7, // 0x10: XK_7 + XK_8, // 0x11: XK_8 + XK_9, // 0x12: XK_9 + XK_0, // 0x13: XK_0 + XK_minus, // 0x14: XK_minus + XK_equal, // 0x15: XK_equal + XK_BackSpace, // 0x16: XK_BackSpace + XK_Tab, // 0x17: XK_Tab + XK_q, // 0x18: XK_q + XK_w, // 0x19: XK_w + XK_e, // 0x1A: XK_e + XK_r, // 0x1B: XK_r + XK_t, // 0x1C: XK_t + XK_y, // 0x1D: XK_y + XK_u, // 0x1E: XK_u + XK_i, // 0x1F: XK_i + XK_o, // 0x20: XK_o + XK_p, // 0x21: XK_p + XK_bracketleft, // 0x22: XK_bracketleft + XK_bracketright, // 0x23: XK_bracketright + XK_Return, // 0x24: XK_Return + XK_Control_L, // 0x25: XK_Control_L + XK_a, // 0x26: XK_a + XK_s, // 0x27: XK_s + XK_d, // 0x28: XK_d + XK_f, // 0x29: XK_f + XK_g, // 0x2A: XK_g + XK_h, // 0x2B: XK_h + XK_j, // 0x2C: XK_j + XK_k, // 0x2D: XK_k + XK_l, // 0x2E: XK_l + XK_semicolon, // 0x2F: XK_semicolon + XK_apostrophe, // 0x30: XK_apostrophe + XK_grave, // 0x31: XK_grave + XK_Shift_L, // 0x32: XK_Shift_L + XK_backslash, // 0x33: XK_backslash + XK_z, // 0x34: XK_z + XK_x, // 0x35: XK_x + XK_c, // 0x36: XK_c + XK_v, // 0x37: XK_v + XK_b, // 0x38: XK_b + XK_n, // 0x39: XK_n + XK_m, // 0x3A: XK_m + XK_comma, // 0x3B: XK_comma + XK_period, // 0x3C: XK_period + XK_slash, // 0x3D: XK_slash + XK_Shift_R, // 0x3E: XK_Shift_R + 0, // 0x3F: XK_KP_Multiply + XK_Alt_L, // 0x40: XK_Alt_L + XK_space, // 0x41: XK_space + XK_Caps_Lock, // 0x42: XK_Caps_Lock + XK_F1, // 0x43: XK_F1 + XK_F2, // 0x44: XK_F2 + XK_F3, // 0x45: XK_F3 + XK_F4, // 0x46: XK_F4 + XK_F5, // 0x47: XK_F5 + XK_F6, // 0x48: XK_F6 + XK_F7, // 0x49: XK_F7 + XK_F8, // 0x4A: XK_F8 + XK_F9, // 0x4B: XK_F9 + XK_F10, // 0x4C: XK_F10 + XK_Num_Lock, // 0x4D: XK_Num_Lock + XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock + }; + + return hardware_code < arraysize(kHardwareKeycodeMap) ? + kHardwareKeycodeMap[hardware_code] : 0; +} + } // namespace ui diff --git a/ui/base/keycodes/keyboard_code_conversion_x.h b/ui/base/keycodes/keyboard_code_conversion_x.h index 3f780a2..5611c53 100644 --- a/ui/base/keycodes/keyboard_code_conversion_x.h +++ b/ui/base/keycodes/keyboard_code_conversion_x.h @@ -13,6 +13,11 @@ namespace ui { KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev); +KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym); + +// Converts a hardware keycode into a key symbol on a standard US PC keyboard. +unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int keycode); + } // namespace ui #endif // UI_BASE_KEYCODES_KEYBOARD_CODE_CONVERSION_X_H_ |