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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // A mapping from an input method id to a string for the language indicator. The | 30 // A mapping from an input method id to a string for the language indicator. The |
31 // mapping is necessary since some input methods belong to the same language. | 31 // mapping is necessary since some input methods belong to the same language. |
32 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. | 32 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. |
33 const struct { | 33 const struct { |
34 const char* input_method_id; | 34 const char* input_method_id; |
35 const char* indicator_text; | 35 const char* indicator_text; |
36 } kMappingFromIdToIndicatorText[] = { | 36 } kMappingFromIdToIndicatorText[] = { |
37 // To distinguish from "xkb:jp::jpn" | 37 // To distinguish from "xkb:jp::jpn" |
38 // TODO(nona): Make following variables configurable. http://crbug.com/232260. | 38 // TODO(nona): Make following variables configurable. http://crbug.com/232260. |
39 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us", "\xe3\x81\x82" }, | 39 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us", "\xe3\x81\x82" }, |
40 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp", "\xe3\x81\x82" }, | 40 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp", "\xe3\x81\x82" }, |
41 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_us", "\xe3\x81\x82" }, | 41 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_us", "\xe3\x81\x82" }, |
42 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_jp", "\xe3\x81\x82" }, | 42 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_jp", "\xe3\x81\x82" }, |
43 // For simplified Chinese input methods | 43 // For simplified Chinese input methods |
44 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC | 44 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC |
45 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", | 45 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", |
46 "\xe6\x8b\xbc" }, | 46 "\xe6\x8b\xbc" }, |
47 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin", | 47 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin", |
48 "\xe6\x8b\xbc" }, | 48 "\xe6\x8b\xbc" }, |
49 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-wubi-1986", | 49 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-wubi-1986", |
50 "\xe4\xba\x94" }, // U+4E94 | 50 "\xe4\xba\x94" }, // U+4E94 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // Due to asynchronous initialization of component extension manager, | 118 // Due to asynchronous initialization of component extension manager, |
119 // GetFirstLogingInputMethodIds may miss component extension IMEs. To enable | 119 // GetFirstLogingInputMethodIds may miss component extension IMEs. To enable |
120 // component extension IME as the first loging input method, we have to prepare | 120 // component extension IME as the first loging input method, we have to prepare |
121 // component extension IME IDs. | 121 // component extension IME IDs. |
122 const struct { | 122 const struct { |
123 const char* locale; | 123 const char* locale; |
124 const char* layout; | 124 const char* layout; |
125 const char* input_method_id; | 125 const char* input_method_id; |
126 } kDefaultInputMethodRecommendation[] = { | 126 } kDefaultInputMethodRecommendation[] = { |
127 { "ja", "us", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" }, | 127 { "ja", "us", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us" }, |
128 { "ja", "jp", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp" }, | 128 { "ja", "jp", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp" }, |
129 { "zh-CN", "us", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin" }, | 129 { "zh-CN", "us", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin" }, |
130 { "zh-TW", "us", | 130 { "zh-TW", "us", |
131 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und" }, | 131 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und" }, |
132 #if defined(OFFICIAL_BUILD) | 132 #if defined(OFFICIAL_BUILD) |
133 { "th", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_th" }, | 133 { "th", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_th" }, |
134 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, | 134 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, |
135 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, | 135 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, |
136 #else | 136 #else |
137 { "th", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_th" }, | 137 { "th", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_th" }, |
138 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, | 138 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 {"si", "SI"}, | 188 {"si", "SI"}, |
189 {"sk", "SK"}, | 189 {"sk", "SK"}, |
190 {"tr", "TR"}, | 190 {"tr", "TR"}, |
191 {"ua", "UA"}, | 191 {"ua", "UA"}, |
192 {"us", "US"}, | 192 {"us", "US"}, |
193 {"us(altgr-intl)", "EXTD"}, | 193 {"us(altgr-intl)", "EXTD"}, |
194 {"us(colemak)", "CO"}, | 194 {"us(colemak)", "CO"}, |
195 {"us(dvorak)", "DV"}, | 195 {"us(dvorak)", "DV"}, |
196 {"us(intl)", "INTL"}, }; | 196 {"us(intl)", "INTL"}, }; |
197 | 197 |
198 // The old chinese input method ids for migration. | 198 // The extension ID map for migration. |
199 // See crbug.com/357384. | 199 const char* const kExtensionIdMigrationMap[][2] = { |
200 const char* kOldChineseExtensionIds[] = { | 200 // Official Japanese IME extension ID. |
201 "goedamlknlnjaengojinmfgpmdjmkooo", | 201 {"fpfbhcjppmaeaijcidgiibchfbnhbelj", "gjaehgfemfahhmlgpdfknkhdnemmolop"}, |
202 "nmblnjkfdkabgdofidlkienfnnbjhnab", | |
203 "gjhclobljhjhgoebiipblnmdodbmpdgd" | |
204 }; | 202 }; |
205 | 203 |
206 // The new chinese input method id for migration. | |
207 // See crbug.com/357384. | |
208 const char* kNewChineseExtensionId = "gjaehgfemfahhmlgpdfknkhdnemmolop"; | |
209 | |
210 const size_t kExtensionIdLen = 32; | 204 const size_t kExtensionIdLen = 32; |
211 | 205 |
212 } // namespace | 206 } // namespace |
213 | 207 |
214 namespace chromeos { | 208 namespace chromeos { |
215 | 209 |
216 extern const char* kExtensionImePrefix; | 210 extern const char* kExtensionImePrefix; |
217 | 211 |
218 namespace input_method { | 212 namespace input_method { |
219 | 213 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 const std::string& language_code) { | 696 const std::string& language_code) { |
703 std::vector<std::string> candidates; | 697 std::vector<std::string> candidates; |
704 GetInputMethodIdsFromLanguageCode( | 698 GetInputMethodIdsFromLanguageCode( |
705 language_code, input_method::kKeyboardLayoutsOnly, &candidates); | 699 language_code, input_method::kKeyboardLayoutsOnly, &candidates); |
706 if (candidates.size()) | 700 if (candidates.size()) |
707 return candidates.front(); | 701 return candidates.front(); |
708 | 702 |
709 return std::string(); | 703 return std::string(); |
710 } | 704 } |
711 | 705 |
712 bool InputMethodUtil::MigrateXkbInputMethods( | 706 bool InputMethodUtil::MigrateInputMethods( |
713 std::vector<std::string>* input_method_ids) { | 707 std::vector<std::string>* input_method_ids) { |
714 bool rewritten = false; | 708 bool rewritten = false; |
715 std::vector<std::string>& ids = *input_method_ids; | 709 std::vector<std::string>& ids = *input_method_ids; |
716 for (size_t i = 0; i < ids.size(); ++i) { | 710 for (size_t i = 0; i < ids.size(); ++i) { |
717 std::string id = | 711 std::string id = |
718 extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); | 712 extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); |
719 // Migrates the old chinese ime id to new ones. | 713 // Migrates old ime id's to new ones. |
720 // TODO(shuchen): Change the function name to MigrateInputMethods, | 714 for (size_t j = 0; j < arraysize(kExtensionIdMigrationMap); ++j) { |
721 // and create an abstract layer to map a comprehensive input method id to | 715 size_t pos = id.find(kExtensionIdMigrationMap[j][0]); |
722 // the real extension based input method id. | 716 if (pos != std::string::npos) |
723 // e.g. "zh-t-i0-pinyin" maps to | 717 id.replace(pos, kExtensionIdLen, kExtensionIdMigrationMap[j][1]); |
724 // "_comp_id_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin". | 718 if (id != ids[i]) { |
725 // See crbug.com/358083. | 719 ids[i] = id; |
726 for (size_t j = 0; j < arraysize(kOldChineseExtensionIds); ++j) { | 720 rewritten = true; |
727 size_t pos = id.find(kOldChineseExtensionIds[j]); | |
728 if (pos != std::string::npos) { | |
729 id.replace(pos, kExtensionIdLen, kNewChineseExtensionId); | |
730 break; | |
731 } | 721 } |
732 } | 722 } |
733 if (id != ids[i]) { | |
734 ids[i] = id; | |
735 rewritten = true; | |
736 } | |
737 } | 723 } |
738 if (rewritten) { | 724 if (rewritten) { |
739 // Removes the duplicates. | 725 // Removes the duplicates. |
740 std::vector<std::string> new_ids; | 726 std::vector<std::string> new_ids; |
741 for (size_t i = 0; i < ids.size(); ++i) { | 727 for (size_t i = 0; i < ids.size(); ++i) { |
742 if (std::find(new_ids.begin(), new_ids.end(), ids[i]) == new_ids.end()) | 728 if (std::find(new_ids.begin(), new_ids.end(), ids[i]) == new_ids.end()) |
743 new_ids.push_back(ids[i]); | 729 new_ids.push_back(ids[i]); |
744 } | 730 } |
745 ids.swap(new_ids); | 731 ids.swap(new_ids); |
746 } | 732 } |
747 return rewritten; | 733 return rewritten; |
748 } | 734 } |
749 | 735 |
750 void InputMethodUtil::UpdateHardwareLayoutCache() { | 736 void InputMethodUtil::UpdateHardwareLayoutCache() { |
751 DCHECK(thread_checker_.CalledOnValidThread()); | 737 DCHECK(thread_checker_.CalledOnValidThread()); |
752 hardware_layouts_.clear(); | 738 hardware_layouts_.clear(); |
753 hardware_login_layouts_.clear(); | 739 hardware_login_layouts_.clear(); |
754 if (cached_hardware_layouts_.empty()) | 740 if (cached_hardware_layouts_.empty()) |
755 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", | 741 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", |
756 &cached_hardware_layouts_); | 742 &cached_hardware_layouts_); |
757 hardware_layouts_ = cached_hardware_layouts_; | 743 hardware_layouts_ = cached_hardware_layouts_; |
758 MigrateXkbInputMethods(&hardware_layouts_); | 744 MigrateInputMethods(&hardware_layouts_); |
759 | 745 |
760 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { | 746 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { |
761 if (IsLoginKeyboard(hardware_layouts_[i])) | 747 if (IsLoginKeyboard(hardware_layouts_[i])) |
762 hardware_login_layouts_.push_back(hardware_layouts_[i]); | 748 hardware_login_layouts_.push_back(hardware_layouts_[i]); |
763 } | 749 } |
764 if (hardware_layouts_.empty()) { | 750 if (hardware_layouts_.empty()) { |
765 // This is totally fine if it's empty. The hardware keyboard layout is | 751 // This is totally fine if it's empty. The hardware keyboard layout is |
766 // not stored if startup_manifest.json (OEM customization data) is not | 752 // not stored if startup_manifest.json (OEM customization data) is not |
767 // present (ex. Cr48 doen't have that file). | 753 // present (ex. Cr48 doen't have that file). |
768 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); | 754 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 std::make_pair(language_codes[i], input_method_id)); | 893 std::make_pair(language_codes[i], input_method_id)); |
908 // Remember the pairs. | 894 // Remember the pairs. |
909 id_to_language_code_.insert( | 895 id_to_language_code_.insert( |
910 std::make_pair(input_method_id, language_codes[i])); | 896 std::make_pair(input_method_id, language_codes[i])); |
911 } | 897 } |
912 } | 898 } |
913 } | 899 } |
914 | 900 |
915 } // namespace input_method | 901 } // namespace input_method |
916 } // namespace chromeos | 902 } // namespace chromeos |
OLD | NEW |