diff options
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/options/language_config_model.cc | 41 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/language_config_model.h | 19 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.h | 1 |
4 files changed, 51 insertions, 25 deletions
diff --git a/chrome/browser/chromeos/options/language_config_model.cc b/chrome/browser/chromeos/options/language_config_model.cc index 93818aec..fafa2f6 100644 --- a/chrome/browser/chromeos/options/language_config_model.cc +++ b/chrome/browser/chromeos/options/language_config_model.cc @@ -76,12 +76,14 @@ LanguageConfigModel::LanguageConfigModel(PrefService* pref_service) // Initialize the maps and vectors. InitInputMethodIdVectors(); - preload_engines_.Init( + preferred_languages_pref_.Init( + prefs::kLanguagePreferredLanguages, pref_service_, this); + preload_engines_pref_.Init( prefs::kLanguagePreloadEngines, pref_service_, this); // TODO(yusukes): It might be safer to call GetActiveLanguages() cros API - // here and compare the result and preload_engines_.GetValue(). If there's - // a discrepancy between IBus setting and Chrome prefs, we can resolve it - // by calling preload_engines_SetValue() here. + // here and compare the result and preload_engines_pref_.GetValue(). + // If there's a discrepancy between IBus setting and Chrome prefs, we + // can resolve it by calling preload_engines_pref_SetValue() here. // Initialize the language codes currently activated. NotifyPrefChanged(); @@ -122,11 +124,15 @@ size_t LanguageConfigModel::AddLanguageCode( std::find(preferred_language_codes_.begin(), preferred_language_codes_.end(), language_code)); + preferred_languages_pref_.SetValue( + JoinString(preferred_language_codes_, ',')); return added_at; } void LanguageConfigModel::RemoveLanguageAt(size_t row) { preferred_language_codes_.erase(preferred_language_codes_.begin() + row); + preferred_languages_pref_.SetValue( + JoinString(preferred_language_codes_, ',')); } void LanguageConfigModel::UpdateInputMethodPreferences( @@ -136,7 +142,7 @@ void LanguageConfigModel::UpdateInputMethodPreferences( // function below uses stable sort, the relateve order of input methods that // belong to the same language (e.g. "mozc" and "xkb:jp::jpn") is maintained. input_method::SortInputMethodIdsByNames(&new_input_method_ids); - preload_engines_.SetValue(JoinString(new_input_method_ids, ',')); + preload_engines_pref_.SetValue(JoinString(new_input_method_ids, ',')); } void LanguageConfigModel::DeactivateInputMethodsFor( @@ -186,12 +192,20 @@ bool LanguageConfigModel::InputMethodIsActivated( void LanguageConfigModel::GetActiveInputMethodIds( std::vector<std::string>* out_input_method_ids) { - const std::string value = preload_engines_.GetValue(); + const std::string value = preload_engines_pref_.GetValue(); out_input_method_ids->clear(); if (!value.empty()) SplitString(value, ',', out_input_method_ids); } +void LanguageConfigModel::GetPreferredLanguageCodes( + std::vector<std::string>* out_language_codes) { + const std::string value = preferred_languages_pref_.GetValue(); + out_language_codes->clear(); + if (!value.empty()) + SplitString(value, ',', out_language_codes); +} + void LanguageConfigModel::GetInputMethodIdsFromLanguageCode( const std::string& language_code, std::vector<std::string>* input_method_ids) const { @@ -206,20 +220,7 @@ void LanguageConfigModel::GetInputMethodIdsFromLanguageCode( } void LanguageConfigModel::NotifyPrefChanged() { - std::vector<std::string> input_method_ids; - GetActiveInputMethodIds(&input_method_ids); - - std::set<std::string> language_code_set; - for (size_t i = 0; i < input_method_ids.size(); ++i) { - const std::string language_code = - input_method::GetLanguageCodeFromInputMethodId(input_method_ids[i]); - language_code_set.insert(language_code); - } - - preferred_language_codes_.clear(); - preferred_language_codes_.assign( - language_code_set.begin(), language_code_set.end()); - input_method::SortLanguageCodesByNames(&preferred_language_codes_); + GetPreferredLanguageCodes(&preferred_language_codes_); } void LanguageConfigModel::Observe(NotificationType type, diff --git a/chrome/browser/chromeos/options/language_config_model.h b/chrome/browser/chromeos/options/language_config_model.h index 014ea14..ec79bc6 100644 --- a/chrome/browser/chromeos/options/language_config_model.h +++ b/chrome/browser/chromeos/options/language_config_model.h @@ -48,7 +48,7 @@ class AddLanguageComboboxModel : public LanguageComboboxModel { // The model of LanguageConfigView. class LanguageConfigModel : public NotificationObserver { public: - LanguageConfigModel(PrefService* pref_service); + explicit LanguageConfigModel(PrefService* pref_service); // Counts the number of active input methods for the given language code. size_t CountNumActiveInputMethods(const std::string& language_code); @@ -77,18 +77,26 @@ class LanguageConfigModel : public NotificationObserver { // Returns true if an IME of |input_method_id| is activated. bool InputMethodIsActivated(const std::string& input_method_id); - // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd". + // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd" from + // the underlying preference object. The original contents of + // |out_input_method_ids| are lost. void GetActiveInputMethodIds( std::vector<std::string>* out_input_method_ids); + // Gets the list of preferred language codes like "en-US" and "fr" from + // the underlying preference object. The original contents of + // |out_language_codes| are lost. + void GetPreferredLanguageCodes( + std::vector<std::string>* out_language_codes); + // Gets the list of input method ids associated with the given language // code. The original contents of |input_method_ids| will be lost. void GetInputMethodIdsFromLanguageCode( const std::string& language_code, std::vector<std::string>* input_method_ids) const; - // Callback for |preload_engines_| pref updates. Initializes the preferred - // language codes based on the updated pref value. + // Callback for |preferred_language_codes_| pref updates. Initializes + // the preferred language codes based on the updated pref value. void NotifyPrefChanged(); // NotificationObserver overrides. @@ -124,7 +132,8 @@ class LanguageConfigModel : public NotificationObserver { PrefService* pref_service_; // The codes of the preferred languages. std::vector<std::string> preferred_language_codes_; - StringPrefMember preload_engines_; + StringPrefMember preferred_languages_pref_; + StringPrefMember preload_engines_pref_; // List of supported language codes like "en" and "ja". std::vector<std::string> supported_language_codes_; // List of supported IME IDs like "pinyin" and "m17n:ar:kbd". diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 0fe3b48..7a993d9 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -36,6 +36,7 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) { kHotkeyNextEngineInMenu); prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine, kHotkeyPreviousEngine); + prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages, ""); prefs->RegisterStringPref(prefs::kLanguagePreloadEngines, kFallbackInputMethodId); // EN layout for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { @@ -94,6 +95,8 @@ void Preferences::Init(PrefService* prefs) { prefs::kLanguageHotkeyNextEngineInMenu, prefs, this); language_hotkey_previous_engine_.Init( prefs::kLanguageHotkeyPreviousEngine, prefs, this); + language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages, + prefs, this); language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this); for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { language_chewing_boolean_prefs_[i].Init( @@ -136,6 +139,10 @@ void Preferences::Init(PrefService* prefs) { } std::string locale(g_browser_process->GetApplicationLocale()); + // Add input methods based on the application locale when the user first + // logs in. For instance, if the user chooses Japanese as the UI + // language at the first login, we'll add input methods associated with + // Japanese, such as mozc. if (locale != kFallbackInputMethodLocale && !prefs->HasPrefPath(prefs::kLanguagePreloadEngines)) { std::string preload_engines(language_preload_engines_.GetValue()); @@ -149,6 +156,10 @@ void Preferences::Init(PrefService* prefs) { } language_preload_engines_.SetValue(preload_engines); } + // Add the UI language to the preferred languages the user first logs in. + if (!prefs->HasPrefPath(prefs::kLanguagePreferredLanguages)) { + language_preferred_languages_.SetValue(locale); + } // Initialize touchpad settings to what's saved in user preferences. NotifyPrefChanged(NULL); @@ -198,6 +209,10 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) { kPreviousEngineConfigName, language_hotkey_previous_engine_.GetValue()); } + if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) { + // Unlike kLanguagePreloadEngines and some other input method + // preferencs, we don't need to send this to ibus-daemon. + } if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) { SetLanguageConfigStringListAsCSV(kGeneralSectionName, kPreloadEnginesConfigName, diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index e0b93fc..a9a2250 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -83,6 +83,7 @@ class Preferences : public NotificationObserver { // Input method preferences. StringPrefMember language_hotkey_next_engine_in_menu_; StringPrefMember language_hotkey_previous_engine_; + StringPrefMember language_preferred_languages_; StringPrefMember language_preload_engines_; BooleanPrefMember language_chewing_boolean_prefs_[kNumChewingBooleanPrefs]; StringPrefMember language_chewing_multiple_choice_prefs_[ |