diff options
6 files changed, 39 insertions, 17 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc index 91446b5..ccf37d7 100644 --- a/chrome/browser/chromeos/cros/language_library.cc +++ b/chrome/browser/chromeos/cros/language_library.cc @@ -148,6 +148,7 @@ std::string LanguageLibrary::GetLanguageCodeFromDescriptor( LanguageLibraryImpl::LanguageLibraryImpl() : input_method_status_connection_(NULL), + previous_input_method_("", "", "", ""), current_input_method_("", "", "", "") { scoped_ptr<InputMethodDescriptors> input_method_descriptors( CreateFallbackInputMethodDescriptors()); @@ -336,25 +337,28 @@ bool LanguageLibraryImpl::EnsureLoadedAndStarted() { } void LanguageLibraryImpl::UpdateCurrentInputMethod( - const chromeos::InputMethodDescriptor& current_input_method) { + const chromeos::InputMethodDescriptor& new_input_method) { // Make sure we run on UI thread. if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { DLOG(INFO) << "UpdateCurrentInputMethod (Background thread)"; ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, - // NewRunnableMethod() copies |current_input_method| by value. + // NewRunnableMethod() copies |new_input_method| by value. NewRunnableMethod( this, &LanguageLibraryImpl::UpdateCurrentInputMethod, - current_input_method)); + new_input_method)); return; } DLOG(INFO) << "UpdateCurrentInputMethod (UI thread)"; // Change the keyboard layout to a preferred layout for the input method. chromeos::SetCurrentKeyboardLayoutByName( - current_input_method.keyboard_layout); + new_input_method.keyboard_layout); - current_input_method_ = current_input_method; + if (current_input_method_.id != new_input_method.id) { + previous_input_method_ = current_input_method_; + current_input_method_ = new_input_method; + } FOR_EACH_OBSERVER(Observer, observers_, InputMethodChanged(this)); } diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h index 53a94b3..3cf3d3f 100644 --- a/chrome/browser/chromeos/cros/language_library.h +++ b/chrome/browser/chromeos/cros/language_library.h @@ -77,6 +77,7 @@ class LanguageLibrary { const char* config_name, const ImeConfigValue& value) = 0; + virtual const InputMethodDescriptor& previous_input_method() const = 0; virtual const InputMethodDescriptor& current_input_method() const = 0; virtual const ImePropertyList& current_ime_properties() const = 0; @@ -135,6 +136,9 @@ class LanguageLibraryImpl : public LanguageLibrary { const char* config_name, const ImeConfigValue& value); + virtual const InputMethodDescriptor& previous_input_method() const { + return previous_input_method_; + } virtual const InputMethodDescriptor& current_input_method() const { return current_input_method_; } @@ -191,7 +195,8 @@ class LanguageLibraryImpl : public LanguageLibrary { InputMethodStatusConnection* input_method_status_connection_; ObserverList<Observer> observers_; - // The input method which is currently selected. + // The input method which was/is selected. + InputMethodDescriptor previous_input_method_; InputMethodDescriptor current_input_method_; // The input method properties which the current input method uses. The list diff --git a/chrome/browser/chromeos/cros/mock_language_library.h b/chrome/browser/chromeos/cros/mock_language_library.h index 62d5a84..2e9f9f5 100644 --- a/chrome/browser/chromeos/cros/mock_language_library.h +++ b/chrome/browser/chromeos/cros/mock_language_library.h @@ -28,6 +28,7 @@ class MockLanguageLibrary : public LanguageLibrary { MOCK_METHOD3(GetImeConfig, bool(const char*, const char*, ImeConfigValue*)); MOCK_METHOD3(SetImeConfig, bool(const char*, const char*, const ImeConfigValue&)); + MOCK_CONST_METHOD0(previous_input_method, const InputMethodDescriptor&(void)); MOCK_CONST_METHOD0(current_input_method, const InputMethodDescriptor&(void)); MOCK_CONST_METHOD0(current_ime_properties, const ImePropertyList&(void)); }; diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index bb59ef7..3c30fc2 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -88,8 +88,8 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, saved_active_input_method_list_.empty()) { chromeos::LanguageLibrary* language = chromeos::CrosLibrary::Get()->GetLanguageLibrary(); + saved_previous_input_method_id_ = language->previous_input_method().id; saved_current_input_method_id_ = language->current_input_method().id; - // TODO(yusukes): save/restore previous input method ID. scoped_ptr<chromeos::InputMethodDescriptors> active_input_method_list( language->GetActiveInputMethods()); @@ -125,14 +125,20 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, language->SetImeConfig(chromeos::kGeneralSectionName, chromeos::kPreloadEnginesConfigName, value); - language->ChangeInputMethod(saved_current_input_method_id_); + // Send previous input method id first so Ctrl+space would work fine. + if (!saved_previous_input_method_id_.empty()) + language->ChangeInputMethod(saved_previous_input_method_id_); + if (!saved_current_input_method_id_.empty()) + language->ChangeInputMethod(saved_current_input_method_id_); + saved_previous_input_method_id_.clear(); saved_current_input_method_id_.clear(); saved_active_input_method_list_.clear(); } } NotificationRegistrar registrar_; + std::string saved_previous_input_method_id_; std::string saved_current_input_method_id_; std::vector<std::string> saved_active_input_method_list_; @@ -298,7 +304,7 @@ class MouseEventRelay : public MessageLoopForUI::Observer { // without asking password. Used in BWSI and auto login mode. class InputEventObserver : public MessageLoopForUI::Observer { public: - InputEventObserver(ScreenLocker* screen_locker) + explicit InputEventObserver(ScreenLocker* screen_locker) : screen_locker_(screen_locker), activated_(false) { } diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc index 42ec6df..c89808a 100644 --- a/chrome/browser/chromeos/status/language_menu_button.cc +++ b/chrome/browser/chromeos/status/language_menu_button.cc @@ -402,17 +402,17 @@ void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) { UserMetrics::RecordAction( UserMetricsAction("LanguageMenuButton_InputMethodChanged")); - const InputMethodDescriptor& input_method = + const InputMethodDescriptor& previous_input_method = + obj->previous_input_method(); + const InputMethodDescriptor& current_input_method = obj->current_input_method(); - UpdateIconFromInputMethod(input_method); + UpdateIconFromInputMethod(current_input_method); + // Update Chrome prefs as well. if (GetPrefService(host_)) { - const std::wstring& previous_input_method_id = - current_input_method_pref_.GetValue(); - // Sometimes (e.g. initial boot) |previous_input_method_id| is an empty - // string. - previous_input_method_pref_.SetValue(previous_input_method_id); - current_input_method_pref_.SetValue(UTF8ToWide(input_method.id)); + // Sometimes (e.g. initial boot) |previous_input_method.id| is empty. + previous_input_method_pref_.SetValue(UTF8ToWide(previous_input_method.id)); + current_input_method_pref_.SetValue(UTF8ToWide(current_input_method.id)); } } diff --git a/chrome/browser/chromeos/status/language_menu_button_browsertest.cc b/chrome/browser/chromeos/status/language_menu_button_browsertest.cc index 247d476..74b9c41 100644 --- a/chrome/browser/chromeos/status/language_menu_button_browsertest.cc +++ b/chrome/browser/chromeos/status/language_menu_button_browsertest.cc @@ -64,6 +64,12 @@ IN_PROC_BROWSER_TEST_F(LanguageMenuButtonTest, InitialIndicatorTest) { } IN_PROC_BROWSER_TEST_F(LanguageMenuButtonTest, IndicatorAndTooltipUpdateTest) { + EXPECT_CALL(*mock_language_library_, previous_input_method()) + .Times(3) + .WillOnce(ReturnRef(invalid_desc_)) + .WillOnce(ReturnRef(invalid_desc_)) + .WillOnce(ReturnRef(invalid_desc_)) + .RetiresOnSaturation(); EXPECT_CALL(*mock_language_library_, current_input_method()) .Times(3) .WillOnce(ReturnRef(korean_desc_)) |