@@ -44,12 +44,19 @@ static const int kMaxTouchDeviceId = 128;
4444
4545} // namespace
4646
47- WindowWin32::WindowWin32 ()
48- : touch_id_generator_(kMinTouchDeviceId , kMaxTouchDeviceId ) {
47+ WindowWin32::WindowWin32 () : WindowWin32(nullptr ) {}
48+
49+ WindowWin32::WindowWin32 (
50+ std::unique_ptr<TextInputManagerWin32> text_input_manager)
51+ : touch_id_generator_(kMinTouchDeviceId , kMaxTouchDeviceId ),
52+ text_input_manager_ (std::move(text_input_manager)) {
4953 // Get the DPI of the primary monitor as the initial DPI. If Per-Monitor V2 is
5054 // supported, |current_dpi_| should be updated in the
5155 // kWmDpiChangedBeforeParent message.
5256 current_dpi_ = GetDpiForHWND (nullptr );
57+ if (text_input_manager_ == nullptr ) {
58+ text_input_manager_ = std::make_unique<TextInputManagerWin32>();
59+ }
5360}
5461
5562WindowWin32::~WindowWin32 () {
@@ -119,7 +126,7 @@ LRESULT CALLBACK WindowWin32::WndProc(HWND const window,
119126
120127 auto that = static_cast <WindowWin32*>(cs->lpCreateParams );
121128 that->window_handle_ = window;
122- that->text_input_manager_ . SetWindowHandle (window);
129+ that->text_input_manager_ -> SetWindowHandle (window);
123130 RegisterTouchWindow (window, 0 );
124131 } else if (WindowWin32* that = GetThisFromHandle (window)) {
125132 return that->HandleMessage (message, wparam, lparam);
@@ -170,36 +177,37 @@ void WindowWin32::OnImeSetContext(UINT const message,
170177 WPARAM const wparam,
171178 LPARAM const lparam) {
172179 if (wparam != 0 ) {
173- text_input_manager_. CreateImeWindow ();
180+ text_input_manager_-> CreateImeWindow ();
174181 }
175182}
176183
177184void WindowWin32::OnImeStartComposition (UINT const message,
178185 WPARAM const wparam,
179186 LPARAM const lparam) {
180- text_input_manager_. CreateImeWindow ();
187+ text_input_manager_-> CreateImeWindow ();
181188 OnComposeBegin ();
182189}
183190
184191void WindowWin32::OnImeComposition (UINT const message,
185192 WPARAM const wparam,
186193 LPARAM const lparam) {
187194 // Update the IME window position.
188- text_input_manager_. UpdateImeWindow ();
195+ text_input_manager_-> UpdateImeWindow ();
189196
190197 if (lparam & GCS_COMPSTR) {
191198 // Read the in-progress composing string.
192- long pos = text_input_manager_. GetComposingCursorPosition ();
199+ long pos = text_input_manager_-> GetComposingCursorPosition ();
193200 std::optional<std::u16string> text =
194- text_input_manager_. GetComposingString ();
201+ text_input_manager_-> GetComposingString ();
195202 if (text) {
196203 OnComposeChange (text.value (), pos);
197204 }
198- } else if (lparam & GCS_RESULTSTR) {
205+ }
206+ if (lparam & GCS_RESULTSTR) {
199207 // Commit but don't end composing.
200208 // Read the committed composing string.
201- long pos = text_input_manager_. GetComposingCursorPosition ();
202- std::optional<std::u16string> text = text_input_manager_. GetResultString ();
209+ long pos = text_input_manager_-> GetComposingCursorPosition ();
210+ std::optional<std::u16string> text = text_input_manager_-> GetResultString ();
203211 if (text) {
204212 OnComposeChange (text.value (), pos);
205213 OnComposeCommit ();
@@ -210,7 +218,7 @@ void WindowWin32::OnImeComposition(UINT const message,
210218void WindowWin32::OnImeEndComposition (UINT const message,
211219 WPARAM const wparam,
212220 LPARAM const lparam) {
213- text_input_manager_. DestroyImeWindow ();
221+ text_input_manager_-> DestroyImeWindow ();
214222 OnComposeEnd ();
215223}
216224
@@ -223,11 +231,11 @@ void WindowWin32::OnImeRequest(UINT const message,
223231}
224232
225233void WindowWin32::AbortImeComposing () {
226- text_input_manager_. AbortComposing ();
234+ text_input_manager_-> AbortComposing ();
227235}
228236
229237void WindowWin32::UpdateCursorRect (const Rect& rect) {
230- text_input_manager_. UpdateCaretRect (rect);
238+ text_input_manager_-> UpdateCaretRect (rect);
231239}
232240
233241static uint16_t ResolveKeyCode (uint16_t original,
@@ -588,7 +596,7 @@ HWND WindowWin32::GetWindowHandle() {
588596
589597void WindowWin32::Destroy () {
590598 if (window_handle_) {
591- text_input_manager_. SetWindowHandle (nullptr );
599+ text_input_manager_-> SetWindowHandle (nullptr );
592600 DestroyWindow (window_handle_);
593601 window_handle_ = nullptr ;
594602 }
0 commit comments