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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 { "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN }, | 286 { "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN }, |
287 { "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC }, | 287 { "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC }, |
288 { "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN }, | 288 { "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN }, |
289 { "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN }, | 289 { "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN }, |
290 | 290 |
291 { "english-m", IDS_STATUSBAR_LAYOUT_USA_MYSTERY }, | 291 { "english-m", IDS_STATUSBAR_LAYOUT_USA_MYSTERY }, |
292 }; | 292 }; |
293 const size_t kEnglishToResourceIdArraySize = | 293 const size_t kEnglishToResourceIdArraySize = |
294 arraysize(kEnglishToResourceIdArray); | 294 arraysize(kEnglishToResourceIdArray); |
295 | 295 |
296 // The list of language that do not have associated input methods in IBus. | |
297 // For these languages, we associate input methods here. | |
298 const struct ExtraLanguage { | |
299 const char* language_code; | |
300 const char* input_method_id; | |
301 } kExtraLanguages[] = { | |
302 // Language Code Input Method ID | |
303 { "en-AU", "xkb:us::eng" }, // For Austrailia, use US keyboard layout. | |
304 { "id", "xkb:us::eng" }, // For Indonesian, use US keyboard layout. | |
305 // The code "fil" comes from l10_util.cc. | |
306 { "fil", "xkb:us::eng" }, // For Filipino, use US keyboard layout. | |
307 // For Netherlands, use US international keyboard layout. | |
308 { "nl", "xkb:us:intl:eng" }, | |
309 // The code "es-419" comes from l10_util.cc. | |
310 // For Spanish in Latin America, use Latin American keyboard layout. | |
311 { "es-419", "xkb:latam::spa" }, | |
312 // For Malay, use US keyboard layout. crosbug.com/p/8288 | |
313 { "ms", "xkb:us::eng" }, | |
314 // For Brazil, it is common to use US-international keyboard layout. | |
315 { "pt-BR", "xkb:us:intl:eng" }, | |
316 | |
317 // TODO(yusukes): Add {"sw", "xkb:us::eng"} once Swahili is removed from the | |
318 // blacklist in src/ui/base/l10n/l10n_util_posix.cc. | |
319 }; | |
320 const size_t kExtraLanguagesLength = arraysize(kExtraLanguages); | |
321 | |
322 } // namespace | 296 } // namespace |
323 | 297 |
324 InputMethodUtil::InputMethodUtil( | 298 InputMethodUtil::InputMethodUtil( |
325 InputMethodDelegate* delegate, | 299 InputMethodDelegate* delegate, |
326 scoped_ptr<InputMethodDescriptors> supported_input_methods) | 300 scoped_ptr<InputMethodDescriptors> supported_input_methods) |
327 : supported_input_methods_(supported_input_methods.Pass()), | 301 : supported_input_methods_(supported_input_methods.Pass()), |
328 delegate_(delegate) { | 302 delegate_(delegate) { |
329 ReloadInternalMaps(); | 303 ReloadInternalMaps(); |
330 | 304 |
331 // Initialize a map from English string to Chrome string resource ID as well. | 305 // Initialize a map from English string to Chrome string resource ID as well. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 return text; | 476 return text; |
503 } | 477 } |
504 | 478 |
505 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( | 479 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( |
506 const std::string& input_method_id) const { | 480 const std::string& input_method_id) const { |
507 InputMethodIdToDescriptorMap::const_iterator iter | 481 InputMethodIdToDescriptorMap::const_iterator iter |
508 = id_to_descriptor_.find(input_method_id); | 482 = id_to_descriptor_.find(input_method_id); |
509 return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); | 483 return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); |
510 } | 484 } |
511 | 485 |
512 std::vector<std::string> InputMethodUtil::GetExtraLanguageCodesFromId( | |
513 const std::string& input_method_id) const { | |
514 std::vector<std::string> result; | |
515 for (size_t i = 0; i < kExtraLanguagesLength; ++i) { | |
516 if (input_method_id == kExtraLanguages[i].input_method_id) | |
517 result.push_back(kExtraLanguages[i].language_code); | |
518 } | |
519 return result; | |
520 } | |
521 | |
522 std::vector<std::string> InputMethodUtil::GetExtraLanguageCodeList() const { | |
523 std::vector<std::string> result; | |
524 for (size_t i = 0; i < kExtraLanguagesLength; ++i) | |
525 result.push_back(kExtraLanguages[i].language_code); | |
526 return result; | |
527 } | |
528 | |
529 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( | 486 bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( |
530 const std::string& normalized_language_code, | 487 const std::string& normalized_language_code, |
531 InputMethodType type, | 488 InputMethodType type, |
532 std::vector<std::string>* out_input_method_ids) const { | 489 std::vector<std::string>* out_input_method_ids) const { |
533 return GetInputMethodIdsFromLanguageCodeInternal( | 490 return GetInputMethodIdsFromLanguageCodeInternal( |
534 language_code_to_ids_, | 491 language_code_to_ids_, |
535 normalized_language_code, type, out_input_method_ids); | 492 normalized_language_code, type, out_input_method_ids); |
536 } | 493 } |
537 | 494 |
538 bool InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal( | 495 bool InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 std::make_pair(input_method.id(), language_codes[i])); | 665 std::make_pair(input_method.id(), language_codes[i])); |
709 } | 666 } |
710 id_to_descriptor_.insert( | 667 id_to_descriptor_.insert( |
711 std::make_pair(input_method.id(), input_method)); | 668 std::make_pair(input_method.id(), input_method)); |
712 if (IsKeyboardLayout(input_method.id())) { | 669 if (IsKeyboardLayout(input_method.id())) { |
713 xkb_id_to_descriptor_.insert( | 670 xkb_id_to_descriptor_.insert( |
714 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 671 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
715 input_method)); | 672 input_method)); |
716 } | 673 } |
717 } | 674 } |
718 | |
719 // Go through the languages listed in kExtraLanguages. | |
720 for (size_t i = 0; i < kExtraLanguagesLength; ++i) { | |
721 const char* language_code = kExtraLanguages[i].language_code; | |
722 const char* input_method_id = kExtraLanguages[i].input_method_id; | |
723 InputMethodIdToDescriptorMap::const_iterator iter = | |
724 id_to_descriptor_.find(input_method_id); | |
725 // If the associated input method descriptor is found, add the language | |
726 // code and the input method. | |
727 if (iter != id_to_descriptor_.end()) { | |
728 const InputMethodDescriptor& input_method = iter->second; | |
729 language_code_to_ids_.insert( | |
730 std::make_pair(language_code, input_method.id())); | |
731 } | |
732 } | |
733 } | 675 } |
734 | 676 |
735 } // namespace input_method | 677 } // namespace input_method |
736 } // namespace chromeos | 678 } // namespace chromeos |
OLD | NEW |