summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-07 09:42:59 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-07 09:42:59 +0000
commit60c7d526f362bc2b478e019505ad8a9a8d7dd00a (patch)
treecc5e39dac54094b2c1145790c4439247e9e739de /chrome/browser/chromeos
parent874920625238d347268d76a9ede231f89ab39625 (diff)
downloadchromium_src-60c7d526f362bc2b478e019505ad8a9a8d7dd00a.zip
chromium_src-60c7d526f362bc2b478e019505ad8a9a8d7dd00a.tar.gz
chromium_src-60c7d526f362bc2b478e019505ad8a9a8d7dd00a.tar.bz2
Clean up code in LanguageConfigView.
The changes were mostly done in a mechanical way - language_id -> input_method_id (language_id was so misleading) - LanguageID -> InputMethodId - InputLanguage -> InputMethod TEST=manually BUG=crosbug.com/2403 Review URL: http://codereview.chromium.org/1629003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/options/language_config_view.cc142
-rw-r--r--chrome/browser/chromeos/options/language_config_view.h39
2 files changed, 94 insertions, 87 deletions
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc
index 09f97be..f7e51eb 100644
--- a/chrome/browser/chromeos/options/language_config_view.cc
+++ b/chrome/browser/chromeos/options/language_config_view.cc
@@ -219,7 +219,7 @@ void LanguageConfigView::ButtonPressed(
} else if (sender == static_cast<views::Button*>(remove_language_button_)) {
const int row = preferred_language_table_->GetFirstSelectedRow();
const std::string& language_code = preferred_language_codes_[row];
- DeactivateInputLanguagesFor(language_code);
+ DeactivateInputMethodsFor(language_code);
// Remove the language code and the row from the table.
preferred_language_codes_.erase(preferred_language_codes_.begin() + row);
preferred_language_table_->OnItemsRemoved(row, 1);
@@ -237,8 +237,8 @@ void LanguageConfigView::ButtonPressed(
radio_button->SetChecked(true);
} else if (radio_button->checked()) {
// Deactivate all input methods first, then activate one that checked.
- DeactivateInputLanguagesFor(GetLanguageCodeFromID(input_method_id));
- SetLanguageActivated(input_method_id, true);
+ DeactivateInputMethodsFor(GetLanguageCodeFromId(input_method_id));
+ SetInputMethodActivated(input_method_id, true);
}
} else if (input_method_buttons_.count(
static_cast<InputMethodButton*>(sender)) > 0) {
@@ -312,20 +312,20 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView(
input_method_radio_buttons_.clear();
const int kInputMethodRadioButtonGroupId = 0;
- std::vector<std::string> language_ids;
- GetSupportedLanguageIDs(&language_ids);
- for (size_t i = 0; i < language_ids.size(); ++i) {
- const std::string& language_id = language_ids[i];
- const std::string language_code = GetLanguageCodeFromID(language_id);
- const std::string display_name = GetDisplayNameFromID(language_id);
+ std::vector<std::string> input_method_ids;
+ GetSupportedInputMethodIds(&input_method_ids);
+ for (size_t i = 0; i < input_method_ids.size(); ++i) {
+ const std::string& input_method_id = input_method_ids[i];
+ const std::string language_code = GetLanguageCodeFromId(input_method_id);
+ const std::string display_name = GetDisplayNameFromId(input_method_id);
if (language_code == target_language_code &&
// For now, we ignore keyboard layouts.
- !IsKeyboardLayout(language_id)) {
+ !IsKeyboardLayout(input_method_id)) {
layout->StartRow(0, kDoubleColumnSetId);
InputMethodRadioButton* radio_button
= new InputMethodRadioButton(UTF8ToWide(display_name),
kInputMethodRadioButtonGroupId,
- language_id);
+ input_method_id);
radio_button->set_listener(this);
// We should check the radio button associated with the active input
// method here by radio_button->SetChecked(), but this does not work
@@ -336,11 +336,11 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView(
input_method_radio_buttons_.insert(radio_button);
// Add "configure" button for the input method if we have a
// configuration dialog for it.
- if (input_method_config_view_map_.count(language_id) > 0) {
+ if (input_method_config_view_map_.count(input_method_id) > 0) {
InputMethodButton* button = new InputMethodButton(
this,
l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE),
- language_id);
+ input_method_id);
layout->AddView(button);
input_method_buttons_.insert(button);
}
@@ -396,7 +396,7 @@ int LanguageConfigView::RowCount() {
void LanguageConfigView::InitControlLayout() {
// Initialize the maps.
- InitLanguageIdMaps();
+ InitInputMethodIdMaps();
InitInputMethodConfigViewMap();
preload_engines_.Init(
@@ -450,20 +450,23 @@ void LanguageConfigView::InitInputMethodConfigViewMap() {
CreateLanguageHangulConfigView;
}
-void LanguageConfigView::InitLanguageIdMaps() {
+void LanguageConfigView::InitInputMethodIdMaps() {
+ // TODO(satorux): Use GetSupportedInputMethods() instead.
// GetSupportedLanguages() never return NULL.
- scoped_ptr<InputLanguageList> supported_language_list(
+ scoped_ptr<InputLanguageList> supported_input_methods(
CrosLibrary::Get()->GetLanguageLibrary()->GetSupportedLanguages());
- for (size_t i = 0; i < supported_language_list->size(); ++i) {
- const InputLanguage& language = supported_language_list->at(i);
+ for (size_t i = 0; i < supported_input_methods->size(); ++i) {
+ // TODO(satorux): Use InputMethodDescriptor instead.
+ const InputLanguage& input_method = supported_input_methods->at(i);
// Normalize the language code as some engines return three-letter
// codes like "jpn" wheres some other engines return two-letter codes
// like "ja".
- std::string language_code = NormalizeLanguageCode(language.language_code);
+ const std::string language_code = NormalizeLanguageCode(
+ input_method.language_code);
id_to_language_code_map_.insert(
- std::make_pair(language.id, language_code));
+ std::make_pair(input_method.id, language_code));
id_to_display_name_map_.insert(
- std::make_pair(language.id, language.display_name));
+ std::make_pair(input_method.id, input_method.display_name));
}
}
@@ -473,7 +476,7 @@ void LanguageConfigView::InitInputMethodRadioButtons() {
iter != input_method_radio_buttons_.end(); ++iter) {
// Check the radio button associated with the active input method.
// There should be only one active input method here.
- if (LanguageIsActivated((*iter)->input_method_id())) {
+ if (InputMethodIsActivated((*iter)->input_method_id())) {
(*iter)->SetChecked(true);
break;
}
@@ -542,11 +545,11 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) {
// Activate the first input language associated with the language. We have
// to call this before the OnItemsAdded() call below so the radio button
// for the first input language gets checked.
- std::vector<std::string> language_ids;
- GetSupportedLanguageIDs(&language_ids);
- for (size_t i = 0; i < language_ids.size(); ++i) {
- if (GetLanguageCodeFromID(language_ids[i]) == language_code) {
- SetLanguageActivated(language_ids[i], true);
+ std::vector<std::string> input_method_ids;
+ GetSupportedInputMethodIds(&input_method_ids);
+ for (size_t i = 0; i < input_method_ids.size(); ++i) {
+ if (GetLanguageCodeFromId(input_method_ids[i]) == language_code) {
+ SetInputMethodActivated(input_method_ids[i], true);
break;
}
}
@@ -559,13 +562,13 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) {
}
}
-void LanguageConfigView::DeactivateInputLanguagesFor(
+void LanguageConfigView::DeactivateInputMethodsFor(
const std::string& language_code) {
- std::vector<std::string> language_ids;
- GetSupportedLanguageIDs(&language_ids);
- for (size_t i = 0; i < language_ids.size(); ++i) {
- if (GetLanguageCodeFromID(language_ids[i]) == language_code) {
- SetLanguageActivated(language_ids[i], false);
+ std::vector<std::string> input_method_ids;
+ GetSupportedInputMethodIds(&input_method_ids);
+ for (size_t i = 0; i < input_method_ids.size(); ++i) {
+ if (GetLanguageCodeFromId(input_method_ids[i]) == language_code) {
+ SetInputMethodActivated(input_method_ids[i], false);
// Do not break; here in order to disable all engines that belong to
// |language_code|.
}
@@ -578,9 +581,9 @@ void LanguageConfigView::DeactivateInputLanguagesFor(
}
views::DialogDelegate* LanguageConfigView::CreateInputMethodConfigureView(
- const std::string& language_id) {
+ const std::string& input_method_id) {
InputMethodConfigViewMap::const_iterator iter =
- input_method_config_view_map_.find(language_id);
+ input_method_config_view_map_.find(input_method_id);
if (iter != input_method_config_view_map_.end()) {
CreateDialogDelegateFunction function = iter->second;
return function(profile());
@@ -596,47 +599,49 @@ void LanguageConfigView::Observe(NotificationType type,
}
}
-void LanguageConfigView::SetLanguageActivated(
- const std::string& language_id, bool activated) {
- DCHECK(!language_id.empty());
- std::vector<std::string> language_ids;
- GetActiveLanguageIDs(&language_ids);
+void LanguageConfigView::SetInputMethodActivated(
+ const std::string& input_method_id, bool activated) {
+ DCHECK(!input_method_id.empty());
+ std::vector<std::string> input_method_ids;
+ GetActiveInputMethodIds(&input_method_ids);
- std::set<std::string> id_set(language_ids.begin(), language_ids.end());
+ std::set<std::string> id_set(input_method_ids.begin(),
+ input_method_ids.end());
if (activated) {
// Add |id| if it's not already added.
- id_set.insert(language_id);
+ id_set.insert(input_method_id);
} else {
- id_set.erase(language_id);
+ id_set.erase(input_method_id);
}
// Update Chrome's preference.
- std::vector<std::string> new_language_ids(id_set.begin(), id_set.end());
- preload_engines_.SetValue(UTF8ToWide(JoinString(new_language_ids, ',')));
+ std::vector<std::string> new_input_method_ids(id_set.begin(), id_set.end());
+ preload_engines_.SetValue(UTF8ToWide(JoinString(new_input_method_ids, ',')));
}
-bool LanguageConfigView::LanguageIsActivated(const std::string& language_id) {
- std::vector<std::string> language_ids;
- GetActiveLanguageIDs(&language_ids);
- return (std::find(language_ids.begin(), language_ids.end(), language_id) !=
- language_ids.end());
+bool LanguageConfigView::InputMethodIsActivated(
+ const std::string& input_method_id) {
+ std::vector<std::string> input_method_ids;
+ GetActiveInputMethodIds(&input_method_ids);
+ return (std::find(input_method_ids.begin(), input_method_ids.end(),
+ input_method_id) != input_method_ids.end());
}
-void LanguageConfigView::GetActiveLanguageIDs(
- std::vector<std::string>* out_language_ids) {
+void LanguageConfigView::GetActiveInputMethodIds(
+ std::vector<std::string>* out_input_method_ids) {
const std::wstring value = preload_engines_.GetValue();
- out_language_ids->clear();
- SplitString(WideToUTF8(value), ',', out_language_ids);
+ out_input_method_ids->clear();
+ SplitString(WideToUTF8(value), ',', out_input_method_ids);
}
-void LanguageConfigView::GetSupportedLanguageIDs(
- std::vector<std::string>* out_language_ids) const {
- out_language_ids->clear();
+void LanguageConfigView::GetSupportedInputMethodIds(
+ std::vector<std::string>* out_input_method_ids) const {
+ out_input_method_ids->clear();
std::map<std::string, std::string>::const_iterator iter;
for (iter = id_to_language_code_map_.begin();
iter != id_to_language_code_map_.end();
++iter) {
- out_language_ids->push_back(iter->first);
+ out_input_method_ids->push_back(iter->first);
}
}
@@ -654,27 +659,28 @@ void LanguageConfigView::GetSupportedLanguageCodes(
language_code_set.begin(), language_code_set.end());
}
-std::string LanguageConfigView::GetLanguageCodeFromID(
- const std::string& language_id) const {
+std::string LanguageConfigView::GetLanguageCodeFromId(
+ const std::string& input_method_id) const {
std::map<std::string, std::string>::const_iterator iter
- = id_to_language_code_map_.find(language_id);
+ = id_to_language_code_map_.find(input_method_id);
return (iter == id_to_language_code_map_.end()) ? "" : iter->second;
}
-std::string LanguageConfigView::GetDisplayNameFromID(
- const std::string& language_id) const {
+std::string LanguageConfigView::GetDisplayNameFromId(
+ const std::string& input_method_id) const {
std::map<std::string, std::string>::const_iterator iter
- = id_to_display_name_map_.find(language_id);
+ = id_to_display_name_map_.find(input_method_id);
return (iter == id_to_display_name_map_.end()) ? "" : iter->second;
}
void LanguageConfigView::NotifyPrefChanged() {
- std::vector<std::string> language_ids;
- GetActiveLanguageIDs(&language_ids);
+ std::vector<std::string> input_method_ids;
+ GetActiveInputMethodIds(&input_method_ids);
std::set<std::string> language_code_set;
- for (size_t i = 0; i < language_ids.size(); ++i) {
- const std::string language_code = GetLanguageCodeFromID(language_ids[i]);
+ for (size_t i = 0; i < input_method_ids.size(); ++i) {
+ const std::string language_code =
+ GetLanguageCodeFromId(input_method_ids[i]);
language_code_set.insert(language_code);
}
diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h
index 38becfb..03fc711 100644
--- a/chrome/browser/chromeos/options/language_config_view.h
+++ b/chrome/browser/chromeos/options/language_config_view.h
@@ -98,7 +98,7 @@ class LanguageConfigView : public TableModel,
void InitInputMethodConfigViewMap();
// Initializes id_to_{code,display_name}_map_ member variables.
- void InitLanguageIdMaps();
+ void InitInputMethodIdMaps();
// Initializes the input method radio buttons.
void InitInputMethodRadioButtons();
@@ -109,37 +109,38 @@ class LanguageConfigView : public TableModel,
// Creates the per-language config view.
views::View* CreatePerLanguageConfigView(const std::string& language_code);
- // Deactivates the input languages for the given language code.
- void DeactivateInputLanguagesFor(const std::string& language_code);
+ // Deactivates the input methods for the given language code.
+ void DeactivateInputMethodsFor(const std::string& language_code);
- // Creates the input method config view based on the given |language_id|.
+ // Creates the input method config view based on the given |input_method_id|.
// Returns NULL if the config view is not found.
views::DialogDelegate* CreateInputMethodConfigureView(
- const std::string& language_id);
+ const std::string& input_method_id);
- // Activates or deactivates an IME whose ID is |language_id|.
- void SetLanguageActivated(const std::string& language_id, bool activated);
+ // Activates or deactivates an IME whose ID is |input_method_id|.
+ void SetInputMethodActivated(const std::string& input_method_id,
+ bool activated);
- // Returns true if an IME of |language_id| is activated.
- bool LanguageIsActivated(const std::string& language_id);
+ // 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".
- void GetActiveLanguageIDs(std::vector<std::string>* out_language_ids);
+ void GetActiveInputMethodIds(std::vector<std::string>* out_input_method_ids);
// Gets the list of supported IME IDs like "pinyin" and "m17n:ar:kbd".
- void GetSupportedLanguageIDs(
- std::vector<std::string>* out_language_ids) const;
+ void GetSupportedInputMethodIds(
+ std::vector<std::string>* out_input_method_ids) const;
- // Converts a language ID to a language code of the IME. Returns "" when
- // |language_id| is unknown.
+ // Converts an input method ID to a language code of the IME. Returns "" when
+ // |input_method_id| is unknown.
// Example: "hangul" => "ko"
- std::string GetLanguageCodeFromID(const std::string& language_id) const;
+ std::string GetLanguageCodeFromId(const std::string& input_method_id) const;
- // Converts a language ID to a display name of the IME. Returns "" when
- // |language_id| is unknown.
+ // Converts an input method ID to a display name of the IME. Returns "" when
+ // |input_method_id| is unknown.
// Examples: "pinyin" => "Pinyin"
// "m17n:ar:kbd" => "kbd (m17n)"
- std::string GetDisplayNameFromID(const std::string& language_id) const;
+ std::string GetDisplayNameFromId(const std::string& input_method_id) const;
// Callback for |preload_engines_| pref updates. Initializes the preferred
// language codes based on the updated pref value.
@@ -147,7 +148,7 @@ class LanguageConfigView : public TableModel,
// The codes of the preferred languages.
std::vector<std::string> preferred_language_codes_;
- // The map of the input language id to a pointer to the function for
+ // The map of the input method id to a pointer to the function for
// creating the input method configuration dialog.
typedef views::DialogDelegate* (*CreateDialogDelegateFunction)(Profile*);
typedef std::map<std::string,