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 "chrome/browser/chromeos/input_method/input_method_util.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 return hardware_login_layouts_; | 793 return hardware_login_layouts_; |
794 } | 794 } |
795 | 795 |
796 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 796 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
797 const { | 797 const { |
798 const InputMethodDescriptor* ime = | 798 const InputMethodDescriptor* ime = |
799 GetInputMethodDescriptorFromId(input_method_id); | 799 GetInputMethodDescriptorFromId(input_method_id); |
800 return ime ? ime->is_login_keyboard() : false; | 800 return ime ? ime->is_login_keyboard() : false; |
801 } | 801 } |
802 | 802 |
803 void InputMethodUtil::SetComponentExtensions( | 803 void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) { |
804 const InputMethodDescriptors& imes) { | |
805 for (size_t i = 0; i < imes.size(); ++i) { | 804 for (size_t i = 0; i < imes.size(); ++i) { |
806 const InputMethodDescriptor& input_method = imes[i]; | 805 const InputMethodDescriptor& input_method = imes[i]; |
807 DCHECK(!input_method.language_codes().empty()); | 806 DCHECK(!input_method.language_codes().empty()); |
808 const std::vector<std::string>& language_codes = | 807 const std::vector<std::string>& language_codes = |
809 input_method.language_codes(); | 808 input_method.language_codes(); |
810 id_to_language_code_[input_method.id()] = language_codes[0]; | 809 id_to_language_code_[input_method.id()] = language_codes[0]; |
811 id_to_descriptor_[input_method.id()] = input_method; | 810 id_to_descriptor_[input_method.id()] = input_method; |
812 | 811 |
813 typedef LanguageCodeToIdsMap::const_iterator It; | 812 typedef LanguageCodeToIdsMap::const_iterator It; |
814 for (size_t j = 0; j < language_codes.size(); ++j) { | 813 for (size_t j = 0; j < language_codes.size(); ++j) { |
815 std::pair<It, It> range = | 814 std::pair<It, It> range = |
816 language_code_to_ids_.equal_range(language_codes[j]); | 815 language_code_to_ids_.equal_range(language_codes[j]); |
817 It it = range.first; | 816 It it = range.first; |
818 for (; it != range.second; ++it) { | 817 for (; it != range.second; ++it) { |
819 if (it->second == input_method.id()) | 818 if (it->second == input_method.id()) |
820 break; | 819 break; |
821 } | 820 } |
822 if (it == range.second) | 821 if (it == range.second) |
823 language_code_to_ids_.insert( | 822 language_code_to_ids_.insert( |
824 std::make_pair(language_codes[j], input_method.id())); | 823 std::make_pair(language_codes[j], input_method.id())); |
825 } | 824 } |
826 } | 825 } |
827 } | 826 } |
828 | 827 |
| 828 void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) { |
| 829 // Clear the existing maps. |
| 830 language_code_to_ids_.clear(); |
| 831 id_to_language_code_.clear(); |
| 832 id_to_descriptor_.clear(); |
| 833 |
| 834 AppendInputMethods(imes); |
| 835 } |
| 836 |
829 void InputMethodUtil::InitXkbInputMethodsForTesting() { | 837 void InputMethodUtil::InitXkbInputMethodsForTesting() { |
830 cached_hardware_layouts_.clear(); | 838 cached_hardware_layouts_.clear(); |
831 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) | 839 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) |
832 return; | 840 return; |
833 scoped_ptr<InputMethodDescriptors> original_imes = | 841 scoped_ptr<InputMethodDescriptors> original_imes = |
834 InputMethodWhitelist().GetSupportedInputMethods(); | 842 InputMethodWhitelist().GetSupportedInputMethods(); |
835 InputMethodDescriptors whitelist_imes; | 843 InputMethodDescriptors whitelist_imes; |
836 for (size_t i = 0; i < original_imes->size(); ++i) { | 844 for (size_t i = 0; i < original_imes->size(); ++i) { |
837 const InputMethodDescriptor& ime = (*original_imes)[i]; | 845 const InputMethodDescriptor& ime = (*original_imes)[i]; |
838 whitelist_imes.push_back(InputMethodDescriptor( | 846 whitelist_imes.push_back(InputMethodDescriptor( |
839 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), | 847 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), |
840 "", | 848 "", |
841 ime.indicator(), | 849 ime.indicator(), |
842 ime.keyboard_layouts(), | 850 ime.keyboard_layouts(), |
843 ime.language_codes(), | 851 ime.language_codes(), |
844 ime.is_login_keyboard(), | 852 ime.is_login_keyboard(), |
845 ime.options_page_url(), | 853 ime.options_page_url(), |
846 ime.input_view_url())); | 854 ime.input_view_url())); |
847 } | 855 } |
848 SetComponentExtensions(whitelist_imes); | 856 ResetInputMethods(whitelist_imes); |
849 } | 857 } |
850 | 858 |
851 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 859 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
852 std::vector<std::string> layouts; | 860 std::vector<std::string> layouts; |
853 layouts.push_back("us"); | 861 layouts.push_back("us"); |
854 std::vector<std::string> languages; | 862 std::vector<std::string> languages; |
855 languages.push_back("en-US"); | 863 languages.push_back("en-US"); |
856 return InputMethodDescriptor( | 864 return InputMethodDescriptor( |
857 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), | 865 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), |
858 "", | 866 "", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 std::make_pair(language_codes[i], input_method_id)); | 907 std::make_pair(language_codes[i], input_method_id)); |
900 // Remember the pairs. | 908 // Remember the pairs. |
901 id_to_language_code_.insert( | 909 id_to_language_code_.insert( |
902 std::make_pair(input_method_id, language_codes[i])); | 910 std::make_pair(input_method_id, language_codes[i])); |
903 } | 911 } |
904 } | 912 } |
905 } | 913 } |
906 | 914 |
907 } // namespace input_method | 915 } // namespace input_method |
908 } // namespace chromeos | 916 } // namespace chromeos |
OLD | NEW |