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 // The map from xkb layout to the indicator text. | |
130 // Refer to crbug.com/349829. | |
131 const char* const kXkbIndicators[][2] = { | |
Alexander Alekseev
2014/03/07 13:19:31
Will this be translated?
Shu Chen
2014/03/07 13:22:26
Thanks for your quick review.
There is no need to
| |
132 {"am", "AM"}, | |
133 {"be", "BE"}, | |
134 {"bg", "BG"}, | |
135 {"bg(phonetic)", "BG"}, | |
136 {"br", "BR"}, | |
137 {"by", "BY"}, | |
138 {"ca", "CA"}, | |
139 {"ca(eng)", "CA"}, | |
140 {"ca(multix)", "CA"}, | |
141 {"ch", "CH"}, | |
142 {"ch(fr)", "CH"}, | |
143 {"cz", "CZ"}, | |
144 {"cz(qwerty)", "CS"}, | |
145 {"de", "DE"}, | |
146 {"de(neo)", "NEO"}, | |
147 {"dk", "DK"}, | |
148 {"ee", "EE"}, | |
149 {"es", "ES"}, | |
150 {"es(cat)", "CAS"}, | |
151 {"fi", "FI"}, | |
152 {"fr", "FR"}, | |
153 {"gb(dvorak)", "DV"}, | |
154 {"gb(extd)", "GB"}, | |
155 {"ge", "GE"}, | |
156 {"gr", "GR"}, | |
157 {"hr", "HR"}, | |
158 {"hu", "HU"}, | |
159 {"il", "IL"}, | |
160 {"is", "IS"}, | |
161 {"it", "IT"}, | |
162 {"jp", "JA"}, | |
163 {"latam", "LA"}, | |
164 {"lt", "LT"}, | |
165 {"lv(apostrophe)", "LV"}, | |
166 {"mn", "MN"}, | |
167 {"no", "NO"}, | |
168 {"pl", "PL"}, | |
169 {"pt", "PT"}, | |
170 {"ro", "RO"}, | |
171 {"rs", "RS"}, | |
172 {"ru", "RU"}, | |
173 {"ru(phonetic)", "RU"}, | |
174 {"se", "SE"}, | |
175 {"si", "SI"}, | |
176 {"sk", "SK"}, | |
177 {"tr", "TR"}, | |
178 {"ua", "UA"}, | |
179 {"us", "US"}, | |
180 {"us(altgr-intl)", "EXTD"}, | |
181 {"us(colemak)", "CO"}, | |
182 {"us(dvorak)", "DV"}, | |
183 {"us(intl)", "INTL"}, | |
184 }; | |
185 | |
129 } // namespace | 186 } // namespace |
130 | 187 |
131 namespace chromeos { | 188 namespace chromeos { |
132 | 189 |
133 extern const char* kExtensionImePrefix; | 190 extern const char* kExtensionImePrefix; |
134 | 191 |
135 namespace input_method { | 192 namespace input_method { |
136 | 193 |
137 namespace { | 194 namespace { |
138 | 195 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 ReloadInternalMaps(); | 351 ReloadInternalMaps(); |
295 | 352 |
296 // Initialize a map from English string to Chrome string resource ID as well. | 353 // Initialize a map from English string to Chrome string resource ID as well. |
297 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { | 354 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { |
298 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; | 355 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; |
299 const bool result = english_to_resource_id_.insert(std::make_pair( | 356 const bool result = english_to_resource_id_.insert(std::make_pair( |
300 map_entry.english_string_from_ibus, map_entry.resource_id)).second; | 357 map_entry.english_string_from_ibus, map_entry.resource_id)).second; |
301 DCHECK(result) << "Duplicated string is found: " | 358 DCHECK(result) << "Duplicated string is found: " |
302 << map_entry.english_string_from_ibus; | 359 << map_entry.english_string_from_ibus; |
303 } | 360 } |
361 | |
362 // Initialize the map from xkb layout to indicator text. | |
363 for (size_t i = 0; i < arraysize(kXkbIndicators); ++i) { | |
364 xkb_layout_to_indicator_[kXkbIndicators[i][0]] = | |
365 kXkbIndicators[i][1]; | |
366 } | |
304 } | 367 } |
305 | 368 |
306 InputMethodUtil::~InputMethodUtil() { | 369 InputMethodUtil::~InputMethodUtil() { |
307 } | 370 } |
308 | 371 |
309 bool InputMethodUtil::TranslateStringInternal( | 372 bool InputMethodUtil::TranslateStringInternal( |
310 const std::string& english_string, base::string16 *out_string) const { | 373 const std::string& english_string, base::string16 *out_string) const { |
311 DCHECK(out_string); | 374 DCHECK(out_string); |
312 HashType::const_iterator iter = english_to_resource_id_.find(english_string); | 375 HashType::const_iterator iter = english_to_resource_id_.find(english_string); |
313 if (iter == english_to_resource_id_.end()) { | 376 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. | 454 // Check special cases first. |
392 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { | 455 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { |
393 if (kMappingFromIdToIndicatorText[i].input_method_id == | 456 if (kMappingFromIdToIndicatorText[i].input_method_id == |
394 input_method.id()) { | 457 input_method.id()) { |
395 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); | 458 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); |
396 break; | 459 break; |
397 } | 460 } |
398 } | 461 } |
399 | 462 |
400 // Display the keyboard layout name when using a keyboard layout. | 463 // Display the keyboard layout name when using a keyboard layout. |
401 if (text.empty() && | 464 if (text.empty() && IsKeyboardLayout(input_method.id())) { |
402 IsKeyboardLayout(input_method.id())) { | 465 std::map<std::string, std::string>::const_iterator it = |
403 const size_t kMaxKeyboardLayoutNameLen = 2; | 466 xkb_layout_to_indicator_.find(GetKeyboardLayoutName( |
404 const base::string16 keyboard_layout = | 467 input_method.id())); |
405 base::UTF8ToUTF16(GetKeyboardLayoutName(input_method.id())); | 468 if (it != xkb_layout_to_indicator_.end()) |
406 text = StringToUpperASCII(keyboard_layout).substr( | 469 text = base::UTF8ToUTF16(it->second); |
407 0, kMaxKeyboardLayoutNameLen); | |
408 } | 470 } |
409 | 471 |
410 // TODO(yusukes): Some languages have two or more input methods. For example, | 472 // 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 | 473 // 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: | 474 // the same time, we should do either of the following: |
413 // (1) Add mappings to |kMappingFromIdToIndicatorText| | 475 // (1) Add mappings to |kMappingFromIdToIndicatorText| |
414 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. | 476 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. |
415 | 477 |
416 if (text.empty()) { | 478 if (text.empty()) { |
417 const size_t kMaxLanguageNameLen = 2; | 479 const size_t kMaxLanguageNameLen = 2; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 } | 538 } |
477 | 539 |
478 DCHECK(!text.empty()); | 540 DCHECK(!text.empty()); |
479 return text; | 541 return text; |
480 } | 542 } |
481 | 543 |
482 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( | 544 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( |
483 const std::string& input_method_id) const { | 545 const std::string& input_method_id) const { |
484 InputMethodIdToDescriptorMap::const_iterator iter | 546 InputMethodIdToDescriptorMap::const_iterator iter |
485 = id_to_descriptor_.find(input_method_id); | 547 = id_to_descriptor_.find(input_method_id); |
486 if (iter == id_to_descriptor_.end()) { | 548 if (iter == id_to_descriptor_.end()) |
487 // If failed to find the descriptor for given id, it may because of the id | 549 return NULL; |
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; | |
498 } | |
499 return &(iter->second); | 550 return &(iter->second); |
500 } | 551 } |
501 | 552 |
502 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( | 553 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( |
503 const std::string& normalized_language_code, | 554 const std::string& normalized_language_code, |
504 InputMethodType type, | 555 InputMethodType type, |
505 std::vector<std::string>* out_input_method_ids) const { | 556 std::vector<std::string>* out_input_method_ids) const { |
506 return GetInputMethodIdsFromLanguageCodeInternal( | 557 return GetInputMethodIdsFromLanguageCodeInternal( |
507 language_code_to_ids_, | 558 language_code_to_ids_, |
508 normalized_language_code, type, out_input_method_ids); | 559 normalized_language_code, type, out_input_method_ids); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 | 752 |
702 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 753 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
703 const { | 754 const { |
704 const InputMethodDescriptor* ime = | 755 const InputMethodDescriptor* ime = |
705 GetInputMethodDescriptorFromId(input_method_id); | 756 GetInputMethodDescriptorFromId(input_method_id); |
706 return ime ? ime->is_login_keyboard() : false; | 757 return ime ? ime->is_login_keyboard() : false; |
707 } | 758 } |
708 | 759 |
709 void InputMethodUtil::SetComponentExtensions( | 760 void InputMethodUtil::SetComponentExtensions( |
710 const InputMethodDescriptors& imes) { | 761 const InputMethodDescriptors& imes) { |
711 component_extension_ime_id_to_descriptor_.clear(); | |
712 for (size_t i = 0; i < imes.size(); ++i) { | 762 for (size_t i = 0; i < imes.size(); ++i) { |
713 const InputMethodDescriptor& input_method = imes.at(i); | 763 const InputMethodDescriptor& input_method = imes[i]; |
714 DCHECK(!input_method.language_codes().empty()); | 764 DCHECK(!input_method.language_codes().empty()); |
715 const std::string language_code = input_method.language_codes().at(0); | 765 const std::vector<std::string>& language_codes = |
716 id_to_language_code_.insert( | 766 input_method.language_codes(); |
717 std::make_pair(input_method.id(), language_code)); | 767 id_to_language_code_[input_method.id()] = language_codes[0]; |
718 id_to_descriptor_.insert( | 768 id_to_descriptor_[input_method.id()] = input_method; |
719 std::make_pair(input_method.id(), input_method)); | 769 for (size_t j = 0; j < language_codes.size(); ++j) { |
770 language_code_to_ids_.insert( | |
771 std::make_pair(language_codes[j], input_method.id())); | |
772 } | |
720 } | 773 } |
721 } | 774 } |
722 | 775 |
723 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 776 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
724 std::vector<std::string> layouts; | 777 std::vector<std::string> layouts; |
725 layouts.push_back("us"); | 778 layouts.push_back("us"); |
726 std::vector<std::string> languages; | 779 std::vector<std::string> languages; |
727 languages.push_back("en-US"); | 780 languages.push_back("en-US"); |
728 return InputMethodDescriptor( | 781 return InputMethodDescriptor( |
729 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), | 782 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())) { | 818 if (IsKeyboardLayout(input_method.id())) { |
766 xkb_id_to_descriptor_.insert( | 819 xkb_id_to_descriptor_.insert( |
767 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 820 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
768 input_method)); | 821 input_method)); |
769 } | 822 } |
770 } | 823 } |
771 } | 824 } |
772 | 825 |
773 } // namespace input_method | 826 } // namespace input_method |
774 } // namespace chromeos | 827 } // namespace chromeos |
OLD | NEW |