| Index: chrome/browser/chromeos/input_method/input_method_util.cc
|
| diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc
|
| index 4a5ae064650103c25192cc22672a1ab2f6eed05f..dcc0732d692d2f3c20bab4a750fcc7dc599dc5ad 100644
|
| --- a/chrome/browser/chromeos/input_method/input_method_util.cc
|
| +++ b/chrome/browser/chromeos/input_method/input_method_util.cc
|
| @@ -11,12 +11,11 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/prefs/public/pref_service_base.h"
|
| #include "base/string_split.h"
|
| #include "base/string_util.h"
|
| #include "base/utf_string_conversions.h"
|
| -#include "chrome/browser/browser_process.h"
|
| -#include "chrome/browser/prefs/pref_service.h"
|
| -#include "chrome/common/pref_names.h"
|
| +#include "chrome/browser/chromeos/input_method/input_method_delegate.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/l10n/l10n_util_collator.h"
|
| @@ -82,13 +81,7 @@ const struct {
|
| const size_t kMappingImeIdToMediumLenNameResourceIdLen =
|
| ARRAYSIZE_UNSAFE(kMappingImeIdToMediumLenNameResourceId);
|
|
|
| -string16 GetLanguageName(const std::string& language_code) {
|
| - const string16 language_name = l10n_util::GetDisplayNameForLocale(
|
| - language_code, g_browser_process->GetApplicationLocale(), true);
|
| - return language_name;
|
| -}
|
| -
|
| -}
|
| +} // namespace
|
|
|
| namespace chromeos {
|
|
|
| @@ -267,20 +260,22 @@ const size_t kEnglishToResourceIdArraySize =
|
| // corresponding language names, using the ICU collator.
|
| struct CompareLanguageCodesByLanguageName
|
| : std::binary_function<const std::string&, const std::string&, bool> {
|
| - explicit CompareLanguageCodesByLanguageName(icu::Collator* collator)
|
| - : collator_(collator) {
|
| + CompareLanguageCodesByLanguageName(InputMethodUtil* util,
|
| + icu::Collator* collator)
|
| + : util_(util), collator_(collator) {
|
| }
|
|
|
| // Calling GetLanguageDisplayNameFromCode() in the comparator is not
|
| // efficient, but acceptable as the function is cheap, and the language
|
| // list is short (about 60 at most).
|
| bool operator()(const std::string& s1, const std::string& s2) const {
|
| - const string16 key1 = InputMethodUtil::GetLanguageDisplayNameFromCode(s1);
|
| - const string16 key2 = InputMethodUtil::GetLanguageDisplayNameFromCode(s2);
|
| + const string16 key1 = util_->GetLanguageDisplayNameFromCode(s1);
|
| + const string16 key2 = util_->GetLanguageDisplayNameFromCode(s2);
|
| return l10n_util::StringComparator<string16>(collator_)(key1, key2);
|
| }
|
|
|
| private:
|
| + InputMethodUtil* util_;
|
| icu::Collator* collator_;
|
| };
|
|
|
| @@ -306,8 +301,10 @@ const ExtraLanguage kExtraLanguages[] = {
|
| const size_t kExtraLanguagesLength = arraysize(kExtraLanguages);
|
|
|
| InputMethodUtil::InputMethodUtil(
|
| + InputMethodDelegate* delegate,
|
| scoped_ptr<InputMethodDescriptors> supported_input_methods)
|
| - : supported_input_methods_(supported_input_methods.Pass()) {
|
| + : supported_input_methods_(supported_input_methods.Pass()),
|
| + delegate_(delegate) {
|
| ReloadInternalMaps();
|
|
|
| // Initialize a map from English string to Chrome string resource ID as well.
|
| @@ -484,7 +481,10 @@ string16 InputMethodUtil::GetInputMethodLongName(
|
| language_code == "de" ||
|
| language_code == "fr" ||
|
| language_code == "nl") {
|
| - text = GetLanguageName(language_code) + UTF8ToUTF16(" - ") + text;
|
| + const string16 language_name = l10n_util::GetDisplayNameForLocale(
|
| + language_code, delegate_->GetActiveLocale(), true);
|
| +
|
| + text = language_name + UTF8ToUTF16(" - ") + text;
|
| }
|
|
|
| DCHECK(!text.empty());
|
| @@ -508,11 +508,8 @@ const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromXkbId(
|
| // static
|
| string16 InputMethodUtil::GetLanguageDisplayNameFromCode(
|
| const std::string& language_code) {
|
| - if (!g_browser_process) {
|
| - return string16();
|
| - }
|
| return l10n_util::GetDisplayNameForLocale(
|
| - language_code, g_browser_process->GetApplicationLocale(), true);
|
| + language_code, delegate_->GetActiveLocale(), true);
|
| }
|
|
|
| // static
|
| @@ -521,23 +518,19 @@ string16 InputMethodUtil::GetLanguageNativeDisplayNameFromCode(
|
| return l10n_util::GetDisplayNameForLocale(language_code, language_code, true);
|
| }
|
|
|
| -// static
|
| void InputMethodUtil::SortLanguageCodesByNames(
|
| std::vector<std::string>* language_codes) {
|
| - if (!g_browser_process) {
|
| - return;
|
| - }
|
| // We should build collator outside of the comparator. We cannot have
|
| // scoped_ptr<> in the comparator for a subtle STL reason.
|
| UErrorCode error = U_ZERO_ERROR;
|
| - icu::Locale locale(g_browser_process->GetApplicationLocale().c_str());
|
| + icu::Locale locale(delegate_->GetActiveLocale().c_str());
|
| scoped_ptr<icu::Collator> collator(
|
| icu::Collator::createInstance(locale, error));
|
| if (U_FAILURE(error)) {
|
| collator.reset();
|
| }
|
| std::sort(language_codes->begin(), language_codes->end(),
|
| - CompareLanguageCodesByLanguageName(collator.get()));
|
| + CompareLanguageCodesByLanguageName(this, collator.get()));
|
| }
|
|
|
| bool InputMethodUtil::GetInputMethodIdsFromLanguageCode(
|
| @@ -647,27 +640,8 @@ void InputMethodUtil::GetLanguageCodesFromInputMethodIds(
|
| }
|
|
|
| std::string InputMethodUtil::GetHardwareInputMethodId() const {
|
| - if (!hardware_input_method_id_for_testing_.empty()) {
|
| - return hardware_input_method_id_for_testing_;
|
| - }
|
| + const std::string input_method_id = delegate_->GetHardwareKeyboardLayout();
|
|
|
| - if (!(g_browser_process && g_browser_process->local_state())) {
|
| - // This shouldn't happen but just in case.
|
| - DVLOG(1) << "Local state is not yet ready";
|
| - return InputMethodDescriptor::GetFallbackInputMethodDescriptor().id();
|
| - }
|
| -
|
| - PrefService* local_state = g_browser_process->local_state();
|
| - if (!local_state->FindPreference(prefs::kHardwareKeyboardLayout)) {
|
| - // This could happen in unittests. We register the preference in
|
| - // BrowserMain::InitializeLocalState and that method is not called during
|
| - // unittests.
|
| - DVLOG(1) << prefs::kHardwareKeyboardLayout << " is not registered";
|
| - return InputMethodDescriptor::GetFallbackInputMethodDescriptor().id();
|
| - }
|
| -
|
| - const std::string input_method_id =
|
| - local_state->GetString(prefs::kHardwareKeyboardLayout);
|
| if (input_method_id.empty()) {
|
| // This is totally fine if it's empty. The hardware keyboard layout is
|
| // not stored if startup_manifest.json (OEM customization data) is not
|
| @@ -726,10 +700,5 @@ void InputMethodUtil::OnLocaleChanged() {
|
| ReloadInternalMaps();
|
| }
|
|
|
| -void InputMethodUtil::SetHardwareInputMethodIdForTesting(
|
| - const std::string& input_method_id) {
|
| - hardware_input_method_id_for_testing_ = input_method_id;
|
| -}
|
| -
|
| } // namespace input_method
|
| } // namespace chromeos
|
|
|