Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 56fa63c

Browse files
authored
[Windows] Begin decoupling text input plugin from the view (#47833)
Currently the text input plugin is strongly tied to a single view. This change makes the text input plugin tied to the engine in preparation for multi-view world. Part of flutter/flutter#115611 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent d1b5d09 commit 56fa63c

10 files changed

+248
-121
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7166,7 +7166,6 @@ ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.cc + ../../..
71667166
ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.h + ../../../flutter/LICENSE
71677167
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.cc + ../../../flutter/LICENSE
71687168
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.h + ../../../flutter/LICENSE
7169-
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h + ../../../flutter/LICENSE
71707169
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler.h + ../../../flutter/LICENSE
71717170
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h + ../../../flutter/LICENSE
71727171
ORIGIN: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc + ../../../flutter/LICENSE
@@ -9990,7 +9989,6 @@ FILE: ../../../flutter/shell/platform/windows/text_input_manager.cc
99909989
FILE: ../../../flutter/shell/platform/windows/text_input_manager.h
99919990
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc
99929991
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h
9993-
FILE: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h
99949992
FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h
99959993
FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
99969994
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc

shell/platform/windows/cursor_handler_unittests.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ class CursorHandlerTest : public WindowsTest {
6363
FlutterWindowsView* view() { return view_.get(); }
6464
MockWindowBindingHandler* window() { return window_; }
6565

66-
void use_headless_engine() {
66+
void UseHeadlessEngine() {
6767
FlutterWindowsEngineBuilder builder{GetContext()};
6868

6969
engine_ = builder.Build();
7070
}
7171

72-
void use_engine_with_view() {
72+
void UseEngineWithView() {
7373
FlutterWindowsEngineBuilder builder{GetContext()};
7474

7575
auto window = std::make_unique<MockWindowBindingHandler>();
@@ -93,7 +93,7 @@ class CursorHandlerTest : public WindowsTest {
9393
};
9494

9595
TEST_F(CursorHandlerTest, ActivateSystemCursor) {
96-
use_engine_with_view();
96+
UseEngineWithView();
9797

9898
TestBinaryMessenger messenger;
9999
CursorHandler cursor_handler(&messenger, engine());
@@ -119,7 +119,7 @@ TEST_F(CursorHandlerTest, ActivateSystemCursor) {
119119
}
120120

121121
TEST_F(CursorHandlerTest, ActivateSystemCursorRequiresView) {
122-
use_headless_engine();
122+
UseHeadlessEngine();
123123

124124
TestBinaryMessenger messenger;
125125
CursorHandler cursor_handler(&messenger, engine());
@@ -146,7 +146,7 @@ TEST_F(CursorHandlerTest, ActivateSystemCursorRequiresView) {
146146
}
147147

148148
TEST_F(CursorHandlerTest, CreateCustomCursor) {
149-
use_engine_with_view();
149+
UseEngineWithView();
150150

151151
TestBinaryMessenger messenger;
152152
CursorHandler cursor_handler(&messenger, engine());
@@ -177,7 +177,7 @@ TEST_F(CursorHandlerTest, CreateCustomCursor) {
177177
}
178178

179179
TEST_F(CursorHandlerTest, SetCustomCursor) {
180-
use_engine_with_view();
180+
UseEngineWithView();
181181

182182
TestBinaryMessenger messenger;
183183
CursorHandler cursor_handler(&messenger, engine());
@@ -217,7 +217,7 @@ TEST_F(CursorHandlerTest, SetCustomCursor) {
217217
}
218218

219219
TEST_F(CursorHandlerTest, SetCustomCursorRequiresView) {
220-
use_headless_engine();
220+
UseHeadlessEngine();
221221

222222
TestBinaryMessenger messenger;
223223
CursorHandler cursor_handler(&messenger, engine());
@@ -258,7 +258,7 @@ TEST_F(CursorHandlerTest, SetCustomCursorRequiresView) {
258258
}
259259

260260
TEST_F(CursorHandlerTest, SetNonexistentCustomCursor) {
261-
use_engine_with_view();
261+
UseEngineWithView();
262262

263263
TestBinaryMessenger messenger;
264264
CursorHandler cursor_handler(&messenger, engine());
@@ -287,7 +287,7 @@ TEST_F(CursorHandlerTest, SetNonexistentCustomCursor) {
287287
}
288288

289289
TEST_F(CursorHandlerTest, DeleteCustomCursor) {
290-
use_engine_with_view();
290+
UseEngineWithView();
291291

292292
TestBinaryMessenger messenger;
293293
CursorHandler cursor_handler(&messenger, engine());
@@ -325,7 +325,7 @@ TEST_F(CursorHandlerTest, DeleteCustomCursor) {
325325
}
326326

327327
TEST_F(CursorHandlerTest, DeleteNonexistentCustomCursor) {
328-
use_engine_with_view();
328+
UseEngineWithView();
329329

330330
TestBinaryMessenger messenger;
331331
CursorHandler cursor_handler(&messenger, engine());

shell/platform/windows/flutter_windows_engine.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ FlutterWindowsEngine::CreateKeyboardKeyHandler(
666666

667667
std::unique_ptr<TextInputPlugin> FlutterWindowsEngine::CreateTextInputPlugin(
668668
BinaryMessenger* messenger) {
669-
return std::make_unique<TextInputPlugin>(messenger, view_);
669+
return std::make_unique<TextInputPlugin>(messenger, this);
670670
}
671671

672672
bool FlutterWindowsEngine::RegisterExternalTexture(int64_t texture_id) {

shell/platform/windows/flutter_windows_view.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "flutter/shell/platform/windows/angle_surface_manager.h"
2121
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
2222
#include "flutter/shell/platform/windows/public/flutter_windows.h"
23-
#include "flutter/shell/platform/windows/text_input_plugin_delegate.h"
2423
#include "flutter/shell/platform/windows/window_binding_handler.h"
2524
#include "flutter/shell/platform/windows/window_binding_handler_delegate.h"
2625
#include "flutter/shell/platform/windows/window_state.h"
@@ -30,10 +29,9 @@ namespace flutter {
3029
// ID for the window frame buffer.
3130
inline constexpr uint32_t kWindowFrameBufferID = 0;
3231

33-
// An OS-windowing neutral abstration for flutter
34-
// view that works with win32 hwnds and Windows::UI::Composition visuals.
35-
class FlutterWindowsView : public WindowBindingHandlerDelegate,
36-
public TextInputPluginDelegate {
32+
// An OS-windowing neutral abstration for a Flutter view that works
33+
// with win32 HWNDs.
34+
class FlutterWindowsView : public WindowBindingHandlerDelegate {
3735
public:
3836
// Creates a FlutterWindowsView with the given implementor of
3937
// WindowBindingHandler.
@@ -186,11 +184,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
186184
// |WindowBindingHandlerDelegate|
187185
virtual gfx::NativeViewAccessible GetNativeViewAccessible() override;
188186

189-
// |TextInputPluginDelegate|
190-
void OnCursorRectUpdated(const Rect& rect) override;
187+
// Notifies the delegate of the updated the cursor rect in Flutter root view
188+
// coordinates.
189+
virtual void OnCursorRectUpdated(const Rect& rect);
191190

192-
// |TextInputPluginDelegate|
193-
void OnResetImeComposing() override;
191+
// Notifies the delegate that the system IME composing state should be reset.
192+
virtual void OnResetImeComposing();
194193

195194
// Called when a WM_ONCOMPOSITIONCHANGED message is received.
196195
void OnDwmCompositionChanged();

shell/platform/windows/platform_handler_unittests.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ class PlatformHandlerTest : public WindowsTest {
142142
protected:
143143
FlutterWindowsEngine* engine() { return engine_.get(); }
144144

145-
void use_headless_engine() {
145+
void UseHeadlessEngine() {
146146
FlutterWindowsEngineBuilder builder{GetContext()};
147147

148148
engine_ = builder.Build();
149149
}
150150

151-
void use_engine_with_view() {
151+
void UseEngineWithView() {
152152
FlutterWindowsEngineBuilder builder{GetContext()};
153153

154154
auto window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
@@ -166,7 +166,7 @@ class PlatformHandlerTest : public WindowsTest {
166166
};
167167

168168
TEST_F(PlatformHandlerTest, GetClipboardData) {
169-
use_engine_with_view();
169+
UseEngineWithView();
170170

171171
TestBinaryMessenger messenger;
172172
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -190,7 +190,7 @@ TEST_F(PlatformHandlerTest, GetClipboardData) {
190190
}
191191

192192
TEST_F(PlatformHandlerTest, GetClipboardDataRejectsUnknownContentType) {
193-
use_engine_with_view();
193+
UseEngineWithView();
194194

195195
TestBinaryMessenger messenger;
196196
PlatformHandler platform_handler(&messenger, engine());
@@ -203,7 +203,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataRejectsUnknownContentType) {
203203
}
204204

205205
TEST_F(PlatformHandlerTest, GetClipboardDataRequiresView) {
206-
use_headless_engine();
206+
UseHeadlessEngine();
207207

208208
TestBinaryMessenger messenger;
209209
PlatformHandler platform_handler(&messenger, engine());
@@ -217,7 +217,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataRequiresView) {
217217
}
218218

219219
TEST_F(PlatformHandlerTest, GetClipboardDataReportsOpenFailure) {
220-
use_engine_with_view();
220+
UseEngineWithView();
221221

222222
TestBinaryMessenger messenger;
223223
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -237,7 +237,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataReportsOpenFailure) {
237237
}
238238

239239
TEST_F(PlatformHandlerTest, GetClipboardDataReportsGetDataFailure) {
240-
use_engine_with_view();
240+
UseEngineWithView();
241241

242242
TestBinaryMessenger messenger;
243243
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -261,7 +261,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataReportsGetDataFailure) {
261261
}
262262

263263
TEST_F(PlatformHandlerTest, ClipboardHasStrings) {
264-
use_engine_with_view();
264+
UseEngineWithView();
265265

266266
TestBinaryMessenger messenger;
267267
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -282,7 +282,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStrings) {
282282
}
283283

284284
TEST_F(PlatformHandlerTest, ClipboardHasStringsReturnsFalse) {
285-
use_engine_with_view();
285+
UseEngineWithView();
286286

287287
TestBinaryMessenger messenger;
288288
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -303,7 +303,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsReturnsFalse) {
303303
}
304304

305305
TEST_F(PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType) {
306-
use_engine_with_view();
306+
UseEngineWithView();
307307

308308
TestBinaryMessenger messenger;
309309
PlatformHandler platform_handler(&messenger, engine());
@@ -315,7 +315,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType) {
315315
}
316316

317317
TEST_F(PlatformHandlerTest, ClipboardHasStringsRequiresView) {
318-
use_headless_engine();
318+
UseHeadlessEngine();
319319

320320
TestBinaryMessenger messenger;
321321
PlatformHandler platform_handler(&messenger, engine());
@@ -330,7 +330,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsRequiresView) {
330330

331331
// Regression test for https://github.com/flutter/flutter/issues/95817.
332332
TEST_F(PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors) {
333-
use_engine_with_view();
333+
UseEngineWithView();
334334

335335
TestBinaryMessenger messenger;
336336
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -350,7 +350,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors) {
350350
}
351351

352352
TEST_F(PlatformHandlerTest, ClipboardHasStringsReportsErrors) {
353-
use_engine_with_view();
353+
UseEngineWithView();
354354

355355
TestBinaryMessenger messenger;
356356
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -370,7 +370,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsReportsErrors) {
370370
}
371371

372372
TEST_F(PlatformHandlerTest, ClipboardSetData) {
373-
use_engine_with_view();
373+
UseEngineWithView();
374374

375375
TestBinaryMessenger messenger;
376376
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -397,7 +397,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetData) {
397397

398398
// Regression test for: https://github.com/flutter/flutter/issues/121976
399399
TEST_F(PlatformHandlerTest, ClipboardSetDataTextMustBeString) {
400-
use_engine_with_view();
400+
UseEngineWithView();
401401

402402
TestBinaryMessenger messenger;
403403
PlatformHandler platform_handler(&messenger, engine());
@@ -409,7 +409,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataTextMustBeString) {
409409
}
410410

411411
TEST_F(PlatformHandlerTest, ClipboardSetDataUnknownType) {
412-
use_engine_with_view();
412+
UseEngineWithView();
413413

414414
TestBinaryMessenger messenger;
415415
PlatformHandler platform_handler(&messenger, engine());
@@ -421,7 +421,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataUnknownType) {
421421
}
422422

423423
TEST_F(PlatformHandlerTest, ClipboardSetDataRequiresView) {
424-
use_headless_engine();
424+
UseHeadlessEngine();
425425

426426
TestBinaryMessenger messenger;
427427
PlatformHandler platform_handler(&messenger, engine());
@@ -435,7 +435,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataRequiresView) {
435435
}
436436

437437
TEST_F(PlatformHandlerTest, ClipboardSetDataReportsOpenFailure) {
438-
use_engine_with_view();
438+
UseEngineWithView();
439439

440440
TestBinaryMessenger messenger;
441441
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -455,7 +455,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataReportsOpenFailure) {
455455
}
456456

457457
TEST_F(PlatformHandlerTest, ClipboardSetDataReportsSetDataFailure) {
458-
use_engine_with_view();
458+
UseEngineWithView();
459459

460460
TestBinaryMessenger messenger;
461461
PlatformHandler platform_handler(&messenger, engine(), []() {
@@ -478,7 +478,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataReportsSetDataFailure) {
478478
}
479479

480480
TEST_F(PlatformHandlerTest, PlaySystemSound) {
481-
use_headless_engine();
481+
UseHeadlessEngine();
482482

483483
TestBinaryMessenger messenger;
484484
MockPlatformHandler platform_handler(&messenger, engine());
@@ -496,7 +496,7 @@ TEST_F(PlatformHandlerTest, PlaySystemSound) {
496496
}
497497

498498
TEST_F(PlatformHandlerTest, SystemExitApplicationRequired) {
499-
use_headless_engine();
499+
UseHeadlessEngine();
500500
UINT exit_code = 0;
501501

502502
TestBinaryMessenger messenger([](const std::string& channel,
@@ -518,7 +518,7 @@ TEST_F(PlatformHandlerTest, SystemExitApplicationRequired) {
518518
}
519519

520520
TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableCancel) {
521-
use_headless_engine();
521+
UseHeadlessEngine();
522522
bool called_cancel = false;
523523

524524
TestBinaryMessenger messenger(
@@ -539,7 +539,7 @@ TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableCancel) {
539539
}
540540

541541
TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableExit) {
542-
use_headless_engine();
542+
UseHeadlessEngine();
543543
bool called_cancel = false;
544544
UINT exit_code = 0;
545545

0 commit comments

Comments
 (0)