diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-31 01:50:32 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-31 01:50:32 +0000 |
commit | bd883b833f20d010ba6682a2bf7e780240d909b3 (patch) | |
tree | 521f89de769df4034e6cf2ebdeff7874876bbeac /chrome/browser/chromeos/options | |
parent | 2a72bb972a684f6e3ad7469d6a47288ba8154f3e (diff) | |
download | chromium_src-bd883b833f20d010ba6682a2bf7e780240d909b3.zip chromium_src-bd883b833f20d010ba6682a2bf7e780240d909b3.tar.gz chromium_src-bd883b833f20d010ba6682a2bf7e780240d909b3.tar.bz2 |
Change the IME config dialog to present a list of checkboxes instead of radio buttons.
BUG=chromium-os:2538
TEST=Open the IME config dialog. Select a language with multiple input types. Try to select more than one.
Review URL: http://codereview.chromium.org/2221005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/options')
-rw-r--r-- | chrome/browser/chromeos/options/language_config_view.cc | 115 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/language_config_view.h | 18 |
2 files changed, 60 insertions, 73 deletions
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc index 5ee8528..b1b59fb 100644 --- a/chrome/browser/chromeos/options/language_config_view.cc +++ b/chrome/browser/chromeos/options/language_config_view.cc @@ -30,7 +30,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" -#include "views/controls/button/radio_button.h" +#include "views/controls/button/checkbox.h" #include "views/controls/label.h" #include "views/fill_layout.h" #include "views/standard_layout.h" @@ -166,13 +166,12 @@ class UiLanguageButton : public views::NativeButton { DISALLOW_COPY_AND_ASSIGN(UiLanguageButton); }; -// This is a radio button associated with input method information. -class InputMethodRadioButton : public views::RadioButton { +// This is a checkbox button associated with input method information. +class InputMethodCheckbox : public views::Checkbox { public: - InputMethodRadioButton(const std::wstring& display_name, - int group_id, - const std::string& input_method_id) - : views::RadioButton(display_name, group_id), + InputMethodCheckbox(const std::wstring& display_name, + const std::string& input_method_id) + : views::Checkbox(display_name), input_method_id_(input_method_id) { } @@ -182,7 +181,7 @@ class InputMethodRadioButton : public views::RadioButton { private: std::string input_method_id_; - DISALLOW_COPY_AND_ASSIGN(InputMethodRadioButton); + DISALLOW_COPY_AND_ASSIGN(InputMethodCheckbox); }; LanguageConfigView::LanguageConfigView(Profile* profile) @@ -201,14 +200,14 @@ void LanguageConfigView::ButtonPressed( if (sender->tag() == kRemoveLanguageButton) { OnRemoveLanguage(); } else if (sender->tag() == kSelectInputMethodButton) { - InputMethodRadioButton* radio_button = - static_cast<InputMethodRadioButton*>(sender); - const std::string& input_method_id = radio_button->input_method_id(); - if (radio_button->checked()) { - // Deactivate all input methods first, then activate one that checked. - DeactivateInputMethodsFor(GetLanguageCodeFromInputMethodId( - input_method_id)); - SetInputMethodActivated(input_method_id, true); + InputMethodCheckbox* checkbox = + static_cast<InputMethodCheckbox*>(sender); + const std::string& input_method_id = checkbox->input_method_id(); + SetInputMethodActivated(input_method_id, checkbox->checked()); + if (checkbox->checked()) { + EnableAllCheckboxes(); + } else { + MaybeDisableLastCheckbox(); } } else if (sender->tag() == kConfigureInputMethodButton) { InputMethodButton* button = static_cast<InputMethodButton*>(sender); @@ -341,26 +340,10 @@ void LanguageConfigView::AddInputMethodSection( layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); // Add input method names and configuration buttons. - input_method_radio_buttons_.clear(); + input_method_checkboxes_.clear(); - const int kInputMethodRadioButtonGroupId = 0; std::vector<std::string> input_method_ids; GetSupportedInputMethodIds(&input_method_ids); - // We only show keyboard layouts for languages that don't use IME - // (ex. English and French). For languages that use IME, we don't show - // keybard layouts for now. - // TODO(satorux): This is a temporary hack. Will rework this. - bool should_show_keyboard_layouts = true; - for (size_t i = 0; i < input_method_ids.size(); ++i) { - const std::string candidate_language_code = - GetLanguageCodeFromInputMethodId(input_method_ids[i]); - if (language_code == candidate_language_code && - !LanguageLibrary::IsKeyboardLayout(input_method_ids[i])) { - should_show_keyboard_layouts = false; - break; - } - } - for (size_t i = 0; i < input_method_ids.size(); ++i) { const std::string& input_method_id = input_method_ids[i]; const std::string candidate_language_code = @@ -368,25 +351,19 @@ void LanguageConfigView::AddInputMethodSection( const std::string display_name = GetInputMethodDisplayNameFromId( input_method_id); if (language_code == candidate_language_code) { - if (LanguageLibrary::IsKeyboardLayout(input_method_id) - && !should_show_keyboard_layouts) { - continue; // Skip this input method. - } layout->StartRow(0, kPerLanguageDoubleColumnSetId); // TODO(satorux): Translate display_name. - InputMethodRadioButton* radio_button - = new InputMethodRadioButton(UTF8ToWide(display_name), - kInputMethodRadioButtonGroupId, - input_method_id); - radio_button->set_listener(this); - radio_button->set_tag(kSelectInputMethodButton); - // 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); + InputMethodCheckbox* checkbox + = new InputMethodCheckbox(UTF8ToWide(display_name), + input_method_id); + checkbox->set_listener(this); + checkbox->set_tag(kSelectInputMethodButton); + if (InputMethodIsActivated(input_method_id)) { + checkbox->SetChecked(true); + } + + layout->AddView(checkbox); + 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(input_method_id) > 0) { @@ -415,7 +392,7 @@ void LanguageConfigView::OnSelectionChanged() { // Add the per language config view to the right area. right_container_->AddChildView(CreatePerLanguageConfigView(language_code)); - InitInputMethodRadioButtons(); + MaybeDisableLastCheckbox(); // Let the parent container layout again. This is needed to the the // contents on the right to display. root_container_->Layout(); @@ -533,19 +510,6 @@ void LanguageConfigView::InitInputMethodIdMaps() { } } -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 (InputMethodIsActivated((*iter)->input_method_id())) { - (*iter)->SetChecked(true); - break; - } - } -} - views::View* LanguageConfigView::CreateContentsOnLeft() { views::View* contents = new views::View; GridLayout* layout = new GridLayout(contents); @@ -634,7 +598,7 @@ void LanguageConfigView::OnAddLanguage(const std::string& language_code) { return; } // Activate the first input language associated with the language. We have - // to call this before the OnItemsAdded() call below so the radio button + // to call this before the OnItemsAdded() call below so the checkbox // for the first input language gets checked. std::vector<std::string> input_method_ids; GetSupportedInputMethodIds(&input_method_ids); @@ -789,6 +753,27 @@ void LanguageConfigView::GetActiveInputMethodIds( SplitString(WideToUTF8(value), ',', out_input_method_ids); } +void LanguageConfigView::MaybeDisableLastCheckbox() { + std::vector<std::string> input_method_ids; + GetActiveInputMethodIds(&input_method_ids); + if (input_method_ids.size() <= 1) { + for (std::set<InputMethodCheckbox*>::iterator checkbox = + input_method_checkboxes_.begin(); + checkbox != input_method_checkboxes_.end(); ++checkbox) { + if ((*checkbox)->checked()) + (*checkbox)->SetEnabled(false); + } + } +} + +void LanguageConfigView::EnableAllCheckboxes() { + for (std::set<InputMethodCheckbox*>::iterator checkbox = + input_method_checkboxes_.begin(); + checkbox != input_method_checkboxes_.end(); ++checkbox) { + (*checkbox)->SetEnabled(true); + } +} + void LanguageConfigView::GetSupportedInputMethodIds( std::vector<std::string>* out_input_method_ids) const { out_input_method_ids->clear(); diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h index 61f1f51..fab1c76 100644 --- a/chrome/browser/chromeos/options/language_config_view.h +++ b/chrome/browser/chromeos/options/language_config_view.h @@ -27,7 +27,7 @@ class Profile; namespace chromeos { class InputMethodButton; -class InputMethodRadioButton; +class InputMethodCheckbox; class PreferredLanguageTableModel; // The combobox model is used for adding languages in the language config @@ -153,9 +153,6 @@ class LanguageConfigView : public TableModel, // Initializes id_to_{code,display_name}_map_ member variables. void InitInputMethodIdMaps(); - // Initializes the input method radio buttons. - void InitInputMethodRadioButtons(); - // Creates the contents on the left, including the language table. views::View* CreateContentsOnLeft(); @@ -191,6 +188,13 @@ class LanguageConfigView : public TableModel, // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd". void GetActiveInputMethodIds(std::vector<std::string>* out_input_method_ids); + // If there is only one input method left, disable the selected method. + // This is done to prevent the user from disabling all input methods. + void MaybeDisableLastCheckbox(); + + // Enable all input method checkboxes. + void EnableAllCheckboxes(); + // Gets the list of supported IME IDs like "pinyin" and "m17n:ar:kbd". void GetSupportedInputMethodIds( std::vector<std::string>* out_input_method_ids) const; @@ -221,10 +225,8 @@ class LanguageConfigView : public TableModel, CreateDialogDelegateFunction> InputMethodConfigViewMap; InputMethodConfigViewMap input_method_config_view_map_; - // The radio buttons for activating input methods for a language. - // TODO(satorux): Remove this once we get rid of the hack in - // InitInputMethodRadioButtons(). - std::set<InputMethodRadioButton*> input_method_radio_buttons_; + // The checkboxes for activating input methods for a language. + std::set<InputMethodCheckbox*> input_method_checkboxes_; views::View* root_container_; views::View* right_container_; |