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

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: nits Created 6 years, 2 months 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 ASCII Control or space keys which should directly map to key code
463 // instead of stripping the modifier states and go through the fallback maps.
Wez 2014/10/24 22:29:18 _Why_ should they do this, though? What would Ctr
Wez 2014/10/24 22:31:22 The example you give in CL description is AltGr+V
Shu Chen 2014/10/25 05:46:19 Enter is an ascii control key: keysym=0xff0d (XK_R
Shu Chen 2014/10/25 05:46:19 The range 0xff01-0xff1f contains XK_Tab, XK_Return
464 bool IsAsciiControlOrSpaceKey(KeySym keysym) {
465 // 0xff01 to 0xff1f (instead of 0x01 to 0x1f) represent ASCII control in
466 // keysym world.
467 return (keysym > 0xff00 && keysym <= 0xff1f) || keysym == XK_Delete ||
468 keysym == XK_Escape || keysym == XK_space;
469 }
470
462 } // namespace 471 } // namespace
463 472
464 // Get an ui::KeyboardCode from an X keyevent 473 // Get an ui::KeyboardCode from an X keyevent
465 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) { 474 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) {
466 // Gets correct VKEY code from XEvent is performed as the following steps: 475 // Gets correct VKEY code from XEvent is performed as the following steps:
467 // 1. Gets the keysym without modifier states. 476 // 1. Gets the keysym without modifier states.
468 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly. 477 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly.
469 // 3. Find keysym in map0. 478 // 3. Find keysym in map0.
470 // 4. If not found, fallback to find keysym + hardware_code in map1. 479 // 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 480 // 5. If not found, fallback to find keysym + keysym_shift + hardware_code
(...skipping 13 matching lines...) Expand all
485 } else { 494 } else {
486 xkeyevent.xkey = xev->xkey; 495 xkeyevent.xkey = xev->xkey;
487 } 496 }
488 KeyboardCode keycode = VKEY_UNKNOWN; 497 KeyboardCode keycode = VKEY_UNKNOWN;
489 XKeyEvent* xkey = &xkeyevent.xkey; 498 XKeyEvent* xkey = &xkeyevent.xkey;
490 // XLookupKeysym does not take into consideration the state of the lock/shift 499 // XLookupKeysym does not take into consideration the state of the lock/shift
491 // etc. keys. So it is necessary to use XLookupString instead. 500 // etc. keys. So it is necessary to use XLookupString instead.
492 XLookupString(xkey, NULL, 0, &keysym, NULL); 501 XLookupString(xkey, NULL, 0, &keysym, NULL);
493 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) || 502 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) ||
494 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) || 503 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) ||
495 IsModifierKey(keysym)) { 504 IsModifierKey(keysym) || IsAsciiControlOrSpaceKey(keysym)) {
496 return KeyboardCodeFromXKeysym(keysym); 505 return KeyboardCodeFromXKeysym(keysym);
497 } 506 }
498 507
499 // If |xkey| has modifiers set, other than NumLock, then determine the 508 // 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 509 // un-modified KeySym and use that to map, so that e.g. Ctrl+D correctly
501 // generates VKEY_D. 510 // generates VKEY_D.
502 if (xkey->state & 0xFF & ~Mod2Mask) { 511 if (xkey->state & 0xFF & ~Mod2Mask) {
503 xkey->state &= (~0xFF | Mod2Mask); 512 xkey->state &= (~0xFF | Mod2Mask);
504 XLookupString(xkey, NULL, 0, &keysym, NULL); 513 XLookupString(xkey, NULL, 0, &keysym, NULL);
505 } 514 }
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND 1367 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND
1359 // (the '<>' key between Shift and Z on 105-key keyboards) which does. 1368 // (the '<>' key between Shift and Z on 105-key keyboards) which does.
1360 // 1369 //
1361 // crbug.com/386066 and crbug.com/390263 are examples of problems 1370 // crbug.com/386066 and crbug.com/390263 are examples of problems
1362 // associated with this. 1371 // associated with this.
1363 // 1372 //
1364 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); 1373 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false));
1365 } 1374 }
1366 1375
1367 } // namespace ui 1376 } // 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