Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion_x.cc

Issue 664893004: If keysym is ASCII control or space keys, directly map to keycode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make a list for TTY function and space keys Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/keyboard_code_conversion_x.h" 5 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #define XK_3270 // for XK_3270_BackTab 9 #define XK_3270 // for XK_3270_BackTab
10 #include <X11/XF86keysym.h> 10 #include <X11/XF86keysym.h>
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 template <class T_MAP> 453 template <class T_MAP>
454 KeyboardCode FindVK(const T_MAP& key, const T_MAP* map, size_t size) { 454 KeyboardCode FindVK(const T_MAP& key, const T_MAP* map, size_t size) {
455 T_MAP comp = {0}; 455 T_MAP comp = {0};
456 const T_MAP* p = std::lower_bound(map, map + size, key, comp); 456 const T_MAP* p = std::lower_bound(map, map + size, key, comp);
457 if (p != map + size && !comp(*p, key) && !comp(key, *p)) 457 if (p != map + size && !comp(*p, key) && !comp(key, *p))
458 return static_cast<KeyboardCode>(p->vk); 458 return static_cast<KeyboardCode>(p->vk);
459 return VKEY_UNKNOWN; 459 return VKEY_UNKNOWN;
460 } 460 }
461 461
462 // Check for TTY function keys or space key which should always be mapped
463 // based on KeySym, and never fall back to MAP0~MAP3, since some layouts
464 // generate them by applying the Control/AltGr modifier to some other key.
465 // e.g. in de(neo), AltGr+V generates XK_Enter.
466 bool IsTtyFunctionOrSpaceKey(KeySym keysym) {
467 KeySym keysyms[] = {
468 XK_BackSpace,
469 XK_Tab,
470 XK_Linefeed,
471 XK_Clear,
472 XK_Return,
473 XK_Pause,
474 XK_Scroll_Lock,
475 XK_Sys_Req,
476 XK_Escape,
477 XK_Delete,
478 XK_space
479 };
480
481 for (size_t i = 0; i < arraysize(keysyms); ++i) {
482 if (keysyms[i] == keysym)
483 return true;
484 }
485 return false;
486 }
487
462 } // namespace 488 } // namespace
463 489
464 // Get an ui::KeyboardCode from an X keyevent 490 // Get an ui::KeyboardCode from an X keyevent
465 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) { 491 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) {
466 // Gets correct VKEY code from XEvent is performed as the following steps: 492 // Gets correct VKEY code from XEvent is performed as the following steps:
467 // 1. Gets the keysym without modifier states. 493 // 1. Gets the keysym without modifier states.
468 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly. 494 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly.
469 // 3. Find keysym in map0. 495 // 3. Find keysym in map0.
470 // 4. If not found, fallback to find keysym + hardware_code in map1. 496 // 4. If not found, fallback to find keysym + hardware_code in map1.
471 // 5. If not found, fallback to find keysym + keysym_shift + hardware_code 497 // 5. If not found, fallback to find keysym + keysym_shift + hardware_code
(...skipping 13 matching lines...) Expand all
485 } else { 511 } else {
486 xkeyevent.xkey = xev->xkey; 512 xkeyevent.xkey = xev->xkey;
487 } 513 }
488 KeyboardCode keycode = VKEY_UNKNOWN; 514 KeyboardCode keycode = VKEY_UNKNOWN;
489 XKeyEvent* xkey = &xkeyevent.xkey; 515 XKeyEvent* xkey = &xkeyevent.xkey;
490 // XLookupKeysym does not take into consideration the state of the lock/shift 516 // XLookupKeysym does not take into consideration the state of the lock/shift
491 // etc. keys. So it is necessary to use XLookupString instead. 517 // etc. keys. So it is necessary to use XLookupString instead.
492 XLookupString(xkey, NULL, 0, &keysym, NULL); 518 XLookupString(xkey, NULL, 0, &keysym, NULL);
493 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) || 519 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) ||
494 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) || 520 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) ||
495 IsModifierKey(keysym)) { 521 IsModifierKey(keysym) || IsTtyFunctionOrSpaceKey(keysym)) {
496 return KeyboardCodeFromXKeysym(keysym); 522 return KeyboardCodeFromXKeysym(keysym);
497 } 523 }
498 524
499 // If |xkey| has modifiers set, other than NumLock, then determine the 525 // If |xkey| has modifiers set, other than NumLock, then determine the
500 // un-modified KeySym and use that to map, so that e.g. Ctrl+D correctly 526 // un-modified KeySym and use that to map, so that e.g. Ctrl+D correctly
501 // generates VKEY_D. 527 // generates VKEY_D.
502 if (xkey->state & 0xFF & ~Mod2Mask) { 528 if (xkey->state & 0xFF & ~Mod2Mask) {
503 xkey->state &= (~0xFF | Mod2Mask); 529 xkey->state &= (~0xFF | Mod2Mask);
504 XLookupString(xkey, NULL, 0, &keysym, NULL); 530 XLookupString(xkey, NULL, 0, &keysym, NULL);
505 } 531 }
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND 1384 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND
1359 // (the '<>' key between Shift and Z on 105-key keyboards) which does. 1385 // (the '<>' key between Shift and Z on 105-key keyboards) which does.
1360 // 1386 //
1361 // crbug.com/386066 and crbug.com/390263 are examples of problems 1387 // crbug.com/386066 and crbug.com/390263 are examples of problems
1362 // associated with this. 1388 // associated with this.
1363 // 1389 //
1364 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); 1390 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false));
1365 } 1391 }
1366 1392
1367 } // namespace ui 1393 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698