OLD | NEW |
---|---|
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 Loading... | |
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 bool IsAsciiControlKey(KeySym keysym) { | |
463 if ((keysym > 0xff00 && keysym < 0xff1f) || keysym == XK_Delete) | |
Yuki
2014/10/23 07:13:56
keysym <= 0xff1f ?
I think we'd like to include 0x
Shu Chen
2014/10/23 07:44:33
Done.
| |
464 return true; | |
465 return false; | |
466 } | |
467 | |
462 } // namespace | 468 } // namespace |
463 | 469 |
464 // Get an ui::KeyboardCode from an X keyevent | 470 // Get an ui::KeyboardCode from an X keyevent |
465 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) { | 471 KeyboardCode KeyboardCodeFromXKeyEvent(const XEvent* xev) { |
466 // Gets correct VKEY code from XEvent is performed as the following steps: | 472 // Gets correct VKEY code from XEvent is performed as the following steps: |
467 // 1. Gets the keysym without modifier states. | 473 // 1. Gets the keysym without modifier states. |
468 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly. | 474 // 2. For [a-z] & [0-9] cases, returns the VKEY code accordingly. |
469 // 3. Find keysym in map0. | 475 // 3. Find keysym in map0. |
470 // 4. If not found, fallback to find keysym + hardware_code in map1. | 476 // 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 | 477 // 5. If not found, fallback to find keysym + keysym_shift + hardware_code |
(...skipping 13 matching lines...) Expand all Loading... | |
485 } else { | 491 } else { |
486 xkeyevent.xkey = xev->xkey; | 492 xkeyevent.xkey = xev->xkey; |
487 } | 493 } |
488 KeyboardCode keycode = VKEY_UNKNOWN; | 494 KeyboardCode keycode = VKEY_UNKNOWN; |
489 XKeyEvent* xkey = &xkeyevent.xkey; | 495 XKeyEvent* xkey = &xkeyevent.xkey; |
490 // XLookupKeysym does not take into consideration the state of the lock/shift | 496 // XLookupKeysym does not take into consideration the state of the lock/shift |
491 // etc. keys. So it is necessary to use XLookupString instead. | 497 // etc. keys. So it is necessary to use XLookupString instead. |
492 XLookupString(xkey, NULL, 0, &keysym, NULL); | 498 XLookupString(xkey, NULL, 0, &keysym, NULL); |
493 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) || | 499 if (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym) || |
494 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) || | 500 IsCursorKey(keysym) || IsPFKey(keysym) || IsFunctionKey(keysym) || |
495 IsModifierKey(keysym)) { | 501 IsModifierKey(keysym) || IsAsciiControlKey(keysym) || |
502 keysym == XK_space) { | |
496 return KeyboardCodeFromXKeysym(keysym); | 503 return KeyboardCodeFromXKeysym(keysym); |
497 } | 504 } |
498 | 505 |
499 // If |xkey| has modifiers set, other than NumLock, then determine the | 506 // 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 | 507 // un-modified KeySym and use that to map, so that e.g. Ctrl+D correctly |
501 // generates VKEY_D. | 508 // generates VKEY_D. |
502 if (xkey->state & 0xFF & ~Mod2Mask) { | 509 if (xkey->state & 0xFF & ~Mod2Mask) { |
503 xkey->state &= (~0xFF | Mod2Mask); | 510 xkey->state &= (~0xFF | Mod2Mask); |
504 XLookupString(xkey, NULL, 0, &keysym, NULL); | 511 XLookupString(xkey, NULL, 0, &keysym, NULL); |
505 } | 512 } |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND | 1365 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND |
1359 // (the '<>' key between Shift and Z on 105-key keyboards) which does. | 1366 // (the '<>' key between Shift and Z on 105-key keyboards) which does. |
1360 // | 1367 // |
1361 // crbug.com/386066 and crbug.com/390263 are examples of problems | 1368 // crbug.com/386066 and crbug.com/390263 are examples of problems |
1362 // associated with this. | 1369 // associated with this. |
1363 // | 1370 // |
1364 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); | 1371 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); |
1365 } | 1372 } |
1366 | 1373 |
1367 } // namespace ui | 1374 } // namespace ui |
OLD | NEW |