| 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/layout_util.h" | 5 #include "ui/events/ozone/layout/layout_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "ui/events/event_constants.h" | 7 #include "ui/events/event_constants.h" |
| 10 #include "ui/events/keycodes/dom3/dom_code.h" | |
| 11 #include "ui/events/keycodes/dom3/dom_key.h" | 8 #include "ui/events/keycodes/dom3/dom_key.h" |
| 12 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
| 13 | 9 |
| 14 namespace ui { | 10 namespace ui { |
| 15 | 11 |
| 16 namespace { | |
| 17 | |
| 18 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code | |
| 19 // values to legacy Windows-based VKEY values, where the VKEYs are | |
| 20 // interpreted positionally. | |
| 21 const struct DomCodeToKeyboardCodeEntry { | |
| 22 DomCode dom_code; | |
| 23 KeyboardCode key_code; | |
| 24 } dom_code_to_keyboard_code[] = { | |
| 25 // Entries are ordered by numeric value of the DomCode enum, | |
| 26 // which is the USB physical key code. | |
| 27 // DomCode::HYPER 0x000010 Hyper | |
| 28 // DomCode::SUPER 0x000011 Super | |
| 29 // DomCode::FN 0x000012 Fn | |
| 30 // DomCode::FN_LOCK 0x000013 FLock | |
| 31 // DomCode::SUSPEND 0x000014 Suspend | |
| 32 // DomCode::RESUME 0x000015 Resume | |
| 33 // DomCode::TURBO 0x000016 Turbo | |
| 34 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep | |
| 35 // DomCode::WAKE_UP 0x010083 WakeUp | |
| 36 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA | |
| 37 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB | |
| 38 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC | |
| 39 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD | |
| 40 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE | |
| 41 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF | |
| 42 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG | |
| 43 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH | |
| 44 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI | |
| 45 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ | |
| 46 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK | |
| 47 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL | |
| 48 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM | |
| 49 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN | |
| 50 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO | |
| 51 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP | |
| 52 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ | |
| 53 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR | |
| 54 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS | |
| 55 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT | |
| 56 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU | |
| 57 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV | |
| 58 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW | |
| 59 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX | |
| 60 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY | |
| 61 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ | |
| 62 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1 | |
| 63 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2 | |
| 64 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3 | |
| 65 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4 | |
| 66 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5 | |
| 67 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6 | |
| 68 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7 | |
| 69 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8 | |
| 70 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9 | |
| 71 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0 | |
| 72 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter | |
| 73 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape | |
| 74 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace | |
| 75 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab | |
| 76 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space | |
| 77 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus | |
| 78 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal | |
| 79 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft | |
| 80 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight | |
| 81 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash | |
| 82 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash | |
| 83 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon | |
| 84 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote | |
| 85 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote | |
| 86 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma | |
| 87 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period | |
| 88 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash | |
| 89 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock | |
| 90 {DomCode::F1, VKEY_F1}, // 0x07003A F1 | |
| 91 {DomCode::F2, VKEY_F2}, // 0x07003B F2 | |
| 92 {DomCode::F3, VKEY_F3}, // 0x07003C F3 | |
| 93 {DomCode::F4, VKEY_F4}, // 0x07003D F4 | |
| 94 {DomCode::F5, VKEY_F5}, // 0x07003E F5 | |
| 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 | |
| 203 }; | |
| 204 | |
| 205 } // anonymous namespace | |
| 206 | |
| 207 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. | |
| 208 // The returned VKEY is non-positional (e.g. VKEY_SHIFT). | |
| 209 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) { | |
| 210 switch (dom_key) { | |
| 211 // No value. | |
| 212 case DomKey::NONE: | |
| 213 return VKEY_UNKNOWN; | |
| 214 // Character values. | |
| 215 // Special Key Values | |
| 216 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special | |
| 217 case DomKey::UNIDENTIFIED: | |
| 218 return VKEY_UNKNOWN; | |
| 219 // Modifier Keys | |
| 220 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier | |
| 221 case DomKey::ALT: | |
| 222 return VKEY_MENU; | |
| 223 case DomKey::ALT_GRAPH: | |
| 224 return VKEY_ALTGR; | |
| 225 case DomKey::CAPS_LOCK: | |
| 226 return VKEY_CAPITAL; | |
| 227 case DomKey::CONTROL: | |
| 228 return VKEY_CONTROL; | |
| 229 case DomKey::NUM_LOCK: | |
| 230 return VKEY_NUMLOCK; | |
| 231 case DomKey::OS: | |
| 232 return VKEY_LWIN; | |
| 233 case DomKey::SCROLL_LOCK: | |
| 234 return VKEY_SCROLL; | |
| 235 case DomKey::SHIFT: | |
| 236 return VKEY_SHIFT; | |
| 237 // Whitespace Keys | |
| 238 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace | |
| 239 case DomKey::ENTER: | |
| 240 return VKEY_RETURN; | |
| 241 case DomKey::SEPARATOR: | |
| 242 return VKEY_SEPARATOR; | |
| 243 case DomKey::TAB: | |
| 244 return VKEY_TAB; | |
| 245 // Navigation Keys | |
| 246 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation | |
| 247 case DomKey::ARROW_DOWN: | |
| 248 return VKEY_DOWN; | |
| 249 case DomKey::ARROW_LEFT: | |
| 250 return VKEY_LEFT; | |
| 251 case DomKey::ARROW_RIGHT: | |
| 252 return VKEY_RIGHT; | |
| 253 case DomKey::ARROW_UP: | |
| 254 return VKEY_UP; | |
| 255 case DomKey::END: | |
| 256 return VKEY_END; | |
| 257 case DomKey::HOME: | |
| 258 return VKEY_HOME; | |
| 259 case DomKey::PAGE_DOWN: | |
| 260 return VKEY_NEXT; | |
| 261 case DomKey::PAGE_UP: | |
| 262 return VKEY_PRIOR; | |
| 263 // Editing Keys | |
| 264 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing | |
| 265 case DomKey::BACKSPACE: | |
| 266 return VKEY_BACK; | |
| 267 case DomKey::CLEAR: | |
| 268 return VKEY_CLEAR; | |
| 269 case DomKey::CR_SEL: | |
| 270 return VKEY_CRSEL; | |
| 271 case DomKey::DEL: | |
| 272 return VKEY_DELETE; | |
| 273 case DomKey::ERASE_EOF: | |
| 274 return VKEY_EREOF; | |
| 275 case DomKey::EX_SEL: | |
| 276 return VKEY_EXSEL; | |
| 277 case DomKey::INSERT: | |
| 278 return VKEY_INSERT; | |
| 279 // UI Keys | |
| 280 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui | |
| 281 case DomKey::ACCEPT: | |
| 282 return VKEY_ACCEPT; | |
| 283 case DomKey::ATTN: | |
| 284 return VKEY_ATTN; | |
| 285 case DomKey::CONTEXT_MENU: | |
| 286 return VKEY_APPS; | |
| 287 case DomKey::ESCAPE: | |
| 288 return VKEY_ESCAPE; | |
| 289 case DomKey::EXECUTE: | |
| 290 return VKEY_EXECUTE; | |
| 291 case DomKey::HELP: | |
| 292 return VKEY_HELP; | |
| 293 case DomKey::PAUSE: | |
| 294 return VKEY_PAUSE; | |
| 295 case DomKey::PLAY: | |
| 296 return VKEY_PLAY; | |
| 297 case DomKey::SELECT: | |
| 298 return VKEY_SELECT; | |
| 299 // Device Keys | |
| 300 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device | |
| 301 case DomKey::BRIGHTNESS_DOWN: | |
| 302 return VKEY_BRIGHTNESS_DOWN; | |
| 303 case DomKey::BRIGHTNESS_UP: | |
| 304 return VKEY_BRIGHTNESS_UP; | |
| 305 case DomKey::POWER: | |
| 306 return VKEY_POWER; | |
| 307 case DomKey::PRINT_SCREEN: | |
| 308 return VKEY_SNAPSHOT; | |
| 309 // IME and Composition Keys | |
| 310 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition | |
| 311 #if 0 // TODO(kpschoedel) | |
| 312 case DomKey::COMPOSE: | |
| 313 return VKEY_COMPOSE; | |
| 314 #endif | |
| 315 case DomKey::CONVERT: | |
| 316 return VKEY_CONVERT; | |
| 317 case DomKey::FINAL_MODE: | |
| 318 return VKEY_FINAL; | |
| 319 case DomKey::MODE_CHANGE: | |
| 320 return VKEY_MODECHANGE; | |
| 321 case DomKey::NON_CONVERT: | |
| 322 return VKEY_NONCONVERT; | |
| 323 case DomKey::PROCESS: | |
| 324 return VKEY_PROCESSKEY; | |
| 325 // Keys specific to Korean keyboards | |
| 326 case DomKey::HANGUL_MODE: | |
| 327 return VKEY_HANGUL; | |
| 328 case DomKey::HANJA_MODE: | |
| 329 return VKEY_HANJA; | |
| 330 case DomKey::JUNJA_MODE: | |
| 331 return VKEY_JUNJA; | |
| 332 // Keys specific to Japanese keyboards | |
| 333 case DomKey::HANKAKU: | |
| 334 return VKEY_DBE_SBCSCHAR; | |
| 335 case DomKey::KANA_MODE: | |
| 336 return VKEY_KANA; | |
| 337 case DomKey::KANJI_MODE: | |
| 338 return VKEY_KANJI; | |
| 339 case DomKey::ZENKAKU: | |
| 340 return VKEY_DBE_DBCSCHAR; | |
| 341 case DomKey::ZENKAKU_HANKAKU: | |
| 342 return VKEY_DBE_DBCSCHAR; | |
| 343 // General-Purpose Function Keys | |
| 344 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function | |
| 345 case DomKey::F1: | |
| 346 return VKEY_F1; | |
| 347 case DomKey::F2: | |
| 348 return VKEY_F2; | |
| 349 case DomKey::F3: | |
| 350 return VKEY_F3; | |
| 351 case DomKey::F4: | |
| 352 return VKEY_F4; | |
| 353 case DomKey::F5: | |
| 354 return VKEY_F5; | |
| 355 case DomKey::F6: | |
| 356 return VKEY_F6; | |
| 357 case DomKey::F7: | |
| 358 return VKEY_F7; | |
| 359 case DomKey::F8: | |
| 360 return VKEY_F8; | |
| 361 case DomKey::F9: | |
| 362 return VKEY_F9; | |
| 363 case DomKey::F10: | |
| 364 return VKEY_F10; | |
| 365 case DomKey::F11: | |
| 366 return VKEY_F11; | |
| 367 case DomKey::F12: | |
| 368 return VKEY_F12; | |
| 369 case DomKey::F13: | |
| 370 return VKEY_F13; | |
| 371 case DomKey::F14: | |
| 372 return VKEY_F14; | |
| 373 case DomKey::F15: | |
| 374 return VKEY_F15; | |
| 375 case DomKey::F16: | |
| 376 return VKEY_F16; | |
| 377 case DomKey::F17: | |
| 378 return VKEY_F17; | |
| 379 case DomKey::F18: | |
| 380 return VKEY_F18; | |
| 381 case DomKey::F19: | |
| 382 return VKEY_F19; | |
| 383 case DomKey::F20: | |
| 384 return VKEY_F20; | |
| 385 case DomKey::F21: | |
| 386 return VKEY_F21; | |
| 387 case DomKey::F22: | |
| 388 return VKEY_F22; | |
| 389 case DomKey::F23: | |
| 390 return VKEY_F23; | |
| 391 case DomKey::F24: | |
| 392 return VKEY_F24; | |
| 393 // Multimedia Keys | |
| 394 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia | |
| 395 case DomKey::MEDIA_PLAY_PAUSE: | |
| 396 return VKEY_MEDIA_PLAY_PAUSE; | |
| 397 case DomKey::MEDIA_SELECT: | |
| 398 return VKEY_MEDIA_LAUNCH_MEDIA_SELECT; | |
| 399 case DomKey::MEDIA_STOP: | |
| 400 return VKEY_MEDIA_STOP; | |
| 401 case DomKey::MEDIA_TRACK_NEXT: | |
| 402 return VKEY_MEDIA_NEXT_TRACK; | |
| 403 case DomKey::MEDIA_TRACK_PREVIOUS: | |
| 404 return VKEY_MEDIA_PREV_TRACK; | |
| 405 case DomKey::PRINT: | |
| 406 return VKEY_PRINT; | |
| 407 case DomKey::VOLUME_DOWN: | |
| 408 return VKEY_VOLUME_DOWN; | |
| 409 case DomKey::VOLUME_MUTE: | |
| 410 return VKEY_VOLUME_MUTE; | |
| 411 case DomKey::VOLUME_UP: | |
| 412 return VKEY_VOLUME_UP; | |
| 413 // Application Keys | |
| 414 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps | |
| 415 case DomKey::LAUNCH_CALCULATOR: | |
| 416 return VKEY_MEDIA_LAUNCH_APP2; | |
| 417 case DomKey::LAUNCH_MAIL: | |
| 418 return VKEY_MEDIA_LAUNCH_MAIL; | |
| 419 case DomKey::LAUNCH_MY_COMPUTER: | |
| 420 return VKEY_MEDIA_LAUNCH_APP1; | |
| 421 // Browser Keys | |
| 422 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser | |
| 423 case DomKey::BROWSER_BACK: | |
| 424 return VKEY_BACK; | |
| 425 case DomKey::BROWSER_FAVORITES: | |
| 426 return VKEY_BROWSER_FAVORITES; | |
| 427 case DomKey::BROWSER_FORWARD: | |
| 428 return VKEY_BROWSER_FORWARD; | |
| 429 case DomKey::BROWSER_HOME: | |
| 430 return VKEY_BROWSER_HOME; | |
| 431 case DomKey::BROWSER_REFRESH: | |
| 432 return VKEY_BROWSER_REFRESH; | |
| 433 case DomKey::BROWSER_SEARCH: | |
| 434 return VKEY_BROWSER_SEARCH; | |
| 435 case DomKey::BROWSER_STOP: | |
| 436 return VKEY_BROWSER_STOP; | |
| 437 // Media Controller Keys | |
| 438 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller | |
| 439 case DomKey::ZOOM_TOGGLE: | |
| 440 return VKEY_ZOOM; | |
| 441 // No value. | |
| 442 default: | |
| 443 return VKEY_UNKNOWN; | |
| 444 } | |
| 445 } | |
| 446 | |
| 447 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. | |
| 448 // The returned VKEY is located (e.g. VKEY_LSHIFT). | |
| 449 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { | |
| 450 const DomCodeToKeyboardCodeEntry* end = | |
| 451 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code); | |
| 452 const DomCodeToKeyboardCodeEntry* found = | |
| 453 std::lower_bound(dom_code_to_keyboard_code, end, dom_code, | |
| 454 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { | |
| 455 return static_cast<int>(a.dom_code) < static_cast<int>(b); | |
| 456 }); | |
| 457 if ((found != end) && (found->dom_code == dom_code)) | |
| 458 return found->key_code; | |
| 459 return VKEY_UNKNOWN; | |
| 460 } | |
| 461 | |
| 462 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. | |
| 463 // The returned VKEY is non-located (e.g. VKEY_SHIFT). | |
| 464 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) { | |
| 465 return LocatedToNonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code)); | |
| 466 } | |
| 467 | |
| 468 bool LookupControlCharacter(DomCode dom_code, | |
| 469 int flags, | |
| 470 DomKey* dom_key, | |
| 471 base::char16* character, | |
| 472 KeyboardCode* key_code) { | |
| 473 if ((flags & EF_CONTROL_DOWN) == 0) | |
| 474 return false; | |
| 475 | |
| 476 int code = static_cast<int>(dom_code); | |
| 477 const int kKeyA = static_cast<int>(DomCode::KEY_A); | |
| 478 // Control-A - Control-Z map to 0x01 - 0x1A. | |
| 479 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { | |
| 480 *character = static_cast<base::char16>(code - kKeyA + 1); | |
| 481 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A); | |
| 482 switch (dom_code) { | |
| 483 case DomCode::KEY_H: | |
| 484 *dom_key = DomKey::BACKSPACE; | |
| 485 case DomCode::KEY_I: | |
| 486 *dom_key = DomKey::TAB; | |
| 487 case DomCode::KEY_M: | |
| 488 *dom_key = DomKey::ENTER; | |
| 489 default: | |
| 490 *dom_key = DomKey::CHARACTER; | |
| 491 } | |
| 492 return true; | |
| 493 } | |
| 494 | |
| 495 switch (dom_code) { | |
| 496 case DomCode::DIGIT2: | |
| 497 // NUL | |
| 498 *character = 0; | |
| 499 *dom_key = DomKey::CHARACTER; | |
| 500 *key_code = VKEY_2; | |
| 501 return true; | |
| 502 case DomCode::ENTER: | |
| 503 // NL | |
| 504 *character = 0x0A; | |
| 505 *dom_key = DomKey::CHARACTER; | |
| 506 *key_code = VKEY_RETURN; | |
| 507 return true; | |
| 508 case DomCode::BRACKET_LEFT: | |
| 509 // ESC | |
| 510 *character = 0x1B; | |
| 511 *dom_key = DomKey::ESCAPE; | |
| 512 *key_code = VKEY_OEM_4; | |
| 513 return true; | |
| 514 case DomCode::BACKSLASH: | |
| 515 // FS | |
| 516 *character = 0x1C; | |
| 517 *dom_key = DomKey::CHARACTER; | |
| 518 *key_code = VKEY_OEM_5; | |
| 519 return true; | |
| 520 case DomCode::BRACKET_RIGHT: | |
| 521 // GS | |
| 522 *character = 0x1D; | |
| 523 *dom_key = DomKey::CHARACTER; | |
| 524 *key_code = VKEY_OEM_6; | |
| 525 return true; | |
| 526 case DomCode::DIGIT6: | |
| 527 // RS | |
| 528 *character = 0x1E; | |
| 529 *dom_key = DomKey::CHARACTER; | |
| 530 *key_code = VKEY_6; | |
| 531 return true; | |
| 532 case DomCode::MINUS: | |
| 533 // US | |
| 534 *character = 0x1F; | |
| 535 *dom_key = DomKey::CHARACTER; | |
| 536 *key_code = VKEY_OEM_MINUS; | |
| 537 return true; | |
| 538 default: | |
| 539 return false; | |
| 540 } | |
| 541 } | |
| 542 | |
| 543 int ModifierDomKeyToEventFlag(DomKey key) { | 12 int ModifierDomKeyToEventFlag(DomKey key) { |
| 544 switch (key) { | 13 switch (key) { |
| 545 case DomKey::ALT: | 14 case DomKey::ALT: |
| 546 return EF_ALT_DOWN; | 15 return EF_ALT_DOWN; |
| 547 case DomKey::ALT_GRAPH: | 16 case DomKey::ALT_GRAPH: |
| 548 return EF_ALTGR_DOWN; | 17 return EF_ALTGR_DOWN; |
| 549 case DomKey::CAPS_LOCK: | 18 case DomKey::CAPS_LOCK: |
| 550 return EF_CAPS_LOCK_DOWN; | 19 return EF_CAPS_LOCK_DOWN; |
| 551 case DomKey::CONTROL: | 20 case DomKey::CONTROL: |
| 552 return EF_CONTROL_DOWN; | 21 return EF_CONTROL_DOWN; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 567 // DomKey::ACCEL | 36 // DomKey::ACCEL |
| 568 // DomKey::FN | 37 // DomKey::FN |
| 569 // DomKey::FN_LOCK | 38 // DomKey::FN_LOCK |
| 570 // DomKey::NUM_LOCK | 39 // DomKey::NUM_LOCK |
| 571 // DomKey::SCROLL_LOCK | 40 // DomKey::SCROLL_LOCK |
| 572 // DomKey::SYMBOL | 41 // DomKey::SYMBOL |
| 573 // DomKey::SYMBOL_LOCK | 42 // DomKey::SYMBOL_LOCK |
| 574 } | 43 } |
| 575 | 44 |
| 576 } // namespace ui | 45 } // namespace ui |
| OLD | NEW |