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 | |
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')
4 files changed, 94 insertions, 93 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_; diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc index fe9a613..85a87b6 100644 --- a/chrome/browser/chromeos/status/language_menu_button.cc +++ b/chrome/browser/chromeos/status/language_menu_button.cc @@ -82,7 +82,8 @@ std::wstring GetLanguageName(const std::string& language_code) { // Returns a string for the drop-down menu if |for_menu| is true. Otherwise, // returns a string for the status area. std::wstring FormatInputLanguage( - const chromeos::InputMethodDescriptor& input_method, bool for_menu) { + const chromeos::InputMethodDescriptor& input_method, bool for_menu, + bool add_method_name) { const std::string language_code = chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor(input_method); @@ -99,6 +100,11 @@ std::wstring FormatInputLanguage( // like "Pinyin" and "Anthy". if (formatted.empty()) { formatted = GetLanguageName(language_code); + if (add_method_name) { + formatted += L" - "; + formatted += chromeos::LanguageMenuL10nUtil::GetString( + input_method.display_name); + } } } else { // For the status area, we use two-letter, upper-case language code like @@ -112,19 +118,6 @@ std::wstring FormatInputLanguage( return formatted; } -// Returns localized language name + display name for the |input_method|. -// For example, "Hebrew: Standard input method" would be returned for the Hebrew -// input method in US locale, and "Japanese: Google Japanese Input" for Japanese -// in the locale. -std::wstring GetTooltipText( - const chromeos::InputMethodDescriptor& input_method) { - const std::wstring tooltip = - FormatInputLanguage(input_method, true) + L": " + - chromeos::LanguageMenuL10nUtil::GetString(input_method.display_name); - // TODO(yusukes): it might be better to add "intra-IME" status to the tooltip. - return tooltip; -} - } // namespace namespace chromeos { @@ -157,7 +150,7 @@ LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) UpdateIcon(kSpacer, L"" /* no tooltip */); // Display the default input method name. const std::wstring name - = FormatInputLanguage(input_method_descriptors_->at(0), false); + = FormatInputLanguage(input_method_descriptors_->at(0), false, false); // TODO(yusukes): The assumption that the input method at index 0 is enabled // by default is not always true. We should fix the logic once suzhe's patches // for issue 2627 (get/set ibus state without focus) are submitted. @@ -296,7 +289,12 @@ string16 LanguageMenuButton::GetLabelAt(int index) const { std::wstring name; if (IndexIsInInputMethodList(index)) { - name = FormatInputLanguage(input_method_descriptors_->at(index), true); + const std::string language_code = + chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor( + input_method_descriptors_->at(index)); + bool need_method_name = (need_method_name_.count(language_code) > 0); + name = FormatInputLanguage(input_method_descriptors_->at(index), true, + need_method_name); } else if (GetPropertyIndex(index, &index)) { const ImePropertyList& property_list = CrosLibrary::Get()->GetLanguageLibrary()->current_ime_properties(); @@ -373,8 +371,8 @@ void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) { const chromeos::InputMethodDescriptor& input_method = obj->current_input_method(); - const std::wstring name = FormatInputLanguage(input_method, false); - const std::wstring tooltip = ::GetTooltipText(input_method); + const std::wstring name = FormatInputLanguage(input_method, false, false); + const std::wstring tooltip = FormatInputLanguage(input_method, true, true); UpdateIcon(name, tooltip); } @@ -387,8 +385,8 @@ void LanguageMenuButton::ImePropertiesChanged(LanguageLibrary* obj) { void LanguageMenuButton::LocaleChanged() { const chromeos::InputMethodDescriptor& input_method = CrosLibrary::Get()->GetLanguageLibrary()->current_input_method(); - const std::wstring name = FormatInputLanguage(input_method, false); - const std::wstring tooltip = ::GetTooltipText(input_method); + const std::wstring name = FormatInputLanguage(input_method, false, false); + const std::wstring tooltip = FormatInputLanguage(input_method, true, true); UpdateIcon(name, tooltip); Layout(); SchedulePaint(); @@ -416,12 +414,25 @@ void LanguageMenuButton::RebuildModel() { // Indicates if separator's needed before each section. bool need_separator = false; + need_method_name_.clear(); + std::set<std::string> languages_seen; if (!input_method_descriptors_->empty()) { // We "abuse" the command_id and group_id arguments of AddRadioItem method. // A COMMAND_ID_XXX enum value is passed as command_id, and array index of // |input_method_descriptors_| or |property_list| is passed as group_id. for (size_t i = 0; i < input_method_descriptors_->size(); ++i) { model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); + + const std::string language_code + = chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor( + input_method_descriptors_->at(i)); + // If there is more than one input method for this language, then we need + // to display the method name. + if (languages_seen.find(language_code) == languages_seen.end()) { + languages_seen.insert(language_code); + } else { + need_method_name_.insert(language_code); + } } need_separator = true; } diff --git a/chrome/browser/chromeos/status/language_menu_button.h b/chrome/browser/chromeos/status/language_menu_button.h index a4adda6..c044c5f 100644 --- a/chrome/browser/chromeos/status/language_menu_button.h +++ b/chrome/browser/chromeos/status/language_menu_button.h @@ -81,6 +81,9 @@ class LanguageMenuButton : public views::MenuButton, // The current input method list. scoped_ptr<InputMethodDescriptors> input_method_descriptors_; + // Languages that need the input method name displayed. + std::set<std::string> need_method_name_; + // We borrow menus::SimpleMenuModel implementation to maintain the current // content of the pop-up menu. The menus::MenuModel is implemented using this // |model_|. |