| 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 <xkbcommon/xkbcommon-names.h> | 7 #include <xkbcommon/xkbcommon-names.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
| 16 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 17 #include "ui/events/keycodes/dom3/dom_code.h" | 17 #include "ui/events/keycodes/dom3/dom_code.h" |
| 18 #include "ui/events/keycodes/dom3/dom_key.h" | 18 #include "ui/events/keycodes/dom3/dom_key.h" |
| 19 #include "ui/events/keycodes/dom4/keycode_converter.h" | 19 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 20 #include "ui/events/keycodes/keyboard_code_conversion.h" | 20 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 21 #include "ui/events/ozone/layout/layout_util.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h" |
| 22 #include "ui/events/ozone/layout/xkb/xkb_keyboard_code_conversion.h" | 22 #include "ui/events/ozone/layout/xkb/xkb_keyboard_code_conversion.h" |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 typedef base::Callback<void(const std::string&, | 28 typedef base::Callback<void(const std::string&, |
| 29 scoped_ptr<char, base::FreeDeleter>)> | 29 scoped_ptr<char, base::FreeDeleter>)> |
| 30 LoadKeymapCallback; | 30 LoadKeymapCallback; |
| 31 | 31 |
| 32 DomKey CharacterToDomKey(base::char16 character) { | |
| 33 switch (character) { | |
| 34 case 0x08: | |
| 35 return DomKey::BACKSPACE; | |
| 36 case 0x09: | |
| 37 return DomKey::TAB; | |
| 38 case 0x0A: | |
| 39 case 0x0D: | |
| 40 return DomKey::ENTER; | |
| 41 case 0x1B: | |
| 42 return DomKey::ESCAPE; | |
| 43 default: | |
| 44 return DomKey::CHARACTER; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 KeyboardCode AlphanumericKeyboardCode(base::char16 character) { | 32 KeyboardCode AlphanumericKeyboardCode(base::char16 character) { |
| 49 // Plain ASCII letters and digits map directly to VKEY values. | 33 // Plain ASCII letters and digits map directly to VKEY values. |
| 50 if ((character >= '0') && (character <= '9')) | 34 if ((character >= '0') && (character <= '9')) |
| 51 return static_cast<KeyboardCode>(VKEY_0 + character - '0'); | 35 return static_cast<KeyboardCode>(VKEY_0 + character - '0'); |
| 52 if ((character >= 'a') && (character <= 'z')) | 36 if ((character >= 'a') && (character <= 'z')) |
| 53 return static_cast<KeyboardCode>(VKEY_A + character - 'a'); | 37 return static_cast<KeyboardCode>(VKEY_A + character - 'a'); |
| 54 if ((character >= 'A') && (character <= 'Z')) | 38 if ((character >= 'A') && (character <= 'Z')) |
| 55 return static_cast<KeyboardCode>(VKEY_A + character - 'A'); | 39 return static_cast<KeyboardCode>(VKEY_A + character - 'A'); |
| 56 return VKEY_UNKNOWN; | 40 return VKEY_UNKNOWN; |
| 57 } | 41 } |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 << KeycodeConverter::DomCodeToCodeString(dom_code) << "'"; | 742 << KeycodeConverter::DomCodeToCodeString(dom_code) << "'"; |
| 759 return false; | 743 return false; |
| 760 } | 744 } |
| 761 xkb_mod_mask_t xkb_flags = EventFlagsToXkbFlags(flags); | 745 xkb_mod_mask_t xkb_flags = EventFlagsToXkbFlags(flags); |
| 762 // Obtain keysym and character. | 746 // Obtain keysym and character. |
| 763 xkb_keysym_t xkb_keysym; | 747 xkb_keysym_t xkb_keysym; |
| 764 if (!XkbLookup(xkb_keycode, xkb_flags, &xkb_keysym, character)) | 748 if (!XkbLookup(xkb_keycode, xkb_flags, &xkb_keysym, character)) |
| 765 return false; | 749 return false; |
| 766 *platform_keycode = xkb_keysym; | 750 *platform_keycode = xkb_keysym; |
| 767 // Classify the keysym and convert to DOM and VKEY representations. | 751 // Classify the keysym and convert to DOM and VKEY representations. |
| 768 *dom_key = NonPrintableXkbKeySymToDomKey(xkb_keysym); | 752 *dom_key = NonPrintableXKeySymToDomKey(xkb_keysym); |
| 769 if (*dom_key == DomKey::NONE) { | 753 if (*dom_key == DomKey::NONE) { |
| 770 *dom_key = CharacterToDomKey(*character); | 754 *dom_key = CharacterToDomKey(*character); |
| 771 *key_code = AlphanumericKeyboardCode(*character); | 755 *key_code = AlphanumericKeyboardCode(*character); |
| 772 if (*key_code == VKEY_UNKNOWN) { | 756 if (*key_code == VKEY_UNKNOWN) { |
| 773 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, | 757 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, |
| 774 xkb_keysym, *dom_key, *character); | 758 xkb_keysym, *dom_key, *character); |
| 775 if (*key_code == VKEY_UNKNOWN) | 759 if (*key_code == VKEY_UNKNOWN) |
| 776 *key_code = DomCodeToUsLayoutKeyboardCode(dom_code); | 760 *key_code = DomCodeToUsLayoutKeyboardCode(dom_code); |
| 777 } | 761 } |
| 778 // If the Control key is down, only allow ASCII control characters to be | 762 // If the Control key is down, only allow ASCII control characters to be |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 DomKey dom_key, | 847 DomKey dom_key, |
| 864 base::char16 character) const { | 848 base::char16 character) const { |
| 865 // Get the layout interpretation without modifiers, so that | 849 // Get the layout interpretation without modifiers, so that |
| 866 // e.g. Ctrl+D correctly generates VKEY_D. | 850 // e.g. Ctrl+D correctly generates VKEY_D. |
| 867 xkb_keysym_t plain_keysym; | 851 xkb_keysym_t plain_keysym; |
| 868 base::char16 plain_character; | 852 base::char16 plain_character; |
| 869 if (!XkbLookup(xkb_keycode, 0, &plain_keysym, &plain_character)) | 853 if (!XkbLookup(xkb_keycode, 0, &plain_keysym, &plain_character)) |
| 870 return VKEY_UNKNOWN; | 854 return VKEY_UNKNOWN; |
| 871 | 855 |
| 872 // If the plain key is non-printable, that determines the VKEY. | 856 // If the plain key is non-printable, that determines the VKEY. |
| 873 DomKey plain_key = NonPrintableXkbKeySymToDomKey(plain_keysym); | 857 DomKey plain_key = NonPrintableXKeySymToDomKey(plain_keysym); |
| 874 if (plain_key != ui::DomKey::NONE) | 858 if (plain_key != ui::DomKey::NONE) |
| 875 return NonPrintableDomKeyToKeyboardCode(dom_key); | 859 return NonPrintableDomKeyToKeyboardCode(dom_key); |
| 876 | 860 |
| 877 // Plain ASCII letters and digits map directly to VKEY values. | 861 // Plain ASCII letters and digits map directly to VKEY values. |
| 878 KeyboardCode key_code = AlphanumericKeyboardCode(plain_character); | 862 KeyboardCode key_code = AlphanumericKeyboardCode(plain_character); |
| 879 if (key_code != VKEY_UNKNOWN) | 863 if (key_code != VKEY_UNKNOWN) |
| 880 return key_code; | 864 return key_code; |
| 881 | 865 |
| 882 // Check the multi-character tables. | 866 // Check the multi-character tables. |
| 883 const PrintableMultiEntry* multi_end = kMultiMap + arraysize(kMultiMap); | 867 const PrintableMultiEntry* multi_end = kMultiMap + arraysize(kMultiMap); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 close_index = layout_name.size(); | 939 close_index = layout_name.size(); |
| 956 *layout_variant = layout_name.substr(parentheses_index + 1, | 940 *layout_variant = layout_name.substr(parentheses_index + 1, |
| 957 close_index - parentheses_index - 1); | 941 close_index - parentheses_index - 1); |
| 958 } else if (dash_index != std::string::npos) { | 942 } else if (dash_index != std::string::npos) { |
| 959 *layout_id = layout_name.substr(0, dash_index); | 943 *layout_id = layout_name.substr(0, dash_index); |
| 960 *layout_variant = layout_name.substr(dash_index + 1); | 944 *layout_variant = layout_name.substr(dash_index + 1); |
| 961 } | 945 } |
| 962 } | 946 } |
| 963 | 947 |
| 964 } // namespace ui | 948 } // namespace ui |
| OLD | NEW |