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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 { "ja", "us", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" }, | 119 { "ja", "us", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" }, |
120 { "ja", "jp", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp" }, | 120 { "ja", "jp", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp" }, |
121 { "zh-CN", "us", "_comp_ime_nmblnjkfdkabgdofidlkienfnnbjhnabzh-t-i0-pinyin" }, | 121 { "zh-CN", "us", "_comp_ime_nmblnjkfdkabgdofidlkienfnnbjhnabzh-t-i0-pinyin" }, |
122 { "zh-TW", "us", | 122 { "zh-TW", "us", |
123 "_comp_ime_goedamlknlnjaengojinmfgpmdjmkooozh-hant-t-i0-und" }, | 123 "_comp_ime_goedamlknlnjaengojinmfgpmdjmkooozh-hant-t-i0-und" }, |
124 { "th", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_th" }, | 124 { "th", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_th" }, |
125 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, | 125 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, |
126 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, | 126 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, |
127 }; | 127 }; |
128 | 128 |
129 struct _XkbConfigItem { | |
Yuki
2014/03/07 07:47:04
Do not start with the underscore followed by a cap
Shu Chen
2014/03/07 08:24:09
Done.
| |
130 std::string layout_name; | |
131 std::string indicator; | |
132 bool allow_login; | |
133 }; | |
134 | |
135 const _XkbConfigItem kXkbIndicators[] = { | |
Seigo Nonaka
2014/03/07 07:21:21
nit: Please leave comment this is related to crbug
Shu Chen
2014/03/07 07:30:29
Done.
Yuki
2014/03/07 07:47:04
Static initialization of non-trivial types are pro
Shu Chen
2014/03/07 08:24:09
Sorry I forgot to remove the type _XkbConfigItem.
| |
136 {"am", "AM"}, | |
137 {"be", "BE"}, | |
138 {"be", "BE"}, | |
139 {"be", "BE"}, | |
140 {"bg", "BG"}, | |
141 {"bg(phonetic)", "BG"}, | |
142 {"br", "BR"}, | |
143 {"by", "BY"}, | |
144 {"ca", "CA"}, | |
145 {"ca(eng)", "CA"}, | |
146 {"ca(multix)", "CA"}, | |
147 {"ch", "CH"}, | |
148 {"ch(fr)", "CH"}, | |
149 {"cz", "CZ"}, | |
150 {"cz(qwerty)", "CS"}, | |
151 {"de", "DE"}, | |
152 {"de(neo)", "NEO"}, | |
153 {"dk", "DK"}, | |
154 {"ee", "EE"}, | |
155 {"es", "ES"}, | |
156 {"es(cat)", "CAS"}, | |
157 {"fi", "FI"}, | |
158 {"fr", "FR"}, | |
159 {"gb(dvorak)", "DV"}, | |
160 {"gb(extd)", "GB"}, | |
161 {"ge", "GE"}, | |
162 {"gr", "GR"}, | |
163 {"hr", "HR"}, | |
164 {"hu", "HU"}, | |
165 {"il", "IL"}, | |
166 {"is", "IS"}, | |
167 {"it", "IT"}, | |
168 {"jp", "JA"}, | |
169 {"latam", "LA"}, | |
170 {"lt", "LT"}, | |
171 {"lv(apostrophe)", "LV"}, | |
172 {"mn", "MN"}, | |
173 {"no", "NO"}, | |
174 {"pl", "PL"}, | |
175 {"pt", "PT"}, | |
176 {"ro", "RO"}, | |
177 {"rs", "RS"}, | |
178 {"ru", "RU"}, | |
179 {"ru(phonetic)", "RU"}, | |
180 {"se", "SE"}, | |
181 {"si", "SI"}, | |
182 {"sk", "SK"}, | |
183 {"tr", "TR"}, | |
184 {"ua", "UA"}, | |
185 {"us", "US"}, | |
186 {"us(altgr-intl)", "EXTD"}, | |
187 {"us(colemak)", "CO"}, | |
188 {"us(dvorak)", "DV"}, | |
189 {"us(intl)", "INTL"}, | |
190 }; | |
191 | |
129 } // namespace | 192 } // namespace |
130 | 193 |
131 namespace chromeos { | 194 namespace chromeos { |
132 | 195 |
133 extern const char* kExtensionImePrefix; | 196 extern const char* kExtensionImePrefix; |
134 | 197 |
135 namespace input_method { | 198 namespace input_method { |
136 | 199 |
137 namespace { | 200 namespace { |
138 | 201 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 ReloadInternalMaps(); | 357 ReloadInternalMaps(); |
295 | 358 |
296 // Initialize a map from English string to Chrome string resource ID as well. | 359 // Initialize a map from English string to Chrome string resource ID as well. |
297 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { | 360 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { |
298 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; | 361 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; |
299 const bool result = english_to_resource_id_.insert(std::make_pair( | 362 const bool result = english_to_resource_id_.insert(std::make_pair( |
300 map_entry.english_string_from_ibus, map_entry.resource_id)).second; | 363 map_entry.english_string_from_ibus, map_entry.resource_id)).second; |
301 DCHECK(result) << "Duplicated string is found: " | 364 DCHECK(result) << "Duplicated string is found: " |
302 << map_entry.english_string_from_ibus; | 365 << map_entry.english_string_from_ibus; |
303 } | 366 } |
367 | |
368 // Initialize the map from xkb layout to indicator text. | |
369 for (size_t i = 0; i < arraysize(kXkbIndicators); ++i) { | |
370 xkb_layout_to_indicator_[kXkbIndicators[i].layout_name] = | |
371 kXkbIndicators[i].indicator; | |
372 } | |
304 } | 373 } |
305 | 374 |
306 InputMethodUtil::~InputMethodUtil() { | 375 InputMethodUtil::~InputMethodUtil() { |
307 } | 376 } |
308 | 377 |
309 bool InputMethodUtil::TranslateStringInternal( | 378 bool InputMethodUtil::TranslateStringInternal( |
310 const std::string& english_string, base::string16 *out_string) const { | 379 const std::string& english_string, base::string16 *out_string) const { |
311 DCHECK(out_string); | 380 DCHECK(out_string); |
312 HashType::const_iterator iter = english_to_resource_id_.find(english_string); | 381 HashType::const_iterator iter = english_to_resource_id_.find(english_string); |
313 if (iter == english_to_resource_id_.end()) { | 382 if (iter == english_to_resource_id_.end()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 // Check special cases first. | 460 // Check special cases first. |
392 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { | 461 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { |
393 if (kMappingFromIdToIndicatorText[i].input_method_id == | 462 if (kMappingFromIdToIndicatorText[i].input_method_id == |
394 input_method.id()) { | 463 input_method.id()) { |
395 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); | 464 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); |
396 break; | 465 break; |
397 } | 466 } |
398 } | 467 } |
399 | 468 |
400 // Display the keyboard layout name when using a keyboard layout. | 469 // Display the keyboard layout name when using a keyboard layout. |
401 if (text.empty() && | 470 if (text.empty() && IsKeyboardLayout(input_method.id())) { |
402 IsKeyboardLayout(input_method.id())) { | 471 std::map<std::string, std::string>::const_iterator it = |
403 const size_t kMaxKeyboardLayoutNameLen = 2; | 472 xkb_layout_to_indicator_.find(GetKeyboardLayoutName( |
404 const base::string16 keyboard_layout = | 473 input_method.id())); |
405 base::UTF8ToUTF16(GetKeyboardLayoutName(input_method.id())); | 474 if (it != xkb_layout_to_indicator_.end()) |
406 text = StringToUpperASCII(keyboard_layout).substr( | 475 text = base::UTF8ToUTF16(it->second); |
407 0, kMaxKeyboardLayoutNameLen); | |
408 } | 476 } |
409 | 477 |
410 // TODO(yusukes): Some languages have two or more input methods. For example, | 478 // TODO(yusukes): Some languages have two or more input methods. For example, |
411 // Thai has 3, Vietnamese has 4. If these input methods could be activated at | 479 // Thai has 3, Vietnamese has 4. If these input methods could be activated at |
412 // the same time, we should do either of the following: | 480 // the same time, we should do either of the following: |
413 // (1) Add mappings to |kMappingFromIdToIndicatorText| | 481 // (1) Add mappings to |kMappingFromIdToIndicatorText| |
414 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. | 482 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. |
415 | 483 |
416 if (text.empty()) { | 484 if (text.empty()) { |
417 const size_t kMaxLanguageNameLen = 2; | 485 const size_t kMaxLanguageNameLen = 2; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 } | 544 } |
477 | 545 |
478 DCHECK(!text.empty()); | 546 DCHECK(!text.empty()); |
479 return text; | 547 return text; |
480 } | 548 } |
481 | 549 |
482 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( | 550 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( |
483 const std::string& input_method_id) const { | 551 const std::string& input_method_id) const { |
484 InputMethodIdToDescriptorMap::const_iterator iter | 552 InputMethodIdToDescriptorMap::const_iterator iter |
485 = id_to_descriptor_.find(input_method_id); | 553 = id_to_descriptor_.find(input_method_id); |
486 if (iter == id_to_descriptor_.end()) { | 554 if (iter == id_to_descriptor_.end()) |
487 // If failed to find the descriptor for given id, it may because of the id | |
488 // is a component extension xkb id (_comp_ime_...xkb:...). | |
489 // So try to convert it to legacy xkb id and find again. | |
490 // This hack is mainly for OOBE session, which requires a sync call to get | |
491 // the input method descriptor for extension xkb id. | |
492 // TODO(shuchen): need to support async wait for component extension | |
493 // loading in OOBE session. This hack won't be needed when it's been done. | |
494 iter = id_to_descriptor_.find( | |
495 extension_ime_util::MaybeGetLegacyXkbId(input_method_id)); | |
496 if (iter == id_to_descriptor_.end()) | |
497 return NULL; | 555 return NULL; |
Yuki
2014/03/07 07:47:04
nit: Fix the indent. 4 spaces => 2 spaces.
Shu Chen
2014/03/07 08:24:09
Done.
| |
498 } | |
499 return &(iter->second); | 556 return &(iter->second); |
500 } | 557 } |
501 | 558 |
502 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( | 559 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( |
503 const std::string& normalized_language_code, | 560 const std::string& normalized_language_code, |
504 InputMethodType type, | 561 InputMethodType type, |
505 std::vector<std::string>* out_input_method_ids) const { | 562 std::vector<std::string>* out_input_method_ids) const { |
506 return GetInputMethodIdsFromLanguageCodeInternal( | 563 return GetInputMethodIdsFromLanguageCodeInternal( |
507 language_code_to_ids_, | 564 language_code_to_ids_, |
508 normalized_language_code, type, out_input_method_ids); | 565 normalized_language_code, type, out_input_method_ids); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 | 758 |
702 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 759 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
703 const { | 760 const { |
704 const InputMethodDescriptor* ime = | 761 const InputMethodDescriptor* ime = |
705 GetInputMethodDescriptorFromId(input_method_id); | 762 GetInputMethodDescriptorFromId(input_method_id); |
706 return ime ? ime->is_login_keyboard() : false; | 763 return ime ? ime->is_login_keyboard() : false; |
707 } | 764 } |
708 | 765 |
709 void InputMethodUtil::SetComponentExtensions( | 766 void InputMethodUtil::SetComponentExtensions( |
710 const InputMethodDescriptors& imes) { | 767 const InputMethodDescriptors& imes) { |
711 component_extension_ime_id_to_descriptor_.clear(); | |
712 for (size_t i = 0; i < imes.size(); ++i) { | 768 for (size_t i = 0; i < imes.size(); ++i) { |
713 const InputMethodDescriptor& input_method = imes.at(i); | 769 const InputMethodDescriptor& input_method = imes[i]; |
714 DCHECK(!input_method.language_codes().empty()); | 770 DCHECK(!input_method.language_codes().empty()); |
715 const std::string language_code = input_method.language_codes().at(0); | 771 const std::vector<std::string>& language_codes = |
716 id_to_language_code_.insert( | 772 input_method.language_codes(); |
717 std::make_pair(input_method.id(), language_code)); | 773 id_to_language_code_[input_method.id()] = language_codes[0]; |
718 id_to_descriptor_.insert( | 774 id_to_descriptor_[input_method.id()] = input_method; |
719 std::make_pair(input_method.id(), input_method)); | 775 for (size_t j = 0; j < language_codes.size(); ++j) { |
776 language_code_to_ids_.insert( | |
777 std::make_pair(language_codes[j], input_method.id())); | |
778 } | |
720 } | 779 } |
721 } | 780 } |
722 | 781 |
723 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 782 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
724 std::vector<std::string> layouts; | 783 std::vector<std::string> layouts; |
725 layouts.push_back("us"); | 784 layouts.push_back("us"); |
726 std::vector<std::string> languages; | 785 std::vector<std::string> languages; |
727 languages.push_back("en-US"); | 786 languages.push_back("en-US"); |
728 return InputMethodDescriptor( | 787 return InputMethodDescriptor( |
729 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), | 788 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 if (IsKeyboardLayout(input_method.id())) { | 824 if (IsKeyboardLayout(input_method.id())) { |
766 xkb_id_to_descriptor_.insert( | 825 xkb_id_to_descriptor_.insert( |
767 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 826 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
768 input_method)); | 827 input_method)); |
769 } | 828 } |
770 } | 829 } |
771 } | 830 } |
772 | 831 |
773 } // namespace input_method | 832 } // namespace input_method |
774 } // namespace chromeos | 833 } // namespace chromeos |
OLD | NEW |