diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-07 08:07:48 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-07 08:07:48 +0000 |
commit | b7ba0fe43c23772ccfb90e25bed0c9a8e95744fe (patch) | |
tree | 32358dfc86ab8e343c5f2a53da7cee5bce6ba523 /chrome/browser/chromeos | |
parent | 0c44a7345488f95e6c193f773df1d95a1867c2cb (diff) | |
download | chromium_src-b7ba0fe43c23772ccfb90e25bed0c9a8e95744fe.zip chromium_src-b7ba0fe43c23772ccfb90e25bed0c9a8e95744fe.tar.gz chromium_src-b7ba0fe43c23772ccfb90e25bed0c9a8e95744fe.tar.bz2 |
Use radio buttons for input methods, rather than checkboxes.
This means we'll have one active input method per one language,
and things will be simpler. We could revisit this if the restriction
turns out to be a problem.
TEST=manually
BUG=crosbug.com/2432
Review URL: http://codereview.chromium.org/1630007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/options/language_config_view.cc | 99 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/language_config_view.h | 11 |
2 files changed, 70 insertions, 40 deletions
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc index 7b15653..09f97be 100644 --- a/chrome/browser/chromeos/options/language_config_view.cc +++ b/chrome/browser/chromeos/options/language_config_view.cc @@ -22,7 +22,7 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "third_party/icu/public/common/unicode/uloc.h" -#include "views/controls/button/checkbox.h" +#include "views/controls/button/radio_button.h" #include "views/controls/combobox/combobox.h" #include "views/controls/label.h" #include "views/fill_layout.h" @@ -164,36 +164,37 @@ class InputMethodButton : public views::NativeButton { public: InputMethodButton(views::ButtonListener* listener, const std::wstring& label, - const std::string& language_id) + const std::string& input_method_id) : views::NativeButton(listener, label), - language_id_(language_id) { + input_method_id_(input_method_id) { } - const std::string& language_id() const { - return language_id_; + const std::string& input_method_id() const { + return input_method_id_; } private: - std::string language_id_; + std::string input_method_id_; DISALLOW_COPY_AND_ASSIGN(InputMethodButton); }; -// This is a checkbox associated with input method information. -class InputMethodCheckbox : public views::Checkbox { +// This is a radio button associated with input method information. +class InputMethodRadioButton : public views::RadioButton { public: - InputMethodCheckbox( - const std::string& language_id, const std::string& display_name) - : views::Checkbox(UTF8ToWide(display_name)), - language_id_(language_id) { + InputMethodRadioButton(const std::wstring& display_name, + int group_id, + const std::string& input_method_id) + : views::RadioButton(display_name, group_id), + input_method_id_(input_method_id) { } - const std::string& language_id() const { - return language_id_; + const std::string& input_method_id() const { + return input_method_id_; } private: - std::string language_id_; - DISALLOW_COPY_AND_ASSIGN(InputMethodCheckbox); + std::string input_method_id_; + DISALLOW_COPY_AND_ASSIGN(InputMethodRadioButton); }; LanguageConfigView::LanguageConfigView(Profile* profile) @@ -225,24 +226,27 @@ 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 if (input_method_checkboxes_.count( - static_cast<InputMethodCheckbox*>(sender)) > 0) { - InputMethodCheckbox* checkbox = static_cast<InputMethodCheckbox*>(sender); - const std::string language_id = checkbox->language_id(); - if (language_id == "USA") { + } else if (input_method_radio_buttons_.count( + static_cast<InputMethodRadioButton*>(sender)) > 0) { + InputMethodRadioButton* radio_button = + static_cast<InputMethodRadioButton*>(sender); + const std::string& input_method_id = radio_button->input_method_id(); + if (input_method_id == "USA") { // For the time being, we don't allow users to disable "USA" layout. // TODO(yusukes): remove this hack when XKB switcher gets ready. - checkbox->SetChecked(true); - } else { - SetLanguageActivated(language_id, checkbox->checked()); + 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); } } else if (input_method_buttons_.count( static_cast<InputMethodButton*>(sender)) > 0) { InputMethodButton* button = static_cast<InputMethodButton*>(sender); views::DialogDelegate* config_view = - CreateInputMethodConfigureView(button->language_id()); + CreateInputMethodConfigureView(button->input_method_id()); if (!config_view) { - DLOG(FATAL) << "Config view not found: " << button->language_id(); + DLOG(FATAL) << "Config view not found: " << button->input_method_id(); return; } views::Window* window = views::Window::CreateChromeWindow( @@ -305,22 +309,31 @@ views::View* LanguageConfigView::CreatePerLanguageConfigView( // Add input method names and configuration buttons. input_method_buttons_.clear(); - input_method_checkboxes_.clear(); + 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); - if (language_code == target_language_code) { + if (language_code == target_language_code && + // For now, we ignore keyboard layouts. + !IsKeyboardLayout(language_id)) { layout->StartRow(0, kDoubleColumnSetId); - InputMethodCheckbox* checkbox - = new InputMethodCheckbox(language_id, display_name); - checkbox->set_listener(this); - checkbox->SetChecked(LanguageIsActivated(language_id)); - layout->AddView(checkbox); - input_method_checkboxes_.insert(checkbox); + InputMethodRadioButton* radio_button + = new InputMethodRadioButton(UTF8ToWide(display_name), + kInputMethodRadioButtonGroupId, + language_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 + // for a complicated reason. Instead, we'll initialize the radio + // buttons in InitInputMethodRadioButtons() later. + // TODO(satorux): Get rid of the workaround. + layout->AddView(radio_button); + 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) { @@ -352,6 +365,7 @@ void LanguageConfigView::OnSelectionChanged() { // Add the per language config view to the right area. right_container_->AddChildView(CreatePerLanguageConfigView(language_code)); + InitInputMethodRadioButtons(); // Let the parent container layout again. This is needed to the the // contents on the right to display. root_container_->Layout(); @@ -453,6 +467,19 @@ void LanguageConfigView::InitLanguageIdMaps() { } } +void LanguageConfigView::InitInputMethodRadioButtons() { + for (std::set<InputMethodRadioButton*>::iterator + iter = input_method_radio_buttons_.begin(); + 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())) { + (*iter)->SetChecked(true); + break; + } + } +} + views::View* LanguageConfigView::CreateContentsOnLeft() { views::View* contents = new views::View; GridLayout* layout = new GridLayout(contents); @@ -513,8 +540,8 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) { preferred_language_codes_.end(), language_code) == preferred_language_codes_.end()) { // Activate the first input language associated with the language. We have - // to call this before the OnItemsAdded() call below so the checkbox for - // the first input language gets checked. + // 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) { diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h index 1ef971c..38becfb 100644 --- a/chrome/browser/chromeos/options/language_config_view.h +++ b/chrome/browser/chromeos/options/language_config_view.h @@ -24,7 +24,7 @@ class Profile; namespace chromeos { class InputMethodButton; -class InputMethodCheckbox; +class InputMethodRadioButton; class PreferredLanguageTableModel; // A dialog box for showing a password textfield. class LanguageConfigView : public TableModel, @@ -97,9 +97,12 @@ class LanguageConfigView : public TableModel, // Initializes the input method config view. void InitInputMethodConfigViewMap(); - // Initialize id_to_{code,display_name}_map_ member variables. + // Initializes id_to_{code,display_name}_map_ member variables. void InitLanguageIdMaps(); + // Initializes the input method radio buttons. + void InitInputMethodRadioButtons(); + // Creates the contents on the left, including the language table. views::View* CreateContentsOnLeft(); @@ -153,8 +156,8 @@ class LanguageConfigView : public TableModel, // 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_; + // The radio buttons for activating input methods for a language. + std::set<InputMethodRadioButton*> input_method_radio_buttons_; views::View* root_container_; views::View* right_container_; |