diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 09:26:00 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 09:26:00 +0000 |
commit | 12175182ad05fa72b6bcf76cfa2b1027ff9752f4 (patch) | |
tree | 6b41e3c47b84f7183becc88e25299b36add73afa /chrome/browser/chromeos | |
parent | 85b01c001effec913e29c9cb5e8fdd32b1bec3b1 (diff) | |
download | chromium_src-12175182ad05fa72b6bcf76cfa2b1027ff9752f4.zip chromium_src-12175182ad05fa72b6bcf76cfa2b1027ff9752f4.tar.gz chromium_src-12175182ad05fa72b6bcf76cfa2b1027ff9752f4.tar.bz2 |
Hide the input language menu if there is only one input method and it's a XKB keyboard layout.
For instance, if English USA keyboard layout is the only input method enabled,
we don't show the input language menu on the right upper corner.
On the other hand, if Japanese input method is the only input method enabled,
we still show the input language menu so users can change the intra input method
modes, like Hiragana and Katakana modes.
BUG=chromium-os:2275
TEST=manually on the netbook
Review URL: http://codereview.chromium.org/2729009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49375 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
5 files changed, 51 insertions, 12 deletions
diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc index 7128a9b..4a73ceb 100644 --- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc +++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc @@ -123,8 +123,8 @@ void CrosInProcessBrowserTest::SetLanguageLibraryStatusAreaExpectations() { .Times(1) .RetiresOnSaturation(); EXPECT_CALL(*mock_language_library_, GetActiveInputMethods()) - .Times(1) - .WillOnce(Return(CreateFallbackInputMethodDescriptors())) + .Times(AnyNumber()) + .WillRepeatedly(InvokeWithoutArgs(CreateFallbackInputMethodDescriptors)) .RetiresOnSaturation(); EXPECT_CALL(*mock_language_library_, current_ime_properties()) .Times(1) diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc index d1dc57c..91446b5 100644 --- a/chrome/browser/chromeos/cros/language_library.cc +++ b/chrome/browser/chromeos/cros/language_library.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/language_preferences.h" #include "third_party/cros/chromeos_keyboard.h" #include "third_party/icu/public/common/unicode/uloc.h" @@ -243,6 +244,7 @@ bool LanguageLibraryImpl::SetImeConfig( } void LanguageLibraryImpl::FlushImeConfig() { + bool active_input_methods_are_changed = false; if (EnsureLoadedAndStarted()) { LOG(INFO) << "Sending " << pending_config_requests_.size() << " set config command(s)"; @@ -255,6 +257,10 @@ void LanguageLibraryImpl::FlushImeConfig() { section.c_str(), config_name.c_str(), value)) { // Successfully sent. Remove the command and proceed to the next one. pending_config_requests_.erase(iter++); + // Check if it's a change in active input methods. + if (config_name == kPreloadEnginesConfigName) { + active_input_methods_are_changed = true; + } } else { LOG(ERROR) << "chromeos::SetImeConfig failed. Will retry later: " << section << "/" << config_name; @@ -271,6 +277,9 @@ void LanguageLibraryImpl::FlushImeConfig() { &LanguageLibraryImpl::FlushImeConfig); } } + if (active_input_methods_are_changed) { + FOR_EACH_OBSERVER(Observer, observers_, ActiveInputMethodsChanged(this)); + } } // static diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h index 4d90df5..53a94b3 100644 --- a/chrome/browser/chromeos/cros/language_library.h +++ b/chrome/browser/chromeos/cros/language_library.h @@ -26,6 +26,7 @@ class LanguageLibrary { virtual ~Observer() = 0; virtual void InputMethodChanged(LanguageLibrary* obj) = 0; virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0; + virtual void ActiveInputMethodsChanged(LanguageLibrary* obj) = 0; }; virtual ~LanguageLibrary() {} diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc index ead895e6..156bb66 100644 --- a/chrome/browser/chromeos/status/language_menu_button.cc +++ b/chrome/browser/chromeos/status/language_menu_button.cc @@ -149,6 +149,7 @@ LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD)); SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha + SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible) SetShowHighlighted(false); // Update the model RebuildModel(); @@ -316,7 +317,7 @@ string16 LanguageMenuButton::GetLabelAt(int index) const { std::wstring name; if (IndexIsInInputMethodList(index)) { const std::string language_code = - chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor( + 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, @@ -395,11 +396,9 @@ void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { // LanguageLibrary::Observer implementation: void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) { - const chromeos::InputMethodDescriptor& input_method = + const InputMethodDescriptor& input_method = obj->current_input_method(); - const std::wstring name = FormatInputLanguage(input_method, false, false); - const std::wstring tooltip = FormatInputLanguage(input_method, true, true); - UpdateIcon(name, tooltip); + UpdateIconFromInputMethod(input_method); // Update Chrome prefs as well. if (GetPrefService(host_)) { const std::wstring& previous_input_method_id = @@ -411,6 +410,12 @@ void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) { } } +void LanguageMenuButton::ActiveInputMethodsChanged(LanguageLibrary* obj) { + // Update the icon if active input methods are changed. See also + // comments in UpdateIcon() + UpdateIconFromInputMethod(obj->current_input_method()); +} + void LanguageMenuButton::ImePropertiesChanged(LanguageLibrary* obj) { } @@ -418,11 +423,9 @@ void LanguageMenuButton::ImePropertiesChanged(LanguageLibrary* obj) { // views::View implementation: void LanguageMenuButton::LocaleChanged() { - const chromeos::InputMethodDescriptor& input_method = + const InputMethodDescriptor& input_method = CrosLibrary::Get()->GetLanguageLibrary()->current_input_method(); - const std::wstring name = FormatInputLanguage(input_method, false, false); - const std::wstring tooltip = FormatInputLanguage(input_method, true, true); - UpdateIcon(name, tooltip); + UpdateIconFromInputMethod(input_method); Layout(); SchedulePaint(); } @@ -432,11 +435,32 @@ void LanguageMenuButton::UpdateIcon( if (!tooltip.empty()) { SetTooltipText(tooltip); } + // Hide the button only if there is only one input method, and the input + // method is a XKB keyboard layout. We don't hide the button for other + // types of input methods as these might have intra input method modes, + // like Hiragana and Katakana modes in Japanese input methods. + scoped_ptr<InputMethodDescriptors> active_input_methods( + CrosLibrary::Get()->GetLanguageLibrary()->GetActiveInputMethods()); + if (active_input_methods->size() == 1 && + LanguageLibrary::IsKeyboardLayout(active_input_methods->at(0).id)) { + // As the disabled color is set to invisible, disabling makes the + // button disappear. + SetEnabled(false); + } else { + SetEnabled(true); + } SetText(name); set_alignment(TextButton::ALIGN_RIGHT); SchedulePaint(); } +void LanguageMenuButton::UpdateIconFromInputMethod( + const InputMethodDescriptor& input_method) { + const std::wstring name = FormatInputLanguage(input_method, false, false); + const std::wstring tooltip = FormatInputLanguage(input_method, true, true); + UpdateIcon(name, tooltip); +} + void LanguageMenuButton::RebuildModel() { model_.reset(new menus::SimpleMenuModel(NULL)); string16 dummy_label = UTF8ToUTF16(""); @@ -453,7 +477,7 @@ void LanguageMenuButton::RebuildModel() { model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); const std::string language_code - = chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor( + = 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. diff --git a/chrome/browser/chromeos/status/language_menu_button.h b/chrome/browser/chromeos/status/language_menu_button.h index a74d5c6..78fe470 100644 --- a/chrome/browser/chromeos/status/language_menu_button.h +++ b/chrome/browser/chromeos/status/language_menu_button.h @@ -52,6 +52,7 @@ class LanguageMenuButton : public views::MenuButton, // LanguageLibrary::Observer implementation. virtual void InputMethodChanged(LanguageLibrary* obj); virtual void ImePropertiesChanged(LanguageLibrary* obj); + virtual void ActiveInputMethodsChanged(LanguageLibrary* obj); // NotificationObserver implementation. virtual void Observe(NotificationType type, @@ -69,6 +70,10 @@ class LanguageMenuButton : public views::MenuButton, // Updates the status area with |name| and tooltip with |tooltip|. void UpdateIcon(const std::wstring& name, const std::wstring& tooltip); + // Updates the status area from the given input method. + void UpdateIconFromInputMethod( + const InputMethodDescriptor& input_method); + // Rebuilds |model_|. This function should be called whenever // |input_method_descriptors_| is updated, or ImePropertiesChanged() is // called. |