| 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/stub/stub_keyboard_layout_engine.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/events/keycodes/dom3/dom_code.h" | 11 #include "ui/events/keycodes/dom3/dom_code.h" |
| 12 #include "ui/events/keycodes/dom3/dom_key.h" | 12 #include "ui/events/keycodes/dom3/dom_key.h" |
| 13 #include "ui/events/keycodes/keyboard_code_conversion.h" | 13 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 14 #include "ui/events/ozone/layout/layout_util.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // All of the characters have low ordinals, so we use bit 15 to flag dead keys. | 20 // All of the characters have low ordinals, so we use bit 15 to flag dead keys. |
| 20 #define DK 0x8000 | 21 #define DK 0x8000 |
| 21 | 22 |
| 22 const struct PrintableCodeEntry { | 23 const struct PrintableCodeEntry { |
| 23 DomCode dom_code; | 24 DomCode dom_code; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 {DomCode::TAB, DomKey::TAB, 0x0009}, | 221 {DomCode::TAB, DomKey::TAB, 0x0009}, |
| 221 {DomCode::UNDO, DomKey::UNDO}, | 222 {DomCode::UNDO, DomKey::UNDO}, |
| 222 // {DomCode::VOICE_COMMAND, DomKey::_} | 223 // {DomCode::VOICE_COMMAND, DomKey::_} |
| 223 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN}, | 224 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN}, |
| 224 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE}, | 225 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE}, |
| 225 {DomCode::VOLUME_UP, DomKey::VOLUME_UP}, | 226 {DomCode::VOLUME_UP, DomKey::VOLUME_UP}, |
| 226 {DomCode::WAKE_UP, DomKey::WAKE_UP}, | 227 {DomCode::WAKE_UP, DomKey::WAKE_UP}, |
| 227 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE}, | 228 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE}, |
| 228 }; | 229 }; |
| 229 | 230 |
| 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) { | |
| 235 // No value. | |
| 236 case DomKey::NONE: | |
| 237 return VKEY_UNKNOWN; | |
| 238 // Special Key Values | |
| 239 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special | |
| 240 case DomKey::UNIDENTIFIED: | |
| 241 return VKEY_UNKNOWN; | |
| 242 // Modifier Keys | |
| 243 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier | |
| 244 case DomKey::ALT: | |
| 245 return VKEY_MENU; | |
| 246 case DomKey::ALT_GRAPH: | |
| 247 return VKEY_ALTGR; | |
| 248 case DomKey::CAPS_LOCK: | |
| 249 return VKEY_CAPITAL; | |
| 250 case DomKey::CONTROL: | |
| 251 return VKEY_CONTROL; | |
| 252 case DomKey::NUM_LOCK: | |
| 253 return VKEY_NUMLOCK; | |
| 254 case DomKey::OS: | |
| 255 return VKEY_LWIN; | |
| 256 case DomKey::SCROLL_LOCK: | |
| 257 return VKEY_SCROLL; | |
| 258 case DomKey::SHIFT: | |
| 259 return VKEY_SHIFT; | |
| 260 // Whitespace Keys | |
| 261 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace | |
| 262 case DomKey::ENTER: | |
| 263 return VKEY_RETURN; | |
| 264 case DomKey::SEPARATOR: | |
| 265 return VKEY_SEPARATOR; | |
| 266 case DomKey::TAB: | |
| 267 return VKEY_TAB; | |
| 268 // Navigation Keys | |
| 269 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation | |
| 270 case DomKey::ARROW_DOWN: | |
| 271 return VKEY_DOWN; | |
| 272 case DomKey::ARROW_LEFT: | |
| 273 return VKEY_LEFT; | |
| 274 case DomKey::ARROW_RIGHT: | |
| 275 return VKEY_RIGHT; | |
| 276 case DomKey::ARROW_UP: | |
| 277 return VKEY_UP; | |
| 278 case DomKey::END: | |
| 279 return VKEY_END; | |
| 280 case DomKey::HOME: | |
| 281 return VKEY_HOME; | |
| 282 case DomKey::PAGE_DOWN: | |
| 283 return VKEY_NEXT; | |
| 284 case DomKey::PAGE_UP: | |
| 285 return VKEY_PRIOR; | |
| 286 // Editing Keys | |
| 287 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing | |
| 288 case DomKey::BACKSPACE: | |
| 289 return VKEY_BACK; | |
| 290 case DomKey::CLEAR: | |
| 291 return VKEY_CLEAR; | |
| 292 case DomKey::CR_SEL: | |
| 293 return VKEY_CRSEL; | |
| 294 case DomKey::DEL: | |
| 295 return VKEY_DELETE; | |
| 296 case DomKey::ERASE_EOF: | |
| 297 return VKEY_EREOF; | |
| 298 case DomKey::EX_SEL: | |
| 299 return VKEY_EXSEL; | |
| 300 case DomKey::INSERT: | |
| 301 return VKEY_INSERT; | |
| 302 // UI Keys | |
| 303 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui | |
| 304 case DomKey::ACCEPT: | |
| 305 return VKEY_ACCEPT; | |
| 306 case DomKey::ATTN: | |
| 307 return VKEY_ATTN; | |
| 308 case DomKey::CONTEXT_MENU: | |
| 309 return VKEY_APPS; | |
| 310 case DomKey::ESCAPE: | |
| 311 return VKEY_ESCAPE; | |
| 312 case DomKey::EXECUTE: | |
| 313 return VKEY_EXECUTE; | |
| 314 case DomKey::HELP: | |
| 315 return VKEY_HELP; | |
| 316 case DomKey::PAUSE: | |
| 317 return VKEY_PAUSE; | |
| 318 case DomKey::PLAY: | |
| 319 return VKEY_PLAY; | |
| 320 case DomKey::SELECT: | |
| 321 return VKEY_SELECT; | |
| 322 // Device Keys | |
| 323 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device | |
| 324 case DomKey::BRIGHTNESS_DOWN: | |
| 325 return VKEY_BRIGHTNESS_DOWN; | |
| 326 case DomKey::BRIGHTNESS_UP: | |
| 327 return VKEY_BRIGHTNESS_UP; | |
| 328 case DomKey::POWER: | |
| 329 return VKEY_POWER; | |
| 330 case DomKey::PRINT_SCREEN: | |
| 331 return VKEY_SNAPSHOT; | |
| 332 // IME and Composition Keys | |
| 333 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition | |
| 334 #if 0 // TODO(kpschoedel) | |
| 335 case DomKey::COMPOSE: | |
| 336 return VKEY_COMPOSE; | |
| 337 #endif | |
| 338 case DomKey::CONVERT: | |
| 339 return VKEY_CONVERT; | |
| 340 case DomKey::FINAL_MODE: | |
| 341 return VKEY_FINAL; | |
| 342 case DomKey::MODE_CHANGE: | |
| 343 return VKEY_MODECHANGE; | |
| 344 case DomKey::NON_CONVERT: | |
| 345 return VKEY_NONCONVERT; | |
| 346 case DomKey::PROCESS: | |
| 347 return VKEY_PROCESSKEY; | |
| 348 // Keys specific to Korean keyboards | |
| 349 case DomKey::HANGUL_MODE: | |
| 350 return VKEY_HANGUL; | |
| 351 case DomKey::HANJA_MODE: | |
| 352 return VKEY_HANJA; | |
| 353 case DomKey::JUNJA_MODE: | |
| 354 return VKEY_JUNJA; | |
| 355 // Keys specific to Japanese keyboards | |
| 356 case DomKey::HANKAKU: | |
| 357 return VKEY_DBE_SBCSCHAR; | |
| 358 case DomKey::KANA_MODE: | |
| 359 return VKEY_KANA; | |
| 360 case DomKey::KANJI_MODE: | |
| 361 return VKEY_KANJI; | |
| 362 case DomKey::ZENKAKU: | |
| 363 return VKEY_DBE_DBCSCHAR; | |
| 364 case DomKey::ZENKAKU_HANKAKU: | |
| 365 return VKEY_DBE_DBCSCHAR; | |
| 366 // General-Purpose Function Keys | |
| 367 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function | |
| 368 case DomKey::F1: | |
| 369 return VKEY_F1; | |
| 370 case DomKey::F2: | |
| 371 return VKEY_F2; | |
| 372 case DomKey::F3: | |
| 373 return VKEY_F3; | |
| 374 case DomKey::F4: | |
| 375 return VKEY_F4; | |
| 376 case DomKey::F5: | |
| 377 return VKEY_F5; | |
| 378 case DomKey::F6: | |
| 379 return VKEY_F6; | |
| 380 case DomKey::F7: | |
| 381 return VKEY_F7; | |
| 382 case DomKey::F8: | |
| 383 return VKEY_F8; | |
| 384 case DomKey::F9: | |
| 385 return VKEY_F9; | |
| 386 case DomKey::F10: | |
| 387 return VKEY_F10; | |
| 388 case DomKey::F11: | |
| 389 return VKEY_F11; | |
| 390 case DomKey::F12: | |
| 391 return VKEY_F12; | |
| 392 case DomKey::F13: | |
| 393 return VKEY_F13; | |
| 394 case DomKey::F14: | |
| 395 return VKEY_F14; | |
| 396 case DomKey::F15: | |
| 397 return VKEY_F15; | |
| 398 case DomKey::F16: | |
| 399 return VKEY_F16; | |
| 400 case DomKey::F17: | |
| 401 return VKEY_F17; | |
| 402 case DomKey::F18: | |
| 403 return VKEY_F18; | |
| 404 case DomKey::F19: | |
| 405 return VKEY_F19; | |
| 406 case DomKey::F20: | |
| 407 return VKEY_F20; | |
| 408 case DomKey::F21: | |
| 409 return VKEY_F21; | |
| 410 case DomKey::F22: | |
| 411 return VKEY_F22; | |
| 412 case DomKey::F23: | |
| 413 return VKEY_F23; | |
| 414 case DomKey::F24: | |
| 415 return VKEY_F24; | |
| 416 // Multimedia Keys | |
| 417 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia | |
| 418 case DomKey::MEDIA_PLAY_PAUSE: | |
| 419 return VKEY_MEDIA_PLAY_PAUSE; | |
| 420 case DomKey::MEDIA_SELECT: | |
| 421 return VKEY_MEDIA_LAUNCH_MEDIA_SELECT; | |
| 422 case DomKey::MEDIA_STOP: | |
| 423 return VKEY_MEDIA_STOP; | |
| 424 case DomKey::MEDIA_TRACK_NEXT: | |
| 425 return VKEY_MEDIA_NEXT_TRACK; | |
| 426 case DomKey::MEDIA_TRACK_PREVIOUS: | |
| 427 return VKEY_MEDIA_PREV_TRACK; | |
| 428 case DomKey::PRINT: | |
| 429 return VKEY_PRINT; | |
| 430 case DomKey::VOLUME_DOWN: | |
| 431 return VKEY_VOLUME_DOWN; | |
| 432 case DomKey::VOLUME_MUTE: | |
| 433 return VKEY_VOLUME_MUTE; | |
| 434 case DomKey::VOLUME_UP: | |
| 435 return VKEY_VOLUME_UP; | |
| 436 // Application Keys | |
| 437 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps | |
| 438 case DomKey::LAUNCH_CALCULATOR: | |
| 439 return VKEY_MEDIA_LAUNCH_APP2; | |
| 440 case DomKey::LAUNCH_MAIL: | |
| 441 return VKEY_MEDIA_LAUNCH_MAIL; | |
| 442 case DomKey::LAUNCH_MY_COMPUTER: | |
| 443 return VKEY_MEDIA_LAUNCH_APP1; | |
| 444 // Browser Keys | |
| 445 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser | |
| 446 case DomKey::BROWSER_BACK: | |
| 447 return VKEY_BACK; | |
| 448 case DomKey::BROWSER_FAVORITES: | |
| 449 return VKEY_BROWSER_FAVORITES; | |
| 450 case DomKey::BROWSER_FORWARD: | |
| 451 return VKEY_BROWSER_FORWARD; | |
| 452 case DomKey::BROWSER_HOME: | |
| 453 return VKEY_BROWSER_HOME; | |
| 454 case DomKey::BROWSER_REFRESH: | |
| 455 return VKEY_BROWSER_REFRESH; | |
| 456 case DomKey::BROWSER_SEARCH: | |
| 457 return VKEY_BROWSER_SEARCH; | |
| 458 case DomKey::BROWSER_STOP: | |
| 459 return VKEY_BROWSER_STOP; | |
| 460 // Media Controller Keys | |
| 461 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller | |
| 462 case DomKey::ZOOM_TOGGLE: | |
| 463 return VKEY_ZOOM; | |
| 464 // No value. | |
| 465 default: | |
| 466 return VKEY_UNKNOWN; | |
| 467 } | |
| 468 } | |
| 469 | |
| 470 // TODO(kpschoedel): move this to a shared location. | |
| 471 // This table maps DOM Level 3 .code values to legacy Windows-based VKEY | |
| 472 // values, where the VKEYs are interpreted positionally. | |
| 473 const struct DomCodeToKeyboardCodeEntry { | |
| 474 DomCode dom_code; | |
| 475 KeyboardCode key_code; | |
| 476 } dom_code_to_keyboard_code[] = { | |
| 477 // Entries are ordered by numeric value of the DomCode enum, | |
| 478 // which is the USB physical key code. | |
| 479 // DomCode::HYPER 0x000010 Hyper | |
| 480 // DomCode::SUPER 0x000011 Super | |
| 481 // DomCode::FN 0x000012 Fn | |
| 482 // DomCode::FN_LOCK 0x000013 FLock | |
| 483 // DomCode::SUSPEND 0x000014 Suspend | |
| 484 // DomCode::RESUME 0x000015 Resume | |
| 485 // DomCode::TURBO 0x000016 Turbo | |
| 486 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep | |
| 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 } | |
| 672 | |
| 673 // TODO(kpschoedel): move this to a shared location. | |
| 674 bool ControlCharacter(DomCode dom_code, | |
| 675 DomKey* dom_key, | |
| 676 base::char16* character) { | |
| 677 int code = static_cast<int>(dom_code); | |
| 678 const int kKeyA = static_cast<int>(DomCode::KEY_A); | |
| 679 // Control-A - Control-Z map to 0x01 - 0x1A. | |
| 680 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { | |
| 681 *character = static_cast<base::char16>(code - kKeyA + 1); | |
| 682 switch (dom_code) { | |
| 683 case DomCode::KEY_H: | |
| 684 *dom_key = DomKey::BACKSPACE; | |
| 685 case DomCode::KEY_I: | |
| 686 *dom_key = DomKey::TAB; | |
| 687 case DomCode::KEY_M: | |
| 688 *dom_key = DomKey::ENTER; | |
| 689 default: | |
| 690 *dom_key = DomKey::CHARACTER; | |
| 691 } | |
| 692 return true; | |
| 693 } | |
| 694 switch (dom_code) { | |
| 695 case DomCode::DIGIT2: | |
| 696 // NUL | |
| 697 *character = 0; | |
| 698 *dom_key = DomKey::CHARACTER; | |
| 699 return true; | |
| 700 case DomCode::ENTER: | |
| 701 // NL | |
| 702 *character = 0x0A; | |
| 703 *dom_key = DomKey::CHARACTER; | |
| 704 return true; | |
| 705 case DomCode::BRACKET_LEFT: | |
| 706 // ESC | |
| 707 *character = 0x1B; | |
| 708 *dom_key = DomKey::ESCAPE; | |
| 709 return true; | |
| 710 case DomCode::BACKSLASH: | |
| 711 // FS | |
| 712 *character = 0x1C; | |
| 713 *dom_key = DomKey::CHARACTER; | |
| 714 return true; | |
| 715 case DomCode::BRACKET_RIGHT: | |
| 716 // GS | |
| 717 *character = 0x1D; | |
| 718 *dom_key = DomKey::CHARACTER; | |
| 719 return true; | |
| 720 case DomCode::DIGIT6: | |
| 721 // RS | |
| 722 *character = 0x1E; | |
| 723 *dom_key = DomKey::CHARACTER; | |
| 724 return true; | |
| 725 case DomCode::MINUS: | |
| 726 // US | |
| 727 *character = 0x1F; | |
| 728 *dom_key = DomKey::CHARACTER; | |
| 729 return true; | |
| 730 default: | |
| 731 return false; | |
| 732 } | |
| 733 } | |
| 734 | |
| 735 } // anonymous namespace | 231 } // anonymous namespace |
| 736 | 232 |
| 737 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() { | 233 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() { |
| 738 } | 234 } |
| 739 | 235 |
| 740 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() { | 236 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() { |
| 741 } | 237 } |
| 742 | 238 |
| 743 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const { | 239 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const { |
| 744 return false; | 240 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 756 bool StubKeyboardLayoutEngine::UsesAltGr() const { | 252 bool StubKeyboardLayoutEngine::UsesAltGr() const { |
| 757 return true; | 253 return true; |
| 758 } | 254 } |
| 759 | 255 |
| 760 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code, | 256 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code, |
| 761 int flags, | 257 int flags, |
| 762 DomKey* out_dom_key, | 258 DomKey* out_dom_key, |
| 763 base::char16* out_character, | 259 base::char16* out_character, |
| 764 KeyboardCode* out_key_code) const { | 260 KeyboardCode* out_key_code) const { |
| 765 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { | 261 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { |
| 766 if (ControlCharacter(dom_code, out_dom_key, out_character)) { | 262 if (LookupControlCharacter(dom_code, flags, out_dom_key, out_character, |
| 767 *out_key_code = DomCodeToKeyboardCode(dom_code); | 263 out_key_code)) { |
| 768 return true; | 264 return true; |
| 769 } | 265 } |
| 770 } else { | 266 } else { |
| 771 for (size_t i = 0; i < arraysize(printable_code_map); ++i) { | 267 for (size_t i = 0; i < arraysize(printable_code_map); ++i) { |
| 772 const PrintableCodeEntry* e = &printable_code_map[i]; | 268 const PrintableCodeEntry* e = &printable_code_map[i]; |
| 773 if (e->dom_code == dom_code) { | 269 if (e->dom_code == dom_code) { |
| 774 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) | | 270 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) | |
| 775 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN); | 271 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN); |
| 776 base::char16 ch = e->character[state]; | 272 base::char16 ch = e->character[state]; |
| 777 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER; | 273 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER; |
| 778 *out_character = ch; | 274 *out_character = ch; |
| 779 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) { | 275 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) { |
| 780 ch = (ch & ~DK) | 0x20; | 276 ch = (ch & ~DK) | 0x20; |
| 781 if ((ch >= 'a') && (ch <= 'z')) | 277 if ((ch >= 'a') && (ch <= 'z')) |
| 782 *out_character = e->character[state ^ 1]; | 278 *out_character = e->character[state ^ 1]; |
| 783 } | 279 } |
| 784 *out_key_code = DomCodeToKeyboardCode(dom_code); | 280 *out_key_code = DomCodeToKeyboardCode(dom_code); |
| 785 return true; | 281 return true; |
| 786 } | 282 } |
| 787 } | 283 } |
| 788 } | 284 } |
| 789 | 285 |
| 790 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) { | 286 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) { |
| 791 const NonPrintableCodeEntry* e = &non_printable_code_map[i]; | 287 const NonPrintableCodeEntry* e = &non_printable_code_map[i]; |
| 792 if (e->dom_code == dom_code) { | 288 if (e->dom_code == dom_code) { |
| 793 *out_dom_key = e->dom_key; | 289 *out_dom_key = e->dom_key; |
| 794 *out_character = e->character; | 290 *out_character = e->character; |
| 795 *out_key_code = DomKeyToKeyboardCode(e->dom_key); | 291 *out_key_code = NonPrintableDomKeyToKeyboardCode(e->dom_key); |
| 796 return true; | 292 return true; |
| 797 } | 293 } |
| 798 } | 294 } |
| 799 | 295 |
| 800 return false; | 296 return false; |
| 801 } | 297 } |
| 802 | 298 |
| 803 } // namespace ui | 299 } // namespace ui |
| OLD | NEW |