diff options
author | shuchen <shuchen@chromium.org> | 2015-05-03 18:54:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-04 01:54:38 +0000 |
commit | 5fe79f98d2ce802f37931402e678a2dc65f941a7 (patch) | |
tree | 5f63949313f2792ac3b8e056d7418ab2d6337fc5 /ui | |
parent | ee199616e511de9e2db3356f205038a6d0df69a7 (diff) | |
download | chromium_src-5fe79f98d2ce802f37931402e678a2dc65f941a7.zip chromium_src-5fe79f98d2ce802f37931402e678a2dc65f941a7.tar.gz chromium_src-5fe79f98d2ce802f37931402e678a2dc65f941a7.tar.bz2 |
Implements OnFocus/OnBlur for InputMethodWin.
The OnFocus/OnBlur caller is implemented in
DNWA::HandleActivationChanged(), so that we can remove the "always
focused" model in InputMethodWin.
And removed the Init() method which is useless because the caller always
pass true and calls OnFocus().
BUG=474828
TEST=Verified on local.
Review URL: https://codereview.chromium.org/1109333002
Cr-Commit-Position: refs/heads/master@{#328084}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/ime/dummy_input_method.cc | 3 | ||||
-rw-r--r-- | ui/base/ime/dummy_input_method.h | 1 | ||||
-rw-r--r-- | ui/base/ime/input_method.h | 4 | ||||
-rw-r--r-- | ui/base/ime/input_method_auralinux.cc | 6 | ||||
-rw-r--r-- | ui/base/ime/input_method_auralinux.h | 1 | ||||
-rw-r--r-- | ui/base/ime/input_method_base.cc | 5 | ||||
-rw-r--r-- | ui/base/ime/input_method_base.h | 1 | ||||
-rw-r--r-- | ui/base/ime/input_method_chromeos_unittest.cc | 39 | ||||
-rw-r--r-- | ui/base/ime/input_method_win.cc | 49 | ||||
-rw-r--r-- | ui/base/ime/input_method_win.h | 5 | ||||
-rw-r--r-- | ui/base/ime/mock_input_method.cc | 3 | ||||
-rw-r--r-- | ui/base/ime/mock_input_method.h | 1 | ||||
-rw-r--r-- | ui/base/ime/remote_input_method_win.cc | 2 | ||||
-rw-r--r-- | ui/wm/core/input_method_event_filter.cc | 6 |
14 files changed, 37 insertions, 89 deletions
diff --git a/ui/base/ime/dummy_input_method.cc b/ui/base/ime/dummy_input_method.cc index 700e793..cc84618 100644 --- a/ui/base/ime/dummy_input_method.cc +++ b/ui/base/ime/dummy_input_method.cc @@ -15,9 +15,6 @@ DummyInputMethod::~DummyInputMethod() { void DummyInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) { } -void DummyInputMethod::Init(bool focused) { -} - void DummyInputMethod::OnFocus() { } diff --git a/ui/base/ime/dummy_input_method.h b/ui/base/ime/dummy_input_method.h index edad7b8..7635b35 100644 --- a/ui/base/ime/dummy_input_method.h +++ b/ui/base/ime/dummy_input_method.h @@ -18,7 +18,6 @@ class DummyInputMethod : public InputMethod { // InputMethod overrides: void SetDelegate(internal::InputMethodDelegate* delegate) override; - void Init(bool focused) override; void OnFocus() override; void OnBlur() override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, diff --git a/ui/base/ime/input_method.h b/ui/base/ime/input_method.h index 164b1f1..778b99d 100644 --- a/ui/base/ime/input_method.h +++ b/ui/base/ime/input_method.h @@ -59,10 +59,6 @@ class InputMethod { // called by an object which manages the whole UI. virtual void SetDelegate(internal::InputMethodDelegate* delegate) = 0; - // Initializes the InputMethod object. Pass true if the system toplevel window - // already has keyboard focus. - virtual void Init(bool focused) = 0; - // Called when the top-level system window gets keyboard focus. virtual void OnFocus() = 0; diff --git a/ui/base/ime/input_method_auralinux.cc b/ui/base/ime/input_method_auralinux.cc index 2ae42d7..eebfc32 100644 --- a/ui/base/ime/input_method_auralinux.cc +++ b/ui/base/ime/input_method_auralinux.cc @@ -36,12 +36,6 @@ LinuxInputMethodContext* InputMethodAuraLinux::GetContextForTesting( // Overriden from InputMethod. -void InputMethodAuraLinux::Init(bool focused) { - InputMethodBase::Init(focused); - - UpdateContextFocusState(); -} - bool InputMethodAuraLinux::OnUntranslatedIMEMessage( const base::NativeEvent& event, NativeEventResult* result) { diff --git a/ui/base/ime/input_method_auralinux.h b/ui/base/ime/input_method_auralinux.h index c1076b6..3472221 100644 --- a/ui/base/ime/input_method_auralinux.h +++ b/ui/base/ime/input_method_auralinux.h @@ -25,7 +25,6 @@ class UI_BASE_IME_EXPORT InputMethodAuraLinux LinuxInputMethodContext* GetContextForTesting(bool is_simple); // Overriden from InputMethod. - void Init(bool focused) override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; bool DispatchKeyEvent(const ui::KeyEvent& event) override; diff --git a/ui/base/ime/input_method_base.cc b/ui/base/ime/input_method_base.cc index dd11947..26c2d40 100644 --- a/ui/base/ime/input_method_base.cc +++ b/ui/base/ime/input_method_base.cc @@ -32,11 +32,6 @@ void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { delegate_ = delegate; } -void InputMethodBase::Init(bool focused) { - if (focused) - OnFocus(); -} - void InputMethodBase::OnFocus() { system_toplevel_window_focused_ = true; } diff --git a/ui/base/ime/input_method_base.h b/ui/base/ime/input_method_base.h index ce76d40..d014500 100644 --- a/ui/base/ime/input_method_base.h +++ b/ui/base/ime/input_method_base.h @@ -33,7 +33,6 @@ class UI_BASE_IME_EXPORT InputMethodBase // Overriden from InputMethod. void SetDelegate(internal::InputMethodDelegate* delegate) override; - void Init(bool focused) override; // If a derived class overrides OnFocus()/OnBlur(), it should call parent's // implementation first, to make sure |system_toplevel_window_focused_| flag // can be updated correctly. diff --git a/ui/base/ime/input_method_chromeos_unittest.cc b/ui/base/ime/input_method_chromeos_unittest.cc index f2d1631..d5c1d88 100644 --- a/ui/base/ime/input_method_chromeos_unittest.cc +++ b/ui/base/ime/input_method_chromeos_unittest.cc @@ -348,18 +348,18 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, TEST_F(InputMethodChromeOSTest, GetInputLocale) { // ui::InputMethodChromeOS does not support the API. - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ("", ime_->GetInputLocale()); } TEST_F(InputMethodChromeOSTest, IsActive) { - ime_->Init(true); + ime_->OnFocus(); // ui::InputMethodChromeOS always returns true. EXPECT_TRUE(ime_->IsActive()); } TEST_F(InputMethodChromeOSTest, GetInputTextType) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); input_type_ = TEXT_INPUT_TYPE_PASSWORD; ime_->OnTextInputTypeChanged(this); @@ -370,7 +370,7 @@ TEST_F(InputMethodChromeOSTest, GetInputTextType) { } TEST_F(InputMethodChromeOSTest, CanComposeInline) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_TRUE(ime_->CanComposeInline()); can_compose_inline_ = false; ime_->OnTextInputTypeChanged(this); @@ -378,7 +378,7 @@ TEST_F(InputMethodChromeOSTest, CanComposeInline) { } TEST_F(InputMethodChromeOSTest, GetTextInputClient) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(this, ime_->GetTextInputClient()); if (switches::IsTextInputFocusManagerEnabled()) TextInputFocusManager::GetInstance()->BlurTextInputClient(this); @@ -388,7 +388,7 @@ TEST_F(InputMethodChromeOSTest, GetTextInputClient) { } TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); if (switches::IsTextInputFocusManagerEnabled()) TextInputFocusManager::GetInstance()->BlurTextInputClient(this); @@ -409,7 +409,7 @@ TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { } TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); if (switches::IsTextInputFocusManagerEnabled()) TextInputFocusManager::GetInstance()->BlurTextInputClient(this); @@ -430,12 +430,9 @@ TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { } TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { - // We no longer support the case that |ime_->Init(false)| because no one - // actually uses it. if (switches::IsTextInputFocusManagerEnabled()) return; - ime_->Init(false); // the top-level is initially unfocused. EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); input_type_ = TEXT_INPUT_TYPE_PASSWORD; ime_->OnTextInputTypeChanged(this); @@ -449,7 +446,7 @@ TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { // Confirm that IBusClient::FocusIn is called on "connected" if input_type_ is // TEXT. TEST_F(InputMethodChromeOSTest, FocusIn_Text) { - ime_->Init(true); + ime_->OnFocus(); // A context shouldn't be created since the daemon is not running. EXPECT_EQ(0U, on_input_method_changed_call_count_); // Click a text input form. @@ -469,7 +466,7 @@ TEST_F(InputMethodChromeOSTest, FocusIn_Text) { // Confirm that InputMethodEngine::FocusIn is called on "connected" even if // input_type_ is PASSWORD. TEST_F(InputMethodChromeOSTest, FocusIn_Password) { - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(0U, on_input_method_changed_call_count_); input_type_ = TEXT_INPUT_TYPE_PASSWORD; ime_->OnTextInputTypeChanged(this); @@ -481,7 +478,7 @@ TEST_F(InputMethodChromeOSTest, FocusIn_Password) { // Confirm that IBusClient::FocusOut is called as expected. TEST_F(InputMethodChromeOSTest, FocusOut_None) { input_type_ = TEXT_INPUT_TYPE_TEXT; - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(1, mock_ime_engine_handler_->focus_in_call_count()); EXPECT_EQ(0, mock_ime_engine_handler_->focus_out_call_count()); input_type_ = TEXT_INPUT_TYPE_NONE; @@ -493,7 +490,7 @@ TEST_F(InputMethodChromeOSTest, FocusOut_None) { // Confirm that IBusClient::FocusOut is called as expected. TEST_F(InputMethodChromeOSTest, FocusOut_Password) { input_type_ = TEXT_INPUT_TYPE_TEXT; - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ(1, mock_ime_engine_handler_->focus_in_call_count()); EXPECT_EQ(0, mock_ime_engine_handler_->focus_out_call_count()); input_type_ = TEXT_INPUT_TYPE_PASSWORD; @@ -504,7 +501,7 @@ TEST_F(InputMethodChromeOSTest, FocusOut_Password) { // FocusIn/FocusOut scenario test TEST_F(InputMethodChromeOSTest, Focus_Scenario) { - ime_->Init(true); + ime_->OnFocus(); // Confirm that both FocusIn and FocusOut are NOT called. EXPECT_EQ(0, mock_ime_engine_handler_->focus_in_call_count()); EXPECT_EQ(0, mock_ime_engine_handler_->focus_out_call_count()); @@ -563,7 +560,7 @@ TEST_F(InputMethodChromeOSTest, Focus_Scenario) { // Test if the new |caret_bounds_| is correctly sent to ibus-daemon. TEST_F(InputMethodChromeOSTest, OnCaretBoundsChanged) { input_type_ = TEXT_INPUT_TYPE_TEXT; - ime_->Init(true); + ime_->OnFocus(); EXPECT_EQ( 1, mock_ime_candidate_window_handler_->set_cursor_bounds_call_count()); @@ -798,7 +795,7 @@ TEST_F(InputMethodChromeOSTest, } TEST_F(InputMethodChromeOSTest, SurroundingText_NoSelectionTest) { - ime_->Init(true); + ime_->OnFocus(); // Click a text input form. input_type_ = TEXT_INPUT_TYPE_TEXT; ime_->OnTextInputTypeChanged(this); @@ -826,7 +823,7 @@ TEST_F(InputMethodChromeOSTest, SurroundingText_NoSelectionTest) { } TEST_F(InputMethodChromeOSTest, SurroundingText_SelectionTest) { - ime_->Init(true); + ime_->OnFocus(); // Click a text input form. input_type_ = TEXT_INPUT_TYPE_TEXT; ime_->OnTextInputTypeChanged(this); @@ -853,7 +850,7 @@ TEST_F(InputMethodChromeOSTest, SurroundingText_SelectionTest) { } TEST_F(InputMethodChromeOSTest, SurroundingText_PartialText) { - ime_->Init(true); + ime_->OnFocus(); // Click a text input form. input_type_ = TEXT_INPUT_TYPE_TEXT; ime_->OnTextInputTypeChanged(this); @@ -879,7 +876,7 @@ TEST_F(InputMethodChromeOSTest, SurroundingText_PartialText) { } TEST_F(InputMethodChromeOSTest, SurroundingText_BecomeEmptyText) { - ime_->Init(true); + ime_->OnFocus(); // Click a text input form. input_type_ = TEXT_INPUT_TYPE_TEXT; ime_->OnTextInputTypeChanged(this); @@ -910,7 +907,7 @@ class InputMethodChromeOSKeyEventTest : public InputMethodChromeOSTest { void SetUp() override { InputMethodChromeOSTest::SetUp(); - ime_->Init(true); + ime_->OnFocus(); } DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOSKeyEventTest); diff --git a/ui/base/ime/input_method_win.cc b/ui/base/ime/input_method_win.cc index 6961683..9bea264 100644 --- a/ui/base/ime/input_method_win.cc +++ b/ui/base/ime/input_method_win.cc @@ -35,28 +35,22 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, composing_window_handle_(NULL), default_input_language_initialized_(false) { SetDelegate(delegate); - // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() - // are not implemented yet. To work around this limitation, here we use - // "always focused" model. - // TODO(ime): Fix the caller of OnFocus() and OnBlur() so that appropriate - // focus event will be passed. - InputMethodBase::OnFocus(); -} - -void InputMethodWin::Init(bool focused) { - InputMethodBase::Init(focused); } void InputMethodWin::OnFocus() { - // Ignore OnFocus event for "always focused" model. See the comment in the - // constructor. - // TODO(ime): Implement OnFocus once the callers are fixed. + InputMethodBase::OnFocus(); + if (GetTextInputClient()) + UpdateIMEState(); } void InputMethodWin::OnBlur() { - // Ignore OnBlur event for "always focused" model. See the comment in the - // constructor. - // TODO(ime): Implement OnFocus once the callers are fixed. + ConfirmCompositionText(); + // Gets the focused text input client before calling parent's OnBlur() because + // it will cause GetTextInputClient() returns NULL. + ui::TextInputClient* client = GetTextInputClient(); + InputMethodBase::OnBlur(); + if (client) + UpdateIMEState(); } bool InputMethodWin::OnUntranslatedIMEMessage( @@ -149,7 +143,7 @@ bool InputMethodWin::DispatchKeyEvent(const ui::KeyEvent& event) { void InputMethodWin::OnTextInputTypeChanged(const TextInputClient* client) { if (!IsTextInputClientFocused(client) || !IsWindowFocused(client)) return; - imm32_manager_.CancelIME(GetAttachedWindowHandle(client)); + imm32_manager_.CancelIME(toplevel_window_handle_); UpdateIMEState(); } @@ -165,7 +159,7 @@ void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); const gfx::Rect screen_bounds = gfx::win::DIPToScreenRect(dip_screen_bounds); - HWND attached_window = GetAttachedWindowHandle(client); + HWND attached_window = toplevel_window_handle_; // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this // conversion shouldn't be necessary. RECT r = {}; @@ -179,7 +173,7 @@ void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { void InputMethodWin::CancelComposition(const TextInputClient* client) { if (enabled_ && IsTextInputClientFocused(client)) - imm32_manager_.CancelIME(GetAttachedWindowHandle(client)); + imm32_manager_.CancelIME(toplevel_window_handle_); } void InputMethodWin::OnInputLocaleChanged() { @@ -216,8 +210,6 @@ void InputMethodWin::OnDidChangeFocusedClient( // focus and after it acquires focus again are the same. OnTextInputTypeChanged(focused); - UpdateIMEState(); - // Force to update caret bounds, in case the client thinks that the caret // bounds has not changed. OnCaretBoundsChanged(focused); @@ -583,25 +575,16 @@ LRESULT InputMethodWin::OnQueryCharPosition(IMECHARPOSITION* char_positon) { return 1; // returns non-zero value when succeeded. } -HWND InputMethodWin::GetAttachedWindowHandle( - const TextInputClient* text_input_client) const { - // On Aura environment, we can assume that |toplevel_window_handle_| always - // represents the valid top-level window handle because each top-level window - // is responsible for lifecycle management of corresponding InputMethod - // instance. - return toplevel_window_handle_; -} - bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { if (!client) return false; - HWND attached_window_handle = GetAttachedWindowHandle(client); // When Aura is enabled, |attached_window_handle| should always be a top-level // window. So we can safely assume that |attached_window_handle| is ready for // receiving keyboard input as long as it is an active window. This works well // even when the |attached_window_handle| becomes active but has not received // WM_FOCUS yet. - return attached_window_handle && GetActiveWindow() == attached_window_handle; + return toplevel_window_handle_ && + GetActiveWindow() == toplevel_window_handle_; } bool InputMethodWin::DispatchFabricatedKeyEvent(const ui::KeyEvent& event) { @@ -632,7 +615,7 @@ void InputMethodWin::ConfirmCompositionText() { void InputMethodWin::UpdateIMEState() { // Use switch here in case we are going to add more text input types. // We disable input method in password field. - const HWND window_handle = GetAttachedWindowHandle(GetTextInputClient()); + const HWND window_handle = toplevel_window_handle_; const TextInputType text_input_type = GetTextInputType(); const TextInputMode text_input_mode = GetTextInputMode(); switch (text_input_type) { diff --git a/ui/base/ime/input_method_win.h b/ui/base/ime/input_method_win.h index 8a41ae3..eb6e670 100644 --- a/ui/base/ime/input_method_win.h +++ b/ui/base/ime/input_method_win.h @@ -23,7 +23,6 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { HWND toplevel_window_handle); // Overridden from InputMethod: - void Init(bool focused) override; void OnFocus() override; void OnBlur() override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, @@ -90,10 +89,6 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { LRESULT OnReconvertString(RECONVERTSTRING* reconv); LRESULT OnQueryCharPosition(IMECHARPOSITION* char_positon); - // Returns the window handle to which |text_input_client| is bound. - // On Aura environment, |toplevel_window_handle_| is always returned. - HWND GetAttachedWindowHandle(const TextInputClient* text_input_client) const; - // Returns true if the Win32 native window bound to |client| is considered // to be ready for receiving keyboard input. bool IsWindowFocused(const TextInputClient* client) const; diff --git a/ui/base/ime/mock_input_method.cc b/ui/base/ime/mock_input_method.cc index fb1e6ba..1ea1203 100644 --- a/ui/base/ime/mock_input_method.cc +++ b/ui/base/ime/mock_input_method.cc @@ -47,9 +47,6 @@ bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { return false; } -void MockInputMethod::Init(bool focused) { -} - void MockInputMethod::OnFocus() { FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnFocus()); } diff --git a/ui/base/ime/mock_input_method.h b/ui/base/ime/mock_input_method.h index 5d85482..67cc299 100644 --- a/ui/base/ime/mock_input_method.h +++ b/ui/base/ime/mock_input_method.h @@ -31,7 +31,6 @@ class UI_BASE_IME_EXPORT MockInputMethod // Overriden from InputMethod. void SetDelegate(internal::InputMethodDelegate* delegate) override; - void Init(bool focused) override; void OnFocus() override; void OnBlur() override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, diff --git a/ui/base/ime/remote_input_method_win.cc b/ui/base/ime/remote_input_method_win.cc index 2b0405a..b921382 100644 --- a/ui/base/ime/remote_input_method_win.cc +++ b/ui/base/ime/remote_input_method_win.cc @@ -134,8 +134,6 @@ class RemoteInputMethodWin : public InputMethod, delegate_ = delegate; } - void Init(bool focused) override {} - void OnFocus() override {} void OnBlur() override {} diff --git a/ui/wm/core/input_method_event_filter.cc b/ui/wm/core/input_method_event_filter.cc index f491c78..e3ea50d 100644 --- a/ui/wm/core/input_method_event_filter.cc +++ b/ui/wm/core/input_method_event_filter.cc @@ -19,9 +19,9 @@ namespace wm { InputMethodEventFilter::InputMethodEventFilter(gfx::AcceleratedWidget widget) : input_method_(ui::CreateInputMethod(this, widget)) { - // TODO(yusukes): Check if the root window is currently focused and pass the - // result to Init(). - input_method_->Init(true); + // TODO(shuchen): Check if the root window is currently focused and determine + // whether to call OnFocus. + input_method_->OnFocus(); } InputMethodEventFilter::~InputMethodEventFilter() { |