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" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 scoped_ptr<char, base::FreeDeleter> keymap_str( | 650 scoped_ptr<char, base::FreeDeleter> keymap_str( |
651 xkb_keymap_get_as_string(keymap.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); | 651 xkb_keymap_get_as_string(keymap.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); |
652 reply_runner->PostTask(FROM_HERE, base::Bind(reply_callback, layout_name, | 652 reply_runner->PostTask(FROM_HERE, base::Bind(reply_callback, layout_name, |
653 base::Passed(&keymap_str))); | 653 base::Passed(&keymap_str))); |
654 } else { | 654 } else { |
655 LOG(FATAL) << "Keymap file failed to load: " << layout_name; | 655 LOG(FATAL) << "Keymap file failed to load: " << layout_name; |
656 } | 656 } |
657 } | 657 } |
658 #endif | 658 #endif |
659 | 659 |
| 660 KeyboardCode DomCodeToUsLayoutKeyboardCode(DomCode dom_code) { |
| 661 DomKey dummy_dom_key; |
| 662 base::char16 dummy_character; |
| 663 KeyboardCode key_code; |
| 664 if (DomCodeToUsLayoutMeaning(dom_code, EF_NONE, &dummy_dom_key, |
| 665 &dummy_character, &key_code)) { |
| 666 return key_code; |
| 667 } |
| 668 return VKEY_UNKNOWN; |
| 669 } |
| 670 |
660 } // anonymous namespace | 671 } // anonymous namespace |
661 | 672 |
662 XkbKeyCodeConverter::XkbKeyCodeConverter() { | 673 XkbKeyCodeConverter::XkbKeyCodeConverter() { |
663 } | 674 } |
664 | 675 |
665 XkbKeyCodeConverter::~XkbKeyCodeConverter() { | 676 XkbKeyCodeConverter::~XkbKeyCodeConverter() { |
666 } | 677 } |
667 | 678 |
668 XkbKeyboardLayoutEngine::XkbKeyboardLayoutEngine( | 679 XkbKeyboardLayoutEngine::XkbKeyboardLayoutEngine( |
669 const XkbKeyCodeConverter& converter) | 680 const XkbKeyCodeConverter& converter) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 *platform_keycode = xkb_keysym; | 779 *platform_keycode = xkb_keysym; |
769 // Classify the keysym and convert to DOM and VKEY representations. | 780 // Classify the keysym and convert to DOM and VKEY representations. |
770 *dom_key = NonPrintableXkbKeySymToDomKey(xkb_keysym); | 781 *dom_key = NonPrintableXkbKeySymToDomKey(xkb_keysym); |
771 if (*dom_key == DomKey::NONE) { | 782 if (*dom_key == DomKey::NONE) { |
772 *dom_key = CharacterToDomKey(*character); | 783 *dom_key = CharacterToDomKey(*character); |
773 *key_code = AlphanumericKeyboardCode(*character); | 784 *key_code = AlphanumericKeyboardCode(*character); |
774 if (*key_code == VKEY_UNKNOWN) { | 785 if (*key_code == VKEY_UNKNOWN) { |
775 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, | 786 *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, |
776 xkb_keysym, *dom_key, *character); | 787 xkb_keysym, *dom_key, *character); |
777 if (*key_code == VKEY_UNKNOWN) | 788 if (*key_code == VKEY_UNKNOWN) |
778 *key_code = DomCodeToNonLocatedKeyboardCode(dom_code); | 789 *key_code = DomCodeToUsLayoutKeyboardCode(dom_code); |
779 } | 790 } |
780 | 791 |
781 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { | 792 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { |
782 // Use GetCharacterFromKeyCode() to set |character| to 0x0 for key codes | 793 // Use GetCharacterFromKeyCode() to set |character| to 0x0 for keys that |
783 // that we do not care about. | 794 // are not part of the accepted set of Control+Key combinations. |
784 *character = GetCharacterFromKeyCode(*key_code, flags); | 795 *character = GetCharacterFromKeyCode(*key_code, flags); |
785 } | 796 } |
786 } else if (*dom_key == DomKey::DEAD) { | 797 } else if (*dom_key == DomKey::DEAD) { |
787 *character = DeadXkbKeySymToCombiningCharacter(xkb_keysym); | 798 *character = DeadXkbKeySymToCombiningCharacter(xkb_keysym); |
788 *key_code = DomCodeToNonLocatedKeyboardCode(dom_code); | 799 *key_code = DomCodeToUsLayoutKeyboardCode(dom_code); |
789 } else { | 800 } else { |
790 *key_code = NonPrintableDomKeyToKeyboardCode(*dom_key); | 801 *key_code = NonPrintableDomKeyToKeyboardCode(*dom_key); |
791 if (*key_code == VKEY_UNKNOWN) | 802 if (*key_code == VKEY_UNKNOWN) |
792 *key_code = DomCodeToNonLocatedKeyboardCode(dom_code); | 803 *key_code = DomCodeToUsLayoutKeyboardCode(dom_code); |
793 } | 804 } |
794 return true; | 805 return true; |
795 } | 806 } |
796 | 807 |
797 void XkbKeyboardLayoutEngine::SetKeymap(xkb_keymap* keymap) { | 808 void XkbKeyboardLayoutEngine::SetKeymap(xkb_keymap* keymap) { |
798 xkb_state_.reset(xkb_state_new(keymap)); | 809 xkb_state_.reset(xkb_state_new(keymap)); |
799 // Update flag map. | 810 // Update flag map. |
800 static const struct { | 811 static const struct { |
801 int ui_flag; | 812 int ui_flag; |
802 const char* xkb_name; | 813 const char* xkb_name; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 if (close_index == std::string::npos) | 969 if (close_index == std::string::npos) |
959 close_index = layout_name.size(); | 970 close_index = layout_name.size(); |
960 *layout_variant = layout_name.substr(parentheses_index + 1, | 971 *layout_variant = layout_name.substr(parentheses_index + 1, |
961 close_index - parentheses_index - 1); | 972 close_index - parentheses_index - 1); |
962 } else if (dash_index != std::string::npos) { | 973 } else if (dash_index != std::string::npos) { |
963 *layout_id = layout_name.substr(0, dash_index); | 974 *layout_id = layout_name.substr(0, dash_index); |
964 *layout_variant = layout_name.substr(dash_index + 1); | 975 *layout_variant = layout_name.substr(dash_index + 1); |
965 } | 976 } |
966 } | 977 } |
967 } // namespace ui | 978 } // namespace ui |
OLD | NEW |