OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/keycodes/dom4/keycode_converter.h" | 5 #include "ui/events/keycodes/dom4/keycode_converter.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ui/events/keycodes/dom3/dom_code.h" |
| 10 #include "ui/events/keycodes/dom3/dom_key.h" |
| 11 |
7 namespace ui { | 12 namespace ui { |
8 | 13 |
9 namespace { | 14 namespace { |
10 | 15 |
11 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
12 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code} | 17 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code} |
13 #elif defined(OS_LINUX) | 18 #elif defined(OS_LINUX) |
14 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code} | 19 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code} |
15 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
16 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code} | 21 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code} |
17 #else | 22 #else |
18 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code} | 23 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code} |
19 #endif | 24 #endif |
20 #include "ui/events/keycodes/dom4/keycode_converter_data.h" | 25 #include "ui/events/keycodes/dom4/keycode_converter_data.h" |
21 | 26 |
22 const size_t kKeycodeMapEntries = arraysize(usb_keycode_map); | 27 const size_t kKeycodeMapEntries = arraysize(usb_keycode_map); |
23 | 28 |
| 29 // Mappings from string to enumeration value for DOM |code| and |key|. |
| 30 template <typename T> |
| 31 struct DomKeyCodeEntry { |
| 32 const char* string; |
| 33 T enumeration; |
| 34 |
| 35 // Table search operations. |
| 36 static bool CompareStrings(const DomKeyCodeEntry<T>& a, |
| 37 const DomKeyCodeEntry<T>& b) { |
| 38 if (!a.string) |
| 39 return false; |
| 40 if (!b.string) |
| 41 return true; |
| 42 return strcmp(a.string, b.string) < 0; |
| 43 } |
| 44 static T Map(const DomKeyCodeEntry<T>* begin, |
| 45 const DomKeyCodeEntry<T>* end, |
| 46 const char* s) { |
| 47 if (s) { |
| 48 const DomKeyCodeEntry<T> key = {s, T::NONE}; |
| 49 const DomKeyCodeEntry<T>* found = |
| 50 std::lower_bound(begin, end, key, CompareStrings); |
| 51 if (found && found->string && strcmp(found->string, s) == 0) |
| 52 return found->enumeration; |
| 53 } |
| 54 return T::NONE; |
| 55 } |
| 56 }; |
| 57 |
| 58 const DomKeyCodeEntry<DomCode> dom_code_by_string[] = { |
| 59 // This table is in ASCII order, which can be maintained by 'LANG=C sort'. |
| 60 {"", DomCode::NONE}, |
| 61 {"Abort", DomCode::ABORT}, |
| 62 {"Again", DomCode::AGAIN}, |
| 63 {"AltLeft", DomCode::ALT_LEFT}, |
| 64 {"AltRight", DomCode::ALT_RIGHT}, |
| 65 {"ArrowDown", DomCode::ARROW_DOWN}, |
| 66 {"ArrowLeft", DomCode::ARROW_LEFT}, |
| 67 {"ArrowRight", DomCode::ARROW_RIGHT}, |
| 68 {"ArrowUp", DomCode::ARROW_UP}, |
| 69 {"Backquote", DomCode::BACKQUOTE}, |
| 70 {"Backslash", DomCode::BACKSLASH}, |
| 71 {"Backspace", DomCode::BACKSPACE}, |
| 72 {"BracketLeft", DomCode::BRACKET_LEFT}, |
| 73 {"BracketRight", DomCode::BRACKET_RIGHT}, |
| 74 {"BrowserBack", DomCode::BROWSER_BACK}, |
| 75 {"BrowserFavorites", DomCode::BROWSER_FAVORITES}, |
| 76 {"BrowserForward", DomCode::BROWSER_FORWARD}, |
| 77 {"BrowserHome", DomCode::BROWSER_HOME}, |
| 78 {"BrowserRefresh", DomCode::BROWSER_REFRESH}, |
| 79 {"BrowserSearch", DomCode::BROWSER_SEARCH}, |
| 80 {"BrowserStop", DomCode::BROWSER_STOP}, |
| 81 {"CapsLock", DomCode::CAPS_LOCK}, |
| 82 {"Comma", DomCode::COMMA}, |
| 83 {"ContextMenu", DomCode::CONTEXT_MENU}, |
| 84 {"ControlLeft", DomCode::CONTROL_LEFT}, |
| 85 {"ControlRight", DomCode::CONTROL_RIGHT}, |
| 86 {"Convert", DomCode::CONVERT}, |
| 87 {"Copy", DomCode::COPY}, |
| 88 {"Cut", DomCode::CUT}, |
| 89 {"Delete", DomCode::DELETE}, |
| 90 {"Digit0", DomCode::DIGIT0}, |
| 91 {"Digit1", DomCode::DIGIT1}, |
| 92 {"Digit2", DomCode::DIGIT2}, |
| 93 {"Digit3", DomCode::DIGIT3}, |
| 94 {"Digit4", DomCode::DIGIT4}, |
| 95 {"Digit5", DomCode::DIGIT5}, |
| 96 {"Digit6", DomCode::DIGIT6}, |
| 97 {"Digit7", DomCode::DIGIT7}, |
| 98 {"Digit8", DomCode::DIGIT8}, |
| 99 {"Digit9", DomCode::DIGIT9}, |
| 100 {"Eject", DomCode::EJECT}, |
| 101 {"End", DomCode::END}, |
| 102 {"Enter", DomCode::ENTER}, |
| 103 {"Equal", DomCode::EQUAL}, |
| 104 {"Escape", DomCode::ESCAPE}, |
| 105 {"F1", DomCode::F1}, |
| 106 {"F10", DomCode::F10}, |
| 107 {"F11", DomCode::F11}, |
| 108 {"F12", DomCode::F12}, |
| 109 {"F13", DomCode::F13}, |
| 110 {"F14", DomCode::F14}, |
| 111 {"F15", DomCode::F15}, |
| 112 {"F16", DomCode::F16}, |
| 113 {"F17", DomCode::F17}, |
| 114 {"F18", DomCode::F18}, |
| 115 {"F19", DomCode::F19}, |
| 116 {"F2", DomCode::F2}, |
| 117 {"F20", DomCode::F20}, |
| 118 {"F21", DomCode::F21}, |
| 119 {"F22", DomCode::F22}, |
| 120 {"F23", DomCode::F23}, |
| 121 {"F24", DomCode::F24}, |
| 122 {"F3", DomCode::F3}, |
| 123 {"F4", DomCode::F4}, |
| 124 {"F5", DomCode::F5}, |
| 125 {"F6", DomCode::F6}, |
| 126 {"F7", DomCode::F7}, |
| 127 {"F8", DomCode::F8}, |
| 128 {"F9", DomCode::F9}, |
| 129 {"FLock", DomCode::FN_LOCK}, |
| 130 {"Find", DomCode::FIND}, |
| 131 {"Fn", DomCode::FN}, |
| 132 {"Help", DomCode::HELP}, |
| 133 {"Home", DomCode::HOME}, |
| 134 {"Hyper", DomCode::HYPER}, |
| 135 {"Insert", DomCode::INSERT}, |
| 136 {"IntlBackslash", DomCode::INTL_BACKSLASH}, |
| 137 {"IntlHash", DomCode::INTL_HASH}, |
| 138 {"IntlRo", DomCode::INTL_RO}, |
| 139 {"IntlYen", DomCode::INTL_YEN}, |
| 140 {"KanaMode", DomCode::KANA_MODE}, |
| 141 {"KeyA", DomCode::KEY_A}, |
| 142 {"KeyB", DomCode::KEY_B}, |
| 143 {"KeyC", DomCode::KEY_C}, |
| 144 {"KeyD", DomCode::KEY_D}, |
| 145 {"KeyE", DomCode::KEY_E}, |
| 146 {"KeyF", DomCode::KEY_F}, |
| 147 {"KeyG", DomCode::KEY_G}, |
| 148 {"KeyH", DomCode::KEY_H}, |
| 149 {"KeyI", DomCode::KEY_I}, |
| 150 {"KeyJ", DomCode::KEY_J}, |
| 151 {"KeyK", DomCode::KEY_K}, |
| 152 {"KeyL", DomCode::KEY_L}, |
| 153 {"KeyM", DomCode::KEY_M}, |
| 154 {"KeyN", DomCode::KEY_N}, |
| 155 {"KeyO", DomCode::KEY_O}, |
| 156 {"KeyP", DomCode::KEY_P}, |
| 157 {"KeyQ", DomCode::KEY_Q}, |
| 158 {"KeyR", DomCode::KEY_R}, |
| 159 {"KeyS", DomCode::KEY_S}, |
| 160 {"KeyT", DomCode::KEY_T}, |
| 161 {"KeyU", DomCode::KEY_U}, |
| 162 {"KeyV", DomCode::KEY_V}, |
| 163 {"KeyW", DomCode::KEY_W}, |
| 164 {"KeyX", DomCode::KEY_X}, |
| 165 {"KeyY", DomCode::KEY_Y}, |
| 166 {"KeyZ", DomCode::KEY_Z}, |
| 167 {"Lang1", DomCode::LANG1}, |
| 168 {"Lang2", DomCode::LANG2}, |
| 169 {"Lang3", DomCode::LANG3}, |
| 170 {"Lang4", DomCode::LANG4}, |
| 171 {"Lang5", DomCode::LANG5}, |
| 172 {"LaunchApp1", DomCode::LAUNCH_APP1}, |
| 173 {"LaunchApp2", DomCode::LAUNCH_APP2}, |
| 174 {"LaunchMail", DomCode::LAUNCH_MAIL}, |
| 175 {"MediaPlayPause", DomCode::MEDIA_PLAY_PAUSE}, |
| 176 {"MediaSelect", DomCode::MEDIA_SELECT}, |
| 177 {"MediaStop", DomCode::MEDIA_STOP}, |
| 178 {"MediaTrackNext", DomCode::MEDIA_TRACK_NEXT}, |
| 179 {"MediaTrackPrevious", DomCode::MEDIA_TRACK_PREVIOUS}, |
| 180 {"Minus", DomCode::MINUS}, |
| 181 {"NonConvert", DomCode::NON_CONVERT}, |
| 182 {"NumLock", DomCode::NUM_LOCK}, |
| 183 {"Numpad0", DomCode::NUMPAD0}, |
| 184 {"Numpad1", DomCode::NUMPAD1}, |
| 185 {"Numpad2", DomCode::NUMPAD2}, |
| 186 {"Numpad3", DomCode::NUMPAD3}, |
| 187 {"Numpad4", DomCode::NUMPAD4}, |
| 188 {"Numpad5", DomCode::NUMPAD5}, |
| 189 {"Numpad6", DomCode::NUMPAD6}, |
| 190 {"Numpad7", DomCode::NUMPAD7}, |
| 191 {"Numpad8", DomCode::NUMPAD8}, |
| 192 {"Numpad9", DomCode::NUMPAD9}, |
| 193 {"NumpadAdd", DomCode::NUMPAD_ADD}, |
| 194 {"NumpadBackspace", DomCode::NUMPAD_BACKSPACE}, |
| 195 {"NumpadClear", DomCode::NUMPAD_CLEAR}, |
| 196 {"NumpadClearEntry", DomCode::NUMPAD_CLEAR_ENTRY}, |
| 197 {"NumpadComma", DomCode::NUMPAD_COMMA}, |
| 198 {"NumpadDecimal", DomCode::NUMPAD_DECIMAL}, |
| 199 {"NumpadDivide", DomCode::NUMPAD_DIVIDE}, |
| 200 {"NumpadEnter", DomCode::NUMPAD_ENTER}, |
| 201 {"NumpadEqual", DomCode::NUMPAD_EQUAL}, |
| 202 {"NumpadMemoryAdd", DomCode::NUMPAD_MEMORY_ADD}, |
| 203 {"NumpadMemoryClear", DomCode::NUMPAD_MEMORY_CLEAR}, |
| 204 {"NumpadMemoryRecall", DomCode::NUMPAD_MEMORY_RECALL}, |
| 205 {"NumpadMemoryStore", DomCode::NUMPAD_MEMORY_STORE}, |
| 206 {"NumpadMemorySubtract", DomCode::NUMPAD_MEMORY_SUBTRACT}, |
| 207 {"NumpadMultiply", DomCode::NUMPAD_MULTIPLY}, |
| 208 {"NumpadParenLeft", DomCode::NUMPAD_PAREN_LEFT}, |
| 209 {"NumpadParenRight", DomCode::NUMPAD_PAREN_RIGHT}, |
| 210 {"NumpadSubtract", DomCode::NUMPAD_SUBTRACT}, |
| 211 {"OSLeft", DomCode::OS_LEFT}, |
| 212 {"OSRight", DomCode::OS_RIGHT}, |
| 213 {"Open", DomCode::OPEN}, |
| 214 {"PageDown", DomCode::PAGE_DOWN}, |
| 215 {"PageUp", DomCode::PAGE_UP}, |
| 216 {"Paste", DomCode::PASTE}, |
| 217 {"Pause", DomCode::PAUSE}, |
| 218 {"Period", DomCode::PERIOD}, |
| 219 {"Power", DomCode::POWER}, |
| 220 {"PrintScreen", DomCode::PRINT_SCREEN}, |
| 221 {"Props", DomCode::PROPS}, |
| 222 {"Quote", DomCode::QUOTE}, |
| 223 {"Resume", DomCode::RESUME}, |
| 224 {"ScrollLock", DomCode::SCROLL_LOCK}, |
| 225 {"Select", DomCode::SELECT}, |
| 226 {"Semicolon", DomCode::SEMICOLON}, |
| 227 {"ShiftLeft", DomCode::SHIFT_LEFT}, |
| 228 {"ShiftRight", DomCode::SHIFT_RIGHT}, |
| 229 {"Slash", DomCode::SLASH}, |
| 230 {"Sleep", DomCode::SLEEP}, |
| 231 {"Space", DomCode::SPACE}, |
| 232 {"Super", DomCode::SUPER}, |
| 233 {"Suspend", DomCode::SUSPEND}, |
| 234 {"Tab", DomCode::TAB}, |
| 235 {"Turbo", DomCode::TURBO}, |
| 236 {"Undo", DomCode::UNDO}, |
| 237 {"VolumeDown", DomCode::VOLUME_DOWN}, |
| 238 {"VolumeMute", DomCode::VOLUME_MUTE}, |
| 239 {"VolumeUp", DomCode::VOLUME_UP}, |
| 240 {"WakeUp", DomCode::WAKE_UP}, |
| 241 }; |
| 242 |
| 243 const size_t kDomCodeMapEntries = arraysize(dom_code_by_string); |
| 244 |
| 245 const DomKeyCodeEntry<DomKey> dom_key_by_string[] = { |
| 246 // This table is in ASCII order, which can be maintained by 'LANG=C sort'. |
| 247 {"", DomKey::NONE}, |
| 248 {"AVRInput", DomKey::AVR_INPUT}, |
| 249 {"AVRPower", DomKey::AVR_POWER}, |
| 250 {"Accel", DomKey::ACCEL}, |
| 251 {"Accept", DomKey::ACCEPT}, |
| 252 {"Again", DomKey::AGAIN}, |
| 253 {"AllCandidates", DomKey::ALL_CANDIDATES}, |
| 254 {"Alphanumeric", DomKey::ALPHANUMERIC}, |
| 255 {"Alt", DomKey::ALT}, |
| 256 {"AltGraph", DomKey::ALT_GRAPH}, |
| 257 {"ArrowDown", DomKey::ARROW_DOWN}, |
| 258 {"ArrowLeft", DomKey::ARROW_LEFT}, |
| 259 {"ArrowRight", DomKey::ARROW_RIGHT}, |
| 260 {"ArrowUp", DomKey::ARROW_UP}, |
| 261 {"Attn", DomKey::ATTN}, |
| 262 {"AudioBalanceLeft", DomKey::AUDIO_BALANCE_LEFT}, |
| 263 {"AudioBalanceRight", DomKey::AUDIO_BALANCE_RIGHT}, |
| 264 {"AudioBassBoostDown", DomKey::AUDIO_BASS_BOOST_DOWN}, |
| 265 {"AudioBassBoostUp", DomKey::AUDIO_BASS_BOOST_UP}, |
| 266 {"AudioFaderFront", DomKey::AUDIO_FADER_FRONT}, |
| 267 {"AudioFaderRear", DomKey::AUDIO_FADER_REAR}, |
| 268 {"AudioSurroundModeNext", DomKey::AUDIO_SURROUND_MODE_NEXT}, |
| 269 {"Backspace", DomKey::BACKSPACE}, |
| 270 {"BrightnessDown", DomKey::BRIGHTNESS_DOWN}, |
| 271 {"BrightnessUp", DomKey::BRIGHTNESS_UP}, |
| 272 {"BrowserBack", DomKey::BROWSER_BACK}, |
| 273 {"BrowserFavorites", DomKey::BROWSER_FAVORITES}, |
| 274 {"BrowserForward", DomKey::BROWSER_FORWARD}, |
| 275 {"BrowserHome", DomKey::BROWSER_HOME}, |
| 276 {"BrowserRefresh", DomKey::BROWSER_REFRESH}, |
| 277 {"BrowserSearch", DomKey::BROWSER_SEARCH}, |
| 278 {"BrowserStop", DomKey::BROWSER_STOP}, |
| 279 {"Camera", DomKey::CAMERA}, |
| 280 {"Cancel", DomKey::CANCEL}, |
| 281 {"CapsLock", DomKey::CAPS_LOCK}, |
| 282 {"ChannelDown", DomKey::CHANNEL_DOWN}, |
| 283 {"ChannelUp", DomKey::CHANNEL_UP}, |
| 284 {"Clear", DomKey::CLEAR}, |
| 285 {"Close", DomKey::CLOSE}, |
| 286 {"ClosedCaptionToggle", DomKey::CLOSED_CAPTION_TOGGLE}, |
| 287 {"CodeInput", DomKey::CODE_INPUT}, |
| 288 {"ColorF0Red", DomKey::COLOR_F0_RED}, |
| 289 {"ColorF1Green", DomKey::COLOR_F1_GREEN}, |
| 290 {"ColorF2Yellow", DomKey::COLOR_F2_YELLOW}, |
| 291 {"ColorF3Blue", DomKey::COLOR_F3_BLUE}, |
| 292 {"ColorF4Grey", DomKey::COLOR_F4_GREY}, |
| 293 {"ColorF5Brown", DomKey::COLOR_F5_BROWN}, |
| 294 {"Compose", DomKey::COMPOSE}, |
| 295 {"ContextMenu", DomKey::CONTEXT_MENU}, |
| 296 {"Control", DomKey::CONTROL}, |
| 297 {"Convert", DomKey::CONVERT}, |
| 298 {"Copy", DomKey::COPY}, |
| 299 {"CrSel", DomKey::CR_SEL}, |
| 300 {"Cut", DomKey::CUT}, |
| 301 {"Dead", DomKey::DEAD}, |
| 302 {"Delete", DomKey::DELETE}, |
| 303 {"Dimmer", DomKey::DIMMER}, |
| 304 {"DisplaySwap", DomKey::DISPLAY_SWAP}, |
| 305 {"Eisu", DomKey::EISU}, |
| 306 {"Eject", DomKey::EJECT}, |
| 307 {"End", DomKey::END}, |
| 308 {"Enter", DomKey::ENTER}, |
| 309 {"EraseEof", DomKey::ERASE_EOF}, |
| 310 {"Escape", DomKey::ESCAPE}, |
| 311 {"ExSel", DomKey::EX_SEL}, |
| 312 {"Execute", DomKey::EXECUTE}, |
| 313 {"Exit", DomKey::EXIT}, |
| 314 {"F1", DomKey::F1}, |
| 315 {"F10", DomKey::F10}, |
| 316 {"F11", DomKey::F11}, |
| 317 {"F12", DomKey::F12}, |
| 318 {"F13", DomKey::F13}, |
| 319 {"F14", DomKey::F14}, |
| 320 {"F15", DomKey::F15}, |
| 321 {"F16", DomKey::F16}, |
| 322 {"F17", DomKey::F17}, |
| 323 {"F18", DomKey::F18}, |
| 324 {"F19", DomKey::F19}, |
| 325 {"F2", DomKey::F2}, |
| 326 {"F20", DomKey::F20}, |
| 327 {"F21", DomKey::F21}, |
| 328 {"F22", DomKey::F22}, |
| 329 {"F23", DomKey::F23}, |
| 330 {"F24", DomKey::F24}, |
| 331 {"F3", DomKey::F3}, |
| 332 {"F4", DomKey::F4}, |
| 333 {"F5", DomKey::F5}, |
| 334 {"F6", DomKey::F6}, |
| 335 {"F7", DomKey::F7}, |
| 336 {"F8", DomKey::F8}, |
| 337 {"F9", DomKey::F9}, |
| 338 {"FavoriteClear0", DomKey::FAVORITE_CLEAR0}, |
| 339 {"FavoriteClear1", DomKey::FAVORITE_CLEAR1}, |
| 340 {"FavoriteClear2", DomKey::FAVORITE_CLEAR2}, |
| 341 {"FavoriteClear3", DomKey::FAVORITE_CLEAR3}, |
| 342 {"FavoriteRecall0", DomKey::FAVORITE_RECALL0}, |
| 343 {"FavoriteRecall1", DomKey::FAVORITE_RECALL1}, |
| 344 {"FavoriteRecall2", DomKey::FAVORITE_RECALL2}, |
| 345 {"FavoriteRecall3", DomKey::FAVORITE_RECALL3}, |
| 346 {"FavoriteStore0", DomKey::FAVORITE_STORE0}, |
| 347 {"FavoriteStore1", DomKey::FAVORITE_STORE1}, |
| 348 {"FavoriteStore2", DomKey::FAVORITE_STORE2}, |
| 349 {"FavoriteStore3", DomKey::FAVORITE_STORE3}, |
| 350 {"FinalMode", DomKey::FINAL_MODE}, |
| 351 {"Find", DomKey::FIND}, |
| 352 {"Fn", DomKey::FN}, |
| 353 {"FnLock", DomKey::FN_LOCK}, |
| 354 {"GroupFirst", DomKey::GROUP_FIRST}, |
| 355 {"GroupLast", DomKey::GROUP_LAST}, |
| 356 {"GroupNext", DomKey::GROUP_NEXT}, |
| 357 {"GroupPrevious", DomKey::GROUP_PREVIOUS}, |
| 358 {"Guide", DomKey::GUIDE}, |
| 359 {"GuideNextDay", DomKey::GUIDE_NEXT_DAY}, |
| 360 {"GuidePreviousDay", DomKey::GUIDE_PREVIOUS_DAY}, |
| 361 {"HangulMode", DomKey::HANGUL_MODE}, |
| 362 {"HanjaMode", DomKey::HANJA_MODE}, |
| 363 {"Hankaku", DomKey::HANKAKU}, |
| 364 {"Help", DomKey::HELP}, |
| 365 {"Hibernate", DomKey::HIBERNATE}, |
| 366 {"Hiragana", DomKey::HIRAGANA}, |
| 367 {"HiraganaKatakana", DomKey::HIRAGANA_KATAKANA}, |
| 368 {"Home", DomKey::HOME}, |
| 369 {"Hyper", DomKey::HYPER}, |
| 370 {"Info", DomKey::INFO}, |
| 371 {"Insert", DomKey::INSERT}, |
| 372 {"InstantReplay", DomKey::INSTANT_REPLAY}, |
| 373 {"JunjaMode", DomKey::JUNJA_MODE}, |
| 374 {"KanaMode", DomKey::KANA_MODE}, |
| 375 {"KanjiMode", DomKey::KANJI_MODE}, |
| 376 {"Katakana", DomKey::KATAKANA}, |
| 377 {"LaunchCalculator", DomKey::LAUNCH_CALCULATOR}, |
| 378 {"LaunchCalendar", DomKey::LAUNCH_CALENDAR}, |
| 379 {"LaunchMail", DomKey::LAUNCH_MAIL}, |
| 380 {"LaunchMediaPlayer", DomKey::LAUNCH_MEDIA_PLAYER}, |
| 381 {"LaunchMusicPlayer", DomKey::LAUNCH_MUSIC_PLAYER}, |
| 382 {"LaunchMyComputer", DomKey::LAUNCH_MY_COMPUTER}, |
| 383 {"LaunchScreenSaver", DomKey::LAUNCH_SCREEN_SAVER}, |
| 384 {"LaunchSpreadsheet", DomKey::LAUNCH_SPREADSHEET}, |
| 385 {"LaunchWebBrowser", DomKey::LAUNCH_WEB_BROWSER}, |
| 386 {"LaunchWebCam", DomKey::LAUNCH_WEB_CAM}, |
| 387 {"LaunchWordProcessor", DomKey::LAUNCH_WORD_PROCESSOR}, |
| 388 {"Link", DomKey::LINK}, |
| 389 {"ListProgram", DomKey::LIST_PROGRAM}, |
| 390 {"LiveContent", DomKey::LIVE_CONTENT}, |
| 391 {"Lock", DomKey::LOCK}, |
| 392 {"LogOff", DomKey::LOG_OFF}, |
| 393 {"MailForward", DomKey::MAIL_FORWARD}, |
| 394 {"MailReply", DomKey::MAIL_REPLY}, |
| 395 {"MailSend", DomKey::MAIL_SEND}, |
| 396 {"MediaApps", DomKey::MEDIA_APPS}, |
| 397 {"MediaFastForward", DomKey::MEDIA_FAST_FORWARD}, |
| 398 {"MediaLast", DomKey::MEDIA_LAST}, |
| 399 {"MediaPause", DomKey::MEDIA_PAUSE}, |
| 400 {"MediaPlay", DomKey::MEDIA_PLAY}, |
| 401 {"MediaPlayPause", DomKey::MEDIA_PLAY_PAUSE}, |
| 402 {"MediaRecord", DomKey::MEDIA_RECORD}, |
| 403 {"MediaRewind", DomKey::MEDIA_REWIND}, |
| 404 {"MediaSelect", DomKey::MEDIA_SELECT}, |
| 405 {"MediaSkip", DomKey::MEDIA_SKIP}, |
| 406 {"MediaStop", DomKey::MEDIA_STOP}, |
| 407 {"MediaTrackNext", DomKey::MEDIA_TRACK_NEXT}, |
| 408 {"MediaTrackPrevious", DomKey::MEDIA_TRACK_PREVIOUS}, |
| 409 {"Meta", DomKey::META}, |
| 410 {"ModeChange", DomKey::MODE_CHANGE}, |
| 411 {"New", DomKey::NEW}, |
| 412 {"NextCandidate", DomKey::NEXT_CANDIDATE}, |
| 413 {"NextFavoriteChannel", DomKey::NEXT_FAVORITE_CHANNEL}, |
| 414 {"NextUserProfile", DomKey::NEXT_USER_PROFILE}, |
| 415 {"NonConvert", DomKey::NON_CONVERT}, |
| 416 {"NumLock", DomKey::NUM_LOCK}, |
| 417 {"OS", DomKey::OS}, |
| 418 {"OnDemand", DomKey::ON_DEMAND}, |
| 419 {"Open", DomKey::OPEN}, |
| 420 {"PageDown", DomKey::PAGE_DOWN}, |
| 421 {"PageUp", DomKey::PAGE_UP}, |
| 422 {"Paste", DomKey::PASTE}, |
| 423 {"Pause", DomKey::PAUSE}, |
| 424 {"PinPDown", DomKey::PIN_P_DOWN}, |
| 425 {"PinPMove", DomKey::PIN_P_MOVE}, |
| 426 {"PinPToggle", DomKey::PIN_P_TOGGLE}, |
| 427 {"PinPUp", DomKey::PIN_P_UP}, |
| 428 {"Play", DomKey::PLAY}, |
| 429 {"PlaySpeedDown", DomKey::PLAY_SPEED_DOWN}, |
| 430 {"PlaySpeedReset", DomKey::PLAY_SPEED_RESET}, |
| 431 {"PlaySpeedUp", DomKey::PLAY_SPEED_UP}, |
| 432 {"Power", DomKey::POWER}, |
| 433 {"PowerOff", DomKey::POWER_OFF}, |
| 434 {"PreviousCandidate", DomKey::PREVIOUS_CANDIDATE}, |
| 435 {"Print", DomKey::PRINT}, |
| 436 {"PrintScreen", DomKey::PRINT_SCREEN}, |
| 437 {"Process", DomKey::PROCESS}, |
| 438 {"Props", DomKey::PROPS}, |
| 439 {"RandomToggle", DomKey::RANDOM_TOGGLE}, |
| 440 {"RcLowBattery", DomKey::RC_LOW_BATTERY}, |
| 441 {"RecordSpeedNext", DomKey::RECORD_SPEED_NEXT}, |
| 442 {"Redo", DomKey::REDO}, |
| 443 {"RfBypass", DomKey::RF_BYPASS}, |
| 444 {"Romaji", DomKey::ROMAJI}, |
| 445 {"STBInput", DomKey::STB_INPUT}, |
| 446 {"STBPower", DomKey::STB_POWER}, |
| 447 {"Save", DomKey::SAVE}, |
| 448 {"ScanChannelsToggle", DomKey::SCAN_CHANNELS_TOGGLE}, |
| 449 {"ScreenModeNext", DomKey::SCREEN_MODE_NEXT}, |
| 450 {"ScrollLock", DomKey::SCROLL_LOCK}, |
| 451 {"Select", DomKey::SELECT}, |
| 452 {"Separator", DomKey::SEPARATOR}, |
| 453 {"Settings", DomKey::SETTINGS}, |
| 454 {"Shift", DomKey::SHIFT}, |
| 455 {"SingleCandidate", DomKey::SINGLE_CANDIDATE}, |
| 456 {"Soft1", DomKey::SOFT1}, |
| 457 {"Soft2", DomKey::SOFT2}, |
| 458 {"Soft3", DomKey::SOFT3}, |
| 459 {"Soft4", DomKey::SOFT4}, |
| 460 {"Soft5", DomKey::SOFT5}, |
| 461 {"Soft6", DomKey::SOFT6}, |
| 462 {"Soft7", DomKey::SOFT7}, |
| 463 {"Soft8", DomKey::SOFT8}, |
| 464 {"SpellCheck", DomKey::SPELL_CHECK}, |
| 465 {"SplitScreenToggle", DomKey::SPLIT_SCREEN_TOGGLE}, |
| 466 {"Standby", DomKey::STANDBY}, |
| 467 {"Subtitle", DomKey::SUBTITLE}, |
| 468 {"Super", DomKey::SUPER}, |
| 469 {"Symbol", DomKey::SYMBOL}, |
| 470 {"SymbolLock", DomKey::SYMBOL_LOCK}, |
| 471 {"TV", DomKey::TV}, |
| 472 {"TVInput", DomKey::TV_INPUT}, |
| 473 {"TVPower", DomKey::TV_POWER}, |
| 474 {"Tab", DomKey::TAB}, |
| 475 {"Teletext", DomKey::TELETEXT}, |
| 476 {"Undo", DomKey::UNDO}, |
| 477 {"Unidentified", DomKey::UNIDENTIFIED}, |
| 478 {"VideoModeNext", DomKey::VIDEO_MODE_NEXT}, |
| 479 {"VolumeDown", DomKey::VOLUME_DOWN}, |
| 480 {"VolumeMute", DomKey::VOLUME_MUTE}, |
| 481 {"VolumeUp", DomKey::VOLUME_UP}, |
| 482 {"WakeUp", DomKey::WAKE_UP}, |
| 483 {"Wink", DomKey::WINK}, |
| 484 {"Zenkaku", DomKey::ZENKAKU}, |
| 485 {"ZenkakuHankaku", DomKey::ZENKAKU_HANKAKU}, |
| 486 {"ZoomIn", DomKey::ZOOM_IN}, |
| 487 {"ZoomOut", DomKey::ZOOM_OUT}, |
| 488 {"ZoomToggle", DomKey::ZOOM_TOGGLE}, |
| 489 }; |
| 490 |
| 491 const size_t kDomKeyMapEntries = arraysize(dom_key_by_string); |
| 492 |
24 } // namespace | 493 } // namespace |
25 | 494 |
26 // static | 495 // static |
27 size_t KeycodeConverter::NumKeycodeMapEntriesForTest() { | 496 size_t KeycodeConverter::NumKeycodeMapEntriesForTest() { |
28 return kKeycodeMapEntries; | 497 return kKeycodeMapEntries; |
29 } | 498 } |
30 | 499 |
31 // static | 500 // static |
32 const KeycodeMapEntry* KeycodeConverter::GetKeycodeMapForTest() { | 501 const KeycodeMapEntry* KeycodeConverter::GetKeycodeMapForTest() { |
33 return &usb_keycode_map[0]; | 502 return &usb_keycode_map[0]; |
34 } | 503 } |
35 | 504 |
36 // static | 505 // static |
| 506 const char* KeycodeConverter::DomCodeStringForTest(size_t index) { |
| 507 if (index >= kDomCodeMapEntries) |
| 508 return nullptr; |
| 509 return dom_code_by_string[index].string; |
| 510 } |
| 511 |
| 512 // static |
| 513 const char* KeycodeConverter::DomKeyStringForTest(size_t index) { |
| 514 if (index >= kDomKeyMapEntries) |
| 515 return nullptr; |
| 516 return dom_key_by_string[index].string; |
| 517 } |
| 518 |
| 519 // static |
37 uint16_t KeycodeConverter::InvalidNativeKeycode() { | 520 uint16_t KeycodeConverter::InvalidNativeKeycode() { |
38 return usb_keycode_map[0].native_keycode; | 521 return usb_keycode_map[0].native_keycode; |
39 } | 522 } |
40 | 523 |
41 // static | 524 // static |
42 const char* KeycodeConverter::InvalidKeyboardEventCode() { | 525 const char* KeycodeConverter::InvalidKeyboardEventCode() { |
43 return "Unidentified"; | 526 return "Unidentified"; |
44 } | 527 } |
45 | 528 |
46 // static | 529 // static |
47 const char* KeycodeConverter::NativeKeycodeToCode(uint16_t native_keycode) { | 530 const char* KeycodeConverter::DomCodeToCodeString(DomCode dom_code) { |
48 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 531 for (size_t i = 0; i < kDomCodeMapEntries; ++i) { |
49 if (usb_keycode_map[i].native_keycode == native_keycode) { | 532 if (dom_code == dom_code_by_string[i].enumeration) |
50 if (usb_keycode_map[i].code != NULL) | 533 return dom_code_by_string[i].string; |
51 return usb_keycode_map[i].code; | |
52 break; | |
53 } | |
54 } | 534 } |
55 return InvalidKeyboardEventCode(); | 535 return InvalidKeyboardEventCode(); |
56 } | 536 } |
57 | 537 |
58 // static | 538 // static |
59 uint16_t KeycodeConverter::CodeToNativeKeycode(const char* code) { | 539 DomCode KeycodeConverter::CodeStringToDomCode(const char* code) { |
60 if (!code || | 540 return DomKeyCodeEntry<DomCode>::Map( |
61 strcmp(code, InvalidKeyboardEventCode()) == 0) { | 541 dom_code_by_string, |
62 return InvalidNativeKeycode(); | 542 dom_code_by_string + kDomCodeMapEntries, |
| 543 code); |
| 544 } |
| 545 |
| 546 // static |
| 547 DomCode KeycodeConverter::NativeKeycodeToDomCode(uint16_t native_keycode) { |
| 548 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 549 if (usb_keycode_map[i].native_keycode == native_keycode) |
| 550 return usb_keycode_map[i].code; |
63 } | 551 } |
| 552 return DomCode::NONE; |
| 553 } |
64 | 554 |
| 555 // static |
| 556 uint16_t KeycodeConverter::DomCodeToNativeKeycode(DomCode code) { |
65 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 557 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
66 if (usb_keycode_map[i].code && | 558 if (usb_keycode_map[i].code == code) |
67 strcmp(usb_keycode_map[i].code, code) == 0) { | |
68 return usb_keycode_map[i].native_keycode; | 559 return usb_keycode_map[i].native_keycode; |
69 } | |
70 } | 560 } |
71 return InvalidNativeKeycode(); | 561 return InvalidNativeKeycode(); |
72 } | 562 } |
73 | 563 |
| 564 // static |
| 565 const char* KeycodeConverter::NativeKeycodeToCode(uint16_t native_keycode) { |
| 566 return DomCodeToCodeString(NativeKeycodeToDomCode(native_keycode)); |
| 567 } |
| 568 |
| 569 // static |
| 570 uint16_t KeycodeConverter::CodeToNativeKeycode(const char* code_string) { |
| 571 return DomCodeToNativeKeycode(CodeStringToDomCode(code_string)); |
| 572 } |
| 573 |
74 // USB keycodes | 574 // USB keycodes |
75 // Note that USB keycodes are not part of any web standard. | 575 // Note that USB keycodes are not part of any web standard. |
76 // Please don't use USB keycodes in new code. | 576 // Please don't use USB keycodes in new code. |
77 | 577 |
78 // static | 578 // static |
79 uint16_t KeycodeConverter::InvalidUsbKeycode() { | 579 uint16_t KeycodeConverter::InvalidUsbKeycode() { |
80 return static_cast<uint16_t>(usb_keycode_map[0].usb_keycode); | 580 return static_cast<uint16_t>(usb_keycode_map[0].usb_keycode); |
81 } | 581 } |
82 | 582 |
83 // static | 583 // static |
(...skipping 19 matching lines...) Expand all Loading... |
103 if (usb_keycode_map[i].native_keycode == native_keycode) | 603 if (usb_keycode_map[i].native_keycode == native_keycode) |
104 return usb_keycode_map[i].usb_keycode; | 604 return usb_keycode_map[i].usb_keycode; |
105 } | 605 } |
106 return InvalidUsbKeycode(); | 606 return InvalidUsbKeycode(); |
107 } | 607 } |
108 | 608 |
109 // static | 609 // static |
110 const char* KeycodeConverter::UsbKeycodeToCode(uint32_t usb_keycode) { | 610 const char* KeycodeConverter::UsbKeycodeToCode(uint32_t usb_keycode) { |
111 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 611 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
112 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 612 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
113 return usb_keycode_map[i].code; | 613 return DomCodeToCodeString(usb_keycode_map[i].code); |
114 } | 614 } |
115 return InvalidKeyboardEventCode(); | 615 return InvalidKeyboardEventCode(); |
116 } | 616 } |
117 | 617 |
118 // static | 618 // static |
119 uint32_t KeycodeConverter::CodeToUsbKeycode(const char* code) { | 619 uint32_t KeycodeConverter::CodeToUsbKeycode(const char* code_string) { |
120 if (!code || | 620 DomCode code = CodeStringToDomCode(code_string); |
121 strcmp(code, InvalidKeyboardEventCode()) == 0) { | 621 if (code != DomCode::NONE) { |
122 return InvalidUsbKeycode(); | 622 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
123 } | 623 if (usb_keycode_map[i].code == code) { |
124 | 624 return usb_keycode_map[i].usb_keycode; |
125 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 625 } |
126 if (usb_keycode_map[i].code && | |
127 strcmp(usb_keycode_map[i].code, code) == 0) { | |
128 return usb_keycode_map[i].usb_keycode; | |
129 } | 626 } |
130 } | 627 } |
131 return InvalidUsbKeycode(); | 628 return InvalidUsbKeycode(); |
132 } | 629 } |
133 | 630 |
| 631 // static |
| 632 const char* KeycodeConverter::DomKeyToKeyString(DomKey dom_key) { |
| 633 for (size_t i = 0; i < kDomKeyMapEntries; ++i) { |
| 634 if (dom_key == dom_key_by_string[i].enumeration) |
| 635 return dom_key_by_string[i].string; |
| 636 } |
| 637 return dom_key_by_string[0].string; |
| 638 } |
| 639 |
| 640 // static |
| 641 DomKey KeycodeConverter::KeyStringToDomKey(const char* key) { |
| 642 return DomKeyCodeEntry<DomKey>::Map( |
| 643 dom_key_by_string, |
| 644 dom_key_by_string + kDomKeyMapEntries, |
| 645 key); |
| 646 } |
| 647 |
134 } // namespace ui | 648 } // namespace ui |
OLD | NEW |