OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" | 5 #include "ui/events/ozone/layout/layout_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "ui/events/event_constants.h" |
10 #include "ui/events/event.h" | |
11 #include "ui/events/keycodes/dom3/dom_code.h" | 10 #include "ui/events/keycodes/dom3/dom_code.h" |
12 #include "ui/events/keycodes/dom3/dom_key.h" | 11 #include "ui/events/keycodes/dom3/dom_key.h" |
13 #include "ui/events/keycodes/keyboard_code_conversion.h" | 12 #include "ui/events/ozone/layout/xkb/xkb_keysym.h" |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 // All of the characters have low ordinals, so we use bit 15 to flag dead keys. | 18 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code |
20 #define DK 0x8000 | 19 // values to legacy Windows-based VKEY values, where the VKEYs are |
21 | 20 // interpreted positionally. |
22 const struct PrintableCodeEntry { | 21 const struct DomCodeToKeyboardCodeEntry { |
23 DomCode dom_code; | 22 DomCode dom_code; |
24 base::char16 character[4]; | 23 KeyboardCode key_code; |
25 } printable_code_map[] = { | 24 } dom_code_to_keyboard_code[] = { |
26 // Stub table based on X US international. | 25 // Entries are ordered by numeric value of the DomCode enum, |
27 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}}, | 26 // which is the USB physical key code. |
28 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}}, | 27 // DomCode::HYPER 0x000010 Hyper |
29 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}}, | 28 // DomCode::SUPER 0x000011 Super |
30 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}}, | 29 // DomCode::FN 0x000012 Fn |
31 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}}, | 30 // DomCode::FN_LOCK 0x000013 FLock |
32 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}}, | 31 // DomCode::SUSPEND 0x000014 Suspend |
33 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}}, | 32 // DomCode::RESUME 0x000015 Resume |
34 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}}, | 33 // DomCode::TURBO 0x000016 Turbo |
35 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}}, | 34 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep |
36 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}}, | 35 // DomCode::WAKE_UP 0x010083 WakeUp |
37 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}}, | 36 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA |
38 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}}, | 37 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB |
39 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}}, | 38 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC |
40 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}}, | 39 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD |
41 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}}, | 40 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE |
42 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}}, | 41 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF |
43 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}}, | 42 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG |
44 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}}, | 43 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH |
45 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}}, | 44 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI |
46 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}}, | 45 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ |
47 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}}, | 46 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK |
48 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}}, | 47 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL |
49 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}}, | 48 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM |
50 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}}, | 49 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN |
51 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}}, | 50 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO |
52 {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}}, | 51 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP |
53 {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}}, | 52 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ |
54 {DomCode::DIGIT2, {'2', '@', 0x00B2, DK|0x030B}}, | 53 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR |
55 {DomCode::DIGIT3, {'3', '#', 0x00B3, DK|0x0304}}, | 54 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS |
56 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}}, | 55 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT |
57 {DomCode::DIGIT5, {'5', '%', 0x20AC, DK|0x0327}}, | 56 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU |
58 {DomCode::DIGIT6, {'6', '^', DK|0x0302, 0x00BC}}, | 57 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV |
59 {DomCode::DIGIT7, {'7', '&', 0x00BD, DK|0x031B}}, | 58 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW |
60 {DomCode::DIGIT8, {'8', '*', 0x00BE, DK|0x0328}}, | 59 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX |
61 {DomCode::DIGIT9, {'9', '(', 0x2018, DK|0x0306}}, | 60 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY |
62 {DomCode::DIGIT0, {'0', ')', 0x2019, DK|0x030A}}, | 61 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ |
63 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}}, | 62 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1 |
64 {DomCode::MINUS, {'-', '_', 0x00A5, DK|0x0323}}, | 63 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2 |
65 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}}, | 64 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3 |
66 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}}, | 65 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4 |
67 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}}, | 66 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5 |
68 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}}, | 67 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6 |
69 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}}, | 68 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7 |
70 {DomCode::QUOTE, {'\'', '"', DK|0x0301, DK|0x0308}}, | 69 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8 |
71 {DomCode::BACKQUOTE, {'`', '~', DK|0x0300, DK|0x0303}}, | 70 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9 |
72 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}}, | 71 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0 |
73 {DomCode::PERIOD, {'.', '>', DK|0x0307, DK|0x030C}}, | 72 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter |
74 {DomCode::SLASH, {'/', '?', 0x00BF, DK|0x0309}}, | 73 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape |
75 {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}}, | 74 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace |
76 {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}}, | 75 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab |
77 {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}}, | 76 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space |
78 {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}}, | 77 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus |
79 {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}}, | 78 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal |
80 {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}}, | 79 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft |
81 {DomCode::NUMPAD1, {'1', '1', '1', '1'}}, | 80 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight |
82 {DomCode::NUMPAD2, {'2', '2', '2', '2'}}, | 81 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash |
83 {DomCode::NUMPAD3, {'3', '3', '3', '3'}}, | 82 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash |
84 {DomCode::NUMPAD4, {'4', '4', '4', '4'}}, | 83 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon |
85 {DomCode::NUMPAD5, {'5', '5', '5', '5'}}, | 84 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote |
86 {DomCode::NUMPAD6, {'6', '6', '6', '6'}}, | 85 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote |
87 {DomCode::NUMPAD7, {'7', '7', '7', '7'}}, | 86 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma |
88 {DomCode::NUMPAD8, {'8', '8', '8', '8'}}, | 87 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period |
89 {DomCode::NUMPAD9, {'9', '9', '9', '9'}}, | 88 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash |
90 {DomCode::NUMPAD0, {'0', '0', '0', '0'}}, | 89 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock |
91 {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}}, | 90 {DomCode::F1, VKEY_F1}, // 0x07003A F1 |
92 {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}}, | 91 {DomCode::F2, VKEY_F2}, // 0x07003B F2 |
93 {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}}, | 92 {DomCode::F3, VKEY_F3}, // 0x07003C F3 |
94 {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}}, | 93 {DomCode::F4, VKEY_F4}, // 0x07003D F4 |
95 {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}}, | 94 {DomCode::F5, VKEY_F5}, // 0x07003E F5 |
96 {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}}, | 95 {DomCode::F6, VKEY_F6}, // 0x07003F F6 |
| 96 {DomCode::F7, VKEY_F7}, // 0x070040 F7 |
| 97 {DomCode::F8, VKEY_F8}, // 0x070041 F8 |
| 98 {DomCode::F9, VKEY_F9}, // 0x070042 F9 |
| 99 {DomCode::F10, VKEY_F10}, // 0x070043 F10 |
| 100 {DomCode::F11, VKEY_F11}, // 0x070044 F11 |
| 101 {DomCode::F12, VKEY_F12}, // 0x070045 F12 |
| 102 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen |
| 103 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock |
| 104 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause |
| 105 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert |
| 106 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home |
| 107 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp |
| 108 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete |
| 109 {DomCode::END, VKEY_END}, // 0x07004D End |
| 110 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown |
| 111 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight |
| 112 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft |
| 113 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown |
| 114 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp |
| 115 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock |
| 116 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide |
| 117 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply |
| 118 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract |
| 119 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd |
| 120 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter |
| 121 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1 |
| 122 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2 |
| 123 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3 |
| 124 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4 |
| 125 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5 |
| 126 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6 |
| 127 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7 |
| 128 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8 |
| 129 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9 |
| 130 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0 |
| 131 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal |
| 132 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash |
| 133 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu |
| 134 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power |
| 135 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual |
| 136 // DomCode::OPEN 0x070074 Open |
| 137 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help |
| 138 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select |
| 139 // DomCode::AGAIN 0x070079 Again |
| 140 // DomCode::UNDO 0x07007A Undo |
| 141 // DomCode::CUT 0x07007B Cut |
| 142 // DomCode::COPY 0x07007C Copy |
| 143 // DomCode::PASTE 0x07007D Paste |
| 144 // DomCode::FIND 0x07007E Find |
| 145 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute |
| 146 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp |
| 147 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown |
| 148 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma |
| 149 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo |
| 150 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode |
| 151 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen |
| 152 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert |
| 153 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert |
| 154 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1 |
| 155 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2 |
| 156 // DomCode::LANG3 0x070092 Lang3 |
| 157 // DomCode::LANG4 0x070093 Lang4 |
| 158 // DomCode::LANG5 0x070094 Lang5 |
| 159 // DomCode::ABORT 0x07009B Abort |
| 160 // DomCode::PROPS 0x0700A3 Props |
| 161 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft |
| 162 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight |
| 163 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace |
| 164 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore |
| 165 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall |
| 166 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear |
| 167 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd |
| 168 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4 |
| 169 // NumpadMemorySubtract |
| 170 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear |
| 171 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry |
| 172 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft |
| 173 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft |
| 174 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft |
| 175 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft |
| 176 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight |
| 177 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight |
| 178 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight |
| 179 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight |
| 180 {DomCode::MEDIA_TRACK_NEXT, |
| 181 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext |
| 182 {DomCode::MEDIA_TRACK_PREVIOUS, |
| 183 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious |
| 184 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop |
| 185 // DomCode::EJECT 0x0C00B8 Eject |
| 186 {DomCode::MEDIA_PLAY_PAUSE, |
| 187 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause |
| 188 {DomCode::MEDIA_SELECT, |
| 189 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect |
| 190 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail |
| 191 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2 |
| 192 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1 |
| 193 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch |
| 194 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome |
| 195 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack |
| 196 {DomCode::BROWSER_FORWARD, |
| 197 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward |
| 198 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop |
| 199 {DomCode::BROWSER_REFRESH, |
| 200 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh |
| 201 {DomCode::BROWSER_FAVORITES, |
| 202 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites |
97 }; | 203 }; |
98 | 204 |
99 const struct NonPrintableCodeEntry { | 205 } // anonymous namespace |
100 DomCode dom_code; | 206 |
101 DomKey dom_key; | 207 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. |
102 base::char16 character; | 208 // The returned VKEY is positional (e.g. VKEY_LSHIFT). |
103 } non_printable_code_map[] = { | 209 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { |
104 {DomCode::ABORT, DomKey::CANCEL}, | 210 const DomCodeToKeyboardCodeEntry* end = |
105 {DomCode::AGAIN, DomKey::AGAIN}, | 211 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code); |
106 {DomCode::ALT_LEFT, DomKey::ALT}, | 212 const DomCodeToKeyboardCodeEntry* found = |
107 {DomCode::ALT_RIGHT, DomKey::ALT}, | 213 std::lower_bound(dom_code_to_keyboard_code, end, dom_code, |
108 {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN}, | 214 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { |
109 {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT}, | 215 return static_cast<int>(a.dom_code) < static_cast<int>(b); |
110 {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT}, | 216 }); |
111 {DomCode::ARROW_UP, DomKey::ARROW_UP}, | 217 if ((found != end) && (found->dom_code == dom_code)) |
112 {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008}, | 218 return found->key_code; |
113 {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN}, | 219 return VKEY_UNKNOWN; |
114 {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP}, | 220 } |
115 // {DomCode::BRIGHTNESS_AUTO, DomKey::_} | 221 |
116 // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_} | 222 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. |
117 // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_} | 223 // The returned VKEY is non-positional (e.g. VKEY_SHIFT). |
118 // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_} | 224 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) { |
119 {DomCode::BROWSER_BACK, DomKey::BROWSER_BACK}, | |
120 {DomCode::BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES}, | |
121 {DomCode::BROWSER_FORWARD, DomKey::BROWSER_FORWARD}, | |
122 {DomCode::BROWSER_HOME, DomKey::BROWSER_HOME}, | |
123 {DomCode::BROWSER_REFRESH, DomKey::BROWSER_REFRESH}, | |
124 {DomCode::BROWSER_SEARCH, DomKey::BROWSER_SEARCH}, | |
125 {DomCode::BROWSER_STOP, DomKey::BROWSER_STOP}, | |
126 {DomCode::CAPS_LOCK, DomKey::CAPS_LOCK}, | |
127 {DomCode::CONTEXT_MENU, DomKey::CONTEXT_MENU}, | |
128 {DomCode::CONTROL_LEFT, DomKey::CONTROL}, | |
129 {DomCode::CONTROL_RIGHT, DomKey::CONTROL}, | |
130 {DomCode::CONVERT, DomKey::CONVERT}, | |
131 {DomCode::COPY, DomKey::COPY}, | |
132 {DomCode::CUT, DomKey::CUT}, | |
133 {DomCode::DEL, DomKey::DEL, 0x007F}, | |
134 {DomCode::EJECT, DomKey::EJECT}, | |
135 {DomCode::END, DomKey::END}, | |
136 {DomCode::ENTER, DomKey::ENTER, 0x000D}, | |
137 {DomCode::ESCAPE, DomKey::ESCAPE, 0x001B}, | |
138 {DomCode::F1, DomKey::F1}, | |
139 {DomCode::F2, DomKey::F2}, | |
140 {DomCode::F3, DomKey::F3}, | |
141 {DomCode::F4, DomKey::F4}, | |
142 {DomCode::F5, DomKey::F5}, | |
143 {DomCode::F6, DomKey::F6}, | |
144 {DomCode::F7, DomKey::F7}, | |
145 {DomCode::F8, DomKey::F8}, | |
146 {DomCode::F9, DomKey::F9}, | |
147 {DomCode::F10, DomKey::F10}, | |
148 {DomCode::F11, DomKey::F11}, | |
149 {DomCode::F12, DomKey::F12}, | |
150 {DomCode::F13, DomKey::F13}, | |
151 {DomCode::F14, DomKey::F14}, | |
152 {DomCode::F15, DomKey::F15}, | |
153 {DomCode::F16, DomKey::F16}, | |
154 {DomCode::F17, DomKey::F17}, | |
155 {DomCode::F18, DomKey::F18}, | |
156 {DomCode::F19, DomKey::F19}, | |
157 {DomCode::F20, DomKey::F20}, | |
158 {DomCode::F21, DomKey::F21}, | |
159 {DomCode::F22, DomKey::F22}, | |
160 {DomCode::F23, DomKey::F23}, | |
161 {DomCode::F24, DomKey::F24}, | |
162 {DomCode::FIND, DomKey::FIND}, | |
163 {DomCode::FN, DomKey::FN}, | |
164 {DomCode::FN_LOCK, DomKey::FN_LOCK}, | |
165 {DomCode::HELP, DomKey::HELP}, | |
166 {DomCode::HOME, DomKey::HOME}, | |
167 {DomCode::HYPER, DomKey::HYPER}, | |
168 {DomCode::INSERT, DomKey::INSERT}, | |
169 // {DomCode::INTL_RO, DomKey::_} | |
170 {DomCode::KANA_MODE, DomKey::KANA_MODE}, | |
171 {DomCode::LANG1, DomKey::HANGUL_MODE}, | |
172 {DomCode::LANG2, DomKey::HANJA_MODE}, | |
173 {DomCode::LANG3, DomKey::KATAKANA}, | |
174 {DomCode::LANG4, DomKey::HIRAGANA}, | |
175 {DomCode::LANG5, DomKey::ZENKAKU_HANKAKU}, | |
176 {DomCode::LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, | |
177 {DomCode::LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, | |
178 {DomCode::LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, | |
179 {DomCode::LAUNCH_SCREEN_SAVER, DomKey::LAUNCH_SCREEN_SAVER}, | |
180 // {DomCode::LAUNCH_DOCUMENTS, DomKey::_} | |
181 // {DomCode::LAUNCH_FILE_BROWSER, DomKey::_} | |
182 // {DomCode::LAUNCH_KEYBOARD_LAYOUT, DomKey::_} | |
183 {DomCode::LOCK_SCREEN, DomKey::LAUNCH_SCREEN_SAVER}, | |
184 {DomCode::MAIL_FORWARD, DomKey::MAIL_FORWARD}, | |
185 {DomCode::MAIL_REPLY, DomKey::MAIL_REPLY}, | |
186 {DomCode::MAIL_SEND, DomKey::MAIL_SEND}, | |
187 {DomCode::MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, | |
188 {DomCode::MEDIA_SELECT, DomKey::MEDIA_SELECT}, | |
189 {DomCode::MEDIA_STOP, DomKey::MEDIA_STOP}, | |
190 {DomCode::MEDIA_TRACK_NEXT, DomKey::MEDIA_TRACK_NEXT}, | |
191 {DomCode::MEDIA_TRACK_PREVIOUS, DomKey::MEDIA_TRACK_PREVIOUS}, | |
192 // {DomCode::MENU, DomKey::_} | |
193 {DomCode::NON_CONVERT, DomKey::NON_CONVERT}, | |
194 {DomCode::NUM_LOCK, DomKey::NUM_LOCK}, | |
195 {DomCode::NUMPAD_BACKSPACE, DomKey::BACKSPACE, 0x0008}, | |
196 {DomCode::NUMPAD_CLEAR, DomKey::CLEAR}, | |
197 {DomCode::NUMPAD_ENTER, DomKey::ENTER, 0x000D}, | |
198 // {DomCode::NUMPAD_CLEAR_ENTRY, DomKey::_} | |
199 // {DomCode::NUMPAD_MEMORY_ADD, DomKey::_} | |
200 // {DomCode::NUMPAD_MEMORY_CLEAR, DomKey::_} | |
201 // {DomCode::NUMPAD_MEMORY_RECALL, DomKey::_} | |
202 // {DomCode::NUMPAD_MEMORY_STORE, DomKey::_} | |
203 // {DomCode::NUMPAD_MEMORY_SUBTRACT, DomKey::_} | |
204 {DomCode::OPEN, DomKey::OPEN}, | |
205 {DomCode::OS_LEFT, DomKey::OS}, | |
206 {DomCode::OS_RIGHT, DomKey::OS}, | |
207 {DomCode::PAGE_DOWN, DomKey::PAGE_DOWN}, | |
208 {DomCode::PAGE_UP, DomKey::PAGE_UP}, | |
209 {DomCode::PASTE, DomKey::PASTE}, | |
210 {DomCode::PAUSE, DomKey::PAUSE}, | |
211 {DomCode::POWER, DomKey::POWER}, | |
212 {DomCode::PRINT_SCREEN, DomKey::PRINT_SCREEN}, | |
213 {DomCode::PROPS, DomKey::PROPS}, | |
214 {DomCode::SCROLL_LOCK, DomKey::SCROLL_LOCK}, | |
215 {DomCode::SELECT, DomKey::SELECT}, | |
216 // {DomCode::SELECT_TASK, DomKey::_} | |
217 {DomCode::SHIFT_LEFT, DomKey::SHIFT}, | |
218 {DomCode::SHIFT_RIGHT, DomKey::SHIFT}, | |
219 {DomCode::SUPER, DomKey::SUPER}, | |
220 {DomCode::TAB, DomKey::TAB, 0x0009}, | |
221 {DomCode::UNDO, DomKey::UNDO}, | |
222 // {DomCode::VOICE_COMMAND, DomKey::_} | |
223 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN}, | |
224 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE}, | |
225 {DomCode::VOLUME_UP, DomKey::VOLUME_UP}, | |
226 {DomCode::WAKE_UP, DomKey::WAKE_UP}, | |
227 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE}, | |
228 }; | |
229 | |
230 // TODO(kpschoedel): move this to a shared location. | |
231 // Map DOM Level 3 .key values to legacy Windows-based VKEY values. | |
232 // This applies to non-printable keys. | |
233 KeyboardCode DomKeyToKeyboardCode(DomKey dom_key) { | |
234 switch (dom_key) { | 225 switch (dom_key) { |
235 // No value. | 226 // No value. |
236 case DomKey::NONE: | 227 case DomKey::NONE: |
237 return VKEY_UNKNOWN; | 228 return VKEY_UNKNOWN; |
| 229 // Character values. |
238 // Special Key Values | 230 // Special Key Values |
239 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special | 231 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special |
240 case DomKey::UNIDENTIFIED: | 232 case DomKey::UNIDENTIFIED: |
241 return VKEY_UNKNOWN; | 233 return VKEY_UNKNOWN; |
242 // Modifier Keys | 234 // Modifier Keys |
243 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier | 235 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier |
244 case DomKey::ALT: | 236 case DomKey::ALT: |
245 return VKEY_MENU; | 237 return VKEY_MENU; |
246 case DomKey::ALT_GRAPH: | 238 case DomKey::ALT_GRAPH: |
247 return VKEY_ALTGR; | 239 return VKEY_ALTGR; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // Device Keys | 314 // Device Keys |
323 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device | 315 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device |
324 case DomKey::BRIGHTNESS_DOWN: | 316 case DomKey::BRIGHTNESS_DOWN: |
325 return VKEY_BRIGHTNESS_DOWN; | 317 return VKEY_BRIGHTNESS_DOWN; |
326 case DomKey::BRIGHTNESS_UP: | 318 case DomKey::BRIGHTNESS_UP: |
327 return VKEY_BRIGHTNESS_UP; | 319 return VKEY_BRIGHTNESS_UP; |
328 case DomKey::POWER: | 320 case DomKey::POWER: |
329 return VKEY_POWER; | 321 return VKEY_POWER; |
330 case DomKey::PRINT_SCREEN: | 322 case DomKey::PRINT_SCREEN: |
331 return VKEY_SNAPSHOT; | 323 return VKEY_SNAPSHOT; |
332 // IME and Composition Keys | 324 // IME and Composition Keys |
333 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition | 325 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition |
334 #if 0 // TODO(kpschoedel) | 326 #if 0 // TODO(kpschoedel) |
335 case DomKey::COMPOSE: | 327 case DomKey::COMPOSE: |
336 return VKEY_COMPOSE; | 328 return VKEY_COMPOSE; |
337 #endif | 329 #endif |
338 case DomKey::CONVERT: | 330 case DomKey::CONVERT: |
339 return VKEY_CONVERT; | 331 return VKEY_CONVERT; |
340 case DomKey::FINAL_MODE: | 332 case DomKey::FINAL_MODE: |
341 return VKEY_FINAL; | 333 return VKEY_FINAL; |
342 case DomKey::MODE_CHANGE: | 334 case DomKey::MODE_CHANGE: |
343 return VKEY_MODECHANGE; | 335 return VKEY_MODECHANGE; |
344 case DomKey::NON_CONVERT: | 336 case DomKey::NON_CONVERT: |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // Media Controller Keys | 452 // Media Controller Keys |
461 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller | 453 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller |
462 case DomKey::ZOOM_TOGGLE: | 454 case DomKey::ZOOM_TOGGLE: |
463 return VKEY_ZOOM; | 455 return VKEY_ZOOM; |
464 // No value. | 456 // No value. |
465 default: | 457 default: |
466 return VKEY_UNKNOWN; | 458 return VKEY_UNKNOWN; |
467 } | 459 } |
468 } | 460 } |
469 | 461 |
470 // TODO(kpschoedel): move this to a shared location. | 462 // Determine the non-located VKEY corresponding to a located VKEY. |
471 // This table maps DOM Level 3 .code values to legacy Windows-based VKEY | 463 ui::KeyboardCode DeLocateKeyboardCode(ui::KeyboardCode key_code) { |
472 // values, where the VKEYs are interpreted positionally. | 464 switch (key_code) { |
473 const struct DomCodeToKeyboardCodeEntry { | 465 case VKEY_RWIN: |
474 DomCode dom_code; | 466 return VKEY_LWIN; |
475 KeyboardCode key_code; | 467 case VKEY_LSHIFT: |
476 } dom_code_to_keyboard_code[] = { | 468 case VKEY_RSHIFT: |
477 // Entries are ordered by numeric value of the DomCode enum, | 469 return VKEY_SHIFT; |
478 // which is the USB physical key code. | 470 case VKEY_LCONTROL: |
479 // DomCode::HYPER 0x000010 Hyper | 471 case VKEY_RCONTROL: |
480 // DomCode::SUPER 0x000011 Super | 472 return VKEY_CONTROL; |
481 // DomCode::FN 0x000012 Fn | 473 case VKEY_LMENU: |
482 // DomCode::FN_LOCK 0x000013 FLock | 474 case VKEY_RMENU: |
483 // DomCode::SUSPEND 0x000014 Suspend | 475 return VKEY_MENU; |
484 // DomCode::RESUME 0x000015 Resume | 476 default: |
485 // DomCode::TURBO 0x000016 Turbo | 477 return key_code; |
486 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep | 478 } |
487 // DomCode::WAKE_UP 0x010083 WakeUp | |
488 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA | |
489 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB | |
490 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC | |
491 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD | |
492 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE | |
493 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF | |
494 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG | |
495 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH | |
496 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI | |
497 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ | |
498 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK | |
499 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL | |
500 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM | |
501 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN | |
502 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO | |
503 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP | |
504 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ | |
505 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR | |
506 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS | |
507 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT | |
508 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU | |
509 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV | |
510 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW | |
511 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX | |
512 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY | |
513 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ | |
514 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1 | |
515 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2 | |
516 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3 | |
517 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4 | |
518 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5 | |
519 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6 | |
520 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7 | |
521 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8 | |
522 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9 | |
523 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0 | |
524 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter | |
525 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape | |
526 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace | |
527 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab | |
528 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space | |
529 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus | |
530 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal | |
531 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft | |
532 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight | |
533 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash | |
534 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash | |
535 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon | |
536 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote | |
537 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote | |
538 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma | |
539 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period | |
540 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash | |
541 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock | |
542 {DomCode::F1, VKEY_F1}, // 0x07003A F1 | |
543 {DomCode::F2, VKEY_F2}, // 0x07003B F2 | |
544 {DomCode::F3, VKEY_F3}, // 0x07003C F3 | |
545 {DomCode::F4, VKEY_F4}, // 0x07003D F4 | |
546 {DomCode::F5, VKEY_F5}, // 0x07003E F5 | |
547 {DomCode::F6, VKEY_F6}, // 0x07003F F6 | |
548 {DomCode::F7, VKEY_F7}, // 0x070040 F7 | |
549 {DomCode::F8, VKEY_F8}, // 0x070041 F8 | |
550 {DomCode::F9, VKEY_F9}, // 0x070042 F9 | |
551 {DomCode::F10, VKEY_F10}, // 0x070043 F10 | |
552 {DomCode::F11, VKEY_F11}, // 0x070044 F11 | |
553 {DomCode::F12, VKEY_F12}, // 0x070045 F12 | |
554 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen | |
555 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock | |
556 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause | |
557 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert | |
558 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home | |
559 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp | |
560 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete | |
561 {DomCode::END, VKEY_END}, // 0x07004D End | |
562 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown | |
563 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight | |
564 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft | |
565 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown | |
566 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp | |
567 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock | |
568 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide | |
569 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply | |
570 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract | |
571 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd | |
572 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter | |
573 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1 | |
574 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2 | |
575 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3 | |
576 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4 | |
577 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5 | |
578 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6 | |
579 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7 | |
580 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8 | |
581 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9 | |
582 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0 | |
583 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal | |
584 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash | |
585 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu | |
586 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power | |
587 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual | |
588 // DomCode::OPEN 0x070074 Open | |
589 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help | |
590 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select | |
591 // DomCode::AGAIN 0x070079 Again | |
592 // DomCode::UNDO 0x07007A Undo | |
593 // DomCode::CUT 0x07007B Cut | |
594 // DomCode::COPY 0x07007C Copy | |
595 // DomCode::PASTE 0x07007D Paste | |
596 // DomCode::FIND 0x07007E Find | |
597 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute | |
598 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp | |
599 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown | |
600 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma | |
601 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo | |
602 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode | |
603 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen | |
604 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert | |
605 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert | |
606 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1 | |
607 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2 | |
608 // DomCode::LANG3 0x070092 Lang3 | |
609 // DomCode::LANG4 0x070093 Lang4 | |
610 // DomCode::LANG5 0x070094 Lang5 | |
611 // DomCode::ABORT 0x07009B Abort | |
612 // DomCode::PROPS 0x0700A3 Props | |
613 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft | |
614 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight | |
615 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace | |
616 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore | |
617 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall | |
618 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear | |
619 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd | |
620 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4 | |
621 // NumpadMemorySubtract | |
622 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear | |
623 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry | |
624 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft | |
625 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft | |
626 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft | |
627 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft | |
628 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight | |
629 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight | |
630 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight | |
631 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight | |
632 {DomCode::MEDIA_TRACK_NEXT, | |
633 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext | |
634 {DomCode::MEDIA_TRACK_PREVIOUS, | |
635 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious | |
636 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop | |
637 // DomCode::EJECT 0x0C00B8 Eject | |
638 {DomCode::MEDIA_PLAY_PAUSE, | |
639 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause | |
640 {DomCode::MEDIA_SELECT, | |
641 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect | |
642 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail | |
643 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2 | |
644 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1 | |
645 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch | |
646 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome | |
647 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack | |
648 {DomCode::BROWSER_FORWARD, | |
649 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward | |
650 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop | |
651 {DomCode::BROWSER_REFRESH, | |
652 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh | |
653 {DomCode::BROWSER_FAVORITES, | |
654 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites | |
655 }; | |
656 | |
657 // TODO(kpschoedel): move this to a shared location. | |
658 // Map DOM Level 3 .code values to legacy Windows-based VKEY values, | |
659 // where the VKEYs are interpreted positionally. | |
660 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { | |
661 const DomCodeToKeyboardCodeEntry* end = | |
662 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code); | |
663 const DomCodeToKeyboardCodeEntry* found = | |
664 std::lower_bound(dom_code_to_keyboard_code, end, dom_code, | |
665 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { | |
666 return static_cast<int>(a.dom_code) < static_cast<int>(b); | |
667 }); | |
668 if ((found != end) && (found->dom_code == dom_code)) | |
669 return found->key_code; | |
670 return VKEY_UNKNOWN; | |
671 } | 479 } |
672 | 480 |
673 // TODO(kpschoedel): move this to a shared location. | 481 bool LookupControlCharacter(DomCode dom_code, |
674 bool ControlCharacter(DomCode dom_code, | 482 int flags, |
675 DomKey* dom_key, | 483 DomKey* dom_key, |
676 base::char16* character) { | 484 base::char16* character, |
| 485 KeyboardCode* key_code) { |
| 486 if ((flags & EF_CONTROL_DOWN) == 0) |
| 487 return false; |
| 488 |
677 int code = static_cast<int>(dom_code); | 489 int code = static_cast<int>(dom_code); |
678 const int kKeyA = static_cast<int>(DomCode::KEY_A); | 490 const int kKeyA = static_cast<int>(DomCode::KEY_A); |
679 // Control-A - Control-Z map to 0x01 - 0x1A. | 491 // Control-A - Control-Z map to 0x01 - 0x1A. |
680 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { | 492 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { |
681 *character = static_cast<base::char16>(code - kKeyA + 1); | 493 *character = static_cast<base::char16>(code - kKeyA + 1); |
| 494 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A); |
682 switch (dom_code) { | 495 switch (dom_code) { |
683 case DomCode::KEY_H: | 496 case DomCode::KEY_H: |
684 *dom_key = DomKey::BACKSPACE; | 497 *dom_key = DomKey::BACKSPACE; |
685 case DomCode::KEY_I: | 498 case DomCode::KEY_I: |
686 *dom_key = DomKey::TAB; | 499 *dom_key = DomKey::TAB; |
687 case DomCode::KEY_M: | 500 case DomCode::KEY_M: |
688 *dom_key = DomKey::ENTER; | 501 *dom_key = DomKey::ENTER; |
689 default: | 502 default: |
690 *dom_key = DomKey::CHARACTER; | 503 *dom_key = DomKey::CHARACTER; |
691 } | 504 } |
692 return true; | 505 return true; |
693 } | 506 } |
| 507 |
694 switch (dom_code) { | 508 switch (dom_code) { |
695 case DomCode::DIGIT2: | 509 case DomCode::DIGIT2: |
696 // NUL | 510 // NUL |
697 *character = 0; | 511 *character = 0; |
698 *dom_key = DomKey::CHARACTER; | 512 *dom_key = DomKey::CHARACTER; |
| 513 *key_code = VKEY_2; |
699 return true; | 514 return true; |
700 case DomCode::ENTER: | 515 case DomCode::ENTER: |
701 // NL | 516 // NL |
702 *character = 0x0A; | 517 *character = 0x0A; |
703 *dom_key = DomKey::CHARACTER; | 518 *dom_key = DomKey::CHARACTER; |
| 519 *key_code = VKEY_RETURN; |
704 return true; | 520 return true; |
705 case DomCode::BRACKET_LEFT: | 521 case DomCode::BRACKET_LEFT: |
706 // ESC | 522 // ESC |
707 *character = 0x1B; | 523 *character = 0x1B; |
708 *dom_key = DomKey::ESCAPE; | 524 *dom_key = DomKey::ESCAPE; |
| 525 *key_code = VKEY_OEM_4; |
709 return true; | 526 return true; |
710 case DomCode::BACKSLASH: | 527 case DomCode::BACKSLASH: |
711 // FS | 528 // FS |
712 *character = 0x1C; | 529 *character = 0x1C; |
713 *dom_key = DomKey::CHARACTER; | 530 *dom_key = DomKey::CHARACTER; |
| 531 *key_code = VKEY_OEM_5; |
714 return true; | 532 return true; |
715 case DomCode::BRACKET_RIGHT: | 533 case DomCode::BRACKET_RIGHT: |
716 // GS | 534 // GS |
717 *character = 0x1D; | 535 *character = 0x1D; |
718 *dom_key = DomKey::CHARACTER; | 536 *dom_key = DomKey::CHARACTER; |
| 537 *key_code = VKEY_OEM_6; |
719 return true; | 538 return true; |
720 case DomCode::DIGIT6: | 539 case DomCode::DIGIT6: |
721 // RS | 540 // RS |
722 *character = 0x1E; | 541 *character = 0x1E; |
723 *dom_key = DomKey::CHARACTER; | 542 *dom_key = DomKey::CHARACTER; |
| 543 *key_code = VKEY_6; |
724 return true; | 544 return true; |
725 case DomCode::MINUS: | 545 case DomCode::MINUS: |
726 // US | 546 // US |
727 *character = 0x1F; | 547 *character = 0x1F; |
728 *dom_key = DomKey::CHARACTER; | 548 *dom_key = DomKey::CHARACTER; |
| 549 *key_code = VKEY_OEM_MINUS; |
729 return true; | 550 return true; |
730 default: | 551 default: |
731 return false; | 552 return false; |
732 } | 553 } |
733 } | 554 } |
734 | 555 |
735 } // anonymous namespace | |
736 | |
737 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() { | |
738 } | |
739 | |
740 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() { | |
741 } | |
742 | |
743 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const { | |
744 return false; | |
745 } | |
746 | |
747 bool StubKeyboardLayoutEngine::SetCurrentLayoutByName( | |
748 const std::string& layout_name) { | |
749 return false; | |
750 } | |
751 | |
752 bool StubKeyboardLayoutEngine::UsesISOLevel5Shift() const { | |
753 return false; | |
754 } | |
755 | |
756 bool StubKeyboardLayoutEngine::UsesAltGr() const { | |
757 return true; | |
758 } | |
759 | |
760 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code, | |
761 int flags, | |
762 DomKey* out_dom_key, | |
763 base::char16* out_character, | |
764 KeyboardCode* out_key_code) const { | |
765 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { | |
766 if (ControlCharacter(dom_code, out_dom_key, out_character)) { | |
767 *out_key_code = DomCodeToKeyboardCode(dom_code); | |
768 return true; | |
769 } | |
770 } else { | |
771 for (size_t i = 0; i < arraysize(printable_code_map); ++i) { | |
772 const PrintableCodeEntry* e = &printable_code_map[i]; | |
773 if (e->dom_code == dom_code) { | |
774 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) | | |
775 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN); | |
776 base::char16 ch = e->character[state]; | |
777 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER; | |
778 *out_character = ch; | |
779 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) { | |
780 ch = (ch & ~DK) | 0x20; | |
781 if ((ch >= 'a') && (ch <= 'z')) | |
782 *out_character = e->character[state ^ 1]; | |
783 } | |
784 *out_key_code = DomCodeToKeyboardCode(dom_code); | |
785 return true; | |
786 } | |
787 } | |
788 } | |
789 | |
790 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) { | |
791 const NonPrintableCodeEntry* e = &non_printable_code_map[i]; | |
792 if (e->dom_code == dom_code) { | |
793 *out_dom_key = e->dom_key; | |
794 *out_character = e->character; | |
795 *out_key_code = DomKeyToKeyboardCode(e->dom_key); | |
796 return true; | |
797 } | |
798 } | |
799 | |
800 return false; | |
801 } | |
802 | |
803 } // namespace ui | 556 } // namespace ui |
OLD | NEW |