Index: ui/events/keycodes/keyboard_code_conversion.cc |
diff --git a/ui/events/keycodes/keyboard_code_conversion.cc b/ui/events/keycodes/keyboard_code_conversion.cc |
index b71dd6f0b94bd8600a55d596e574e0442e4f0c37..b87c1f2c1e8a6062b3df4969eb785f007a9f3c57 100644 |
--- a/ui/events/keycodes/keyboard_code_conversion.cc |
+++ b/ui/events/keycodes/keyboard_code_conversion.cc |
@@ -4,6 +4,8 @@ |
#include "ui/events/keycodes/keyboard_code_conversion.h" |
+#include <algorithm> |
+ |
#include "ui/events/event_constants.h" |
#include "ui/events/keycodes/dom3/dom_code.h" |
#include "ui/events/keycodes/dom3/dom_key.h" |
@@ -12,117 +14,576 @@ namespace ui { |
namespace { |
-// This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character. |
-// Only values not otherwise handled by GetMeaningFromKeyCode() are here. |
-const struct KeyboardCodeToMeaning { |
+// This table maps a DomCode to a printable character, assuming US layout. |
+// All of the characters have low ordinals, so we use bit 15 to flag dead keys. |
+const base::char16 kDeadKeyFlag = 0x8000; |
+const struct PrintableCodeEntry { |
+ DomCode dom_code; |
+ base::char16 character[4]; // normal, shift, altgr, shiftaltgr |
+} kPrintableCodeMap[] = { |
+ {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}}, |
+ {DomCode::KEY_B, {'b', 'B', 'b', 'B'}}, |
+ {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}}, |
+ {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}}, |
+ {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}}, |
+ {DomCode::KEY_F, {'f', 'F', 'f', 'F'}}, |
+ {DomCode::KEY_G, {'g', 'G', 'g', 'G'}}, |
+ {DomCode::KEY_H, {'h', 'H', 'h', 'H'}}, |
+ {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}}, |
+ {DomCode::KEY_J, {'j', 'J', 'j', 'J'}}, |
+ {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}}, |
+ {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}}, |
+ {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}}, |
+ {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}}, |
+ {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}}, |
+ {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}}, |
+ {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}}, |
+ {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}}, |
+ {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}}, |
+ {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}}, |
+ {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}}, |
+ {DomCode::KEY_V, {'v', 'V', 'v', 'V'}}, |
+ {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}}, |
+ {DomCode::KEY_X, {'x', 'X', 'x', 'X'}}, |
+ {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}}, |
+ {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}}, |
+ {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}}, |
+ {DomCode::DIGIT2, {'2', '@', 0x00B2, kDeadKeyFlag | 0x030B}}, |
+ {DomCode::DIGIT3, {'3', '#', 0x00B3, kDeadKeyFlag | 0x0304}}, |
+ {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}}, |
+ {DomCode::DIGIT5, {'5', '%', 0x20AC, kDeadKeyFlag | 0x0327}}, |
+ {DomCode::DIGIT6, {'6', '^', kDeadKeyFlag | 0x0302, 0x00BC}}, |
+ {DomCode::DIGIT7, {'7', '&', 0x00BD, kDeadKeyFlag | 0x031B}}, |
+ {DomCode::DIGIT8, {'8', '*', 0x00BE, kDeadKeyFlag | 0x0328}}, |
+ {DomCode::DIGIT9, {'9', '(', 0x2018, kDeadKeyFlag | 0x0306}}, |
+ {DomCode::DIGIT0, {'0', ')', 0x2019, kDeadKeyFlag | 0x030A}}, |
+ {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}}, |
+ {DomCode::MINUS, {'-', '_', 0x00A5, kDeadKeyFlag | 0x0323}}, |
+ {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}}, |
+ {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}}, |
+ {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}}, |
+ {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}}, |
+ {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}}, |
+ {DomCode::QUOTE, |
+ {'\'', '"', kDeadKeyFlag | 0x0301, kDeadKeyFlag | 0x0308}}, |
+ {DomCode::BACKQUOTE, |
+ {'`', '~', kDeadKeyFlag | 0x0300, kDeadKeyFlag | 0x0303}}, |
+ {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}}, |
+ {DomCode::PERIOD,{'.', '>', kDeadKeyFlag | 0x0307, kDeadKeyFlag | 0x030C}}, |
+ {DomCode::SLASH, {'/', '?', 0x00BF, kDeadKeyFlag | 0x0309}}, |
+ {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}}, |
+ {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}}, |
+ {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}}, |
+ {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}}, |
+ {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}}, |
+ {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}}, |
+ {DomCode::NUMPAD1, {'1', '1', '1', '1'}}, |
+ {DomCode::NUMPAD2, {'2', '2', '2', '2'}}, |
+ {DomCode::NUMPAD3, {'3', '3', '3', '3'}}, |
+ {DomCode::NUMPAD4, {'4', '4', '4', '4'}}, |
+ {DomCode::NUMPAD5, {'5', '5', '5', '5'}}, |
+ {DomCode::NUMPAD6, {'6', '6', '6', '6'}}, |
+ {DomCode::NUMPAD7, {'7', '7', '7', '7'}}, |
+ {DomCode::NUMPAD8, {'8', '8', '8', '8'}}, |
+ {DomCode::NUMPAD9, {'9', '9', '9', '9'}}, |
+ {DomCode::NUMPAD0, {'0', '0', '0', '0'}}, |
+ {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}}, |
+ {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}}, |
+ {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}}, |
+ {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}}, |
+ {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}}, |
+ {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}}, |
+}; |
+ |
+// This table maps a DomCode to a DomKey, assuming US keyboard layout. |
+const struct NonPrintableCodeEntry { |
+ DomCode dom_code; |
+ DomKey dom_key; |
+ base::char16 character; |
+} kNonPrintableCodeMap[] = { |
+ {DomCode::ABORT, DomKey::CANCEL}, |
+ {DomCode::AGAIN, DomKey::AGAIN}, |
+ {DomCode::ALT_LEFT, DomKey::ALT}, |
+ {DomCode::ALT_RIGHT, DomKey::ALT}, |
+ {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN}, |
+ {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT}, |
+ {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT}, |
+ {DomCode::ARROW_UP, DomKey::ARROW_UP}, |
+ {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008}, |
+ {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN}, |
+ {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP}, |
+ // {DomCode::BRIGHTNESS_AUTO, DomKey::_} |
+ // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_} |
+ // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_} |
+ // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_} |
+ {DomCode::BROWSER_BACK, DomKey::BROWSER_BACK}, |
+ {DomCode::BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES}, |
+ {DomCode::BROWSER_FORWARD, DomKey::BROWSER_FORWARD}, |
+ {DomCode::BROWSER_HOME, DomKey::BROWSER_HOME}, |
+ {DomCode::BROWSER_REFRESH, DomKey::BROWSER_REFRESH}, |
+ {DomCode::BROWSER_SEARCH, DomKey::BROWSER_SEARCH}, |
+ {DomCode::BROWSER_STOP, DomKey::BROWSER_STOP}, |
+ {DomCode::CAPS_LOCK, DomKey::CAPS_LOCK}, |
+ {DomCode::CONTEXT_MENU, DomKey::CONTEXT_MENU}, |
+ {DomCode::CONTROL_LEFT, DomKey::CONTROL}, |
+ {DomCode::CONTROL_RIGHT, DomKey::CONTROL}, |
+ {DomCode::CONVERT, DomKey::CONVERT}, |
+ {DomCode::COPY, DomKey::COPY}, |
+ {DomCode::CUT, DomKey::CUT}, |
+ {DomCode::DEL, DomKey::DEL, 0x007F}, |
+ {DomCode::EJECT, DomKey::EJECT}, |
+ {DomCode::END, DomKey::END}, |
+ {DomCode::ENTER, DomKey::ENTER, 0x000D}, |
+ {DomCode::ESCAPE, DomKey::ESCAPE, 0x001B}, |
+ {DomCode::F1, DomKey::F1}, |
+ {DomCode::F2, DomKey::F2}, |
+ {DomCode::F3, DomKey::F3}, |
+ {DomCode::F4, DomKey::F4}, |
+ {DomCode::F5, DomKey::F5}, |
+ {DomCode::F6, DomKey::F6}, |
+ {DomCode::F7, DomKey::F7}, |
+ {DomCode::F8, DomKey::F8}, |
+ {DomCode::F9, DomKey::F9}, |
+ {DomCode::F10, DomKey::F10}, |
+ {DomCode::F11, DomKey::F11}, |
+ {DomCode::F12, DomKey::F12}, |
+ {DomCode::F13, DomKey::F13}, |
+ {DomCode::F14, DomKey::F14}, |
+ {DomCode::F15, DomKey::F15}, |
+ {DomCode::F16, DomKey::F16}, |
+ {DomCode::F17, DomKey::F17}, |
+ {DomCode::F18, DomKey::F18}, |
+ {DomCode::F19, DomKey::F19}, |
+ {DomCode::F20, DomKey::F20}, |
+ {DomCode::F21, DomKey::F21}, |
+ {DomCode::F22, DomKey::F22}, |
+ {DomCode::F23, DomKey::F23}, |
+ {DomCode::F24, DomKey::F24}, |
+ {DomCode::FIND, DomKey::FIND}, |
+ {DomCode::FN, DomKey::FN}, |
+ {DomCode::FN_LOCK, DomKey::FN_LOCK}, |
+ {DomCode::HELP, DomKey::HELP}, |
+ {DomCode::HOME, DomKey::HOME}, |
+ {DomCode::HYPER, DomKey::HYPER}, |
+ {DomCode::INSERT, DomKey::INSERT}, |
+ // {DomCode::INTL_RO, DomKey::_} |
+ {DomCode::KANA_MODE, DomKey::KANA_MODE}, |
+ {DomCode::LANG1, DomKey::HANGUL_MODE}, |
+ {DomCode::LANG2, DomKey::HANJA_MODE}, |
+ {DomCode::LANG3, DomKey::KATAKANA}, |
+ {DomCode::LANG4, DomKey::HIRAGANA}, |
+ {DomCode::LANG5, DomKey::ZENKAKU_HANKAKU}, |
+ {DomCode::LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, |
+ {DomCode::LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, |
+ {DomCode::LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, |
+ {DomCode::LAUNCH_SCREEN_SAVER, DomKey::LAUNCH_SCREEN_SAVER}, |
+ // {DomCode::LAUNCH_DOCUMENTS, DomKey::_} |
+ // {DomCode::LAUNCH_FILE_BROWSER, DomKey::_} |
+ // {DomCode::LAUNCH_KEYBOARD_LAYOUT, DomKey::_} |
+ {DomCode::LOCK_SCREEN, DomKey::LAUNCH_SCREEN_SAVER}, |
+ {DomCode::MAIL_FORWARD, DomKey::MAIL_FORWARD}, |
+ {DomCode::MAIL_REPLY, DomKey::MAIL_REPLY}, |
+ {DomCode::MAIL_SEND, DomKey::MAIL_SEND}, |
+ {DomCode::MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, |
+ {DomCode::MEDIA_SELECT, DomKey::MEDIA_SELECT}, |
+ {DomCode::MEDIA_STOP, DomKey::MEDIA_STOP}, |
+ {DomCode::MEDIA_TRACK_NEXT, DomKey::MEDIA_TRACK_NEXT}, |
+ {DomCode::MEDIA_TRACK_PREVIOUS, DomKey::MEDIA_TRACK_PREVIOUS}, |
+ // {DomCode::MENU, DomKey::_} |
+ {DomCode::NON_CONVERT, DomKey::NON_CONVERT}, |
+ {DomCode::NUM_LOCK, DomKey::NUM_LOCK}, |
+ {DomCode::NUMPAD_BACKSPACE, DomKey::BACKSPACE, 0x0008}, |
+ {DomCode::NUMPAD_CLEAR, DomKey::CLEAR}, |
+ {DomCode::NUMPAD_ENTER, DomKey::ENTER, 0x000D}, |
+ // {DomCode::NUMPAD_CLEAR_ENTRY, DomKey::_} |
+ // {DomCode::NUMPAD_MEMORY_ADD, DomKey::_} |
+ // {DomCode::NUMPAD_MEMORY_CLEAR, DomKey::_} |
+ // {DomCode::NUMPAD_MEMORY_RECALL, DomKey::_} |
+ // {DomCode::NUMPAD_MEMORY_STORE, DomKey::_} |
+ // {DomCode::NUMPAD_MEMORY_SUBTRACT, DomKey::_} |
+ {DomCode::OPEN, DomKey::OPEN}, |
+ {DomCode::OS_LEFT, DomKey::OS}, |
+ {DomCode::OS_RIGHT, DomKey::OS}, |
+ {DomCode::PAGE_DOWN, DomKey::PAGE_DOWN}, |
+ {DomCode::PAGE_UP, DomKey::PAGE_UP}, |
+ {DomCode::PASTE, DomKey::PASTE}, |
+ {DomCode::PAUSE, DomKey::PAUSE}, |
+ {DomCode::POWER, DomKey::POWER}, |
+ {DomCode::PRINT_SCREEN, DomKey::PRINT_SCREEN}, |
+ {DomCode::PROPS, DomKey::PROPS}, |
+ {DomCode::SCROLL_LOCK, DomKey::SCROLL_LOCK}, |
+ {DomCode::SELECT, DomKey::SELECT}, |
+ // {DomCode::SELECT_TASK, DomKey::_} |
+ {DomCode::SHIFT_LEFT, DomKey::SHIFT}, |
+ {DomCode::SHIFT_RIGHT, DomKey::SHIFT}, |
+ {DomCode::SUPER, DomKey::SUPER}, |
+ {DomCode::TAB, DomKey::TAB, 0x0009}, |
+ {DomCode::UNDO, DomKey::UNDO}, |
+ // {DomCode::VOICE_COMMAND, DomKey::_} |
+ {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN}, |
+ {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE}, |
+ {DomCode::VOLUME_UP, DomKey::VOLUME_UP}, |
+ {DomCode::WAKE_UP, DomKey::WAKE_UP}, |
+ {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE}, |
+}; |
+ |
+// This table maps a DomKey to a non-located KeyboardCode. |
+const struct DomKeyToKeyboardCodeEntry { |
+ DomKey dom_key; |
KeyboardCode key_code; |
- DomKey key; |
- base::char16 plain_character; |
- base::char16 shift_character; |
-} kKeyboardCodeToMeaning[] = { |
- {VKEY_BACK, DomKey::BACKSPACE, '\b', 0}, |
- {VKEY_TAB, DomKey::TAB, '\t', 0}, |
- {VKEY_RETURN, DomKey::ENTER, '\r', 0}, |
- {VKEY_ESCAPE, DomKey::ESCAPE, 0x1B, 0}, |
- {VKEY_SPACE, DomKey::CHARACTER, ' ', 0}, |
- {VKEY_MULTIPLY, DomKey::CHARACTER, '*', 0}, |
- {VKEY_ADD, DomKey::CHARACTER, '+', 0}, |
- {VKEY_SEPARATOR, DomKey::CHARACTER, ',', 0}, |
- {VKEY_SUBTRACT, DomKey::CHARACTER, '-', 0}, |
- {VKEY_DECIMAL, DomKey::CHARACTER, '.', 0}, |
- {VKEY_DIVIDE, DomKey::CHARACTER, '/', 0}, |
- {VKEY_OEM_1, DomKey::CHARACTER, ';', ':'}, |
- {VKEY_OEM_PLUS, DomKey::CHARACTER, '=', '+'}, |
- {VKEY_OEM_COMMA, DomKey::CHARACTER, ',', '<'}, |
- {VKEY_OEM_MINUS, DomKey::CHARACTER, '-', '_'}, |
- {VKEY_OEM_PERIOD, DomKey::CHARACTER, '.', '>'}, |
- {VKEY_OEM_2, DomKey::CHARACTER, '/', '?'}, |
- {VKEY_OEM_3, DomKey::CHARACTER, '`', '~'}, |
- {VKEY_OEM_4, DomKey::CHARACTER, '[', '{'}, |
- {VKEY_OEM_5, DomKey::CHARACTER, '\\', '|'}, |
- {VKEY_OEM_6, DomKey::CHARACTER, ']', '}'}, |
- {VKEY_OEM_7, DomKey::CHARACTER, '\'', '"'}, |
- {VKEY_OEM_102, DomKey::CHARACTER, '<', '>'}, |
- {VKEY_CLEAR, DomKey::CLEAR, 0, 0}, |
- {VKEY_SHIFT, DomKey::SHIFT, 0, 0}, |
- {VKEY_CONTROL, DomKey::CONTROL, 0, 0}, |
- {VKEY_MENU, DomKey::ALT, 0, 0}, |
- {VKEY_PAUSE, DomKey::PAUSE, 0, 0}, |
- {VKEY_CAPITAL, DomKey::CAPS_LOCK, 0, 0}, |
- // Windows conflates 'KanaMode' and 'HangulMode'. |
- {VKEY_KANA, DomKey::KANA_MODE, 0, 0}, |
- {VKEY_JUNJA, DomKey::JUNJA_MODE, 0, 0}, |
- {VKEY_FINAL, DomKey::FINAL_MODE, 0, 0}, |
- // Windows conflates 'HanjaMode' and 'KanjiMode'. |
- {VKEY_HANJA, DomKey::HANJA_MODE, 0, 0}, |
- {VKEY_CONVERT, DomKey::CONVERT, 0, 0}, |
- {VKEY_NONCONVERT, DomKey::NON_CONVERT, 0, 0}, |
- {VKEY_ACCEPT, DomKey::ACCEPT, 0, 0}, |
- {VKEY_MODECHANGE, DomKey::MODE_CHANGE, 0, 0}, |
- {VKEY_PRIOR, DomKey::PAGE_UP, 0, 0}, |
- {VKEY_NEXT, DomKey::PAGE_DOWN, 0, 0}, |
- {VKEY_END, DomKey::END, 0, 0}, |
- {VKEY_HOME, DomKey::HOME, 0, 0}, |
- {VKEY_LEFT, DomKey::ARROW_LEFT, 0, 0}, |
- {VKEY_UP, DomKey::ARROW_UP, 0, 0}, |
- {VKEY_RIGHT, DomKey::ARROW_RIGHT, 0, 0}, |
- {VKEY_DOWN, DomKey::ARROW_DOWN, 0, 0}, |
- {VKEY_SELECT, DomKey::SELECT, 0, 0}, |
- {VKEY_PRINT, DomKey::PRINT, 0, 0}, |
- {VKEY_EXECUTE, DomKey::EXECUTE, 0, 0}, |
- {VKEY_SNAPSHOT, DomKey::PRINT_SCREEN, 0, 0}, |
- {VKEY_INSERT, DomKey::INSERT, 0, 0}, |
- {VKEY_DELETE, DomKey::DEL, 0, 0}, |
- {VKEY_HELP, DomKey::HELP, 0, 0}, |
- {VKEY_LWIN, DomKey::OS, 0, 0}, |
- {VKEY_RWIN, DomKey::OS, 0, 0}, |
- {VKEY_APPS, DomKey::MEDIA_APPS, 0, 0}, |
- {VKEY_NUMLOCK, DomKey::NUM_LOCK, 0, 0}, |
- {VKEY_SCROLL, DomKey::SCROLL_LOCK, 0, 0}, |
- {VKEY_LSHIFT, DomKey::SHIFT, 0, 0}, |
- {VKEY_RSHIFT, DomKey::SHIFT, 0, 0}, |
- {VKEY_LCONTROL, DomKey::CONTROL, 0, 0}, |
- {VKEY_RCONTROL, DomKey::CONTROL, 0, 0}, |
- {VKEY_LMENU, DomKey::ALT, 0, 0}, |
- {VKEY_RMENU, DomKey::ALT, 0, 0}, |
- {VKEY_BROWSER_BACK, DomKey::BROWSER_BACK, 0, 0}, |
- {VKEY_BROWSER_FORWARD, DomKey::BROWSER_FORWARD, 0, 0}, |
- {VKEY_BROWSER_REFRESH, DomKey::BROWSER_REFRESH, 0, 0}, |
- {VKEY_BROWSER_STOP, DomKey::BROWSER_STOP, 0, 0}, |
- {VKEY_BROWSER_SEARCH, DomKey::BROWSER_SEARCH, 0, 0}, |
- {VKEY_BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES, 0, 0}, |
- {VKEY_BROWSER_HOME, DomKey::BROWSER_HOME, 0, 0}, |
- {VKEY_VOLUME_MUTE, DomKey::VOLUME_MUTE, 0, 0}, |
- {VKEY_VOLUME_DOWN, DomKey::VOLUME_DOWN, 0, 0}, |
- {VKEY_VOLUME_UP, DomKey::VOLUME_UP, 0, 0}, |
- {VKEY_MEDIA_NEXT_TRACK, DomKey::MEDIA_TRACK_NEXT, 0, 0}, |
- {VKEY_MEDIA_PREV_TRACK, DomKey::MEDIA_TRACK_PREVIOUS, 0, 0}, |
- {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP, 0, 0}, |
- {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE, 0, 0}, |
- {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL, 0, 0}, |
- {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER, 0, 0}, |
- {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER, 0, 0}, |
- {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR, 0, 0}, |
- {VKEY_OEM_8, DomKey::SUPER, 0, 0}, // ISO Level 5 Shift in ChromeOS |
- {VKEY_PROCESSKEY, DomKey::PROCESS, 0, 0}, |
- {VKEY_DBE_SBCSCHAR, DomKey::HANKAKU, 0, 0}, |
- {VKEY_DBE_DBCSCHAR, DomKey::ZENKAKU, 0, 0}, |
- {VKEY_ATTN, DomKey::ATTN, 0, 0}, |
- {VKEY_CRSEL, DomKey::CR_SEL, 0, 0}, |
- {VKEY_EXSEL, DomKey::EX_SEL, 0, 0}, |
- {VKEY_EREOF, DomKey::ERASE_EOF, 0, 0}, |
- {VKEY_PLAY, DomKey::MEDIA_PLAY, 0, 0}, |
- {VKEY_ZOOM, DomKey::ZOOM_TOGGLE, 0, 0}, |
- {VKEY_OEM_CLEAR, DomKey::CLEAR, 0, 0}, |
- {VKEY_ALTGR, DomKey::ALT_GRAPH, 0, 0}, |
+} kDomKeyToKeyboardCodeMap[] = { |
+ // No value. |
+ {DomKey::NONE, VKEY_UNKNOWN}, |
+ // Special Key Values |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special |
+ {DomKey::UNIDENTIFIED, VKEY_UNKNOWN}, |
+ // Modifier Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier |
+ {DomKey::ALT, VKEY_MENU}, |
+ {DomKey::ALT_GRAPH, VKEY_ALTGR}, |
+ {DomKey::CAPS_LOCK, VKEY_CAPITAL}, |
+ {DomKey::CONTROL, VKEY_CONTROL}, |
+ {DomKey::NUM_LOCK, VKEY_NUMLOCK}, |
+ {DomKey::OS, VKEY_LWIN}, |
+ {DomKey::SCROLL_LOCK, VKEY_SCROLL}, |
+ {DomKey::SHIFT, VKEY_SHIFT}, |
+ // Whitespace Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace |
+ {DomKey::ENTER, VKEY_RETURN}, |
+ {DomKey::SEPARATOR, VKEY_SEPARATOR}, |
+ {DomKey::TAB, VKEY_TAB}, |
+ // Navigation Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation |
+ {DomKey::ARROW_DOWN, VKEY_DOWN}, |
+ {DomKey::ARROW_LEFT, VKEY_LEFT}, |
+ {DomKey::ARROW_RIGHT, VKEY_RIGHT}, |
+ {DomKey::ARROW_UP, VKEY_UP}, |
+ {DomKey::END, VKEY_END}, |
+ {DomKey::HOME, VKEY_HOME}, |
+ {DomKey::PAGE_DOWN, VKEY_NEXT}, |
+ {DomKey::PAGE_UP, VKEY_PRIOR}, |
+ // Editing Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing |
+ {DomKey::BACKSPACE, VKEY_BACK}, |
+ {DomKey::CLEAR, VKEY_CLEAR}, |
+ {DomKey::CR_SEL, VKEY_CRSEL}, |
+ {DomKey::DEL, VKEY_DELETE}, |
+ {DomKey::ERASE_EOF, VKEY_EREOF}, |
+ {DomKey::EX_SEL, VKEY_EXSEL}, |
+ {DomKey::INSERT, VKEY_INSERT}, |
+ // UI Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui |
+ {DomKey::ACCEPT, VKEY_ACCEPT}, |
+ {DomKey::ATTN, VKEY_ATTN}, |
+ {DomKey::CONTEXT_MENU, VKEY_APPS}, |
+ {DomKey::ESCAPE, VKEY_ESCAPE}, |
+ {DomKey::EXECUTE, VKEY_EXECUTE}, |
+ {DomKey::HELP, VKEY_HELP}, |
+ {DomKey::PAUSE, VKEY_PAUSE}, |
+ {DomKey::PLAY, VKEY_PLAY}, |
+ {DomKey::SELECT, VKEY_SELECT}, |
+ // Device Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device |
+ {DomKey::BRIGHTNESS_DOWN, VKEY_BRIGHTNESS_DOWN}, |
+ {DomKey::BRIGHTNESS_UP, VKEY_BRIGHTNESS_UP}, |
+ {DomKey::POWER, VKEY_POWER}, |
+ {DomKey::PRINT_SCREEN, VKEY_SNAPSHOT}, |
+// IME and Composition Keys |
+// http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition |
#if defined(OS_POSIX) |
- {VKEY_POWER, DomKey::POWER, 0, 0}, |
- {VKEY_BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN, 0, 0}, |
- {VKEY_BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP, 0, 0}, |
- {VKEY_COMPOSE, DomKey::COMPOSE, 0, 0}, |
- {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0}, |
- {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0}, |
+ {DomKey::COMPOSE, VKEY_COMPOSE}, |
#endif |
+ {DomKey::CONVERT, VKEY_CONVERT}, |
+ {DomKey::FINAL_MODE, VKEY_FINAL}, |
+ {DomKey::MODE_CHANGE, VKEY_MODECHANGE}, |
+ {DomKey::NON_CONVERT, VKEY_NONCONVERT}, |
+ {DomKey::PROCESS, VKEY_PROCESSKEY}, |
+ // Keys specific to Korean keyboards |
+ {DomKey::HANGUL_MODE, VKEY_HANGUL}, |
+ {DomKey::HANJA_MODE, VKEY_HANJA}, |
+ {DomKey::JUNJA_MODE, VKEY_JUNJA}, |
+ // Keys specific to Japanese keyboards |
+ {DomKey::HANKAKU, VKEY_DBE_SBCSCHAR}, |
+ {DomKey::KANA_MODE, VKEY_KANA}, |
+ {DomKey::KANJI_MODE, VKEY_KANJI}, |
+ {DomKey::ZENKAKU, VKEY_DBE_DBCSCHAR}, |
+ {DomKey::ZENKAKU_HANKAKU, VKEY_DBE_DBCSCHAR}, |
+ // General-Purpose Function Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function |
+ {DomKey::F1, VKEY_F1}, |
+ {DomKey::F2, VKEY_F2}, |
+ {DomKey::F3, VKEY_F3}, |
+ {DomKey::F4, VKEY_F4}, |
+ {DomKey::F5, VKEY_F5}, |
+ {DomKey::F6, VKEY_F6}, |
+ {DomKey::F7, VKEY_F7}, |
+ {DomKey::F8, VKEY_F8}, |
+ {DomKey::F9, VKEY_F9}, |
+ {DomKey::F10, VKEY_F10}, |
+ {DomKey::F11, VKEY_F11}, |
+ {DomKey::F12, VKEY_F12}, |
+ {DomKey::F13, VKEY_F13}, |
+ {DomKey::F14, VKEY_F14}, |
+ {DomKey::F15, VKEY_F15}, |
+ {DomKey::F16, VKEY_F16}, |
+ {DomKey::F17, VKEY_F17}, |
+ {DomKey::F18, VKEY_F18}, |
+ {DomKey::F19, VKEY_F19}, |
+ {DomKey::F20, VKEY_F20}, |
+ {DomKey::F21, VKEY_F21}, |
+ {DomKey::F22, VKEY_F22}, |
+ {DomKey::F23, VKEY_F23}, |
+ {DomKey::F24, VKEY_F24}, |
+ // Multimedia Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia |
+ {DomKey::MEDIA_PLAY_PAUSE, VKEY_MEDIA_PLAY_PAUSE}, |
+ {DomKey::MEDIA_SELECT, VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, |
+ {DomKey::MEDIA_STOP, VKEY_MEDIA_STOP}, |
+ {DomKey::MEDIA_TRACK_NEXT, VKEY_MEDIA_NEXT_TRACK}, |
+ {DomKey::MEDIA_TRACK_PREVIOUS, VKEY_MEDIA_PREV_TRACK}, |
+ {DomKey::PRINT, VKEY_PRINT}, |
+ {DomKey::VOLUME_DOWN, VKEY_VOLUME_DOWN}, |
+ {DomKey::VOLUME_MUTE, VKEY_VOLUME_MUTE}, |
+ {DomKey::VOLUME_UP, VKEY_VOLUME_UP}, |
+ // Application Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps |
+ {DomKey::LAUNCH_CALCULATOR, VKEY_MEDIA_LAUNCH_APP2}, |
+ {DomKey::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, |
+ {DomKey::LAUNCH_MY_COMPUTER, VKEY_MEDIA_LAUNCH_APP1}, |
+ // Browser Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser |
+ {DomKey::BROWSER_BACK, VKEY_BROWSER_BACK}, |
+ {DomKey::BROWSER_FAVORITES, VKEY_BROWSER_FAVORITES}, |
+ {DomKey::BROWSER_FORWARD, VKEY_BROWSER_FORWARD}, |
+ {DomKey::BROWSER_HOME, VKEY_BROWSER_HOME}, |
+ {DomKey::BROWSER_REFRESH, VKEY_BROWSER_REFRESH}, |
+ {DomKey::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, |
+ {DomKey::BROWSER_STOP, VKEY_BROWSER_STOP}, |
+ // Media Controller Keys |
+ // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller |
+ {DomKey::ZOOM_TOGGLE, VKEY_ZOOM}, |
+}; |
+ |
+// This table, used by DomCodeToKeyboardCode() and KeyboardCodeToDomCode(), |
+// maps between DOM Level 3 .code values and legacy Windows-based VKEY values, |
+// where the VKEYs are interpreted positionally (located). |
+const struct DomCodeToKeyboardCodeEntry { |
+ DomCode dom_code; |
+ KeyboardCode key_code; |
+} kDomCodeToKeyboardCodeMap[] = { |
+ // Entries are ordered by numeric value of the DomCode enum, |
+ // which is the USB physical key code. |
+ // DomCode::HYPER 0x000010 Hyper |
+ // DomCode::SUPER 0x000011 Super |
+ // DomCode::FN 0x000012 Fn |
+ // DomCode::FN_LOCK 0x000013 FLock |
+ // DomCode::SUSPEND 0x000014 Suspend |
+ // DomCode::RESUME 0x000015 Resume |
+ // DomCode::TURBO 0x000016 Turbo |
+ {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep |
+ // DomCode::WAKE_UP 0x010083 WakeUp |
+ {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA |
+ {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB |
+ {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC |
+ {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD |
+ {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE |
+ {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF |
+ {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG |
+ {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH |
+ {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI |
+ {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ |
+ {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK |
+ {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL |
+ {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM |
+ {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN |
+ {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO |
+ {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP |
+ {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ |
+ {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR |
+ {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS |
+ {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT |
+ {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU |
+ {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV |
+ {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW |
+ {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX |
+ {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY |
+ {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ |
+ {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1 |
+ {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2 |
+ {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3 |
+ {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4 |
+ {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5 |
+ {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6 |
+ {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7 |
+ {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8 |
+ {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9 |
+ {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0 |
+ {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter |
+ {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape |
+ {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace |
+ {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab |
+ {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space |
+ {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus |
+ {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal |
+ {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft |
+ {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight |
+ {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash |
+ // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash |
+ {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon |
+ {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote |
+ {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote |
+ {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma |
+ {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period |
+ {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash |
+ {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock |
+ {DomCode::F1, VKEY_F1}, // 0x07003A F1 |
+ {DomCode::F2, VKEY_F2}, // 0x07003B F2 |
+ {DomCode::F3, VKEY_F3}, // 0x07003C F3 |
+ {DomCode::F4, VKEY_F4}, // 0x07003D F4 |
+ {DomCode::F5, VKEY_F5}, // 0x07003E F5 |
+ {DomCode::F6, VKEY_F6}, // 0x07003F F6 |
+ {DomCode::F7, VKEY_F7}, // 0x070040 F7 |
+ {DomCode::F8, VKEY_F8}, // 0x070041 F8 |
+ {DomCode::F9, VKEY_F9}, // 0x070042 F9 |
+ {DomCode::F10, VKEY_F10}, // 0x070043 F10 |
+ {DomCode::F11, VKEY_F11}, // 0x070044 F11 |
+ {DomCode::F12, VKEY_F12}, // 0x070045 F12 |
+ {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen |
+ {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock |
+ {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause |
+ {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert |
+ {DomCode::HOME, VKEY_HOME}, // 0x07004A Home |
+ {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp |
+ {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete |
+ {DomCode::END, VKEY_END}, // 0x07004D End |
+ {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown |
+ {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight |
+ {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft |
+ {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown |
+ {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp |
+ {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock |
+ {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide |
+ {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply |
+ {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract |
+ {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd |
+ {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter |
+ {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1 |
+ {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2 |
+ {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3 |
+ {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4 |
+ {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5 |
+ {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6 |
+ {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7 |
+ {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8 |
+ {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9 |
+ {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0 |
+ {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal |
+ {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash |
+ {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu |
+ {DomCode::POWER, VKEY_POWER}, // 0x070066 Power |
+ // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual |
+ // DomCode::OPEN 0x070074 Open |
+ {DomCode::HELP, VKEY_HELP}, // 0x070075 Help |
+ {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select |
+ // DomCode::AGAIN 0x070079 Again |
+ // DomCode::UNDO 0x07007A Undo |
+ // DomCode::CUT 0x07007B Cut |
+ // DomCode::COPY 0x07007C Copy |
+ // DomCode::PASTE 0x07007D Paste |
+ // DomCode::FIND 0x07007E Find |
+ {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute |
+ {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp |
+ {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown |
+ {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma |
+ {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo |
+ {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode |
+ {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen |
+ {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert |
+ {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert |
+ {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1 |
+ {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2 |
+ // DomCode::LANG3 0x070092 Lang3 |
+ // DomCode::LANG4 0x070093 Lang4 |
+ // DomCode::LANG5 0x070094 Lang5 |
+ // DomCode::ABORT 0x07009B Abort |
+ // DomCode::PROPS 0x0700A3 Props |
+ // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft |
+ // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight |
+ {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace |
+ // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore |
+ // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall |
+ // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear |
+ // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd |
+ // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4 |
+ // NumpadMemorySubtract |
+ {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear |
+ {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry |
+ {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft |
+ {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft |
+ {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft |
+ {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft |
+ {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight |
+ {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight |
+ {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight |
+ {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight |
+ {DomCode::MEDIA_TRACK_NEXT, |
+ VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext |
+ {DomCode::MEDIA_TRACK_PREVIOUS, |
+ VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious |
+ {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop |
+ // DomCode::EJECT 0x0C00B8 Eject |
+ {DomCode::MEDIA_PLAY_PAUSE, |
+ VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause |
+ {DomCode::MEDIA_SELECT, |
+ VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect |
+ {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail |
+ {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2 |
+ {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1 |
+ {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch |
+ {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome |
+ {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack |
+ {DomCode::BROWSER_FORWARD, |
+ VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward |
+ {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop |
+ {DomCode::BROWSER_REFRESH, |
+ VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh |
+ {DomCode::BROWSER_FAVORITES, |
+ VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites |
+}; |
+ |
+const struct CharacterToDomKey { |
+ base::char16 character; |
+ DomKey dom_key; |
+} kCharacterToDomKey[] = { |
+ {0x08, DomKey::BACKSPACE}, |
+ {0x09, DomKey::TAB}, |
+ {0x0A, DomKey::ENTER}, |
+ {0x0D, DomKey::ENTER}, |
+ {0x1B, DomKey::ESCAPE}, |
+}; |
+ |
+const struct DomCodeToCtrlCharacter { |
+ DomCode dom_code; |
+ DomKey dom_key; |
+ base::char16 character; |
+ KeyboardCode key_code; |
+} kDomCodeToCtrlCharacterCtrl[] = { |
+ {DomCode::KEY_H, DomKey::BACKSPACE, 0, VKEY_BACK}, |
+ {DomCode::KEY_I, DomKey::TAB, 0, VKEY_TAB}, |
+ {DomCode::KEY_M, DomKey::ENTER, 0, VKEY_RETURN}, |
+}; |
+ |
+DomCodeToCtrlCharacter kDomCodeToCtrlCharacterShiftDown[] = { |
+ {DomCode::DIGIT2, DomKey::CHARACTER, 0, VKEY_1}, |
+ {DomCode::DIGIT6, DomKey::CHARACTER, 0x1E, VKEY_6}, |
+ {DomCode::MINUS, DomKey::CHARACTER, 0x1F, VKEY_OEM_MINUS}, |
+}; |
+ |
+DomCodeToCtrlCharacter kDomCodeToCtrlCharacterOther[] = { |
+ {DomCode::ENTER, DomKey::CHARACTER, 0x0A, VKEY_RETURN}, |
+ {DomCode::BRACKET_LEFT, DomKey::ESCAPE, 0x1B, VKEY_OEM_4}, |
+ {DomCode::BACKSLASH, DomKey::CHARACTER, 0x1C, VKEY_OEM_5}, |
+ {DomCode::BRACKET_RIGHT, DomKey::CHARACTER, 0x1D, VKEY_OEM_6}, |
}; |
bool IsRightSideDomCode(DomCode code) { |
@@ -130,143 +591,198 @@ bool IsRightSideDomCode(DomCode code) { |
(code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT); |
} |
+bool IsModifierDomCode(DomCode code) { |
+ return (code == DomCode::CONTROL_LEFT) || (code == DomCode::CONTROL_RIGHT) || |
+ (code == DomCode::SHIFT_LEFT) || (code == DomCode::SHIFT_RIGHT) || |
+ (code == DomCode::ALT_LEFT) || (code == DomCode::ALT_RIGHT) || |
+ (code == DomCode::OS_LEFT) || (code == DomCode::OS_RIGHT); |
+} |
+ |
} // anonymous namespace |
-base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { |
- ui::DomKey dom_key; |
+base::char16 DomCodeToCharacter(DomCode dom_code, int flags) { |
base::char16 character; |
- if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character)) |
+ DomKey key; |
+ KeyboardCode key_code; |
+ if (DomCodeToMeaning(dom_code, flags, &key, &character, &key_code)) |
return character; |
return 0; |
} |
-bool GetMeaningFromKeyCode(KeyboardCode key_code, |
- int flags, |
- DomKey* dom_key, |
- base::char16* character) { |
- 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); |
- |
- // Control characters. |
- if (ctrl) { |
- // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A. |
- if (key_code >= VKEY_A && key_code <= VKEY_Z) { |
- *character = static_cast<uint16>(key_code - VKEY_A + 1); |
- switch (key_code) { |
- case VKEY_H: |
- *dom_key = DomKey::BACKSPACE; |
- break; |
- case VKEY_I: |
- *dom_key = DomKey::TAB; |
- break; |
- case VKEY_J: |
- case VKEY_M: |
- *dom_key = DomKey::ENTER; |
- break; |
- default: |
- *dom_key = DomKey::CHARACTER; |
- break; |
- } |
+bool DomCodeToMeaning(DomCode dom_code, |
+ int flags, |
+ DomKey* out_dom_key, |
+ base::char16* out_character, |
+ KeyboardCode* out_key_code) { |
+ if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { |
+ if (DomCodeToControlCharacter(dom_code, flags, out_dom_key, out_character, |
+ out_key_code)) { |
return true; |
} |
- // Other control characters. |
- if (shift) { |
- // The following graphics characters require the shift key to input. |
- switch (key_code) { |
- // ctrl-@ maps to \x00 (Null byte) |
- case VKEY_2: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0; |
- return true; |
- // ctrl-^ maps to \x1E (Record separator, Information separator two) |
- case VKEY_6: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0x1E; |
- return true; |
- // ctrl-_ maps to \x1F (Unit separator, Information separator one) |
- case VKEY_OEM_MINUS: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0x1F; |
- return true; |
- // Returns 0 for all other keys to avoid inputting unexpected chars. |
- default: |
- *dom_key = DomKey::UNIDENTIFIED; |
- *character = 0; |
- return false; |
- } |
- } else { |
- switch (key_code) { |
- // ctrl-[ maps to \x1B (Escape) |
- case VKEY_OEM_4: |
- *dom_key = DomKey::ESCAPE; |
- *character = 0x1B; |
- return true; |
- // ctrl-\ maps to \x1C (File separator, Information separator four) |
- case VKEY_OEM_5: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0x1C; |
- return true; |
- // ctrl-] maps to \x1D (Group separator, Information separator three) |
- case VKEY_OEM_6: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0x1D; |
- return true; |
- // ctrl-Enter maps to \x0A (Line feed) |
- case VKEY_RETURN: |
- *dom_key = DomKey::CHARACTER; |
- *character = 0x0A; |
- return true; |
- // Returns 0 for all other keys to avoid inputting unexpected chars. |
- default: |
- *dom_key = DomKey::UNIDENTIFIED; |
- *character = 0; |
- return false; |
+ if (!IsModifierDomCode(dom_code)) { |
+ *out_dom_key = DomKey::UNIDENTIFIED; |
+ *out_character = 0; |
+ *out_key_code = VKEY_UNKNOWN; |
+ return true; |
+ } |
+ } else { |
+ for (const auto& it : kPrintableCodeMap) { |
+ if (it.dom_code == dom_code) { |
+ int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) | |
+ ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN); |
+ base::char16 ch = it.character[state]; |
+ *out_dom_key = (ch & kDeadKeyFlag) ? DomKey::DEAD : DomKey::CHARACTER; |
+ *out_character = ch; |
+ if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) { |
+ ch = (ch & ~kDeadKeyFlag) | 0x20; |
+ if ((ch >= 'a') && (ch <= 'z')) |
+ *out_character = it.character[state ^ 1]; |
+ } |
+ *out_key_code = |
+ LocatedToNonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code)); |
+ return true; |
} |
} |
} |
- |
- // ASCII alphanumeric characters. |
- if (key_code >= VKEY_A && key_code <= VKEY_Z) { |
- *dom_key = DomKey::CHARACTER; |
- *character = static_cast<uint16>(key_code - VKEY_A + (upper ? 'A' : 'a')); |
- return true; |
- } |
- if (key_code >= VKEY_0 && key_code <= VKEY_9) { |
- *dom_key = DomKey::CHARACTER; |
- *character = |
- shift ? ")!@#$%^&*("[key_code - VKEY_0] : static_cast<uint16>(key_code); |
- return true; |
+ for (const auto& it : kNonPrintableCodeMap) { |
+ if (it.dom_code == dom_code) { |
+ *out_dom_key = it.dom_key; |
+ *out_character = it.character; |
+ *out_key_code = NonPrintableDomKeyToKeyboardCode(it.dom_key); |
+ return true; |
+ } |
} |
- if (key_code >= VKEY_NUMPAD0 && key_code <= VKEY_NUMPAD9) { |
+ return false; |
+} |
+ |
+bool DomCodeToControlCharacter(DomCode dom_code, |
+ int flags, |
+ DomKey* dom_key, |
+ base::char16* character, |
+ KeyboardCode* key_code) { |
+ if ((flags & EF_CONTROL_DOWN) == 0) |
+ return false; |
+ |
+ int code = static_cast<int>(dom_code); |
+ const int kKeyA = static_cast<int>(DomCode::KEY_A); |
+ |
+ // Control-A - Control-Z map to 0x01 - 0x1A. |
+ if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { |
*dom_key = DomKey::CHARACTER; |
- *character = static_cast<uint16>(key_code - VKEY_NUMPAD0 + '0'); |
+ *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A); |
+ *character = static_cast<base::char16>(code - kKeyA + 1); |
+ for (const auto& it: kDomCodeToCtrlCharacterCtrl) { |
+ if (it.dom_code == dom_code) { |
+ *dom_key = it.dom_key; |
+ *key_code = it.key_code; |
+ } |
+ } |
return true; |
} |
- // Function keys. |
- if (key_code >= VKEY_F1 && key_code <= VKEY_F24) { |
- *dom_key = |
- static_cast<DomKey>(key_code - VKEY_F1 + static_cast<int>(DomKey::F1)); |
- *character = 0; |
- return true; |
+ if (flags & EF_SHIFT_DOWN) { |
+ for (const auto& it: kDomCodeToCtrlCharacterShiftDown) { |
+ if (it.dom_code == dom_code) { |
+ *dom_key = it.dom_key; |
+ *key_code = it.key_code; |
+ *character = it.character; |
+ return true; |
+ } |
+ } |
+ return false; |
} |
- // Other keys. |
- for (size_t i = 0; i < arraysize(kKeyboardCodeToMeaning); ++i) { |
- if (kKeyboardCodeToMeaning[i].key_code == key_code) { |
- const KeyboardCodeToMeaning* p = &kKeyboardCodeToMeaning[i]; |
- *dom_key = p->key; |
- *character = (shift && p->shift_character) ? p->shift_character |
- : p->plain_character; |
+ for (const auto& it: kDomCodeToCtrlCharacterOther) { |
+ if (it.dom_code == dom_code) { |
+ *dom_key = it.dom_key; |
+ *key_code = it.key_code; |
+ *character = it.character; |
return true; |
} |
} |
- *dom_key = DomKey::UNIDENTIFIED; |
- *character = 0; |
return false; |
} |
+// Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. |
+// The returned VKEY is non-positional (e.g. VKEY_SHIFT). |
+KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) { |
+ for (const auto& it : kDomKeyToKeyboardCodeMap) { |
+ if (it.dom_key == dom_key) |
+ return it.key_code; |
+ } |
+ return VKEY_UNKNOWN; |
+} |
+ |
+// Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. |
+// The returned VKEY is located (e.g. VKEY_LSHIFT). |
+KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { |
+ const DomCodeToKeyboardCodeEntry* end = |
+ kDomCodeToKeyboardCodeMap + arraysize(kDomCodeToKeyboardCodeMap); |
+ const DomCodeToKeyboardCodeEntry* found = |
+ std::lower_bound(kDomCodeToKeyboardCodeMap, end, dom_code, |
+ [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { |
+ return static_cast<int>(a.dom_code) < static_cast<int>(b); |
+ }); |
+ if ((found != end) && (found->dom_code == dom_code)) |
+ return found->key_code; |
+ return VKEY_UNKNOWN; |
+} |
+ |
+// Returns a DOM Level 3 |code| from a Windows-based VKEY value. |
+// This assumes a US layout and should only be used when |code| cannot be |
+// determined from a physical scan code. |
+DomCode KeyboardCodeToDomCode(KeyboardCode key_code) { |
+ key_code = NonLocatedToLocatedKeyboardCode(key_code, DomCode::NONE); |
+ for (const auto& it : kDomCodeToKeyboardCodeMap) { |
+ if (it.key_code == key_code) |
+ return it.dom_code; |
+ } |
+ return DomCode::NONE; |
+} |
+ |
+// Returns the DomKey value associated with an ASCII/Unicode character. |
+DomKey CharacterToDomKey(base::char16 character) { |
+ for (const auto& it: kCharacterToDomKey) { |
+ if (it.character == character) |
+ return it.dom_key; |
+ } |
+ return DomKey::CHARACTER; |
+} |
+ |
+// Returns the ui::EventFlags value associated with a modifier key. |
+int ModifierDomKeyToEventFlag(DomKey key) { |
+ switch (key) { |
+ case DomKey::ALT: |
+ return EF_ALT_DOWN; |
+ case DomKey::ALT_GRAPH: |
+ return EF_ALTGR_DOWN; |
+ case DomKey::CAPS_LOCK: |
+ return EF_CAPS_LOCK_DOWN; |
+ case DomKey::CONTROL: |
+ return EF_CONTROL_DOWN; |
+ case DomKey::HYPER: |
+ return EF_MOD3_DOWN; |
+ case DomKey::META: |
+ return EF_ALT_DOWN; |
+ case DomKey::OS: |
+ return EF_COMMAND_DOWN; |
+ case DomKey::SHIFT: |
+ return EF_SHIFT_DOWN; |
+ case DomKey::SUPER: |
+ return EF_MOD3_DOWN; |
+ default: |
+ return EF_NONE; |
+ } |
+ // Not represented: |
+ // DomKey::ACCEL |
+ // DomKey::FN |
+ // DomKey::FN_LOCK |
+ // DomKey::NUM_LOCK |
+ // DomKey::SCROLL_LOCK |
+ // DomKey::SYMBOL |
+ // DomKey::SYMBOL_LOCK |
+} |
+ |
// Determine the non-located VKEY corresponding to a located VKEY. |
KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) { |
switch (key_code) { |