From 601e178945a24cfae81ee25046aa178c4defdd02 Mon Sep 17 00:00:00 2001 From: moko256 Date: Wed, 1 Jun 2022 10:01:55 +0900 Subject: [PATCH] [Windows] Google Japanese Input, composing text doesn't rendered after commit text partially (flutter/engine#33605) Reproducible steps is in flutter/flutter#102021. Fixes flutter/flutter#102021. No changes in [flutter/tests] repo. --- .../shell/platform/windows/window_win32.cc | 21 +++++++------ .../windows/window_win32_unittests.cc | 31 +++++++++++++------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/window_win32.cc b/engine/src/flutter/shell/platform/windows/window_win32.cc index 8837c87e37a..e0506334613 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32.cc @@ -233,15 +233,9 @@ void WindowWin32::OnImeComposition(UINT const message, OnComposeCommit(); } - if (lparam & GCS_COMPSTR) { - // Read the in-progress composing string. - long pos = text_input_manager_->GetComposingCursorPosition(); - std::optional text = - text_input_manager_->GetComposingString(); - if (text) { - OnComposeChange(text.value(), pos); - } - } + // Process GCS_RESULTSTR at fisrt, because Google Japanese Input and ATOK send + // both GCS_RESULTSTR and GCS_COMPSTR to commit composed text and send new + // composing text. if (lparam & GCS_RESULTSTR) { // Commit but don't end composing. // Read the committed composing string. @@ -252,6 +246,15 @@ void WindowWin32::OnImeComposition(UINT const message, OnComposeCommit(); } } + if (lparam & GCS_COMPSTR) { + // Read the in-progress composing string. + long pos = text_input_manager_->GetComposingCursorPosition(); + std::optional text = + text_input_manager_->GetComposingString(); + if (text) { + OnComposeChange(text.value(), pos); + } + } } void WindowWin32::OnImeEndComposition(UINT const message, diff --git a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc index e3bb83c48a5..2abf15c466c 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc @@ -7,6 +7,7 @@ #include "gtest/gtest.h" using testing::_; +using testing::InSequence; using testing::Invoke; using testing::Return; @@ -87,24 +88,34 @@ TEST(MockWin32Window, OnImeCompositionResult) { window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_RESULTSTR); } -TEST(MockWin32Window, OnImeCompositionComposeAndResult) { +TEST(MockWin32Window, OnImeCompositionResultAndCompose) { MockTextInputManagerWin32* text_input_manager = new MockTextInputManagerWin32(); std::unique_ptr text_input_manager_ptr( text_input_manager); MockWin32Window window(std::move(text_input_manager_ptr)); - EXPECT_CALL(*text_input_manager, GetComposingString()) - .WillRepeatedly( - Return(std::optional(std::u16string(u"nihao")))); - EXPECT_CALL(*text_input_manager, GetResultString()) - .WillRepeatedly( - Return(std::optional(std::u16string(u"`}")))); + + // This situation is that Google Japanese Input finished composing "今日" in + // "今日は" but is still composing "は". + { + InSequence dummy; + EXPECT_CALL(*text_input_manager, GetResultString()) + .WillRepeatedly( + Return(std::optional(std::u16string(u"今日")))); + EXPECT_CALL(*text_input_manager, GetComposingString()) + .WillRepeatedly( + Return(std::optional(std::u16string(u"は")))); + } + { + InSequence dummy; + EXPECT_CALL(window, OnComposeChange(std::u16string(u"今日"), 0)).Times(1); + EXPECT_CALL(window, OnComposeCommit()).Times(1); + EXPECT_CALL(window, OnComposeChange(std::u16string(u"は"), 0)).Times(1); + } + EXPECT_CALL(*text_input_manager, GetComposingCursorPosition()) .WillRepeatedly(Return((int)0)); - EXPECT_CALL(window, OnComposeChange(std::u16string(u"nihao"), 0)).Times(1); - EXPECT_CALL(window, OnComposeChange(std::u16string(u"`}"), 0)).Times(1); - EXPECT_CALL(window, OnComposeCommit()).Times(1); ON_CALL(window, OnImeComposition) .WillByDefault(Invoke(&window, &MockWin32Window::CallOnImeComposition)); EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);