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/xkb/xkb_keyboard_layout_engine.h" | 5 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <xkbcommon/xkbcommon-names.h> | 8 #include <xkbcommon/xkbcommon-names.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h" | 24 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h" |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 typedef base::Callback<void(const std::string&, | 30 typedef base::Callback<void(const std::string&, |
31 scoped_ptr<char, base::FreeDeleter>)> | 31 scoped_ptr<char, base::FreeDeleter>)> |
32 LoadKeymapCallback; | 32 LoadKeymapCallback; |
33 | 33 |
34 KeyboardCode AlphanumericKeyboardCode(base::char16 character) { | 34 KeyboardCode AlphanumericKeyboardCode(xkb_keysym_t xkb_keysym, |
| 35 base::char16 character) { |
35 // Plain ASCII letters and digits map directly to VKEY values. | 36 // Plain ASCII letters and digits map directly to VKEY values. |
36 if ((character >= '0') && (character <= '9')) | 37 if ((character >= '0') && (character <= '9')) { |
37 return static_cast<KeyboardCode>(VKEY_0 + character - '0'); | 38 int zero = ((xkb_keysym >= XKB_KEY_KP_0) && (xkb_keysym <= XKB_KEY_KP_9)) |
| 39 ? VKEY_NUMPAD0 |
| 40 : VKEY_0; |
| 41 return static_cast<KeyboardCode>(zero + character - '0'); |
| 42 } |
38 if ((character >= 'a') && (character <= 'z')) | 43 if ((character >= 'a') && (character <= 'z')) |
39 return static_cast<KeyboardCode>(VKEY_A + character - 'a'); | 44 return static_cast<KeyboardCode>(VKEY_A + character - 'a'); |
40 if ((character >= 'A') && (character <= 'Z')) | 45 if ((character >= 'A') && (character <= 'Z')) |
41 return static_cast<KeyboardCode>(VKEY_A + character - 'A'); | 46 return static_cast<KeyboardCode>(VKEY_A + character - 'A'); |
42 return VKEY_UNKNOWN; | 47 return VKEY_UNKNOWN; |
43 } | 48 } |
44 | 49 |
45 // These tables map layout-dependent printable characters/codes | 50 // These tables map layout-dependent printable characters/codes |
46 // to legacy Windows-based VKEY values. | 51 // to legacy Windows-based VKEY values. |
47 // | 52 // |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 &normal_character) && | 773 &normal_character) && |
769 !IsControlCharacter(normal_character)) { | 774 !IsControlCharacter(normal_character)) { |
770 flags = normal_ui_flags; | 775 flags = normal_ui_flags; |
771 xkb_flags = normal_xkb_flags; | 776 xkb_flags = normal_xkb_flags; |
772 character = normal_character; | 777 character = normal_character; |
773 xkb_keysym = normal_keysym; | 778 xkb_keysym = normal_keysym; |
774 } | 779 } |
775 } | 780 } |
776 | 781 |
777 *dom_key = DomKey::FromCharacter(character); | 782 *dom_key = DomKey::FromCharacter(character); |
778 *key_code = AlphanumericKeyboardCode(character); | 783 *key_code = AlphanumericKeyboardCode(xkb_keysym, character); |
779 if (*key_code == VKEY_UNKNOWN) { | 784 if (*key_code == VKEY_UNKNOWN) { |
780 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, | 785 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, |
781 xkb_keysym, character); | 786 xkb_keysym, character); |
782 if (*key_code == VKEY_UNKNOWN) | 787 if (*key_code == VKEY_UNKNOWN) |
783 *key_code = DomCodeToUsLayoutNonLocatedKeyboardCode(dom_code); | 788 *key_code = DomCodeToUsLayoutNonLocatedKeyboardCode(dom_code); |
784 } | 789 } |
785 return true; | 790 return true; |
786 } | 791 } |
787 | 792 |
788 void XkbKeyboardLayoutEngine::SetKeymapFromStringForTest( | 793 void XkbKeyboardLayoutEngine::SetKeymapFromStringForTest( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 uint32_t plain_character; | 874 uint32_t plain_character; |
870 if (!XkbLookup(xkb_keycode, 0, &plain_keysym, &plain_character)) | 875 if (!XkbLookup(xkb_keycode, 0, &plain_keysym, &plain_character)) |
871 return VKEY_UNKNOWN; | 876 return VKEY_UNKNOWN; |
872 | 877 |
873 // If the plain key is non-printable, that determines the VKEY. | 878 // If the plain key is non-printable, that determines the VKEY. |
874 DomKey plain_key = NonPrintableXKeySymToDomKey(plain_keysym); | 879 DomKey plain_key = NonPrintableXKeySymToDomKey(plain_keysym); |
875 if (plain_key != ui::DomKey::NONE) | 880 if (plain_key != ui::DomKey::NONE) |
876 return NonPrintableDomKeyToKeyboardCode(plain_key); | 881 return NonPrintableDomKeyToKeyboardCode(plain_key); |
877 | 882 |
878 // Plain ASCII letters and digits map directly to VKEY values. | 883 // Plain ASCII letters and digits map directly to VKEY values. |
879 KeyboardCode key_code = AlphanumericKeyboardCode(plain_character); | 884 KeyboardCode key_code = AlphanumericKeyboardCode(xkb_keysym, plain_character); |
880 if (key_code != VKEY_UNKNOWN) | 885 if (key_code != VKEY_UNKNOWN) |
881 return key_code; | 886 return key_code; |
882 | 887 |
883 // Check the multi-character tables. | 888 // Check the multi-character tables. |
884 const PrintableMultiEntry* multi_end = kMultiMap + arraysize(kMultiMap); | 889 const PrintableMultiEntry* multi_end = kMultiMap + arraysize(kMultiMap); |
885 const PrintableMultiEntry* multi = | 890 const PrintableMultiEntry* multi = |
886 std::lower_bound(kMultiMap, multi_end, plain_character, | 891 std::lower_bound(kMultiMap, multi_end, plain_character, |
887 [](const PrintableMultiEntry& e, base::char16 c) { | 892 [](const PrintableMultiEntry& e, base::char16 c) { |
888 return e.plain_character < c; | 893 return e.plain_character < c; |
889 }); | 894 }); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 close_index = layout_name.size(); | 961 close_index = layout_name.size(); |
957 *layout_variant = layout_name.substr(parentheses_index + 1, | 962 *layout_variant = layout_name.substr(parentheses_index + 1, |
958 close_index - parentheses_index - 1); | 963 close_index - parentheses_index - 1); |
959 } else if (dash_index != std::string::npos) { | 964 } else if (dash_index != std::string::npos) { |
960 *layout_id = layout_name.substr(0, dash_index); | 965 *layout_id = layout_name.substr(0, dash_index); |
961 *layout_variant = layout_name.substr(dash_index + 1); | 966 *layout_variant = layout_name.substr(dash_index + 1); |
962 } | 967 } |
963 } | 968 } |
964 | 969 |
965 } // namespace ui | 970 } // namespace ui |
OLD | NEW |