diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 08:11:44 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 08:11:44 +0000 |
commit | 83e9bf8c710e4c12054414c58530a972722fe340 (patch) | |
tree | bc3831a31063886305015811f4ce4fc9f32499f1 /chrome/browser/chromeos/input_method | |
parent | 67cf3f505be7e3a07e4442be46af41e168c447cf (diff) | |
download | chromium_src-83e9bf8c710e4c12054414c58530a972722fe340.zip chromium_src-83e9bf8c710e4c12054414c58530a972722fe340.tar.gz chromium_src-83e9bf8c710e4c12054414c58530a972722fe340.tar.bz2 |
Add a notification when Input Method is changed via keyboard.
BUG=129324
TEST=Change the IME via alt + shift. Make sure a notification appears
Review URL: https://chromiumcodereview.appspot.com/10407117
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/input_method')
7 files changed, 70 insertions, 25 deletions
diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.cc b/chrome/browser/chromeos/input_method/browser_state_monitor.cc index 0a1b8b0..bf21051 100644 --- a/chrome/browser/chromeos/input_method/browser_state_monitor.cc +++ b/chrome/browser/chromeos/input_method/browser_state_monitor.cc @@ -88,7 +88,8 @@ void BrowserStateMonitor::UpdateUserPreferences( current_input_method); } -void BrowserStateMonitor::InputMethodChanged(InputMethodManager* manager) { +void BrowserStateMonitor::InputMethodChanged(InputMethodManager* manager, + bool show_message) { DCHECK_EQ(manager_, manager); const std::string current_input_method = manager->GetCurrentInputMethod().id(); diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.h b/chrome/browser/chromeos/input_method/browser_state_monitor.h index ddfeeef..568393d 100644 --- a/chrome/browser/chromeos/input_method/browser_state_monitor.h +++ b/chrome/browser/chromeos/input_method/browser_state_monitor.h @@ -39,7 +39,8 @@ class BrowserStateMonitor : public content::NotificationObserver, virtual void UpdateUserPreferences(const std::string& current_input_method); // InputMethodManager::Observer overrides: - virtual void InputMethodChanged(InputMethodManager* manager) OVERRIDE; + virtual void InputMethodChanged(InputMethodManager* manager, + bool show_message) OVERRIDE; virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE; // content::NotificationObserver overrides: diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc index 29ea1df..46d90b5 100644 --- a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc +++ b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc @@ -195,7 +195,7 @@ TEST(BrowserStateMonitorTest, TestObserveScreenLockUnlock) { EXPECT_EQ(InputMethodManager::STATE_LOCK_SCREEN, monitor.state()); // When the screen is locked, the monitor should ignore input method changes. - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); @@ -207,7 +207,7 @@ TEST(BrowserStateMonitorTest, TestObserveScreenLockUnlock) { EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, mock_manager.last_state_); EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor.state()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(1, monitor.update_user_pref_count()); } @@ -232,7 +232,7 @@ TEST(BrowserStateMonitorTest, TestObserveAppTerminating) { EXPECT_EQ(InputMethodManager::STATE_TERMINATING, monitor.state()); // In the terminating state, the monitor should ignore input method changes. - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); } @@ -261,10 +261,10 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnLoginScreen) { monitor.SetPrefServiceForTesting(&prefs); EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor.state()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(1, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(2, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); } @@ -281,10 +281,10 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreen) { content::NotificationService::NoDetails()); EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor.state()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(1, monitor.update_user_pref_count()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(2, monitor.update_user_pref_count()); @@ -293,10 +293,10 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreen) { content::NotificationService::NoDetails()); EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor.state()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(3, monitor.update_user_pref_count()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(4, monitor.update_user_pref_count()); } @@ -311,13 +311,13 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnLoginScreenDetails) { EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor.state()); std::string input_method_id = "xkb:us:dvorak:eng"; mock_manager.SetCurrentInputMethodId(input_method_id); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(1, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id, monitor.last_local_state()); input_method_id = "xkb:us:colemak:eng"; mock_manager.SetCurrentInputMethodId(input_method_id); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(2, monitor.update_local_state_count()); EXPECT_EQ(0, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id, monitor.last_local_state()); @@ -348,14 +348,14 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreenDetails) { const std::string input_method_id = "xkb:us:dvorak:eng"; mock_manager.SetCurrentInputMethodId(input_method_id); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(1, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id, monitor.last_user_pref()); EXPECT_EQ("", previous.GetValue()); EXPECT_EQ(input_method_id, current.GetValue()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(2, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id, monitor.last_user_pref()); @@ -364,7 +364,7 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreenDetails) { const std::string input_method_id_2 = "xkb:us:colemak:eng"; mock_manager.SetCurrentInputMethodId(input_method_id_2); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(3, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id_2, monitor.last_user_pref()); @@ -373,14 +373,14 @@ TEST(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreenDetails) { const std::string input_method_id_3 = "xkb:us::eng"; mock_manager.SetCurrentInputMethodId(input_method_id_3); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(4, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id_3, monitor.last_user_pref()); EXPECT_EQ(input_method_id_2, previous.GetValue()); EXPECT_EQ(input_method_id_3, current.GetValue()); - monitor.InputMethodChanged(&mock_manager); + monitor.InputMethodChanged(&mock_manager, false); EXPECT_EQ(0, monitor.update_local_state_count()); EXPECT_EQ(5, monitor.update_user_pref_count()); EXPECT_EQ(input_method_id_3, monitor.last_user_pref()); diff --git a/chrome/browser/chromeos/input_method/input_method_manager.h b/chrome/browser/chromeos/input_method/input_method_manager.h index 6170111..46f13fb 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager.h +++ b/chrome/browser/chromeos/input_method/input_method_manager.h @@ -39,8 +39,10 @@ class InputMethodManager { class Observer { public: virtual ~Observer() {} - // Called when the current input method is changed. - virtual void InputMethodChanged(InputMethodManager* manager) = 0; + // Called when the current input method is changed. |show_message| + // indicates whether the user should be notified of this change. + virtual void InputMethodChanged(InputMethodManager* manager, + bool show_message) = 0; // Called when the list of properties is changed. virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0; }; diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc index 4a9c113..701a542 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc @@ -221,6 +221,12 @@ bool InputMethodManagerImpl::SetInputMethodConfig( void InputMethodManagerImpl::ChangeInputMethod( const std::string& input_method_id) { + ChangeInputMethodInternal(input_method_id, false); +} + +void InputMethodManagerImpl::ChangeInputMethodInternal( + const std::string& input_method_id, + bool show_message) { if (state_ == STATE_TERMINATING) return; @@ -274,7 +280,7 @@ void InputMethodManagerImpl::ChangeInputMethod( // Update input method indicators (e.g. "US", "DV") in Chrome windows. FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, - InputMethodChanged(this)); + InputMethodChanged(this, show_message)); } void InputMethodManagerImpl::ActivateInputMethodProperty( @@ -385,7 +391,7 @@ bool InputMethodManagerImpl::SwitchToPreviousInputMethod() { // previous_input_method_ is not supported. return SwitchToNextInputMethod(); } - ChangeInputMethod(*iter); + ChangeInputMethodInternal(*iter, true); return true; } @@ -459,7 +465,7 @@ void InputMethodManagerImpl::SwitchToNextInputMethodInternal( ++iter; if (iter == input_method_ids.end()) iter = input_method_ids.begin(); - ChangeInputMethod(*iter); + ChangeInputMethodInternal(*iter, true); } InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h index 912a082..5638846 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h @@ -125,6 +125,9 @@ class InputMethodManagerImpl : public InputMethodManager, const std::vector<std::string>& input_method_ids, const std::string& current_input_method_id); + void ChangeInputMethodInternal(const std::string& input_method_id, + bool show_message); + // true when DisableHotkeys() is called to temporarily disable IME hotkeys. // EnableHotkeys() resets the flag to the default value, false. bool ignore_hotkeys_; diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc index b351619..0bb7cc5 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc @@ -67,12 +67,15 @@ class TestObserver : public InputMethodManager::Observer { public: TestObserver() : input_method_changed_count_(0), - input_method_property_changed_count_(0) { + input_method_property_changed_count_(0), + last_show_message_(false) { } virtual ~TestObserver() {} - virtual void InputMethodChanged(InputMethodManager* manager) OVERRIDE { + virtual void InputMethodChanged(InputMethodManager* manager, + bool show_message) OVERRIDE { ++input_method_changed_count_; + last_show_message_ = show_message; } virtual void InputMethodPropertyChanged( InputMethodManager* manager) OVERRIDE { @@ -81,6 +84,7 @@ class TestObserver : public InputMethodManager::Observer { int input_method_changed_count_; int input_method_property_changed_count_; + bool last_show_message_; private: DISALLOW_COPY_AND_ASSIGN(TestObserver); @@ -147,9 +151,11 @@ TEST_F(InputMethodManagerImplTest, TestObserver) { EXPECT_EQ(1, observer.input_method_changed_count_); EXPECT_EQ(1, observer.input_method_property_changed_count_); manager_->ChangeInputMethod("xkb:us:dvorak:eng"); + EXPECT_FALSE(observer.last_show_message_); EXPECT_EQ(2, observer.input_method_changed_count_); EXPECT_EQ(2, observer.input_method_property_changed_count_); manager_->ChangeInputMethod("xkb:us:dvorak:eng"); + EXPECT_FALSE(observer.last_show_message_); // The observer is always notified even when the same input method ID is // passed to ChangeInputMethod() more than twice. EXPECT_EQ(3, observer.input_method_changed_count_); @@ -594,45 +600,68 @@ TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { } TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { + TestObserver observer; + manager_->AddObserver(&observer); // For http://crbug.com/19655#c11 - (1) manager_->EnableLayouts("en-US", "xkb:us::eng"); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:dvorak:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:colemak:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + + manager_->RemoveObserver(&observer); } TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { + TestObserver observer; + manager_->AddObserver(&observer); manager_->EnableLayouts("en-US", "xkb:us::eng"); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToPreviousInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToPreviousInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToPreviousInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToNextInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToPreviousInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); manager_->SwitchToPreviousInputMethod(); + EXPECT_TRUE(observer.last_show_message_); EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); + + manager_->RemoveObserver(&observer); } TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { + TestObserver observer; + manager_->AddObserver(&observer); manager_->EnableLayouts("en-US", "xkb:us::eng"); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); @@ -641,6 +670,7 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { // and keyboards are enabled. EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); + EXPECT_FALSE(observer.last_show_message_); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); @@ -659,6 +689,8 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_SPACE, ui::EF_SHIFT_DOWN))); EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + + manager_->RemoveObserver(&observer); } TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { |