Index: ui/base/ime/input_method_tsf.cc |
diff --git a/ui/base/ime/input_method_tsf.cc b/ui/base/ime/input_method_tsf.cc |
index 41f0ba0600213ba7ce89f2f419c8965b7f3e231d..29a06b7cf8f35bf0113f52cfae17b3dc30d0b8a6 100644 |
--- a/ui/base/ime/input_method_tsf.cc |
+++ b/ui/base/ime/input_method_tsf.cc |
@@ -1,26 +1,35 @@ |
-// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
#include "ui/base/ime/input_method_tsf.h" |
#include "ui/base/ime/text_input_client.h" |
+#include "ui/base/ime/win/tsf_bridge.h" |
namespace ui { |
InputMethodTSF::InputMethodTSF(internal::InputMethodDelegate* delegate, |
HWND toplevel_window_handle) |
: InputMethodWin(delegate, toplevel_window_handle) { |
+ // 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. |
+ InputMethodWin::OnFocus(); |
} |
void InputMethodTSF::OnFocus() { |
- InputMethodWin::OnFocus(); |
- NOTIMPLEMENTED(); |
+ // Ignore OnFocus event for "always focused" model. See the comment in the |
+ // constructor. |
+ // TODO(ime): Implement OnFocus once the callers are fixed. |
} |
void InputMethodTSF::OnBlur() { |
- NOTIMPLEMENTED(); |
- InputMethodWin::OnBlur(); |
+ // Ignore OnBlur event for "always focused" model. See the comment in the |
+ // constructor. |
+ // TODO(ime): Implement OnFocus once the callers are fixed. |
} |
bool InputMethodTSF::OnUntranslatedIMEMessage( |
@@ -59,35 +68,72 @@ bool InputMethodTSF::OnUntranslatedIMEMessage( |
} |
void InputMethodTSF::OnTextInputTypeChanged(const TextInputClient* client) { |
- NOTIMPLEMENTED(); |
+ if (IsTextInputClientFocused(client) && IsWindowFocused(client)) { |
+ ui::TSFBridge::GetInstance()->CancelComposition(); |
+ ui::TSFBridge::GetInstance()->OnTextInputTypeChanged( |
+ const_cast<TextInputClient*>(client)); |
Seigo Nonaka
2013/06/18 05:22:59
Is there any chance to remove const_cast?
Yohei Yukawa
2013/06/18 05:53:31
Removed the const_cast.
|
+ } |
InputMethodWin::OnTextInputTypeChanged(client); |
} |
void InputMethodTSF::OnCaretBoundsChanged(const TextInputClient* client) { |
- NOTIMPLEMENTED(); |
+ if (IsTextInputClientFocused(client) && IsWindowFocused(client)) { |
Seigo Nonaka
2013/06/18 05:22:59
nit: plz drop braces for one liner.
Yohei Yukawa
2013/06/18 05:53:31
Done.
|
+ ui::TSFBridge::GetInstance()->OnTextLayoutChanged(); |
+ } |
} |
void InputMethodTSF::CancelComposition(const TextInputClient* client) { |
- NOTIMPLEMENTED(); |
+ if (IsTextInputClientFocused(client) && IsWindowFocused(client)) { |
+ ui::TSFBridge::GetInstance()->CancelComposition(); |
+ } |
} |
void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) { |
- NOTIMPLEMENTED(); |
+ if (IsWindowFocused(client)) { |
+ ui::TSFBridge::GetInstance()->SetFocusedClient( |
+ GetAttachedWindowHandle(client), client); |
+ } |
InputMethodWin::SetFocusedTextInputClient(client); |
} |
void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before, |
TextInputClient* focused) { |
- NOTIMPLEMENTED(); |
+ if (IsWindowFocused(focused_before)) { |
+ ConfirmCompositionText(); |
+ ui::TSFBridge::GetInstance()->RemoveFocusedClient(focused_before); |
+ } |
} |
void InputMethodTSF::OnDidChangeFocusedClient(TextInputClient* focused_before, |
TextInputClient* focused) { |
- NOTIMPLEMENTED(); |
+ if (IsWindowFocused(focused)) { |
+ ui::TSFBridge::GetInstance()->SetFocusedClient( |
+ GetAttachedWindowHandle(focused), focused); |
+ // Force to update the input type since client's TextInputStateChanged() |
+ // function might not be called if text input types before the client loses |
+ // focus and after it acquires focus again are the same. |
+ OnTextInputTypeChanged(focused); |
+ |
+ // Force to update caret bounds, in case the client thinks that the caret |
+ // bounds has not changed. |
+ OnCaretBoundsChanged(focused); |
+ } |
} |
void InputMethodTSF::ConfirmCompositionText() { |
- NOTIMPLEMENTED(); |
+ if (!IsTextInputTypeNone()) { |
+ // TSFBridge has not implemented ConfirmComposition yet. So here cancel |
+ // the composition instead as a workaround. |
+ // TODO(ime): Implement ConfirmComposition for TSF. |
+ ui::TSFBridge::GetInstance()->CancelComposition(); |
+ } |
+} |
+ |
+bool InputMethodTSF::IsWindowFocused(const TextInputClient* client) const { |
+ if (!client) |
+ return false; |
+ HWND attached_window_handle = GetAttachedWindowHandle(client); |
+ return attached_window_handle && GetFocus() == attached_window_handle; |
} |
} // namespace ui |