| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 18 #include "chrome/browser/chromeos/language_preferences.h" | 19 #include "chrome/browser/chromeos/language_preferences.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/l10n/l10n_util_collator.h" | 24 #include "ui/base/l10n/l10n_util_collator.h" |
| 24 #include "unicode/uloc.h" | 25 #include "unicode/uloc.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 // For traditional Chinese input methods | 55 // For traditional Chinese input methods |
| 55 { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177 | 56 { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177 |
| 56 { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009 | 57 { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009 |
| 57 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F | 58 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F |
| 58 // For Hangul input method. | 59 // For Hangul input method. |
| 59 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C | 60 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 const size_t kMappingFromIdToIndicatorTextLen = | 63 const size_t kMappingFromIdToIndicatorTextLen = |
| 63 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); | 64 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); |
| 65 |
| 66 string16 GetLanguageName(const std::string& language_code) { |
| 67 const string16 language_name = l10n_util::GetDisplayNameForLocale( |
| 68 language_code, g_browser_process->GetApplicationLocale(), true); |
| 69 return language_name; |
| 70 } |
| 71 |
| 64 } | 72 } |
| 65 | 73 |
| 66 namespace chromeos { | 74 namespace chromeos { |
| 67 | 75 |
| 68 extern const char* kExtensionImePrefix; | 76 extern const char* kExtensionImePrefix; |
| 69 | 77 |
| 70 namespace input_method { | 78 namespace input_method { |
| 71 | 79 |
| 72 namespace { | 80 namespace { |
| 73 | 81 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 if (text.empty()) { | 412 if (text.empty()) { |
| 405 const size_t kMaxLanguageNameLen = 2; | 413 const size_t kMaxLanguageNameLen = 2; |
| 406 const std::string language_code = input_method.language_code(); | 414 const std::string language_code = input_method.language_code(); |
| 407 text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr( | 415 text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr( |
| 408 0, kMaxLanguageNameLen); | 416 0, kMaxLanguageNameLen); |
| 409 } | 417 } |
| 410 DCHECK(!text.empty()); | 418 DCHECK(!text.empty()); |
| 411 return text; | 419 return text; |
| 412 } | 420 } |
| 413 | 421 |
| 422 string16 InputMethodUtil::GetInputMethodLongName( |
| 423 const InputMethodDescriptor& input_method) const { |
| 424 if (!input_method.name().empty()) { |
| 425 // If the descriptor has a name, use it. |
| 426 return UTF8ToUTF16(input_method.name()); |
| 427 } |
| 428 |
| 429 // We don't show language here. Name of keyboard layout or input method |
| 430 // usually imply (or explicitly include) its language. |
| 431 |
| 432 input_method::InputMethodManager* manager = |
| 433 input_method::InputMethodManager::GetInstance(); |
| 434 |
| 435 // Special case for German, French and Dutch: these languages have multiple |
| 436 // keyboard layouts and share the same layout of keyboard (Belgian). We need |
| 437 // to show explicitly the language for the layout. For Arabic, Amharic, and |
| 438 // Indic languages: they share "Standard Input Method". |
| 439 const string16 standard_input_method_text = l10n_util::GetStringUTF16( |
| 440 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); |
| 441 const std::string language_code = input_method.language_code(); |
| 442 |
| 443 string16 text = |
| 444 manager->GetInputMethodUtil()->TranslateString(input_method.id()); |
| 445 if (text == standard_input_method_text || |
| 446 language_code == "de" || |
| 447 language_code == "fr" || |
| 448 language_code == "nl") { |
| 449 text = GetLanguageName(language_code) + UTF8ToUTF16(" - ") + text; |
| 450 } |
| 451 |
| 452 DCHECK(!text.empty()); |
| 453 return text; |
| 454 } |
| 455 |
| 414 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( | 456 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( |
| 415 const std::string& input_method_id) const { | 457 const std::string& input_method_id) const { |
| 416 InputMethodIdToDescriptorMap::const_iterator iter | 458 InputMethodIdToDescriptorMap::const_iterator iter |
| 417 = id_to_descriptor_.find(input_method_id); | 459 = id_to_descriptor_.find(input_method_id); |
| 418 return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); | 460 return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); |
| 419 } | 461 } |
| 420 | 462 |
| 421 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromXkbId( | 463 const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromXkbId( |
| 422 const std::string& xkb_id) const { | 464 const std::string& xkb_id) const { |
| 423 InputMethodIdToDescriptorMap::const_iterator iter | 465 InputMethodIdToDescriptorMap::const_iterator iter |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 ReloadInternalMaps(); | 688 ReloadInternalMaps(); |
| 647 } | 689 } |
| 648 | 690 |
| 649 void InputMethodUtil::SetHardwareInputMethodIdForTesting( | 691 void InputMethodUtil::SetHardwareInputMethodIdForTesting( |
| 650 const std::string& input_method_id) { | 692 const std::string& input_method_id) { |
| 651 hardware_input_method_id_for_testing_ = input_method_id; | 693 hardware_input_method_id_for_testing_ = input_method_id; |
| 652 } | 694 } |
| 653 | 695 |
| 654 } // namespace input_method | 696 } // namespace input_method |
| 655 } // namespace chromeos | 697 } // namespace chromeos |
| OLD | NEW |