diff options
Diffstat (limited to 'ui/events')
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion.cc | 115 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion.h | 38 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_android.cc | 305 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_android.h | 17 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_gtk.cc | 85 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_gtk.h | 57 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_mac.h | 41 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_mac.mm | 558 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_win.cc | 17 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_win.h | 19 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_x.cc | 804 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_code_conversion_x.h | 31 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_codes.h | 16 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_codes_posix.h | 228 | ||||
-rw-r--r-- | ui/events/keycodes/keyboard_codes_win.h | 192 |
15 files changed, 2523 insertions, 0 deletions
diff --git a/ui/events/keycodes/keyboard_code_conversion.cc b/ui/events/keycodes/keyboard_code_conversion.cc new file mode 100644 index 0000000..293790b --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion.cc @@ -0,0 +1,115 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/events/keycodes/keyboard_code_conversion.h" + +#include "ui/base/events/event_constants.h" + +namespace ui { + +uint16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { + const bool ctrl = (flags & EF_CONTROL_DOWN) != 0; + const bool shift = (flags & EF_SHIFT_DOWN) != 0; + const bool upper = shift ^ ((flags & EF_CAPS_LOCK_DOWN) != 0); + + // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A. + if (key_code >= VKEY_A && key_code <= VKEY_Z) + return key_code - VKEY_A + (ctrl ? 1 : (upper ? 'A' : 'a')); + + // Other ctrl characters + if (ctrl) { + if (shift) { + // following graphics chars require shift key to input. + switch (key_code) { + // ctrl-@ maps to \x00 (Null byte) + case VKEY_2: + return 0; + // ctrl-^ maps to \x1E (Record separator, Information separator two) + case VKEY_6: + return 0x1E; + // ctrl-_ maps to \x1F (Unit separator, Information separator one) + case VKEY_OEM_MINUS: + return 0x1F; + // Returns 0 for all other keys to avoid inputting unexpected chars. + default: + return 0; + } + } else { + switch (key_code) { + // ctrl-[ maps to \x1B (Escape) + case VKEY_OEM_4: + return 0x1B; + // ctrl-\ maps to \x1C (File separator, Information separator four) + case VKEY_OEM_5: + return 0x1C; + // ctrl-] maps to \x1D (Group separator, Information separator three) + case VKEY_OEM_6: + return 0x1D; + // ctrl-Enter maps to \x0A (Line feed) + case VKEY_RETURN: + return 0x0A; + // Returns 0 for all other keys to avoid inputting unexpected chars. + default: + return 0; + } + } + } + + // For IME support. + if (key_code == ui::VKEY_PROCESSKEY) + return 0xE5; + + // Normal characters + if (key_code >= VKEY_0 && key_code <= VKEY_9) { + return shift ? ")!@#$%^&*("[key_code - VKEY_0] : + static_cast<uint16>(key_code); + } else if (key_code >= VKEY_NUMPAD0 && key_code <= VKEY_NUMPAD9) { + return key_code - VKEY_NUMPAD0 + '0'; + } + + switch (key_code) { + case VKEY_TAB: + return '\t'; + case VKEY_RETURN: + return '\r'; + case VKEY_MULTIPLY: + return '*'; + case VKEY_ADD: + return '+'; + case VKEY_SUBTRACT: + return '-'; + case VKEY_DECIMAL: + return '.'; + case VKEY_DIVIDE: + return '/'; + case VKEY_SPACE: + return ' '; + case VKEY_OEM_1: + return shift ? ':' : ';'; + case VKEY_OEM_PLUS: + return shift ? '+' : '='; + case VKEY_OEM_COMMA: + return shift ? '<' : ','; + case VKEY_OEM_MINUS: + return shift ? '_' : '-'; + case VKEY_OEM_PERIOD: + return shift ? '>' : '.'; + case VKEY_OEM_2: + return shift ? '?' : '/'; + case VKEY_OEM_3: + return shift ? '~' : '`'; + case VKEY_OEM_4: + return shift ? '{' : '['; + case VKEY_OEM_5: + return shift ? '|' : '\\'; + case VKEY_OEM_6: + return shift ? '}' : ']'; + case VKEY_OEM_7: + return shift ? '"' : '\''; + default: + return 0; + } +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion.h b/ui/events/keycodes/keyboard_code_conversion.h new file mode 100644 index 0000000..0dd5a12 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion.h @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ + +#include "base/basictypes.h" +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes.h" + +namespace ui { + +// A helper function to get the character generated by a key event in a +// platform independent way. It supports control characters as well. +// It assumes a US keyboard layout is used, so it may only be used when there +// is no native event or no better way to get the character. +// For example, if a virtual keyboard implementation can only generate key +// events with key_code and flags information, then there is no way for us to +// determine the actual character that should be generate by the key. Because +// a key_code only represents a physical key on the keyboard, it has nothing +// to do with the actual character printed on that key. In such case, the only +// thing we can do is to assume that we are using a US keyboard and get the +// character according to US keyboard layout definition. +// If a virtual keyboard implementation wants to support other keyboard +// layouts, that may generate different text for a certain key than on a US +// keyboard, a special native event object should be introduced to carry extra +// information to help determine the correct character. +// Take XKeyEvent as an example, it contains not only keycode and modifier +// flags but also group and other extra XKB information to help determine the +// correct character. That's why we can use XLookupString() function to get +// the correct text generated by a X key event (See how is GetCharacter() +// implemented in event_x.cc). +UI_EXPORT uint16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ diff --git a/ui/events/keycodes/keyboard_code_conversion_android.cc b/ui/events/keycodes/keyboard_code_conversion_android.cc new file mode 100644 index 0000000..fa0ed31 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_android.cc @@ -0,0 +1,305 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/events/keycodes/keyboard_code_conversion_android.h" + +#include <android/keycodes.h> + +namespace ui { + +namespace { + +// The Android NDK does not provide values for these yet: +enum { + AKEYCODE_ESCAPE = 111, + AKEYCODE_FORWARD_DEL = 112, + AKEYCODE_CTRL_LEFT = 113, + AKEYCODE_CTRL_RIGHT = 114, + AKEYCODE_CAPS_LOCK = 115, + AKEYCODE_SCROLL_LOCK = 116, + AKEYCODE_META_LEFT = 117, + AKEYCODE_META_RIGHT = 118, + AKEYCODE_BREAK = 121, + AKEYCODE_INSERT = 124, + AKEYCODE_MEDIA_PLAY = 126, + AKEYCODE_MEDIA_PAUSE = 127, + AKEYCODE_F1 = 131, + AKEYCODE_F2 = 132, + AKEYCODE_F3 = 133, + AKEYCODE_F4 = 134, + AKEYCODE_F5 = 135, + AKEYCODE_F6 = 136, + AKEYCODE_F7 = 137, + AKEYCODE_F8 = 138, + AKEYCODE_F9 = 139, + AKEYCODE_F10 = 140, + AKEYCODE_F11 = 141, + AKEYCODE_F12 = 142, + AKEYCODE_NUM_LOCK = 143, + AKEYCODE_NUMPAD_0 = 144, + AKEYCODE_NUMPAD_1 = 145, + AKEYCODE_NUMPAD_2 = 146, + AKEYCODE_NUMPAD_3 = 147, + AKEYCODE_NUMPAD_4 = 148, + AKEYCODE_NUMPAD_5 = 149, + AKEYCODE_NUMPAD_6 = 150, + AKEYCODE_NUMPAD_7 = 151, + AKEYCODE_NUMPAD_8 = 152, + AKEYCODE_NUMPAD_9 = 153, + AKEYCODE_NUMPAD_DIVIDE = 154, + AKEYCODE_NUMPAD_MULTIPLY = 155, + AKEYCODE_NUMPAD_SUBTRACT = 156, + AKEYCODE_NUMPAD_ADD = 157, + AKEYCODE_NUMPAD_DOT = 158, + AKEYCODE_VOLUME_MUTE = 164, + AKEYCODE_CHANNEL_UP = 166, + AKEYCODE_CHANNEL_DOWN = 167, +}; + +} // namespace + +KeyboardCode KeyboardCodeFromAndroidKeyCode(int keycode) { + // Does not provide all key codes, and does not handle all keys. + switch (keycode) { + case AKEYCODE_DEL: + return VKEY_BACK; + case AKEYCODE_TAB: + return VKEY_TAB; + case AKEYCODE_CLEAR: + return VKEY_CLEAR; + case AKEYCODE_DPAD_CENTER: + case AKEYCODE_ENTER: + return VKEY_RETURN; + case AKEYCODE_SHIFT_LEFT: + return VKEY_LSHIFT; + case AKEYCODE_SHIFT_RIGHT: + return VKEY_RSHIFT; + // Back will serve as escape, although we may not have access to it. + case AKEYCODE_BACK: + return VKEY_ESCAPE; + case AKEYCODE_SPACE: + return VKEY_SPACE; + case AKEYCODE_HOME: + return VKEY_HOME; + case AKEYCODE_DPAD_LEFT: + return VKEY_LEFT; + case AKEYCODE_DPAD_UP: + return VKEY_UP; + case AKEYCODE_DPAD_RIGHT: + return VKEY_RIGHT; + case AKEYCODE_DPAD_DOWN: + return VKEY_DOWN; + case AKEYCODE_0: + return VKEY_0; + case AKEYCODE_1: + return VKEY_1; + case AKEYCODE_2: + return VKEY_2; + case AKEYCODE_3: + return VKEY_3; + case AKEYCODE_4: + return VKEY_4; + case AKEYCODE_5: + return VKEY_5; + case AKEYCODE_6: + return VKEY_6; + case AKEYCODE_7: + return VKEY_7; + case AKEYCODE_8: + return VKEY_8; + case AKEYCODE_9: + return VKEY_9; + case AKEYCODE_A: + return VKEY_A; + case AKEYCODE_B: + return VKEY_B; + case AKEYCODE_C: + return VKEY_C; + case AKEYCODE_D: + return VKEY_D; + case AKEYCODE_E: + return VKEY_E; + case AKEYCODE_F: + return VKEY_F; + case AKEYCODE_G: + return VKEY_G; + case AKEYCODE_H: + return VKEY_H; + case AKEYCODE_I: + return VKEY_I; + case AKEYCODE_J: + return VKEY_J; + case AKEYCODE_K: + return VKEY_K; + case AKEYCODE_L: + return VKEY_L; + case AKEYCODE_M: + return VKEY_M; + case AKEYCODE_N: + return VKEY_N; + case AKEYCODE_O: + return VKEY_O; + case AKEYCODE_P: + return VKEY_P; + case AKEYCODE_Q: + return VKEY_Q; + case AKEYCODE_R: + return VKEY_R; + case AKEYCODE_S: + return VKEY_S; + case AKEYCODE_T: + return VKEY_T; + case AKEYCODE_U: + return VKEY_U; + case AKEYCODE_V: + return VKEY_V; + case AKEYCODE_W: + return VKEY_W; + case AKEYCODE_X: + return VKEY_X; + case AKEYCODE_Y: + return VKEY_Y; + case AKEYCODE_Z: + return VKEY_Z; + case AKEYCODE_VOLUME_DOWN: + return VKEY_VOLUME_DOWN; + case AKEYCODE_VOLUME_UP: + return VKEY_VOLUME_UP; + case AKEYCODE_MEDIA_NEXT: + return VKEY_MEDIA_NEXT_TRACK; + case AKEYCODE_MEDIA_PREVIOUS: + return VKEY_MEDIA_PREV_TRACK; + case AKEYCODE_MEDIA_STOP: + return VKEY_MEDIA_STOP; + case AKEYCODE_MEDIA_PAUSE: + return VKEY_MEDIA_PLAY_PAUSE; + // Colon key. + case AKEYCODE_SEMICOLON: + return VKEY_OEM_1; + case AKEYCODE_COMMA: + return VKEY_OEM_COMMA; + case AKEYCODE_MINUS: + return VKEY_OEM_MINUS; + case AKEYCODE_EQUALS: + return VKEY_OEM_PLUS; + case AKEYCODE_PERIOD: + return VKEY_OEM_PERIOD; + case AKEYCODE_SLASH: + return VKEY_OEM_2; + case AKEYCODE_LEFT_BRACKET: + return VKEY_OEM_4; + case AKEYCODE_BACKSLASH: + return VKEY_OEM_5; + case AKEYCODE_RIGHT_BRACKET: + return VKEY_OEM_6; + case AKEYCODE_MUTE: + case AKEYCODE_VOLUME_MUTE: + return VKEY_VOLUME_MUTE; + case AKEYCODE_ESCAPE: + return VKEY_ESCAPE; + case AKEYCODE_MEDIA_PLAY: + case AKEYCODE_MEDIA_PLAY_PAUSE: + return VKEY_MEDIA_PLAY_PAUSE; + case AKEYCODE_CALL: + return VKEY_END; + case AKEYCODE_ALT_LEFT: + return VKEY_LMENU; + case AKEYCODE_ALT_RIGHT: + return VKEY_RMENU; + case AKEYCODE_GRAVE: + return VKEY_OEM_3; + case AKEYCODE_APOSTROPHE: + return VKEY_OEM_3; + case AKEYCODE_MEDIA_REWIND: + return VKEY_OEM_103; + case AKEYCODE_MEDIA_FAST_FORWARD: + return VKEY_OEM_104; + case AKEYCODE_PAGE_UP: + return VKEY_PRIOR; + case AKEYCODE_PAGE_DOWN: + return VKEY_NEXT; + case AKEYCODE_FORWARD_DEL: + return VKEY_DELETE; + case AKEYCODE_CTRL_LEFT: + return VKEY_LCONTROL; + case AKEYCODE_CTRL_RIGHT: + return VKEY_RCONTROL; + case AKEYCODE_CAPS_LOCK: + return VKEY_CAPITAL; + case AKEYCODE_SCROLL_LOCK: + return VKEY_SCROLL; + case AKEYCODE_META_LEFT: + return VKEY_LWIN; + case AKEYCODE_META_RIGHT: + return VKEY_RWIN; + case AKEYCODE_BREAK: + return VKEY_PAUSE; + case AKEYCODE_INSERT: + return VKEY_INSERT; + case AKEYCODE_F1: + return VKEY_F1; + case AKEYCODE_F2: + return VKEY_F2; + case AKEYCODE_F3: + return VKEY_F3; + case AKEYCODE_F4: + return VKEY_F4; + case AKEYCODE_F5: + return VKEY_F5; + case AKEYCODE_F6: + return VKEY_F6; + case AKEYCODE_F7: + return VKEY_F7; + case AKEYCODE_F8: + return VKEY_F8; + case AKEYCODE_F9: + return VKEY_F9; + case AKEYCODE_F10: + return VKEY_F10; + case AKEYCODE_F11: + return VKEY_F11; + case AKEYCODE_F12: + return VKEY_F12; + case AKEYCODE_NUM_LOCK: + return VKEY_NUMLOCK; + case AKEYCODE_NUMPAD_0: + return VKEY_NUMPAD0; + case AKEYCODE_NUMPAD_1: + return VKEY_NUMPAD1; + case AKEYCODE_NUMPAD_2: + return VKEY_NUMPAD2; + case AKEYCODE_NUMPAD_3: + return VKEY_NUMPAD3; + case AKEYCODE_NUMPAD_4: + return VKEY_NUMPAD4; + case AKEYCODE_NUMPAD_5: + return VKEY_NUMPAD5; + case AKEYCODE_NUMPAD_6: + return VKEY_NUMPAD6; + case AKEYCODE_NUMPAD_7: + return VKEY_NUMPAD7; + case AKEYCODE_NUMPAD_8: + return VKEY_NUMPAD8; + case AKEYCODE_NUMPAD_9: + return VKEY_NUMPAD9; + case AKEYCODE_NUMPAD_DIVIDE: + return VKEY_DIVIDE; + case AKEYCODE_NUMPAD_MULTIPLY: + return VKEY_MULTIPLY; + case AKEYCODE_NUMPAD_SUBTRACT: + return VKEY_SUBTRACT; + case AKEYCODE_NUMPAD_ADD: + return VKEY_ADD; + case AKEYCODE_NUMPAD_DOT: + return VKEY_DECIMAL; + case AKEYCODE_CHANNEL_UP: + return VKEY_PRIOR; + case AKEYCODE_CHANNEL_DOWN: + return VKEY_NEXT; + default: + return VKEY_UNKNOWN; + } +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_android.h b/ui/events/keycodes/keyboard_code_conversion_android.h new file mode 100644 index 0000000..8be44c8 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_android.h @@ -0,0 +1,17 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_ANDROID_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_ANDROID_H_ + +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes_posix.h" + +namespace ui { + +UI_EXPORT KeyboardCode KeyboardCodeFromAndroidKeyCode(int keycode); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_ANDROID_H_ diff --git a/ui/events/keycodes/keyboard_code_conversion_gtk.cc b/ui/events/keycodes/keyboard_code_conversion_gtk.cc new file mode 100644 index 0000000..9a39653 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_gtk.cc @@ -0,0 +1,85 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora, Ltd. All rights reserved. + * Copyright (C) 2008, 2009 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// WindowsKeyCodeForGdkKeyCode is copied from platform/gtk/KeyEventGtk.cpp + +#include "ui/events/keycodes/keyboard_code_conversion_gtk.h" + +#include <gdk/gdk.h> +#include <gdk/gdkkeysyms.h> +#include <X11/keysym.h> + +#include "base/basictypes.h" +#include "build/build_config.h" +#include "ui/events/keycodes/keyboard_code_conversion_x.h" +#include "ui/events/keycodes/keyboard_codes_posix.h" + +namespace ui { + +KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) { + // Gdk key codes (e.g. GDK_BackSpace) and X keysyms (e.g. XK_BackSpace) share + // the same values. + return KeyboardCodeFromXKeysym(keycode); +} + +int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) { + // Gdk key codes and X keysyms share the same values. + return XKeysymForWindowsKeyCode(keycode, shift); +} + +// Just in case, test whether Gdk key codes match X ones. +COMPILE_ASSERT(GDK_KP_0 == XK_KP_0, keycode_check); +COMPILE_ASSERT(GDK_A == XK_A, keycode_check); +COMPILE_ASSERT(GDK_Escape == XK_Escape, keycode_check); +COMPILE_ASSERT(GDK_F1 == XK_F1, keycode_check); +COMPILE_ASSERT(GDK_Kanji == XK_Kanji, keycode_check); +COMPILE_ASSERT(GDK_Page_Up == XK_Page_Up, keycode_check); +COMPILE_ASSERT(GDK_Tab == XK_Tab, keycode_check); +COMPILE_ASSERT(GDK_a == XK_a, keycode_check); +COMPILE_ASSERT(GDK_space == XK_space, keycode_check); + +int GdkNativeKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) { + int keyval = GdkKeyCodeForWindowsKeyCode(keycode, shift); + GdkKeymapKey* keys; + gint n_keys; + + int native_keycode = 0; + if (keyval && gdk_keymap_get_entries_for_keyval(0, keyval, &keys, &n_keys)) { + native_keycode = keys[0].keycode; + g_free(keys); + } + + return native_keycode; +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_gtk.h b/ui/events/keycodes/keyboard_code_conversion_gtk.h new file mode 100644 index 0000000..a01bff7 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_gtk.h @@ -0,0 +1,57 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora, Ltd. All rights reserved. + * Copyright (C) 2008, 2009 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// WindowsKeyCodeForGdkKeyCode is copied from platform/gtk/KeyEventGtk.cpp + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_ + +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes_posix.h" + +typedef struct _GdkEventKey GdkEventKey; + +namespace ui { + +UI_EXPORT KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode); + +UI_EXPORT int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift); + +// For WebKit DRT testing: simulate the native keycode for the given +// input |keycode|. Return the native keycode. +UI_EXPORT int GdkNativeKeyCodeForWindowsKeyCode(KeyboardCode keycode, + bool shift); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_ diff --git a/ui/events/keycodes/keyboard_code_conversion_mac.h b/ui/events/keycodes/keyboard_code_conversion_mac.h new file mode 100644 index 0000000..92e6b13 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_mac.h @@ -0,0 +1,41 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_ + +#import <Cocoa/Cocoa.h> + +#include "base/basictypes.h" +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes_posix.h" + +namespace ui { + +// We use windows virtual keycodes throughout our keyboard event related code, +// including unit tests. But Mac uses a different set of virtual keycodes. +// This function converts a windows virtual keycode into Mac's virtual key code +// and corresponding unicode character. |flags| is the modifiers mask such +// as NSControlKeyMask, NSShiftKeyMask, etc. +// When success, the corresponding Mac's virtual key code will be returned. +// The corresponding unicode character will be stored in |character|, and the +// corresponding unicode character ignoring the modifiers will be stored in +// |characterIgnoringModifiers|. +// -1 will be returned if the keycode can't be converted. +// This function is mainly for simulating keyboard events in unit tests. +// See |KeyboardCodeFromNSEvent| for reverse conversion. +UI_EXPORT int MacKeyCodeForWindowsKeyCode(KeyboardCode keycode, + NSUInteger flags, + unichar* character, + unichar* characterIgnoringModifiers); + +// This implementation cribbed from: +// third_party/WebKit/Source/web/mac/WebInputEventFactory.mm +// Converts |event| into a |KeyboardCode|. The mapping is not direct as the Mac +// has a different notion of key codes. +UI_EXPORT KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_MAC_H_ diff --git a/ui/events/keycodes/keyboard_code_conversion_mac.mm b/ui/events/keycodes/keyboard_code_conversion_mac.mm new file mode 100644 index 0000000..ed50392 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_mac.mm @@ -0,0 +1,558 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "ui/events/keycodes/keyboard_code_conversion_mac.h" + +#include <algorithm> + +#import <Carbon/Carbon.h> + +#include "base/logging.h" + +namespace ui { + +namespace { + +// A struct to hold a Windows keycode to Mac virtual keycode mapping. +struct KeyCodeMap { + KeyboardCode keycode; + int macKeycode; + unichar characterIgnoringModifiers; +}; + +// Customized less operator for using std::lower_bound() on a KeyCodeMap array. +bool operator<(const KeyCodeMap& a, const KeyCodeMap& b) { + return a.keycode < b.keycode; +} + +// This array must keep sorted ascending according to the value of |keycode|, +// so that we can binary search it. +// TODO(suzhe): This map is not complete, missing entries have macKeycode == -1. +const KeyCodeMap kKeyCodesMap[] = { + { VKEY_BACK /* 0x08 */, kVK_Delete, kBackspaceCharCode }, + { VKEY_TAB /* 0x09 */, kVK_Tab, kTabCharCode }, + { VKEY_BACKTAB /* 0x0A */, 0x21E4, '\031' }, + { VKEY_CLEAR /* 0x0C */, kVK_ANSI_KeypadClear, kClearCharCode }, + { VKEY_RETURN /* 0x0D */, kVK_Return, kReturnCharCode }, + { VKEY_SHIFT /* 0x10 */, kVK_Shift, 0 }, + { VKEY_CONTROL /* 0x11 */, kVK_Control, 0 }, + { VKEY_MENU /* 0x12 */, kVK_Option, 0 }, + { VKEY_PAUSE /* 0x13 */, -1, NSPauseFunctionKey }, + { VKEY_CAPITAL /* 0x14 */, kVK_CapsLock, 0 }, + { VKEY_KANA /* 0x15 */, kVK_JIS_Kana, 0 }, + { VKEY_HANGUL /* 0x15 */, -1, 0 }, + { VKEY_JUNJA /* 0x17 */, -1, 0 }, + { VKEY_FINAL /* 0x18 */, -1, 0 }, + { VKEY_HANJA /* 0x19 */, -1, 0 }, + { VKEY_KANJI /* 0x19 */, -1, 0 }, + { VKEY_ESCAPE /* 0x1B */, kVK_Escape, kEscapeCharCode }, + { VKEY_CONVERT /* 0x1C */, -1, 0 }, + { VKEY_NONCONVERT /* 0x1D */, -1, 0 }, + { VKEY_ACCEPT /* 0x1E */, -1, 0 }, + { VKEY_MODECHANGE /* 0x1F */, -1, 0 }, + { VKEY_SPACE /* 0x20 */, kVK_Space, kSpaceCharCode }, + { VKEY_PRIOR /* 0x21 */, kVK_PageUp, NSPageUpFunctionKey }, + { VKEY_NEXT /* 0x22 */, kVK_PageDown, NSPageDownFunctionKey }, + { VKEY_END /* 0x23 */, kVK_End, NSEndFunctionKey }, + { VKEY_HOME /* 0x24 */, kVK_Home, NSHomeFunctionKey }, + { VKEY_LEFT /* 0x25 */, kVK_LeftArrow, NSLeftArrowFunctionKey }, + { VKEY_UP /* 0x26 */, kVK_UpArrow, NSUpArrowFunctionKey }, + { VKEY_RIGHT /* 0x27 */, kVK_RightArrow, NSRightArrowFunctionKey }, + { VKEY_DOWN /* 0x28 */, kVK_DownArrow, NSDownArrowFunctionKey }, + { VKEY_SELECT /* 0x29 */, -1, 0 }, + { VKEY_PRINT /* 0x2A */, -1, NSPrintFunctionKey }, + { VKEY_EXECUTE /* 0x2B */, -1, NSExecuteFunctionKey }, + { VKEY_SNAPSHOT /* 0x2C */, -1, NSPrintScreenFunctionKey }, + { VKEY_INSERT /* 0x2D */, -1, NSInsertFunctionKey }, + { VKEY_DELETE /* 0x2E */, kVK_ForwardDelete, kDeleteCharCode }, + { VKEY_HELP /* 0x2F */, kVK_Help, kHelpCharCode }, + { VKEY_0 /* 0x30 */, kVK_ANSI_0, '0' }, + { VKEY_1 /* 0x31 */, kVK_ANSI_1, '1' }, + { VKEY_2 /* 0x32 */, kVK_ANSI_2, '2' }, + { VKEY_3 /* 0x33 */, kVK_ANSI_3, '3' }, + { VKEY_4 /* 0x34 */, kVK_ANSI_4, '4' }, + { VKEY_5 /* 0x35 */, kVK_ANSI_5, '5' }, + { VKEY_6 /* 0x36 */, kVK_ANSI_6, '6' }, + { VKEY_7 /* 0x37 */, kVK_ANSI_7, '7' }, + { VKEY_8 /* 0x38 */, kVK_ANSI_8, '8' }, + { VKEY_9 /* 0x39 */, kVK_ANSI_9, '9' }, + { VKEY_A /* 0x41 */, kVK_ANSI_A, 'a' }, + { VKEY_B /* 0x42 */, kVK_ANSI_B, 'b' }, + { VKEY_C /* 0x43 */, kVK_ANSI_C, 'c' }, + { VKEY_D /* 0x44 */, kVK_ANSI_D, 'd' }, + { VKEY_E /* 0x45 */, kVK_ANSI_E, 'e' }, + { VKEY_F /* 0x46 */, kVK_ANSI_F, 'f' }, + { VKEY_G /* 0x47 */, kVK_ANSI_G, 'g' }, + { VKEY_H /* 0x48 */, kVK_ANSI_H, 'h' }, + { VKEY_I /* 0x49 */, kVK_ANSI_I, 'i' }, + { VKEY_J /* 0x4A */, kVK_ANSI_J, 'j' }, + { VKEY_K /* 0x4B */, kVK_ANSI_K, 'k' }, + { VKEY_L /* 0x4C */, kVK_ANSI_L, 'l' }, + { VKEY_M /* 0x4D */, kVK_ANSI_M, 'm' }, + { VKEY_N /* 0x4E */, kVK_ANSI_N, 'n' }, + { VKEY_O /* 0x4F */, kVK_ANSI_O, 'o' }, + { VKEY_P /* 0x50 */, kVK_ANSI_P, 'p' }, + { VKEY_Q /* 0x51 */, kVK_ANSI_Q, 'q' }, + { VKEY_R /* 0x52 */, kVK_ANSI_R, 'r' }, + { VKEY_S /* 0x53 */, kVK_ANSI_S, 's' }, + { VKEY_T /* 0x54 */, kVK_ANSI_T, 't' }, + { VKEY_U /* 0x55 */, kVK_ANSI_U, 'u' }, + { VKEY_V /* 0x56 */, kVK_ANSI_V, 'v' }, + { VKEY_W /* 0x57 */, kVK_ANSI_W, 'w' }, + { VKEY_X /* 0x58 */, kVK_ANSI_X, 'x' }, + { VKEY_Y /* 0x59 */, kVK_ANSI_Y, 'y' }, + { VKEY_Z /* 0x5A */, kVK_ANSI_Z, 'z' }, + { VKEY_LWIN /* 0x5B */, kVK_Command, 0 }, + { VKEY_RWIN /* 0x5C */, 0x36, 0 }, + { VKEY_APPS /* 0x5D */, 0x36, 0 }, + { VKEY_SLEEP /* 0x5F */, -1, 0 }, + { VKEY_NUMPAD0 /* 0x60 */, kVK_ANSI_Keypad0, '0' }, + { VKEY_NUMPAD1 /* 0x61 */, kVK_ANSI_Keypad1, '1' }, + { VKEY_NUMPAD2 /* 0x62 */, kVK_ANSI_Keypad2, '2' }, + { VKEY_NUMPAD3 /* 0x63 */, kVK_ANSI_Keypad3, '3' }, + { VKEY_NUMPAD4 /* 0x64 */, kVK_ANSI_Keypad4, '4' }, + { VKEY_NUMPAD5 /* 0x65 */, kVK_ANSI_Keypad5, '5' }, + { VKEY_NUMPAD6 /* 0x66 */, kVK_ANSI_Keypad6, '6' }, + { VKEY_NUMPAD7 /* 0x67 */, kVK_ANSI_Keypad7, '7' }, + { VKEY_NUMPAD8 /* 0x68 */, kVK_ANSI_Keypad8, '8' }, + { VKEY_NUMPAD9 /* 0x69 */, kVK_ANSI_Keypad9, '9' }, + { VKEY_MULTIPLY /* 0x6A */, kVK_ANSI_KeypadMultiply, '*' }, + { VKEY_ADD /* 0x6B */, kVK_ANSI_KeypadPlus, '+' }, + { VKEY_SEPARATOR /* 0x6C */, -1, 0 }, + { VKEY_SUBTRACT /* 0x6D */, kVK_ANSI_KeypadMinus, '-' }, + { VKEY_DECIMAL /* 0x6E */, kVK_ANSI_KeypadDecimal, '.' }, + { VKEY_DIVIDE /* 0x6F */, kVK_ANSI_KeypadDivide, '/' }, + { VKEY_F1 /* 0x70 */, kVK_F1, NSF1FunctionKey }, + { VKEY_F2 /* 0x71 */, kVK_F2, NSF2FunctionKey }, + { VKEY_F3 /* 0x72 */, kVK_F3, NSF3FunctionKey }, + { VKEY_F4 /* 0x73 */, kVK_F4, NSF4FunctionKey }, + { VKEY_F5 /* 0x74 */, kVK_F5, NSF5FunctionKey }, + { VKEY_F6 /* 0x75 */, kVK_F6, NSF6FunctionKey }, + { VKEY_F7 /* 0x76 */, kVK_F7, NSF7FunctionKey }, + { VKEY_F8 /* 0x77 */, kVK_F8, NSF8FunctionKey }, + { VKEY_F9 /* 0x78 */, kVK_F9, NSF9FunctionKey }, + { VKEY_F10 /* 0x79 */, kVK_F10, NSF10FunctionKey }, + { VKEY_F11 /* 0x7A */, kVK_F11, NSF11FunctionKey }, + { VKEY_F12 /* 0x7B */, kVK_F12, NSF12FunctionKey }, + { VKEY_F13 /* 0x7C */, kVK_F13, NSF13FunctionKey }, + { VKEY_F14 /* 0x7D */, kVK_F14, NSF14FunctionKey }, + { VKEY_F15 /* 0x7E */, kVK_F15, NSF15FunctionKey }, + { VKEY_F16 /* 0x7F */, kVK_F16, NSF16FunctionKey }, + { VKEY_F17 /* 0x80 */, kVK_F17, NSF17FunctionKey }, + { VKEY_F18 /* 0x81 */, kVK_F18, NSF18FunctionKey }, + { VKEY_F19 /* 0x82 */, kVK_F19, NSF19FunctionKey }, + { VKEY_F20 /* 0x83 */, kVK_F20, NSF20FunctionKey }, + { VKEY_F21 /* 0x84 */, -1, NSF21FunctionKey }, + { VKEY_F22 /* 0x85 */, -1, NSF22FunctionKey }, + { VKEY_F23 /* 0x86 */, -1, NSF23FunctionKey }, + { VKEY_F24 /* 0x87 */, -1, NSF24FunctionKey }, + { VKEY_NUMLOCK /* 0x90 */, -1, 0 }, + { VKEY_SCROLL /* 0x91 */, -1, NSScrollLockFunctionKey }, + { VKEY_LSHIFT /* 0xA0 */, kVK_Shift, 0 }, + { VKEY_RSHIFT /* 0xA1 */, kVK_Shift, 0 }, + { VKEY_LCONTROL /* 0xA2 */, kVK_Control, 0 }, + { VKEY_RCONTROL /* 0xA3 */, kVK_Control, 0 }, + { VKEY_LMENU /* 0xA4 */, -1, 0 }, + { VKEY_RMENU /* 0xA5 */, -1, 0 }, + { VKEY_BROWSER_BACK /* 0xA6 */, -1, 0 }, + { VKEY_BROWSER_FORWARD /* 0xA7 */, -1, 0 }, + { VKEY_BROWSER_REFRESH /* 0xA8 */, -1, 0 }, + { VKEY_BROWSER_STOP /* 0xA9 */, -1, 0 }, + { VKEY_BROWSER_SEARCH /* 0xAA */, -1, 0 }, + { VKEY_BROWSER_FAVORITES /* 0xAB */, -1, 0 }, + { VKEY_BROWSER_HOME /* 0xAC */, -1, 0 }, + { VKEY_VOLUME_MUTE /* 0xAD */, -1, 0 }, + { VKEY_VOLUME_DOWN /* 0xAE */, -1, 0 }, + { VKEY_VOLUME_UP /* 0xAF */, -1, 0 }, + { VKEY_MEDIA_NEXT_TRACK /* 0xB0 */, -1, 0 }, + { VKEY_MEDIA_PREV_TRACK /* 0xB1 */, -1, 0 }, + { VKEY_MEDIA_STOP /* 0xB2 */, -1, 0 }, + { VKEY_MEDIA_PLAY_PAUSE /* 0xB3 */, -1, 0 }, + { VKEY_MEDIA_LAUNCH_MAIL /* 0xB4 */, -1, 0 }, + { VKEY_MEDIA_LAUNCH_MEDIA_SELECT /* 0xB5 */, -1, 0 }, + { VKEY_MEDIA_LAUNCH_APP1 /* 0xB6 */, -1, 0 }, + { VKEY_MEDIA_LAUNCH_APP2 /* 0xB7 */, -1, 0 }, + { VKEY_OEM_1 /* 0xBA */, kVK_ANSI_Semicolon, ';' }, + { VKEY_OEM_PLUS /* 0xBB */, kVK_ANSI_Equal, '=' }, + { VKEY_OEM_COMMA /* 0xBC */, kVK_ANSI_Comma, ',' }, + { VKEY_OEM_MINUS /* 0xBD */, kVK_ANSI_Minus, '-' }, + { VKEY_OEM_PERIOD /* 0xBE */, kVK_ANSI_Period, '.' }, + { VKEY_OEM_2 /* 0xBF */, kVK_ANSI_Slash, '/' }, + { VKEY_OEM_3 /* 0xC0 */, kVK_ANSI_Grave, '`' }, + { VKEY_OEM_4 /* 0xDB */, kVK_ANSI_LeftBracket, '[' }, + { VKEY_OEM_5 /* 0xDC */, kVK_ANSI_Backslash, '\\' }, + { VKEY_OEM_6 /* 0xDD */, kVK_ANSI_RightBracket, ']' }, + { VKEY_OEM_7 /* 0xDE */, kVK_ANSI_Quote, '\'' }, + { VKEY_OEM_8 /* 0xDF */, -1, 0 }, + { VKEY_OEM_102 /* 0xE2 */, -1, 0 }, + { VKEY_PROCESSKEY /* 0xE5 */, -1, 0 }, + { VKEY_PACKET /* 0xE7 */, -1, 0 }, + { VKEY_ATTN /* 0xF6 */, -1, 0 }, + { VKEY_CRSEL /* 0xF7 */, -1, 0 }, + { VKEY_EXSEL /* 0xF8 */, -1, 0 }, + { VKEY_EREOF /* 0xF9 */, -1, 0 }, + { VKEY_PLAY /* 0xFA */, -1, 0 }, + { VKEY_ZOOM /* 0xFB */, -1, 0 }, + { VKEY_NONAME /* 0xFC */, -1, 0 }, + { VKEY_PA1 /* 0xFD */, -1, 0 }, + { VKEY_OEM_CLEAR /* 0xFE */, kVK_ANSI_KeypadClear, kClearCharCode } +}; + +// A convenient array for getting symbol characters on the number keys. +const char kShiftCharsForNumberKeys[] = ")!@#$%^&*("; + +// Translates from character code to keyboard code. +KeyboardCode KeyboardCodeFromCharCode(unichar charCode) { + switch (charCode) { + case 8: case 0x7F: return VKEY_BACK; + case 9: return VKEY_TAB; + case 0xD: case 3: return VKEY_RETURN; + case 0x1B: return VKEY_ESCAPE; + case ' ': return VKEY_SPACE; + case NSHomeFunctionKey: return VKEY_HOME; + case NSEndFunctionKey: return VKEY_END; + case NSPageUpFunctionKey: return VKEY_PRIOR; + case NSPageDownFunctionKey: return VKEY_NEXT; + case NSUpArrowFunctionKey: return VKEY_UP; + case NSDownArrowFunctionKey: return VKEY_DOWN; + case NSLeftArrowFunctionKey: return VKEY_LEFT; + case NSRightArrowFunctionKey: return VKEY_RIGHT; + case NSDeleteFunctionKey: return VKEY_DELETE; + + case '0': case ')': return VKEY_0; + case '1': case '!': return VKEY_1; + case '2': case '@': return VKEY_2; + case '3': case '#': return VKEY_3; + case '4': case '$': return VKEY_4; + case '5': case '%': return VKEY_5; + case '6': case '^': return VKEY_6; + case '7': case '&': return VKEY_7; + case '8': case '*': return VKEY_8; + case '9': case '(': return VKEY_9; + + case 'a': case 'A': return VKEY_A; + case 'b': case 'B': return VKEY_B; + case 'c': case 'C': return VKEY_C; + case 'd': case 'D': return VKEY_D; + case 'e': case 'E': return VKEY_E; + case 'f': case 'F': return VKEY_F; + case 'g': case 'G': return VKEY_G; + case 'h': case 'H': return VKEY_H; + case 'i': case 'I': return VKEY_I; + case 'j': case 'J': return VKEY_J; + case 'k': case 'K': return VKEY_K; + case 'l': case 'L': return VKEY_L; + case 'm': case 'M': return VKEY_M; + case 'n': case 'N': return VKEY_N; + case 'o': case 'O': return VKEY_O; + case 'p': case 'P': return VKEY_P; + case 'q': case 'Q': return VKEY_Q; + case 'r': case 'R': return VKEY_R; + case 's': case 'S': return VKEY_S; + case 't': case 'T': return VKEY_T; + case 'u': case 'U': return VKEY_U; + case 'v': case 'V': return VKEY_V; + case 'w': case 'W': return VKEY_W; + case 'x': case 'X': return VKEY_X; + case 'y': case 'Y': return VKEY_Y; + case 'z': case 'Z': return VKEY_Z; + + case NSPauseFunctionKey: return VKEY_PAUSE; + case NSSelectFunctionKey: return VKEY_SELECT; + case NSPrintFunctionKey: return VKEY_PRINT; + case NSExecuteFunctionKey: return VKEY_EXECUTE; + case NSPrintScreenFunctionKey: return VKEY_SNAPSHOT; + case NSInsertFunctionKey: return VKEY_INSERT; + case NSHelpFunctionKey: return VKEY_INSERT; + + case NSF1FunctionKey: return VKEY_F1; + case NSF2FunctionKey: return VKEY_F2; + case NSF3FunctionKey: return VKEY_F3; + case NSF4FunctionKey: return VKEY_F4; + case NSF5FunctionKey: return VKEY_F5; + case NSF6FunctionKey: return VKEY_F6; + case NSF7FunctionKey: return VKEY_F7; + case NSF8FunctionKey: return VKEY_F8; + case NSF9FunctionKey: return VKEY_F9; + case NSF10FunctionKey: return VKEY_F10; + case NSF11FunctionKey: return VKEY_F11; + case NSF12FunctionKey: return VKEY_F12; + case NSF13FunctionKey: return VKEY_F13; + case NSF14FunctionKey: return VKEY_F14; + case NSF15FunctionKey: return VKEY_F15; + case NSF16FunctionKey: return VKEY_F16; + case NSF17FunctionKey: return VKEY_F17; + case NSF18FunctionKey: return VKEY_F18; + case NSF19FunctionKey: return VKEY_F19; + case NSF20FunctionKey: return VKEY_F20; + + case NSF21FunctionKey: return VKEY_F21; + case NSF22FunctionKey: return VKEY_F22; + case NSF23FunctionKey: return VKEY_F23; + case NSF24FunctionKey: return VKEY_F24; + case NSScrollLockFunctionKey: return VKEY_SCROLL; + + // U.S. Specific mappings. Mileage may vary. + case ';': case ':': return VKEY_OEM_1; + case '=': case '+': return VKEY_OEM_PLUS; + case ',': case '<': return VKEY_OEM_COMMA; + case '-': case '_': return VKEY_OEM_MINUS; + case '.': case '>': return VKEY_OEM_PERIOD; + case '/': case '?': return VKEY_OEM_2; + case '`': case '~': return VKEY_OEM_3; + case '[': case '{': return VKEY_OEM_4; + case '\\': case '|': return VKEY_OEM_5; + case ']': case '}': return VKEY_OEM_6; + case '\'': case '"': return VKEY_OEM_7; + } + + return VKEY_UNKNOWN; +} + +KeyboardCode KeyboardCodeFromKeyCode(unsigned short keyCode) { + static const KeyboardCode kKeyboardCodes[] = { + /* 0 */ VKEY_A, + /* 1 */ VKEY_S, + /* 2 */ VKEY_D, + /* 3 */ VKEY_F, + /* 4 */ VKEY_H, + /* 5 */ VKEY_G, + /* 6 */ VKEY_Z, + /* 7 */ VKEY_X, + /* 8 */ VKEY_C, + /* 9 */ VKEY_V, + /* 0x0A */ VKEY_OEM_3, // Section key. + /* 0x0B */ VKEY_B, + /* 0x0C */ VKEY_Q, + /* 0x0D */ VKEY_W, + /* 0x0E */ VKEY_E, + /* 0x0F */ VKEY_R, + /* 0x10 */ VKEY_Y, + /* 0x11 */ VKEY_T, + /* 0x12 */ VKEY_1, + /* 0x13 */ VKEY_2, + /* 0x14 */ VKEY_3, + /* 0x15 */ VKEY_4, + /* 0x16 */ VKEY_6, + /* 0x17 */ VKEY_5, + /* 0x18 */ VKEY_OEM_PLUS, // =+ + /* 0x19 */ VKEY_9, + /* 0x1A */ VKEY_7, + /* 0x1B */ VKEY_OEM_MINUS, // -_ + /* 0x1C */ VKEY_8, + /* 0x1D */ VKEY_0, + /* 0x1E */ VKEY_OEM_6, // ]} + /* 0x1F */ VKEY_O, + /* 0x20 */ VKEY_U, + /* 0x21 */ VKEY_OEM_4, // {[ + /* 0x22 */ VKEY_I, + /* 0x23 */ VKEY_P, + /* 0x24 */ VKEY_RETURN, // Return + /* 0x25 */ VKEY_L, + /* 0x26 */ VKEY_J, + /* 0x27 */ VKEY_OEM_7, // '" + /* 0x28 */ VKEY_K, + /* 0x29 */ VKEY_OEM_1, // ;: + /* 0x2A */ VKEY_OEM_5, // \| + /* 0x2B */ VKEY_OEM_COMMA, // ,< + /* 0x2C */ VKEY_OEM_2, // /? + /* 0x2D */ VKEY_N, + /* 0x2E */ VKEY_M, + /* 0x2F */ VKEY_OEM_PERIOD, // .> + /* 0x30 */ VKEY_TAB, + /* 0x31 */ VKEY_SPACE, + /* 0x32 */ VKEY_OEM_3, // `~ + /* 0x33 */ VKEY_BACK, // Backspace + /* 0x34 */ VKEY_UNKNOWN, // n/a + /* 0x35 */ VKEY_ESCAPE, + /* 0x36 */ VKEY_APPS, // Right Command + /* 0x37 */ VKEY_LWIN, // Left Command + /* 0x38 */ VKEY_SHIFT, // Left Shift + /* 0x39 */ VKEY_CAPITAL, // Caps Lock + /* 0x3A */ VKEY_MENU, // Left Option + /* 0x3B */ VKEY_CONTROL, // Left Ctrl + /* 0x3C */ VKEY_SHIFT, // Right Shift + /* 0x3D */ VKEY_MENU, // Right Option + /* 0x3E */ VKEY_CONTROL, // Right Ctrl + /* 0x3F */ VKEY_UNKNOWN, // fn + /* 0x40 */ VKEY_F17, + /* 0x41 */ VKEY_DECIMAL, // Num Pad . + /* 0x42 */ VKEY_UNKNOWN, // n/a + /* 0x43 */ VKEY_MULTIPLY, // Num Pad * + /* 0x44 */ VKEY_UNKNOWN, // n/a + /* 0x45 */ VKEY_ADD, // Num Pad + + /* 0x46 */ VKEY_UNKNOWN, // n/a + /* 0x47 */ VKEY_CLEAR, // Num Pad Clear + /* 0x48 */ VKEY_VOLUME_UP, + /* 0x49 */ VKEY_VOLUME_DOWN, + /* 0x4A */ VKEY_VOLUME_MUTE, + /* 0x4B */ VKEY_DIVIDE, // Num Pad / + /* 0x4C */ VKEY_RETURN, // Num Pad Enter + /* 0x4D */ VKEY_UNKNOWN, // n/a + /* 0x4E */ VKEY_SUBTRACT, // Num Pad - + /* 0x4F */ VKEY_F18, + /* 0x50 */ VKEY_F19, + /* 0x51 */ VKEY_OEM_PLUS, // Num Pad =. + /* 0x52 */ VKEY_NUMPAD0, + /* 0x53 */ VKEY_NUMPAD1, + /* 0x54 */ VKEY_NUMPAD2, + /* 0x55 */ VKEY_NUMPAD3, + /* 0x56 */ VKEY_NUMPAD4, + /* 0x57 */ VKEY_NUMPAD5, + /* 0x58 */ VKEY_NUMPAD6, + /* 0x59 */ VKEY_NUMPAD7, + /* 0x5A */ VKEY_F20, + /* 0x5B */ VKEY_NUMPAD8, + /* 0x5C */ VKEY_NUMPAD9, + /* 0x5D */ VKEY_UNKNOWN, // Yen (JIS Keyboard Only) + /* 0x5E */ VKEY_UNKNOWN, // Underscore (JIS Keyboard Only) + /* 0x5F */ VKEY_UNKNOWN, // KeypadComma (JIS Keyboard Only) + /* 0x60 */ VKEY_F5, + /* 0x61 */ VKEY_F6, + /* 0x62 */ VKEY_F7, + /* 0x63 */ VKEY_F3, + /* 0x64 */ VKEY_F8, + /* 0x65 */ VKEY_F9, + /* 0x66 */ VKEY_UNKNOWN, // Eisu (JIS Keyboard Only) + /* 0x67 */ VKEY_F11, + /* 0x68 */ VKEY_UNKNOWN, // Kana (JIS Keyboard Only) + /* 0x69 */ VKEY_F13, + /* 0x6A */ VKEY_F16, + /* 0x6B */ VKEY_F14, + /* 0x6C */ VKEY_UNKNOWN, // n/a + /* 0x6D */ VKEY_F10, + /* 0x6E */ VKEY_UNKNOWN, // n/a (Windows95 key?) + /* 0x6F */ VKEY_F12, + /* 0x70 */ VKEY_UNKNOWN, // n/a + /* 0x71 */ VKEY_F15, + /* 0x72 */ VKEY_INSERT, // Help + /* 0x73 */ VKEY_HOME, // Home + /* 0x74 */ VKEY_PRIOR, // Page Up + /* 0x75 */ VKEY_DELETE, // Forward Delete + /* 0x76 */ VKEY_F4, + /* 0x77 */ VKEY_END, // End + /* 0x78 */ VKEY_F2, + /* 0x79 */ VKEY_NEXT, // Page Down + /* 0x7A */ VKEY_F1, + /* 0x7B */ VKEY_LEFT, // Left Arrow + /* 0x7C */ VKEY_RIGHT, // Right Arrow + /* 0x7D */ VKEY_DOWN, // Down Arrow + /* 0x7E */ VKEY_UP, // Up Arrow + /* 0x7F */ VKEY_UNKNOWN // n/a + }; + + if (keyCode >= 0x80) + return VKEY_UNKNOWN; + + return kKeyboardCodes[keyCode]; +} + +} // namespace + +int MacKeyCodeForWindowsKeyCode(KeyboardCode keycode, + NSUInteger flags, + unichar* character, + unichar* characterIgnoringModifiers) { + KeyCodeMap from; + from.keycode = keycode; + + const KeyCodeMap* ptr = std::lower_bound( + kKeyCodesMap, kKeyCodesMap + arraysize(kKeyCodesMap), from); + + if (ptr >= kKeyCodesMap + arraysize(kKeyCodesMap) || + ptr->keycode != keycode || ptr->macKeycode == -1) + return -1; + + int macKeycode = ptr->macKeycode; + if (characterIgnoringModifiers) + *characterIgnoringModifiers = ptr->characterIgnoringModifiers; + + if (!character) + return macKeycode; + + *character = ptr->characterIgnoringModifiers; + + // Fill in |character| according to flags. + if (flags & NSShiftKeyMask) { + if (keycode >= VKEY_0 && keycode <= VKEY_9) { + *character = kShiftCharsForNumberKeys[keycode - VKEY_0]; + } else if (keycode >= VKEY_A && keycode <= VKEY_Z) { + *character = 'A' + (keycode - VKEY_A); + } else { + switch (macKeycode) { + case kVK_ANSI_Grave: + *character = '~'; + break; + case kVK_ANSI_Minus: + *character = '_'; + break; + case kVK_ANSI_Equal: + *character = '+'; + break; + case kVK_ANSI_LeftBracket: + *character = '{'; + break; + case kVK_ANSI_RightBracket: + *character = '}'; + break; + case kVK_ANSI_Backslash: + *character = '|'; + break; + case kVK_ANSI_Semicolon: + *character = ':'; + break; + case kVK_ANSI_Quote: + *character = '\"'; + break; + case kVK_ANSI_Comma: + *character = '<'; + break; + case kVK_ANSI_Period: + *character = '>'; + break; + case kVK_ANSI_Slash: + *character = '?'; + break; + default: + break; + } + } + } + + // Control characters. + if (flags & NSControlKeyMask) { + if (keycode >= VKEY_A && keycode <= VKEY_Z) + *character = 1 + keycode - VKEY_A; + else if (macKeycode == kVK_ANSI_LeftBracket) + *character = 27; + else if (macKeycode == kVK_ANSI_Backslash) + *character = 28; + else if (macKeycode == kVK_ANSI_RightBracket) + *character = 29; + } + + // TODO(suzhe): Support characters for Option key bindings. + return macKeycode; +} + +KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) { + KeyboardCode code = VKEY_UNKNOWN; + + if ([event type] == NSKeyDown || [event type] == NSKeyUp) { + NSString* characters = [event characters]; + if ([characters length] > 0) + code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); + if (code) + return code; + + characters = [event charactersIgnoringModifiers]; + if ([characters length] > 0) + code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); + if (code) + return code; + } + return KeyboardCodeFromKeyCode([event keyCode]); +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_win.cc b/ui/events/keycodes/keyboard_code_conversion_win.cc new file mode 100644 index 0000000..66eeaa7 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_win.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/events/keycodes/keyboard_code_conversion_win.h" + +namespace ui { + +WORD WindowsKeyCodeForKeyboardCode(KeyboardCode keycode) { + return static_cast<WORD>(keycode); +} + +KeyboardCode KeyboardCodeForWindowsKeyCode(WORD keycode) { + return static_cast<KeyboardCode>(keycode); +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_win.h b/ui/events/keycodes/keyboard_code_conversion_win.h new file mode 100644 index 0000000..9964138 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_win.h @@ -0,0 +1,19 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_WIN_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_WIN_H_ + +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes.h" + +namespace ui { + +// Methods to convert ui::KeyboardCode/Windows virtual key type methods. +UI_EXPORT WORD WindowsKeyCodeForKeyboardCode(KeyboardCode keycode); +UI_EXPORT KeyboardCode KeyboardCodeForWindowsKeyCode(WORD keycode); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_WIN_H_ diff --git a/ui/events/keycodes/keyboard_code_conversion_x.cc b/ui/events/keycodes/keyboard_code_conversion_x.cc new file mode 100644 index 0000000..8b88e39 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_x.cc @@ -0,0 +1,804 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/events/keycodes/keyboard_code_conversion_x.h" + +#define XK_3270 // for XK_3270_BackTab +#include <X11/keysym.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/XF86keysym.h> + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" + +namespace ui { + +// Get an ui::KeyboardCode from an X keyevent +KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { + // XLookupKeysym does not take into consideration the state of the lock/shift + // etc. keys. So it is necessary to use XLookupString instead. + KeySym keysym; + XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); + KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); + if (keycode == VKEY_UNKNOWN) { + keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); + keycode = KeyboardCodeFromXKeysym(keysym); + } + + return keycode; +} + +KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { + // TODO(sad): Have |keysym| go through the X map list? + + switch (keysym) { + case XK_BackSpace: + return VKEY_BACK; + case XK_Delete: + case XK_KP_Delete: + return VKEY_DELETE; + case XK_Tab: + case XK_KP_Tab: + case XK_ISO_Left_Tab: + case XK_3270_BackTab: + return VKEY_TAB; + case XK_Linefeed: + case XK_Return: + case XK_KP_Enter: + case XK_ISO_Enter: + return VKEY_RETURN; + case XK_Clear: + case XK_KP_Begin: // NumPad 5 without Num Lock, for crosbug.com/29169. + return VKEY_CLEAR; + case XK_KP_Space: + case XK_space: + return VKEY_SPACE; + case XK_Home: + case XK_KP_Home: + return VKEY_HOME; + case XK_End: + case XK_KP_End: + return VKEY_END; + case XK_Page_Up: + case XK_KP_Page_Up: // aka XK_KP_Prior + return VKEY_PRIOR; + case XK_Page_Down: + case XK_KP_Page_Down: // aka XK_KP_Next + return VKEY_NEXT; + case XK_Left: + case XK_KP_Left: + return VKEY_LEFT; + case XK_Right: + case XK_KP_Right: + return VKEY_RIGHT; + case XK_Down: + case XK_KP_Down: + return VKEY_DOWN; + case XK_Up: + case XK_KP_Up: + return VKEY_UP; + case XK_Escape: + return VKEY_ESCAPE; + case XK_Kana_Lock: + case XK_Kana_Shift: + return VKEY_KANA; + case XK_Hangul: + return VKEY_HANGUL; + case XK_Hangul_Hanja: + return VKEY_HANJA; + case XK_Kanji: + return VKEY_KANJI; + case XK_Henkan: + return VKEY_CONVERT; + case XK_Muhenkan: + return VKEY_NONCONVERT; + case XK_Zenkaku_Hankaku: + return VKEY_DBE_DBCSCHAR; + case XK_A: + case XK_a: + return VKEY_A; + case XK_B: + case XK_b: + return VKEY_B; + case XK_C: + case XK_c: + return VKEY_C; + case XK_D: + case XK_d: + return VKEY_D; + case XK_E: + case XK_e: + return VKEY_E; + case XK_F: + case XK_f: + return VKEY_F; + case XK_G: + case XK_g: + return VKEY_G; + case XK_H: + case XK_h: + return VKEY_H; + case XK_I: + case XK_i: + return VKEY_I; + case XK_J: + case XK_j: + return VKEY_J; + case XK_K: + case XK_k: + return VKEY_K; + case XK_L: + case XK_l: + return VKEY_L; + case XK_M: + case XK_m: + return VKEY_M; + case XK_N: + case XK_n: + return VKEY_N; + case XK_O: + case XK_o: + return VKEY_O; + case XK_P: + case XK_p: + return VKEY_P; + case XK_Q: + case XK_q: + return VKEY_Q; + case XK_R: + case XK_r: + return VKEY_R; + case XK_S: + case XK_s: + return VKEY_S; + case XK_T: + case XK_t: + return VKEY_T; + case XK_U: + case XK_u: + return VKEY_U; + case XK_V: + case XK_v: + return VKEY_V; + case XK_W: + case XK_w: + return VKEY_W; + case XK_X: + case XK_x: + return VKEY_X; + case XK_Y: + case XK_y: + return VKEY_Y; + case XK_Z: + case XK_z: + return VKEY_Z; + + case XK_0: + case XK_1: + case XK_2: + case XK_3: + case XK_4: + case XK_5: + case XK_6: + case XK_7: + case XK_8: + case XK_9: + return static_cast<KeyboardCode>(VKEY_0 + (keysym - XK_0)); + + case XK_parenright: + return VKEY_0; + case XK_exclam: + return VKEY_1; + case XK_at: + return VKEY_2; + case XK_numbersign: + return VKEY_3; + case XK_dollar: + return VKEY_4; + case XK_percent: + return VKEY_5; + case XK_asciicircum: + return VKEY_6; + case XK_ampersand: + return VKEY_7; + case XK_asterisk: + return VKEY_8; + case XK_parenleft: + return VKEY_9; + + case XK_KP_0: + case XK_KP_1: + case XK_KP_2: + case XK_KP_3: + case XK_KP_4: + case XK_KP_5: + case XK_KP_6: + case XK_KP_7: + case XK_KP_8: + case XK_KP_9: + return static_cast<KeyboardCode>(VKEY_NUMPAD0 + (keysym - XK_KP_0)); + + case XK_multiply: + case XK_KP_Multiply: + return VKEY_MULTIPLY; + case XK_KP_Add: + return VKEY_ADD; + case XK_KP_Separator: + return VKEY_SEPARATOR; + case XK_KP_Subtract: + return VKEY_SUBTRACT; + case XK_KP_Decimal: + return VKEY_DECIMAL; + case XK_KP_Divide: + return VKEY_DIVIDE; + case XK_KP_Equal: + case XK_equal: + case XK_plus: + return VKEY_OEM_PLUS; + case XK_comma: + case XK_less: + return VKEY_OEM_COMMA; + case XK_minus: + case XK_underscore: + return VKEY_OEM_MINUS; + case XK_greater: + case XK_period: + return VKEY_OEM_PERIOD; + case XK_colon: + case XK_semicolon: + return VKEY_OEM_1; + case XK_question: + case XK_slash: + return VKEY_OEM_2; + case XK_asciitilde: + case XK_quoteleft: + return VKEY_OEM_3; + case XK_bracketleft: + case XK_braceleft: + return VKEY_OEM_4; + case XK_backslash: + case XK_bar: + return VKEY_OEM_5; + case XK_bracketright: + case XK_braceright: + return VKEY_OEM_6; + case XK_quoteright: + case XK_quotedbl: + return VKEY_OEM_7; + case XK_ISO_Level5_Shift: + return VKEY_OEM_8; + case XK_Shift_L: + case XK_Shift_R: + return VKEY_SHIFT; + case XK_Control_L: + case XK_Control_R: + return VKEY_CONTROL; + case XK_Meta_L: + case XK_Meta_R: + case XK_Alt_L: + case XK_Alt_R: + return VKEY_MENU; + case XK_ISO_Level3_Shift: + return VKEY_ALTGR; + case XK_Pause: + return VKEY_PAUSE; + case XK_Caps_Lock: + return VKEY_CAPITAL; + case XK_Num_Lock: + return VKEY_NUMLOCK; + case XK_Scroll_Lock: + return VKEY_SCROLL; + case XK_Select: + return VKEY_SELECT; + case XK_Print: + return VKEY_PRINT; + case XK_Execute: + return VKEY_EXECUTE; + case XK_Insert: + case XK_KP_Insert: + return VKEY_INSERT; + case XK_Help: + return VKEY_HELP; + case XK_Super_L: + return VKEY_LWIN; + case XK_Super_R: + return VKEY_RWIN; + case XK_Menu: + return VKEY_APPS; + case XK_F1: + case XK_F2: + case XK_F3: + case XK_F4: + case XK_F5: + case XK_F6: + case XK_F7: + case XK_F8: + case XK_F9: + case XK_F10: + case XK_F11: + case XK_F12: + case XK_F13: + case XK_F14: + case XK_F15: + case XK_F16: + case XK_F17: + case XK_F18: + case XK_F19: + case XK_F20: + case XK_F21: + case XK_F22: + case XK_F23: + case XK_F24: + return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); + case XK_KP_F1: + case XK_KP_F2: + case XK_KP_F3: + case XK_KP_F4: + return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_KP_F1)); + + case XK_guillemotleft: + case XK_guillemotright: + case XK_degree: + // In the case of canadian multilingual keyboard layout, VKEY_OEM_102 is + // assigned to ugrave key. + case XK_ugrave: + case XK_Ugrave: + case XK_brokenbar: + return VKEY_OEM_102; // international backslash key in 102 keyboard. + + // When evdev is in use, /usr/share/X11/xkb/symbols/inet maps F13-18 keys + // to the special XF86XK symbols to support Microsoft Ergonomic keyboards: + // https://bugs.freedesktop.org/show_bug.cgi?id=5783 + // In Chrome, we map these X key symbols back to F13-18 since we don't have + // VKEYs for these XF86XK symbols. + case XF86XK_Tools: + return VKEY_F13; + case XF86XK_Launch5: + return VKEY_F14; + case XF86XK_Launch6: + return VKEY_F15; + case XF86XK_Launch7: + return VKEY_F16; + case XF86XK_Launch8: + return VKEY_F17; + case XF86XK_Launch9: + return VKEY_F18; + +#if defined(TOOLKIT_GTK) + case XF86XK_Refresh: + case XF86XK_History: + case XF86XK_OpenURL: + case XF86XK_AddFavorite: + case XF86XK_Go: + case XF86XK_ZoomIn: + case XF86XK_ZoomOut: + // ui::AcceleratorGtk tries to convert the XF86XK_ keysyms on Chrome + // startup. It's safe to return VKEY_UNKNOWN here since ui::AcceleratorGtk + // also checks a Gdk keysym. http://crbug.com/109843 + return VKEY_UNKNOWN; +#endif + + // For supporting multimedia buttons on a USB keyboard. + case XF86XK_Back: + return VKEY_BROWSER_BACK; + case XF86XK_Forward: + return VKEY_BROWSER_FORWARD; + case XF86XK_Reload: + return VKEY_BROWSER_REFRESH; + case XF86XK_Stop: + return VKEY_BROWSER_STOP; + case XF86XK_Search: + return VKEY_BROWSER_SEARCH; + case XF86XK_Favorites: + return VKEY_BROWSER_FAVORITES; + case XF86XK_HomePage: + return VKEY_BROWSER_HOME; + case XF86XK_AudioMute: + return VKEY_VOLUME_MUTE; + case XF86XK_AudioLowerVolume: + return VKEY_VOLUME_DOWN; + case XF86XK_AudioRaiseVolume: + return VKEY_VOLUME_UP; + case XF86XK_AudioNext: + return VKEY_MEDIA_NEXT_TRACK; + case XF86XK_AudioPrev: + return VKEY_MEDIA_PREV_TRACK; + case XF86XK_AudioStop: + return VKEY_MEDIA_STOP; + case XF86XK_AudioPlay: + return VKEY_MEDIA_PLAY_PAUSE; + case XF86XK_Mail: + return VKEY_MEDIA_LAUNCH_MAIL; + case XF86XK_LaunchA: // F3 on an Apple keyboard. + return VKEY_MEDIA_LAUNCH_APP1; + case XF86XK_LaunchB: // F4 on an Apple keyboard. + case XF86XK_Calculator: + return VKEY_MEDIA_LAUNCH_APP2; + case XF86XK_WLAN: + return VKEY_WLAN; + case XF86XK_PowerOff: + return VKEY_POWER; + case XF86XK_MonBrightnessDown: + return VKEY_BRIGHTNESS_DOWN; + case XF86XK_MonBrightnessUp: + return VKEY_BRIGHTNESS_UP; + case XF86XK_KbdBrightnessDown: + return VKEY_KBD_BRIGHTNESS_DOWN; + case XF86XK_KbdBrightnessUp: + return VKEY_KBD_BRIGHTNESS_UP; + + // TODO(sad): some keycodes are still missing. + } + DLOG(WARNING) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym); + return VKEY_UNKNOWN; +} + +uint16 GetCharacterFromXEvent(XEvent* xev) { + char buf[6]; + int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); + DCHECK_LE(bytes_written, 6); + + string16 result; + return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && + result.length() == 1) ? result[0] : 0; +} + +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; +} + +// TODO(jcampan): this method might be incomplete. +int XKeysymForWindowsKeyCode(KeyboardCode keycode, bool shift) { + switch (keycode) { + case VKEY_NUMPAD0: + return XK_KP_0; + case VKEY_NUMPAD1: + return XK_KP_1; + case VKEY_NUMPAD2: + return XK_KP_2; + case VKEY_NUMPAD3: + return XK_KP_3; + case VKEY_NUMPAD4: + return XK_KP_4; + case VKEY_NUMPAD5: + return XK_KP_5; + case VKEY_NUMPAD6: + return XK_KP_6; + case VKEY_NUMPAD7: + return XK_KP_7; + case VKEY_NUMPAD8: + return XK_KP_8; + case VKEY_NUMPAD9: + return XK_KP_9; + case VKEY_MULTIPLY: + return XK_KP_Multiply; + case VKEY_ADD: + return XK_KP_Add; + case VKEY_SUBTRACT: + return XK_KP_Subtract; + case VKEY_DECIMAL: + return XK_KP_Decimal; + case VKEY_DIVIDE: + return XK_KP_Divide; + + case VKEY_BACK: + return XK_BackSpace; + case VKEY_TAB: + return shift ? XK_ISO_Left_Tab : XK_Tab; + case VKEY_CLEAR: + return XK_Clear; + case VKEY_RETURN: + return XK_Return; + case VKEY_SHIFT: + return XK_Shift_L; + case VKEY_CONTROL: + return XK_Control_L; + case VKEY_MENU: + return XK_Alt_L; + case VKEY_APPS: + return XK_Menu; + case VKEY_ALTGR: + return XK_ISO_Level3_Shift; + + case VKEY_PAUSE: + return XK_Pause; + case VKEY_CAPITAL: + return XK_Caps_Lock; + case VKEY_KANA: + return XK_Kana_Lock; + case VKEY_HANJA: + return XK_Hangul_Hanja; + case VKEY_CONVERT: + return XK_Henkan; + case VKEY_NONCONVERT: + return XK_Muhenkan; + case VKEY_DBE_SBCSCHAR: + return XK_Zenkaku_Hankaku; + case VKEY_DBE_DBCSCHAR: + return XK_Zenkaku_Hankaku; + case VKEY_ESCAPE: + return XK_Escape; + case VKEY_SPACE: + return XK_space; + case VKEY_PRIOR: + return XK_Page_Up; + case VKEY_NEXT: + return XK_Page_Down; + case VKEY_END: + return XK_End; + case VKEY_HOME: + return XK_Home; + case VKEY_LEFT: + return XK_Left; + case VKEY_UP: + return XK_Up; + case VKEY_RIGHT: + return XK_Right; + case VKEY_DOWN: + return XK_Down; + case VKEY_SELECT: + return XK_Select; + case VKEY_PRINT: + return XK_Print; + case VKEY_EXECUTE: + return XK_Execute; + case VKEY_INSERT: + return XK_Insert; + case VKEY_DELETE: + return XK_Delete; + case VKEY_HELP: + return XK_Help; + case VKEY_0: + return shift ? XK_parenright : XK_0; + case VKEY_1: + return shift ? XK_exclam : XK_1; + case VKEY_2: + return shift ? XK_at : XK_2; + case VKEY_3: + return shift ? XK_numbersign : XK_3; + case VKEY_4: + return shift ? XK_dollar : XK_4; + case VKEY_5: + return shift ? XK_percent : XK_5; + case VKEY_6: + return shift ? XK_asciicircum : XK_6; + case VKEY_7: + return shift ? XK_ampersand : XK_7; + case VKEY_8: + return shift ? XK_asterisk : XK_8; + case VKEY_9: + return shift ? XK_parenleft : XK_9; + + case VKEY_A: + case VKEY_B: + case VKEY_C: + case VKEY_D: + case VKEY_E: + case VKEY_F: + case VKEY_G: + case VKEY_H: + case VKEY_I: + case VKEY_J: + case VKEY_K: + case VKEY_L: + case VKEY_M: + case VKEY_N: + case VKEY_O: + case VKEY_P: + case VKEY_Q: + case VKEY_R: + case VKEY_S: + case VKEY_T: + case VKEY_U: + case VKEY_V: + case VKEY_W: + case VKEY_X: + case VKEY_Y: + case VKEY_Z: + return (shift ? XK_A : XK_a) + (keycode - VKEY_A); + + case VKEY_LWIN: + return XK_Super_L; + case VKEY_RWIN: + return XK_Super_R; + + case VKEY_NUMLOCK: + return XK_Num_Lock; + + case VKEY_SCROLL: + return XK_Scroll_Lock; + + case VKEY_OEM_1: + return shift ? XK_colon : XK_semicolon; + case VKEY_OEM_PLUS: + return shift ? XK_plus : XK_equal; + case VKEY_OEM_COMMA: + return shift ? XK_less : XK_comma; + case VKEY_OEM_MINUS: + return shift ? XK_underscore : XK_minus; + case VKEY_OEM_PERIOD: + return shift ? XK_greater : XK_period; + case VKEY_OEM_2: + return shift ? XK_question : XK_slash; + case VKEY_OEM_3: + return shift ? XK_asciitilde : XK_quoteleft; + case VKEY_OEM_4: + return shift ? XK_braceleft : XK_bracketleft; + case VKEY_OEM_5: + return shift ? XK_bar : XK_backslash; + case VKEY_OEM_6: + return shift ? XK_braceright : XK_bracketright; + case VKEY_OEM_7: + return shift ? XK_quotedbl : XK_quoteright; + case VKEY_OEM_8: + return XK_ISO_Level5_Shift; + case VKEY_OEM_102: + return shift ? XK_guillemotleft : XK_guillemotright; + + case VKEY_F1: + case VKEY_F2: + case VKEY_F3: + case VKEY_F4: + case VKEY_F5: + case VKEY_F6: + case VKEY_F7: + case VKEY_F8: + case VKEY_F9: + case VKEY_F10: + case VKEY_F11: + case VKEY_F12: + case VKEY_F13: + case VKEY_F14: + case VKEY_F15: + case VKEY_F16: + case VKEY_F17: + case VKEY_F18: + case VKEY_F19: + case VKEY_F20: + case VKEY_F21: + case VKEY_F22: + case VKEY_F23: + case VKEY_F24: + return XK_F1 + (keycode - VKEY_F1); + + case VKEY_BROWSER_BACK: + return XF86XK_Back; + case VKEY_BROWSER_FORWARD: + return XF86XK_Forward; + case VKEY_BROWSER_REFRESH: + return XF86XK_Reload; + case VKEY_BROWSER_STOP: + return XF86XK_Stop; + case VKEY_BROWSER_SEARCH: + return XF86XK_Search; + case VKEY_BROWSER_FAVORITES: + return XF86XK_Favorites; + case VKEY_BROWSER_HOME: + return XF86XK_HomePage; + case VKEY_VOLUME_MUTE: + return XF86XK_AudioMute; + case VKEY_VOLUME_DOWN: + return XF86XK_AudioLowerVolume; + case VKEY_VOLUME_UP: + return XF86XK_AudioRaiseVolume; + case VKEY_MEDIA_NEXT_TRACK: + return XF86XK_AudioNext; + case VKEY_MEDIA_PREV_TRACK: + return XF86XK_AudioPrev; + case VKEY_MEDIA_STOP: + return XF86XK_AudioStop; + case VKEY_MEDIA_PLAY_PAUSE: + return XF86XK_AudioPlay; + case VKEY_MEDIA_LAUNCH_MAIL: + return XF86XK_Mail; + case VKEY_MEDIA_LAUNCH_APP1: + return XF86XK_LaunchA; + case VKEY_MEDIA_LAUNCH_APP2: + return XF86XK_LaunchB; + case VKEY_WLAN: + return XF86XK_WLAN; + case VKEY_POWER: + return XF86XK_PowerOff; + case VKEY_BRIGHTNESS_DOWN: + return XF86XK_MonBrightnessDown; + case VKEY_BRIGHTNESS_UP: + return XF86XK_MonBrightnessUp; + case VKEY_KBD_BRIGHTNESS_DOWN: + return XF86XK_KbdBrightnessDown; + case VKEY_KBD_BRIGHTNESS_UP: + return XF86XK_KbdBrightnessUp; + + default: + LOG(WARNING) << "Unknown keycode:" << keycode; + return 0; + } +} + +} // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_x.h b/ui/events/keycodes/keyboard_code_conversion_x.h new file mode 100644 index 0000000..8fd1e84 --- /dev/null +++ b/ui/events/keycodes/keyboard_code_conversion_x.h @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_X_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_X_H_ + +#include "base/basictypes.h" +#include "ui/base/ui_export.h" +#include "ui/events/keycodes/keyboard_codes_posix.h" + +typedef union _XEvent XEvent; + +namespace ui { + +UI_EXPORT KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev); + +UI_EXPORT KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym); + +// Returns a character on a standard US PC keyboard from an XEvent. +UI_EXPORT uint16 GetCharacterFromXEvent(XEvent* xev); + +// Converts a KeyboardCode into an X KeySym. +UI_EXPORT int XKeysymForWindowsKeyCode(KeyboardCode keycode, bool shift); + +// Converts an X keycode into an X KeySym. +unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int keycode); + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_X_H_ diff --git a/ui/events/keycodes/keyboard_codes.h b/ui/events/keycodes/keyboard_codes.h new file mode 100644 index 0000000..00a7847 --- /dev/null +++ b/ui/events/keycodes/keyboard_codes.h @@ -0,0 +1,16 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODES_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODES_H_ + +#include "build/build_config.h" + +#if defined(OS_WIN) +#include "ui/events/keycodes/keyboard_codes_win.h" +#elif defined(OS_POSIX) +#include "ui/events/keycodes/keyboard_codes_posix.h" +#endif + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODES_H_ diff --git a/ui/events/keycodes/keyboard_codes_posix.h b/ui/events/keycodes/keyboard_codes_posix.h new file mode 100644 index 0000000..1f7e06f --- /dev/null +++ b/ui/events/keycodes/keyboard_codes_posix.h @@ -0,0 +1,228 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/* + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com. All rights reserved. + * Copyright (C) 2008, 2009 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR + * PROFITS, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODES_POSIX_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODES_POSIX_H_ + +namespace ui { + +enum KeyboardCode { + VKEY_BACK = 0x08, + VKEY_TAB = 0x09, + VKEY_BACKTAB = 0x0A, + VKEY_CLEAR = 0x0C, + VKEY_RETURN = 0x0D, + VKEY_SHIFT = 0x10, + VKEY_CONTROL = 0x11, + VKEY_MENU = 0x12, + VKEY_PAUSE = 0x13, + VKEY_CAPITAL = 0x14, + VKEY_KANA = 0x15, + VKEY_HANGUL = 0x15, + VKEY_JUNJA = 0x17, + VKEY_FINAL = 0x18, + VKEY_HANJA = 0x19, + VKEY_KANJI = 0x19, + VKEY_ESCAPE = 0x1B, + VKEY_CONVERT = 0x1C, + VKEY_NONCONVERT = 0x1D, + VKEY_ACCEPT = 0x1E, + VKEY_MODECHANGE = 0x1F, + VKEY_SPACE = 0x20, + VKEY_PRIOR = 0x21, + VKEY_NEXT = 0x22, + VKEY_END = 0x23, + VKEY_HOME = 0x24, + VKEY_LEFT = 0x25, + VKEY_UP = 0x26, + VKEY_RIGHT = 0x27, + VKEY_DOWN = 0x28, + VKEY_SELECT = 0x29, + VKEY_PRINT = 0x2A, + VKEY_EXECUTE = 0x2B, + VKEY_SNAPSHOT = 0x2C, + VKEY_INSERT = 0x2D, + VKEY_DELETE = 0x2E, + VKEY_HELP = 0x2F, + VKEY_0 = 0x30, + VKEY_1 = 0x31, + VKEY_2 = 0x32, + VKEY_3 = 0x33, + VKEY_4 = 0x34, + VKEY_5 = 0x35, + VKEY_6 = 0x36, + VKEY_7 = 0x37, + VKEY_8 = 0x38, + VKEY_9 = 0x39, + VKEY_A = 0x41, + VKEY_B = 0x42, + VKEY_C = 0x43, + VKEY_D = 0x44, + VKEY_E = 0x45, + VKEY_F = 0x46, + VKEY_G = 0x47, + VKEY_H = 0x48, + VKEY_I = 0x49, + VKEY_J = 0x4A, + VKEY_K = 0x4B, + VKEY_L = 0x4C, + VKEY_M = 0x4D, + VKEY_N = 0x4E, + VKEY_O = 0x4F, + VKEY_P = 0x50, + VKEY_Q = 0x51, + VKEY_R = 0x52, + VKEY_S = 0x53, + VKEY_T = 0x54, + VKEY_U = 0x55, + VKEY_V = 0x56, + VKEY_W = 0x57, + VKEY_X = 0x58, + VKEY_Y = 0x59, + VKEY_Z = 0x5A, + VKEY_LWIN = 0x5B, + VKEY_COMMAND = VKEY_LWIN, // Provide the Mac name for convenience. + VKEY_RWIN = 0x5C, + VKEY_APPS = 0x5D, + VKEY_SLEEP = 0x5F, + VKEY_NUMPAD0 = 0x60, + VKEY_NUMPAD1 = 0x61, + VKEY_NUMPAD2 = 0x62, + VKEY_NUMPAD3 = 0x63, + VKEY_NUMPAD4 = 0x64, + VKEY_NUMPAD5 = 0x65, + VKEY_NUMPAD6 = 0x66, + VKEY_NUMPAD7 = 0x67, + VKEY_NUMPAD8 = 0x68, + VKEY_NUMPAD9 = 0x69, + VKEY_MULTIPLY = 0x6A, + VKEY_ADD = 0x6B, + VKEY_SEPARATOR = 0x6C, + VKEY_SUBTRACT = 0x6D, + VKEY_DECIMAL = 0x6E, + VKEY_DIVIDE = 0x6F, + VKEY_F1 = 0x70, + VKEY_F2 = 0x71, + VKEY_F3 = 0x72, + VKEY_F4 = 0x73, + VKEY_F5 = 0x74, + VKEY_F6 = 0x75, + VKEY_F7 = 0x76, + VKEY_F8 = 0x77, + VKEY_F9 = 0x78, + VKEY_F10 = 0x79, + VKEY_F11 = 0x7A, + VKEY_F12 = 0x7B, + VKEY_F13 = 0x7C, + VKEY_F14 = 0x7D, + VKEY_F15 = 0x7E, + VKEY_F16 = 0x7F, + VKEY_F17 = 0x80, + VKEY_F18 = 0x81, + VKEY_F19 = 0x82, + VKEY_F20 = 0x83, + VKEY_F21 = 0x84, + VKEY_F22 = 0x85, + VKEY_F23 = 0x86, + VKEY_F24 = 0x87, + VKEY_NUMLOCK = 0x90, + VKEY_SCROLL = 0x91, + VKEY_LSHIFT = 0xA0, + VKEY_RSHIFT = 0xA1, + VKEY_LCONTROL = 0xA2, + VKEY_RCONTROL = 0xA3, + VKEY_LMENU = 0xA4, + VKEY_RMENU = 0xA5, + VKEY_BROWSER_BACK = 0xA6, + VKEY_BROWSER_FORWARD = 0xA7, + VKEY_BROWSER_REFRESH = 0xA8, + VKEY_BROWSER_STOP = 0xA9, + VKEY_BROWSER_SEARCH = 0xAA, + VKEY_BROWSER_FAVORITES = 0xAB, + VKEY_BROWSER_HOME = 0xAC, + VKEY_VOLUME_MUTE = 0xAD, + VKEY_VOLUME_DOWN = 0xAE, + VKEY_VOLUME_UP = 0xAF, + VKEY_MEDIA_NEXT_TRACK = 0xB0, + VKEY_MEDIA_PREV_TRACK = 0xB1, + VKEY_MEDIA_STOP = 0xB2, + VKEY_MEDIA_PLAY_PAUSE = 0xB3, + VKEY_MEDIA_LAUNCH_MAIL = 0xB4, + VKEY_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5, + VKEY_MEDIA_LAUNCH_APP1 = 0xB6, + VKEY_MEDIA_LAUNCH_APP2 = 0xB7, + VKEY_OEM_1 = 0xBA, + VKEY_OEM_PLUS = 0xBB, + VKEY_OEM_COMMA = 0xBC, + VKEY_OEM_MINUS = 0xBD, + VKEY_OEM_PERIOD = 0xBE, + VKEY_OEM_2 = 0xBF, + VKEY_OEM_3 = 0xC0, + VKEY_OEM_4 = 0xDB, + VKEY_OEM_5 = 0xDC, + VKEY_OEM_6 = 0xDD, + VKEY_OEM_7 = 0xDE, + VKEY_OEM_8 = 0xDF, + VKEY_OEM_102 = 0xE2, + VKEY_OEM_103 = 0xE3, // GTV KEYCODE_MEDIA_REWIND + VKEY_OEM_104 = 0xE4, // GTV KEYCODE_MEDIA_FAST_FORWARD + VKEY_PROCESSKEY = 0xE5, + VKEY_PACKET = 0xE7, + VKEY_DBE_SBCSCHAR = 0xF3, + VKEY_DBE_DBCSCHAR = 0xF4, + VKEY_ATTN = 0xF6, + VKEY_CRSEL = 0xF7, + VKEY_EXSEL = 0xF8, + VKEY_EREOF = 0xF9, + VKEY_PLAY = 0xFA, + VKEY_ZOOM = 0xFB, + VKEY_NONAME = 0xFC, + VKEY_PA1 = 0xFD, + VKEY_OEM_CLEAR = 0xFE, + VKEY_UNKNOWN = 0, + + // POSIX specific VKEYs. Note that as of Windows SDK 7.1, 0x97-9F, 0xD8-DA, + // and 0xE8 are unassigned. + VKEY_WLAN = 0x97, + VKEY_POWER = 0x98, + VKEY_BRIGHTNESS_DOWN = 0xD8, + VKEY_BRIGHTNESS_UP = 0xD9, + VKEY_KBD_BRIGHTNESS_DOWN = 0xDA, + VKEY_KBD_BRIGHTNESS_UP = 0xE8, + + // Windows does not have a specific key code for AltGr. We use the unused 0xE1 + // (VK_OEM_AX) code to represent AltGr, matching the behaviour of Firefox on + // Linux. + VKEY_ALTGR = 0xE1, +}; + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODES_POSIX_H_ diff --git a/ui/events/keycodes/keyboard_codes_win.h b/ui/events/keycodes/keyboard_codes_win.h new file mode 100644 index 0000000..396d38b --- /dev/null +++ b/ui/events/keycodes/keyboard_codes_win.h @@ -0,0 +1,192 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODES_WIN_H_ +#define UI_EVENTS_KEYCODES_KEYBOARD_CODES_WIN_H_ + +#include <windows.h> +#include <ime.h> + +namespace ui { + +enum KeyboardCode { + VKEY_BACK = VK_BACK, + VKEY_TAB = VK_TAB, + VKEY_CLEAR = VK_CLEAR, + VKEY_RETURN = VK_RETURN, + VKEY_SHIFT = VK_SHIFT, + VKEY_CONTROL = VK_CONTROL, + VKEY_MENU = VK_MENU, // a.k.a. ALT + VKEY_PAUSE = VK_PAUSE, + VKEY_CAPITAL = VK_CAPITAL, + VKEY_KANA = VK_KANA, + VKEY_HANGUL = VK_HANGUL, + VKEY_JUNJA = VK_JUNJA, + VKEY_FINAL = VK_FINAL, + VKEY_HANJA = VK_HANJA, + VKEY_KANJI = VK_KANJI, + VKEY_ESCAPE = VK_ESCAPE, + VKEY_CONVERT = VK_CONVERT, + VKEY_NONCONVERT = VK_NONCONVERT, + VKEY_ACCEPT = VK_ACCEPT, + VKEY_MODECHANGE = VK_MODECHANGE, + VKEY_SPACE = VK_SPACE, + VKEY_PRIOR = VK_PRIOR, + VKEY_NEXT = VK_NEXT, + VKEY_END = VK_END, + VKEY_HOME = VK_HOME, + VKEY_LEFT = VK_LEFT, + VKEY_UP = VK_UP, + VKEY_RIGHT = VK_RIGHT, + VKEY_DOWN = VK_DOWN, + VKEY_SELECT = VK_SELECT, + VKEY_PRINT = VK_PRINT, + VKEY_EXECUTE = VK_EXECUTE, + VKEY_SNAPSHOT = VK_SNAPSHOT, + VKEY_INSERT = VK_INSERT, + VKEY_DELETE = VK_DELETE, + VKEY_HELP = VK_HELP, + VKEY_0 = '0', + VKEY_1 = '1', + VKEY_2 = '2', + VKEY_3 = '3', + VKEY_4 = '4', + VKEY_5 = '5', + VKEY_6 = '6', + VKEY_7 = '7', + VKEY_8 = '8', + VKEY_9 = '9', + VKEY_A = 'A', + VKEY_B = 'B', + VKEY_C = 'C', + VKEY_D = 'D', + VKEY_E = 'E', + VKEY_F = 'F', + VKEY_G = 'G', + VKEY_H = 'H', + VKEY_I = 'I', + VKEY_J = 'J', + VKEY_K = 'K', + VKEY_L = 'L', + VKEY_M = 'M', + VKEY_N = 'N', + VKEY_O = 'O', + VKEY_P = 'P', + VKEY_Q = 'Q', + VKEY_R = 'R', + VKEY_S = 'S', + VKEY_T = 'T', + VKEY_U = 'U', + VKEY_V = 'V', + VKEY_W = 'W', + VKEY_X = 'X', + VKEY_Y = 'Y', + VKEY_Z = 'Z', + VKEY_LWIN = VK_LWIN, + VKEY_COMMAND = VKEY_LWIN, // Provide the Mac name for convenience. + VKEY_RWIN = VK_RWIN, + VKEY_APPS = VK_APPS, + VKEY_SLEEP = VK_SLEEP, + VKEY_NUMPAD0 = VK_NUMPAD0, + VKEY_NUMPAD1 = VK_NUMPAD1, + VKEY_NUMPAD2 = VK_NUMPAD2, + VKEY_NUMPAD3 = VK_NUMPAD3, + VKEY_NUMPAD4 = VK_NUMPAD4, + VKEY_NUMPAD5 = VK_NUMPAD5, + VKEY_NUMPAD6 = VK_NUMPAD6, + VKEY_NUMPAD7 = VK_NUMPAD7, + VKEY_NUMPAD8 = VK_NUMPAD8, + VKEY_NUMPAD9 = VK_NUMPAD9, + VKEY_MULTIPLY = VK_MULTIPLY, + VKEY_ADD = VK_ADD, + VKEY_SEPARATOR = VK_SEPARATOR, + VKEY_SUBTRACT = VK_SUBTRACT, + VKEY_DECIMAL = VK_DECIMAL, + VKEY_DIVIDE = VK_DIVIDE, + VKEY_F1 = VK_F1, + VKEY_F2 = VK_F2, + VKEY_F3 = VK_F3, + VKEY_F4 = VK_F4, + VKEY_F5 = VK_F5, + VKEY_F6 = VK_F6, + VKEY_F7 = VK_F7, + VKEY_F8 = VK_F8, + VKEY_F9 = VK_F9, + VKEY_F10 = VK_F10, + VKEY_F11 = VK_F11, + VKEY_F12 = VK_F12, + VKEY_F13 = VK_F13, + VKEY_F14 = VK_F14, + VKEY_F15 = VK_F15, + VKEY_F16 = VK_F16, + VKEY_F17 = VK_F17, + VKEY_F18 = VK_F18, + VKEY_F19 = VK_F19, + VKEY_F20 = VK_F20, + VKEY_F21 = VK_F21, + VKEY_F22 = VK_F22, + VKEY_F23 = VK_F23, + VKEY_F24 = VK_F24, + VKEY_NUMLOCK = VK_NUMLOCK, + VKEY_SCROLL = VK_SCROLL, + VKEY_LSHIFT = VK_LSHIFT, + VKEY_RSHIFT = VK_RSHIFT, + VKEY_LCONTROL = VK_LCONTROL, + VKEY_RCONTROL = VK_RCONTROL, + VKEY_LMENU = VK_LMENU, + VKEY_RMENU = VK_RMENU, + VKEY_BROWSER_BACK = VK_BROWSER_BACK, + VKEY_BROWSER_FORWARD = VK_BROWSER_FORWARD, + VKEY_BROWSER_REFRESH = VK_BROWSER_REFRESH, + VKEY_BROWSER_STOP = VK_BROWSER_STOP, + VKEY_BROWSER_SEARCH = VK_BROWSER_SEARCH, + VKEY_BROWSER_FAVORITES = VK_BROWSER_FAVORITES, + VKEY_BROWSER_HOME = VK_BROWSER_HOME, + VKEY_VOLUME_MUTE = VK_VOLUME_MUTE, + VKEY_VOLUME_DOWN = VK_VOLUME_DOWN, + VKEY_VOLUME_UP = VK_VOLUME_UP, + VKEY_MEDIA_NEXT_TRACK = VK_MEDIA_NEXT_TRACK, + VKEY_MEDIA_PREV_TRACK = VK_MEDIA_PREV_TRACK, + VKEY_MEDIA_STOP = VK_MEDIA_STOP, + VKEY_MEDIA_PLAY_PAUSE = VK_MEDIA_PLAY_PAUSE, + VKEY_MEDIA_LAUNCH_MAIL = 0xB4, + VKEY_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5, + VKEY_MEDIA_LAUNCH_APP1 = 0xB6, + VKEY_MEDIA_LAUNCH_APP2 = 0xB7, + VKEY_OEM_1 = VK_OEM_1, + VKEY_OEM_PLUS = VK_OEM_PLUS, + VKEY_OEM_COMMA = VK_OEM_COMMA, + VKEY_OEM_MINUS = VK_OEM_MINUS, + VKEY_OEM_PERIOD = VK_OEM_PERIOD, + VKEY_OEM_2 = VK_OEM_2, + VKEY_OEM_3 = VK_OEM_3, + VKEY_OEM_4 = VK_OEM_4, + VKEY_OEM_5 = VK_OEM_5, + VKEY_OEM_6 = VK_OEM_6, + VKEY_OEM_7 = VK_OEM_7, + VKEY_OEM_8 = VK_OEM_8, + VKEY_OEM_102 = VK_OEM_102, + VKEY_PROCESSKEY = VK_PROCESSKEY, + VKEY_PACKET = VK_PACKET, + VKEY_DBE_SBCSCHAR = VK_DBE_SBCSCHAR, + VKEY_DBE_DBCSCHAR = VK_DBE_DBCSCHAR, + VKEY_ATTN = VK_ATTN, + VKEY_CRSEL = VK_CRSEL, + VKEY_EXSEL = VK_EXSEL, + VKEY_EREOF = VK_EREOF, + VKEY_PLAY = VK_PLAY, + VKEY_ZOOM = VK_ZOOM, + VKEY_NONAME = VK_NONAME, + VKEY_PA1 = VK_PA1, + VKEY_OEM_CLEAR = VK_OEM_CLEAR, + VKEY_UNKNOWN = 0, + + // Windows does not have a specific key code for AltGr. We use the unused + // VK_OEM_AX to represent AltGr, matching the behaviour of Firefox on Linux. + VKEY_ALTGR = VK_OEM_AX, +}; + +} // namespace ui + +#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODES_WIN_H_ |