diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-21 06:15:01 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-21 06:15:01 +0000 |
commit | bf898f32cc4e80735e0096fba097af57be469f4f (patch) | |
tree | 8b198686a18602c949870115e74835752fd32d5b /chrome | |
parent | 72126d044d0e08028ff7055d91d4b7eb5e6fae1a (diff) | |
download | chromium_src-bf898f32cc4e80735e0096fba097af57be469f4f.zip chromium_src-bf898f32cc4e80735e0096fba097af57be469f4f.tar.gz chromium_src-bf898f32cc4e80735e0096fba097af57be469f4f.tar.bz2 |
Disable the language menu button when no text input area is focused.
BUG=crosbug.com/2639
TEST=ran browser_tests
Review URL: http://codereview.chromium.org/1645012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
5 files changed, 69 insertions, 22 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc index 6dc4caf..09f3cbe 100644 --- a/chrome/browser/chromeos/cros/language_library.cc +++ b/chrome/browser/chromeos/cros/language_library.cc @@ -154,16 +154,17 @@ std::string LanguageLibrary::GetKeyboardLayoutName( } LanguageLibraryImpl::LanguageLibraryImpl() - : language_status_connection_(NULL), - current_input_method_("", "", "") { + : input_method_status_connection_(NULL), + current_input_method_("", "", ""), + is_focused_(false) { scoped_ptr<InputMethodDescriptors> input_method_descriptors( CreateFallbackInputMethodDescriptors()); current_input_method_ = input_method_descriptors->at(0); } LanguageLibraryImpl::~LanguageLibraryImpl() { - if (language_status_connection_) { - chromeos::DisconnectLanguageStatus(language_status_connection_); + if (input_method_status_connection_) { + chromeos::DisconnectInputMethodStatus(input_method_status_connection_); } } @@ -181,7 +182,7 @@ void LanguageLibraryImpl::RemoveObserver(Observer* observer) { chromeos::InputMethodDescriptors* LanguageLibraryImpl::GetActiveInputMethods() { chromeos::InputMethodDescriptors* result = NULL; if (EnsureLoadedAndStarted()) { - result = chromeos::GetActiveInputMethods(language_status_connection_); + result = chromeos::GetActiveInputMethods(input_method_status_connection_); } if (!result || result->empty()) { result = CreateFallbackInputMethodDescriptors(); @@ -193,7 +194,8 @@ chromeos::InputMethodDescriptors* LanguageLibraryImpl::GetSupportedInputMethods() { chromeos::InputMethodDescriptors* result = NULL; if (EnsureLoadedAndStarted()) { - result = chromeos::GetSupportedInputMethods(language_status_connection_); + result = chromeos::GetSupportedInputMethods( + input_method_status_connection_); } if (!result || result->empty()) { result = CreateFallbackInputMethodDescriptors(); @@ -205,7 +207,7 @@ void LanguageLibraryImpl::ChangeInputMethod( const std::string& input_method_id) { if (EnsureLoadedAndStarted()) { chromeos::ChangeInputMethod( - language_status_connection_, input_method_id.c_str()); + input_method_status_connection_, input_method_id.c_str()); } } @@ -214,7 +216,7 @@ void LanguageLibraryImpl::SetImePropertyActivated(const std::string& key, DCHECK(!key.empty()); if (EnsureLoadedAndStarted()) { chromeos::SetImePropertyActivated( - language_status_connection_, key.c_str(), activated); + input_method_status_connection_, key.c_str(), activated); } } @@ -235,7 +237,7 @@ bool LanguageLibraryImpl::GetImeConfig( bool success = false; if (EnsureLoadedAndStarted()) { success = chromeos::GetImeConfig( - language_status_connection_, section, config_name, out_value); + input_method_status_connection_, section, config_name, out_value); } return success; } @@ -245,7 +247,7 @@ bool LanguageLibraryImpl::SetImeConfig( bool success = false; if (EnsureLoadedAndStarted()) { success = chromeos::SetImeConfig( - language_status_connection_, section, config_name, value); + input_method_status_connection_, section, config_name, value); } return success; } @@ -274,22 +276,29 @@ void LanguageLibraryImpl::UpdatePropertyHandler( language_library->UpdateProperty(prop_list); } +// static +void LanguageLibraryImpl::FocusChangedHandler(void* object, bool is_focused) { + LanguageLibraryImpl* language_library = + static_cast<LanguageLibraryImpl*>(object); + language_library->FocusChanged(is_focused); +} + bool LanguageLibraryImpl::EnsureStarted() { - if (language_status_connection_) { - if (chromeos::LanguageStatusConnectionIsAlive( - language_status_connection_)) { + if (input_method_status_connection_) { + if (chromeos::InputMethodStatusConnectionIsAlive( + input_method_status_connection_)) { return true; } DLOG(WARNING) << "IBus connection is closed. Trying to reconnect..."; - chromeos::DisconnectLanguageStatus(language_status_connection_); + chromeos::DisconnectInputMethodStatus(input_method_status_connection_); } - chromeos::LanguageStatusMonitorFunctions monitor_functions; - monitor_functions.current_language = &InputMethodChangedHandler; - monitor_functions.register_ime_properties = &RegisterPropertiesHandler; - monitor_functions.update_ime_property = &UpdatePropertyHandler; - language_status_connection_ - = chromeos::MonitorLanguageStatus(monitor_functions, this); - return language_status_connection_ != NULL; + input_method_status_connection_ = chromeos::MonitorInputMethodStatus( + this, + &InputMethodChangedHandler, + &RegisterPropertiesHandler, + &UpdatePropertyHandler, + &FocusChangedHandler); + return input_method_status_connection_ != NULL; } bool LanguageLibraryImpl::EnsureLoadedAndStarted() { @@ -356,4 +365,17 @@ void LanguageLibraryImpl::UpdateProperty(const ImePropertyList& prop_list) { FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this)); } +void LanguageLibraryImpl::FocusChanged(bool is_focused) { + if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &LanguageLibraryImpl::FocusChanged, is_focused)); + return; + } + + is_focused_ = is_focused; + FOR_EACH_OBSERVER(Observer, observers_, FocusChanged(this)); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h index c88ab357..0e902fd 100644 --- a/chrome/browser/chromeos/cros/language_library.h +++ b/chrome/browser/chromeos/cros/language_library.h @@ -23,6 +23,7 @@ class LanguageLibrary { virtual ~Observer() = 0; virtual void InputMethodChanged(LanguageLibrary* obj) = 0; virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0; + virtual void FocusChanged(LanguageLibrary* obj) = 0; }; virtual ~LanguageLibrary() {} @@ -74,6 +75,7 @@ class LanguageLibrary { virtual const InputMethodDescriptor& current_input_method() const = 0; virtual const ImePropertyList& current_ime_properties() const = 0; + virtual bool is_focused() const = 0; // Normalizes the language code and returns the normalized version. The // function normalizes the given language code to be compatible with the @@ -137,6 +139,10 @@ class LanguageLibraryImpl : public LanguageLibrary { return current_ime_properties_; } + virtual bool is_focused() const { + return is_focused_; + } + private: // This method is called when there's a change in input method status. static void InputMethodChangedHandler( @@ -151,6 +157,10 @@ class LanguageLibraryImpl : public LanguageLibrary { static void UpdatePropertyHandler( void* object, const ImePropertyList& prop_list); + // This method is called when an input method sends "FocusIn" or "FocusOut" + // signals. + static void FocusChangedHandler(void* object, bool is_focused); + // Ensures that the monitoring of input method changes is started. Starts // the monitoring if necessary. Returns true if the monitoring has been // successfully started. @@ -172,9 +182,12 @@ class LanguageLibraryImpl : public LanguageLibrary { // Called by the handler to update input method properties. void UpdateProperty(const ImePropertyList& prop_list); + // Called by the handler to notify focus changes. + void FocusChanged(bool is_focused); + // A reference to the language api, to allow callbacks when the input method // status changes. - LanguageStatusConnection* language_status_connection_; + InputMethodStatusConnection* input_method_status_connection_; ObserverList<Observer> observers_; // The input method which is currently selected. @@ -184,6 +197,9 @@ class LanguageLibraryImpl : public LanguageLibrary { // might be empty when no input method is used. ImePropertyList current_ime_properties_; + // true if a text input area in Chrome is focused. + bool is_focused_; + DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl); }; diff --git a/chrome/browser/chromeos/cros/mock_language_library.h b/chrome/browser/chromeos/cros/mock_language_library.h index 62d5a84..4bc120f 100644 --- a/chrome/browser/chromeos/cros/mock_language_library.h +++ b/chrome/browser/chromeos/cros/mock_language_library.h @@ -30,6 +30,7 @@ class MockLanguageLibrary : public LanguageLibrary { const ImeConfigValue&)); MOCK_CONST_METHOD0(current_input_method, const InputMethodDescriptor&(void)); MOCK_CONST_METHOD0(current_ime_properties, const ImePropertyList&(void)); + MOCK_CONST_METHOD0(is_focused, bool(void)); }; } // namespace chromeos diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc index 88fc0ae..45dc3ff 100644 --- a/chrome/browser/chromeos/status/language_menu_button.cc +++ b/chrome/browser/chromeos/status/language_menu_button.cc @@ -135,6 +135,7 @@ LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD)); SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha + SetDisabledColor(0x4DFFFFFF); // White with 30% Alpha SetShowHighlighted(false); // Update the model RebuildModel(); @@ -379,6 +380,12 @@ void LanguageMenuButton::LocaleChanged() { SchedulePaint(); } +void LanguageMenuButton::FocusChanged(LanguageLibrary* obj) { + LanguageLibrary* language_library = CrosLibrary::Get()->GetLanguageLibrary(); + SetEnabled(language_library->is_focused()); + SchedulePaint(); +} + void LanguageMenuButton::UpdateIcon(const std::wstring& name) { SetText(name); set_alignment(TextButton::ALIGN_RIGHT); diff --git a/chrome/browser/chromeos/status/language_menu_button.h b/chrome/browser/chromeos/status/language_menu_button.h index 2bfc06a..5b92f07 100644 --- a/chrome/browser/chromeos/status/language_menu_button.h +++ b/chrome/browser/chromeos/status/language_menu_button.h @@ -48,6 +48,7 @@ class LanguageMenuButton : public views::MenuButton, // LanguageLibrary::Observer implementation. virtual void InputMethodChanged(LanguageLibrary* obj); virtual void ImePropertiesChanged(LanguageLibrary* obj); + virtual void FocusChanged(LanguageLibrary* obj); protected: // views::View implementation. |