Commit 906b794a authored by Siye Liu's avatar Siye Liu Committed by Commit Bot

Hook up InputMethodWinTSF with IME extension on Windows.

This CL hooks up InputMethodWinTsf with IME extension. Since ui::TSFBridge
may be null for unit tests, this Cl also adds protection in InputMethodWinTSF.

Bug: 657623
Change-Id: I608ceba376f0fdba537339030d35c11993e16822
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1507234Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Siye Liu <siliu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#641127}
parent 789f0c99
...@@ -517,4 +517,48 @@ ui::EventDispatchDetails InputMethodWinBase::ProcessUnhandledKeyEvent( ...@@ -517,4 +517,48 @@ ui::EventDispatchDetails InputMethodWinBase::ProcessUnhandledKeyEvent(
return details; return details;
} }
void InputMethodWinBase::UpdateCompositionBoundsForEngine(
const TextInputClient* client) {
TextInputType text_input_type = GetTextInputType();
if (client == GetTextInputClient() &&
text_input_type != TEXT_INPUT_TYPE_NONE &&
text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) {
GetEngine()->SetCompositionBounds(GetCompositionBounds(client));
}
}
void InputMethodWinBase::ResetEngine() {
if (GetEngine())
GetEngine()->Reset();
}
void InputMethodWinBase::CancelCompositionForEngine() {
TextInputType text_input_type = GetTextInputType();
if (text_input_type != TEXT_INPUT_TYPE_NONE &&
text_input_type != TEXT_INPUT_TYPE_PASSWORD) {
InputMethodWinBase::ResetEngine();
}
}
void InputMethodWinBase::UpdateEngineFocusAndInputContext() {
if (!ui::IMEBridge::Get()) // IMEBridge could be null for tests.
return;
const TextInputType old_text_input_type =
ui::IMEBridge::Get()->GetCurrentInputContext().type;
ui::IMEEngineHandlerInterface::InputContext context(
GetTextInputType(), GetTextInputMode(), GetTextInputFlags(),
ui::TextInputClient::FOCUS_REASON_OTHER, GetClientShouldDoLearning());
ui::IMEBridge::Get()->SetCurrentInputContext(context);
// Update IME Engine state.
ui::IMEEngineHandlerInterface* engine = GetEngine();
if (engine) {
if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE)
engine->FocusOut();
if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
engine->FocusIn(context);
}
}
} // namespace ui } // namespace ui
...@@ -60,6 +60,19 @@ class UI_BASE_IME_EXPORT InputMethodWinBase : public InputMethodBase { ...@@ -60,6 +60,19 @@ class UI_BASE_IME_EXPORT InputMethodWinBase : public InputMethodBase {
ui::KeyEvent* event, ui::KeyEvent* event,
const std::vector<MSG>* char_msgs); const std::vector<MSG>* char_msgs);
// Update composition bounds for Chromium IME extension.
void UpdateCompositionBoundsForEngine(const TextInputClient* client);
// Reset composition status for Chromium IME extension.
void ResetEngine();
// Cancel composition for Chromium IME extension.
void CancelCompositionForEngine();
// Update focus state for Chromium IME extension and update input context in
// ui::IMEBridge.
void UpdateEngineFocusAndInputContext();
// The toplevel window handle. // The toplevel window handle.
const HWND toplevel_window_handle_; const HWND toplevel_window_handle_;
......
...@@ -100,14 +100,7 @@ void InputMethodWinImm32::OnCaretBoundsChanged(const TextInputClient* client) { ...@@ -100,14 +100,7 @@ void InputMethodWinImm32::OnCaretBoundsChanged(const TextInputClient* client) {
if (!IsTextInputClientFocused(client) || !IsWindowFocused(client)) if (!IsTextInputClientFocused(client) || !IsWindowFocused(client))
return; return;
NotifyTextInputCaretBoundsChanged(client); NotifyTextInputCaretBoundsChanged(client);
TextInputType text_input_type = GetTextInputType(); InputMethodWinBase::UpdateCompositionBoundsForEngine(client);
if (client == GetTextInputClient() &&
text_input_type != TEXT_INPUT_TYPE_NONE &&
text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) {
// |enabled_| == false could be faked, and the engine should rely on the
// real type from GetTextInputType().
GetEngine()->SetCompositionBounds(GetCompositionBounds(client));
}
if (!enabled_) if (!enabled_)
return; return;
...@@ -135,11 +128,7 @@ void InputMethodWinImm32::CancelComposition(const TextInputClient* client) { ...@@ -135,11 +128,7 @@ void InputMethodWinImm32::CancelComposition(const TextInputClient* client) {
if (IsTextInputClientFocused(client)) { if (IsTextInputClientFocused(client)) {
// |enabled_| == false could be faked, and the engine should rely on the // |enabled_| == false could be faked, and the engine should rely on the
// real type get from GetTextInputType(). // real type get from GetTextInputType().
TextInputType text_input_type = GetTextInputType(); InputMethodWinBase::CancelCompositionForEngine();
if (text_input_type != TEXT_INPUT_TYPE_NONE &&
text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) {
GetEngine()->Reset();
}
if (enabled_) if (enabled_)
imm32_manager_.CancelIME(toplevel_window_handle_); imm32_manager_.CancelIME(toplevel_window_handle_);
...@@ -340,8 +329,7 @@ void InputMethodWinImm32::ConfirmCompositionText() { ...@@ -340,8 +329,7 @@ void InputMethodWinImm32::ConfirmCompositionText() {
if (!IsTextInputTypeNone() && GetTextInputClient()->HasCompositionText()) { if (!IsTextInputTypeNone() && GetTextInputClient()->HasCompositionText()) {
GetTextInputClient()->ConfirmCompositionText(); GetTextInputClient()->ConfirmCompositionText();
if (GetEngine()) InputMethodWinBase::ResetEngine();
GetEngine()->Reset();
} }
} }
...@@ -370,23 +358,7 @@ void InputMethodWinImm32::UpdateIMEState() { ...@@ -370,23 +358,7 @@ void InputMethodWinImm32::UpdateIMEState() {
tsf_inputscope::SetInputScopeForTsfUnawareWindow( tsf_inputscope::SetInputScopeForTsfUnawareWindow(
window_handle, text_input_type, text_input_mode); window_handle, text_input_type, text_input_mode);
if (!ui::IMEBridge::Get()) // IMEBridge could be null for tests. InputMethodWinBase::UpdateEngineFocusAndInputContext();
return;
const TextInputType old_text_input_type =
ui::IMEBridge::Get()->GetCurrentInputContext().type;
ui::IMEEngineHandlerInterface::InputContext context(
GetTextInputType(), GetTextInputMode(), GetTextInputFlags(),
ui::TextInputClient::FOCUS_REASON_OTHER, GetClientShouldDoLearning());
ui::IMEBridge::Get()->SetCurrentInputContext(context);
ui::IMEEngineHandlerInterface* engine = GetEngine();
if (engine) {
if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE)
engine->FocusOut();
if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
engine->FocusIn(context);
}
} }
} // namespace ui } // namespace ui
...@@ -39,6 +39,11 @@ InputMethodWinTSF::InputMethodWinTSF(internal::InputMethodDelegate* delegate, ...@@ -39,6 +39,11 @@ InputMethodWinTSF::InputMethodWinTSF(internal::InputMethodDelegate* delegate,
InputMethodWinTSF::~InputMethodWinTSF() {} InputMethodWinTSF::~InputMethodWinTSF() {}
void InputMethodWinTSF::OnFocus() { void InputMethodWinTSF::OnFocus() {
InputMethodBase::OnFocus();
if (!ui::TSFBridge::GetInstance()) {
// TSFBridge can be null for tests.
return;
}
tsf_event_router_->SetManager( tsf_event_router_->SetManager(
ui::TSFBridge::GetInstance()->GetThreadManager().Get()); ui::TSFBridge::GetInstance()->GetThreadManager().Get());
ui::TSFBridge::GetInstance()->SetInputMethodDelegate( ui::TSFBridge::GetInstance()->SetInputMethodDelegate(
...@@ -46,6 +51,11 @@ void InputMethodWinTSF::OnFocus() { ...@@ -46,6 +51,11 @@ void InputMethodWinTSF::OnFocus() {
} }
void InputMethodWinTSF::OnBlur() { void InputMethodWinTSF::OnBlur() {
InputMethodBase::OnBlur();
if (!ui::TSFBridge::GetInstance()) {
// TSFBridge can be null for tests.
return;
}
tsf_event_router_->SetManager(nullptr); tsf_event_router_->SetManager(nullptr);
ui::TSFBridge::GetInstance()->RemoveInputMethodDelegate(); ui::TSFBridge::GetInstance()->RemoveInputMethodDelegate();
} }
...@@ -83,24 +93,38 @@ bool InputMethodWinTSF::OnUntranslatedIMEMessage( ...@@ -83,24 +93,38 @@ bool InputMethodWinTSF::OnUntranslatedIMEMessage(
void InputMethodWinTSF::OnTextInputTypeChanged(const TextInputClient* client) { void InputMethodWinTSF::OnTextInputTypeChanged(const TextInputClient* client) {
InputMethodBase::OnTextInputTypeChanged(client); InputMethodBase::OnTextInputTypeChanged(client);
if (!IsTextInputClientFocused(client) || !IsWindowFocused(client)) if (!ui::TSFBridge::GetInstance() || !IsTextInputClientFocused(client) ||
!IsWindowFocused(client)) {
return; return;
}
ui::TSFBridge::GetInstance()->CancelComposition(); ui::TSFBridge::GetInstance()->CancelComposition();
ui::TSFBridge::GetInstance()->OnTextInputTypeChanged(client); ui::TSFBridge::GetInstance()->OnTextInputTypeChanged(client);
InputMethodWinBase::UpdateEngineFocusAndInputContext();
} }
void InputMethodWinTSF::OnCaretBoundsChanged(const TextInputClient* client) { void InputMethodWinTSF::OnCaretBoundsChanged(const TextInputClient* client) {
if (!IsTextInputClientFocused(client) || !IsWindowFocused(client)) if (!ui::TSFBridge::GetInstance() || !IsTextInputClientFocused(client) ||
!IsWindowFocused(client)) {
return; return;
}
NotifyTextInputCaretBoundsChanged(client);
ui::TSFBridge::GetInstance()->OnTextLayoutChanged(); ui::TSFBridge::GetInstance()->OnTextLayoutChanged();
InputMethodWinBase::UpdateCompositionBoundsForEngine(client);
} }
void InputMethodWinTSF::CancelComposition(const TextInputClient* client) { void InputMethodWinTSF::CancelComposition(const TextInputClient* client) {
if (IsTextInputClientFocused(client) && IsWindowFocused(client)) if (ui::TSFBridge::GetInstance() && IsTextInputClientFocused(client) &&
IsWindowFocused(client)) {
ui::TSFBridge::GetInstance()->CancelComposition(); ui::TSFBridge::GetInstance()->CancelComposition();
InputMethodWinBase::CancelCompositionForEngine();
}
} }
void InputMethodWinTSF::DetachTextInputClient(TextInputClient* client) { void InputMethodWinTSF::DetachTextInputClient(TextInputClient* client) {
if (!ui::TSFBridge::GetInstance()) {
// TSFBridge can be null for tests.
return;
}
InputMethodWinBase::DetachTextInputClient(client); InputMethodWinBase::DetachTextInputClient(client);
ui::TSFBridge::GetInstance()->RemoveFocusedClient(client); ui::TSFBridge::GetInstance()->RemoveFocusedClient(client);
} }
...@@ -121,7 +145,8 @@ void InputMethodWinTSF::OnWillChangeFocusedClient( ...@@ -121,7 +145,8 @@ void InputMethodWinTSF::OnWillChangeFocusedClient(
void InputMethodWinTSF::OnDidChangeFocusedClient( void InputMethodWinTSF::OnDidChangeFocusedClient(
TextInputClient* focused_before, TextInputClient* focused_before,
TextInputClient* focused) { TextInputClient* focused) {
if (IsWindowFocused(focused) && IsTextInputClientFocused(focused)) { if (ui::TSFBridge::GetInstance() && IsWindowFocused(focused) &&
IsTextInputClientFocused(focused)) {
ui::TSFBridge::GetInstance()->SetFocusedClient(toplevel_window_handle_, ui::TSFBridge::GetInstance()->SetFocusedClient(toplevel_window_handle_,
focused); focused);
...@@ -138,8 +163,12 @@ void InputMethodWinTSF::OnDidChangeFocusedClient( ...@@ -138,8 +163,12 @@ void InputMethodWinTSF::OnDidChangeFocusedClient(
} }
void InputMethodWinTSF::ConfirmCompositionText() { void InputMethodWinTSF::ConfirmCompositionText() {
if (!IsTextInputTypeNone()) if (!IsTextInputTypeNone()) {
ui::TSFBridge::GetInstance()->ConfirmComposition(); if (GetTextInputClient()->HasCompositionText())
InputMethodWinBase::ResetEngine();
if (ui::TSFBridge::GetInstance())
ui::TSFBridge::GetInstance()->ConfirmComposition();
}
} }
} // namespace ui } // namespace ui
...@@ -595,7 +595,7 @@ STDMETHODIMP TSFTextStore::RequestLock(DWORD lock_flags, HRESULT* result) { ...@@ -595,7 +595,7 @@ STDMETHODIMP TSFTextStore::RequestLock(DWORD lock_flags, HRESULT* result) {
// If composition_string is empty and there is an existing composition going // If composition_string is empty and there is an existing composition going
// on, we still need to call into blink to complete the composition. // on, we still need to call into blink to complete the composition.
if (previous_composition_string_ != composition_string || if (previous_composition_string_ != composition_string ||
(text_input_client_->HasCompositionText() && (has_composition_range_ && text_input_client_->HasCompositionText() &&
composition_string.empty())) { composition_string.empty())) {
previous_composition_string_ = composition_string; previous_composition_string_ = composition_string;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment