summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 10:00:50 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 10:00:50 +0000
commitef603263bd86678d687520d01d84860daffb688e (patch)
treec7bc2e749b1375bc66673ffa01766ce152f66ac1 /chrome/browser/chromeos
parente6efd025246dc04f22ee0f62a25e1259ab95512e (diff)
downloadchromium_src-ef603263bd86678d687520d01d84860daffb688e.zip
chromium_src-ef603263bd86678d687520d01d84860daffb688e.tar.gz
chromium_src-ef603263bd86678d687520d01d84860daffb688e.tar.bz2
Generalize the logic for adding "configure" buttons for input methods.
BUG=crosbug.com/2001 TEST=manually Review URL: http://codereview.chromium.org/1565003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/options/language_config_view.cc114
-rw-r--r--chrome/browser/chromeos/options/language_config_view.h26
2 files changed, 106 insertions, 34 deletions
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc
index 7c23e73..f97b2c4 100644
--- a/chrome/browser/chromeos/options/language_config_view.cc
+++ b/chrome/browser/chromeos/options/language_config_view.cc
@@ -114,6 +114,25 @@ class AddLanguageView : public views::View,
DISALLOW_COPY_AND_ASSIGN(AddLanguageView);
};
+// This is a native button associated with input method information.
+class InputMethodButton : public views::NativeButton {
+ public:
+ InputMethodButton(views::ButtonListener* listener,
+ const std::wstring& label,
+ const InputLanguage& language)
+ : views::NativeButton(listener, label),
+ language_(language) {
+ }
+
+ const InputLanguage& language() const {
+ return language_;
+ }
+
+ private:
+ InputLanguage language_;
+ DISALLOW_COPY_AND_ASSIGN(InputMethodButton);
+};
+
// This is a checkbox associated with input method information.
class InputMethodCheckbox : public views::Checkbox {
public:
@@ -128,15 +147,24 @@ class InputMethodCheckbox : public views::Checkbox {
private:
InputLanguage language_;
+ DISALLOW_COPY_AND_ASSIGN(InputMethodCheckbox);
};
+namespace {
+// Creates the LanguageHangulConfigView. The function is used to create
+// the object via a function pointer. See also
+// InitInputMethodConfigViewMap().
+views::DialogDelegate* CreateLanguageHangulConfigView() {
+ return new LanguageHangulConfigView;
+}
+} // namespace
+
LanguageConfigView::LanguageConfigView()
: language_library_(NULL),
root_container_(NULL),
right_container_(NULL),
add_language_button_(NULL),
remove_language_button_(NULL),
- hangul_configure_button_(NULL),
preferred_language_table_(NULL) {
}
@@ -145,12 +173,7 @@ LanguageConfigView::~LanguageConfigView() {
void LanguageConfigView::ButtonPressed(
views::Button* sender, const views::Event& event) {
- if (sender == static_cast<views::Button*>(hangul_configure_button_)) {
- views::Window* window = views::Window::CreateChromeWindow(
- NULL, gfx::Rect(), new LanguageHangulConfigView());
- window->SetIsAlwaysOnTop(true);
- window->Show();
- } else if (sender == static_cast<views::Button*>(add_language_button_)) {
+ if (sender == static_cast<views::Button*>(add_language_button_)) {
views::Window* window = views::Window::CreateChromeWindow(
NULL, gfx::Rect(), new AddLanguageView(this));
window->SetIsAlwaysOnTop(true);
@@ -165,23 +188,33 @@ void LanguageConfigView::ButtonPressed(
// Switch to the previous row, or the first row.
// There should be at least one row in the table.
preferred_language_table_->SelectRow(std::max(row - 1, 0));
- } else {
- // Handle the input method checkboxes.
- for (size_t i = 0; i < input_method_checkboxes_.size(); ++i) {
- if (sender == static_cast<views::Button*>(input_method_checkboxes_[i])) {
- InputMethodCheckbox* checkbox = input_method_checkboxes_[i];
- const InputLanguage& language = checkbox->language();
- if (!language_library_->SetLanguageActivated(language.category,
- language.id,
- checkbox->checked())) {
- LOG(ERROR) << "Failed to SetLanguageActivated("
- << language.category << ", " << language.id << ", "
- << checkbox->checked() << ")";
- // Revert the checkbox.
- checkbox->SetChecked(!checkbox->checked());
- }
- }
+ } else if (input_method_checkboxes_.count(
+ static_cast<InputMethodCheckbox*>(sender)) > 0) {
+ InputMethodCheckbox* checkbox = static_cast<InputMethodCheckbox*>(sender);
+ const InputLanguage& language = checkbox->language();
+ if (!language_library_->SetLanguageActivated(language.category,
+ language.id,
+ checkbox->checked())) {
+ LOG(ERROR) << "Failed to SetLanguageActivated("
+ << language.category << ", " << language.id << ", "
+ << checkbox->checked() << ")";
+ // Revert the checkbox.
+ checkbox->SetChecked(!checkbox->checked());
+ }
+ } else if (input_method_buttons_.count(
+ static_cast<InputMethodButton*>(sender)) > 0) {
+ InputMethodButton* button = static_cast<InputMethodButton*>(sender);
+ views::DialogDelegate* config_view =
+ CreateInputMethodConfigureView(button->language());
+ if (!config_view) {
+ DLOG(FATAL) << "Config view not found: "
+ << button->language().ToString();
+ return;
}
+ views::Window* window = views::Window::CreateChromeWindow(
+ NULL, gfx::Rect(), config_view);
+ window->SetIsAlwaysOnTop(true);
+ window->Show();
}
}
@@ -247,6 +280,7 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView(
// Add input method names and configuration buttons.
scoped_ptr<InputLanguageList> supported_language_list(
CrosLibrary::Get()->GetLanguageLibrary()->GetSupportedLanguages());
+ input_method_buttons_.clear();
input_method_checkboxes_.clear();
for (size_t i = 0; i < supported_language_list->size(); ++i) {
@@ -259,14 +293,16 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView(
language_library_->LanguageIsActivated(language.category,
language.id));
layout->AddView(checkbox);
- input_method_checkboxes_.push_back(checkbox);
- // TODO(satorux): For now, we special case the hangul input
- // method. We'll generalize this.
- if (language_code == "ko") {
- hangul_configure_button_ = new views::NativeButton(
+ input_method_checkboxes_.insert(checkbox);
+ // 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) {
+ InputMethodButton* button = new InputMethodButton(
this,
- l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE));
- layout->AddView(hangul_configure_button_);
+ l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE),
+ language);
+ layout->AddView(button);
+ input_method_buttons_.insert(button);
}
}
}
@@ -342,6 +378,8 @@ void LanguageConfigView::Init() {
// Initialize the language codes currently activated.
InitPreferredLanguageCodes();
+ // Initialize the input method config view map.
+ InitInputMethodConfigViewMap();
// Set up the container for the contents on the right. Just adds a
// place holder here. This will get replaced in OnSelectionChanged().
@@ -375,6 +413,11 @@ void LanguageConfigView::InitPreferredLanguageCodes() {
}
}
+void LanguageConfigView::InitInputMethodConfigViewMap() {
+ input_method_config_view_map_["hangul"] =
+ CreateLanguageHangulConfigView;
+}
+
views::View* LanguageConfigView::CreateContentsOnLeft() {
views::View* contents = new views::View;
GridLayout* layout = new GridLayout(contents);
@@ -469,4 +512,15 @@ void LanguageConfigView::DeactivateInputLanguagesFor(
language_library_->ChangeLanguage(chromeos::LANGUAGE_CATEGORY_XKB, "USA");
}
+views::DialogDelegate* LanguageConfigView::CreateInputMethodConfigureView(
+ const InputLanguage& language) {
+ InputMethodConfigViewMap::const_iterator iter =
+ input_method_config_view_map_.find(language.id);
+ if (iter != input_method_config_view_map_.end()) {
+ CreateDialogDelegateFunction function = iter->second;
+ return function();
+ }
+ return NULL;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h
index e07dfb1..f8a6cde 100644
--- a/chrome/browser/chromeos/options/language_config_view.h
+++ b/chrome/browser/chromeos/options/language_config_view.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_VIEW_H_
+#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -18,8 +20,8 @@
namespace chromeos {
+class InputMethodButton;
class InputMethodCheckbox;
-class LanguageHangulConfigView;
class PreferredLanguageTableModel;
// A dialog box for showing a password textfield.
class LanguageConfigView : public TableModel,
@@ -70,6 +72,9 @@ class LanguageConfigView : public TableModel,
// input languages.
void InitPreferredLanguageCodes();
+ // Initializes the input method config view.
+ void InitInputMethodConfigViewMap();
+
// Creates the contents on the left, including the language table.
views::View* CreateContentsOnLeft();
@@ -79,18 +84,31 @@ class LanguageConfigView : public TableModel,
// Deactivates the input languages for the given language code.
void DeactivateInputLanguagesFor(const std::string& language_code);
+ // Creates the input method config view based on the given |language|.
+ // Returns NULL if the config view is not found.
+ views::DialogDelegate* CreateInputMethodConfigureView(
+ const InputLanguage& language);
+
// The language library interface.
LanguageLibrary* language_library_;
// The codes of the preferred languages.
std::vector<std::string> preferred_language_codes_;
- // The checkboxes for input methods for a language.
- std::vector<InputMethodCheckbox*> input_method_checkboxes_;
+ // The map of the input language id to a pointer to the function for
+ // creating the input method configuration dialog.
+ typedef views::DialogDelegate* (*CreateDialogDelegateFunction)();
+ typedef std::map<std::string,
+ CreateDialogDelegateFunction> InputMethodConfigViewMap;
+ InputMethodConfigViewMap input_method_config_view_map_;
+
+ // The buttons for configuring input methods for a language.
+ std::set<InputMethodButton*> input_method_buttons_;
+ // The checkboxes for activating input methods for a language.
+ std::set<InputMethodCheckbox*> input_method_checkboxes_;
views::View* root_container_;
views::View* right_container_;
views::NativeButton* add_language_button_;
views::NativeButton* remove_language_button_;
- views::NativeButton* hangul_configure_button_;
views::TableView2* preferred_language_table_;
DISALLOW_COPY_AND_ASSIGN(LanguageConfigView);