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

Commit 993ce4d

Browse files
committed
[Windows] Begin decoupling text input plugin from the view
1 parent 145785a commit 993ce4d

File tree

7 files changed

+208
-83
lines changed

7 files changed

+208
-83
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5149,7 +5149,6 @@ ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.cc + ../../..
51495149
ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.h + ../../../flutter/LICENSE
51505150
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.cc + ../../../flutter/LICENSE
51515151
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.h + ../../../flutter/LICENSE
5152-
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h + ../../../flutter/LICENSE
51535152
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler.h + ../../../flutter/LICENSE
51545153
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h + ../../../flutter/LICENSE
51555154
ORIGIN: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc + ../../../flutter/LICENSE
@@ -7932,7 +7931,6 @@ FILE: ../../../flutter/shell/platform/windows/text_input_manager.cc
79327931
FILE: ../../../flutter/shell/platform/windows/text_input_manager.h
79337932
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc
79347933
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h
7935-
FILE: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h
79367934
FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h
79377935
FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
79387936
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc

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/text_input_plugin.cc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
// found in the LICENSE file.
44

55
#include "flutter/shell/platform/windows/text_input_plugin.h"
6-
#include "flutter/fml/string_conversion.h"
7-
#include "flutter/shell/platform/common/text_editing_delta.h"
8-
#include "flutter/shell/platform/windows/text_input_plugin_delegate.h"
96

107
#include <windows.h>
118

129
#include <cstdint>
1310

11+
#include "flutter/fml/string_conversion.h"
1412
#include "flutter/shell/platform/common/json_method_codec.h"
13+
#include "flutter/shell/platform/common/text_editing_delta.h"
14+
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
15+
#include "flutter/shell/platform/windows/flutter_windows_view.h"
1516

1617
static constexpr char kSetEditingStateMethod[] = "TextInput.setEditingState";
1718
static constexpr char kClearClientMethod[] = "TextInput.clearClient";
@@ -104,12 +105,12 @@ void TextInputPlugin::KeyboardHook(int key,
104105
}
105106

106107
TextInputPlugin::TextInputPlugin(flutter::BinaryMessenger* messenger,
107-
TextInputPluginDelegate* delegate)
108+
FlutterWindowsEngine* engine)
108109
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
109110
messenger,
110111
kChannelName,
111112
&flutter::JsonMethodCodec::GetInstance())),
112-
delegate_(delegate),
113+
engine_(engine),
113114
active_model_(nullptr) {
114115
channel_->SetMethodCallHandler(
115116
[this](
@@ -217,12 +218,18 @@ void TextInputPlugin::HandleMethodCall(
217218
if (method.compare(kShowMethod) == 0 || method.compare(kHideMethod) == 0) {
218219
// These methods are no-ops.
219220
} else if (method.compare(kClearClientMethod) == 0) {
221+
FlutterWindowsView* view = engine_->view();
222+
if (view == nullptr) {
223+
result->Error(kInternalConsistencyError,
224+
"Text input is not available in Windows headless mode");
225+
return;
226+
}
220227
if (active_model_ != nullptr && active_model_->composing()) {
221228
active_model_->CommitComposing();
222229
active_model_->EndComposing();
223230
SendStateUpdate(*active_model_);
224231
}
225-
delegate_->OnResetImeComposing();
232+
view->OnResetImeComposing();
226233
active_model_ = nullptr;
227234
} else if (method.compare(kSetClientMethod) == 0) {
228235
if (!method_call.arguments() || method_call.arguments()->IsNull()) {
@@ -321,6 +328,12 @@ void TextInputPlugin::HandleMethodCall(
321328
TextRange(composing_base, composing_extent), cursor_offset);
322329
}
323330
} else if (method.compare(kSetMarkedTextRect) == 0) {
331+
FlutterWindowsView* view = engine_->view();
332+
if (view == nullptr) {
333+
result->Error(kInternalConsistencyError,
334+
"Text input is not available in Windows headless mode");
335+
return;
336+
}
324337
if (!method_call.arguments() || method_call.arguments()->IsNull()) {
325338
result->Error(kBadArgumentError, "Method invoked without args");
326339
return;
@@ -342,8 +355,14 @@ void TextInputPlugin::HandleMethodCall(
342355
{width->value.GetDouble(), height->value.GetDouble()}};
343356

344357
Rect transformed_rect = GetCursorRect();
345-
delegate_->OnCursorRectUpdated(transformed_rect);
358+
view->OnCursorRectUpdated(transformed_rect);
346359
} else if (method.compare(kSetEditableSizeAndTransform) == 0) {
360+
FlutterWindowsView* view = engine_->view();
361+
if (view == nullptr) {
362+
result->Error(kInternalConsistencyError,
363+
"Text input is not available in Windows headless mode");
364+
return;
365+
}
347366
if (!method_call.arguments() || method_call.arguments()->IsNull()) {
348367
result->Error(kBadArgumentError, "Method invoked without args");
349368
return;
@@ -367,7 +386,7 @@ void TextInputPlugin::HandleMethodCall(
367386
++i;
368387
}
369388
Rect transformed_rect = GetCursorRect();
370-
delegate_->OnCursorRectUpdated(transformed_rect);
389+
view->OnCursorRectUpdated(transformed_rect);
371390
} else {
372391
result->NotImplemented();
373392
return;

shell/platform/windows/text_input_plugin.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,52 @@
2020

2121
namespace flutter {
2222

23-
class TextInputPluginDelegate;
23+
class FlutterWindowsEngine;
2424

2525
// Implements a text input plugin.
2626
//
2727
// Specifically handles window events within windows.
2828
class TextInputPlugin {
2929
public:
30-
explicit TextInputPlugin(flutter::BinaryMessenger* messenger,
31-
TextInputPluginDelegate* delegate);
30+
TextInputPlugin(flutter::BinaryMessenger* messenger,
31+
FlutterWindowsEngine* engine);
3232

3333
virtual ~TextInputPlugin();
3434

35+
// Called when the Flutter engine receives a raw keyboard message.
3536
virtual void KeyboardHook(int key,
3637
int scancode,
3738
int action,
3839
char32_t character,
3940
bool extended,
4041
bool was_down);
4142

43+
// Called when the Flutter engine receives a keyboard character.
4244
virtual void TextHook(const std::u16string& text);
4345

46+
// Called on an IME compose begin event.
47+
//
48+
// Triggered when the user begins editing composing text using a multi-step
49+
// input method such as in CJK text input.
4450
virtual void ComposeBeginHook();
4551

52+
// Called on an IME compose commit event.
53+
//
54+
// Triggered when the user commits the current composing text while using a
55+
// multi-step input method such as in CJK text input. Composing continues with
56+
// the next keypress.
4657
virtual void ComposeCommitHook();
4758

59+
// Called on an IME compose end event.
60+
//
61+
// Triggered when the user commits the composing text while using a multi-step
62+
// input method such as in CJK text input.
4863
virtual void ComposeEndHook();
4964

65+
// Called on an IME composing region change event.
66+
//
67+
// Triggered when the user edits the composing text while using a multi-step
68+
// input method such as in CJK text input.
5069
virtual void ComposeChangeHook(const std::u16string& text, int cursor_pos);
5170

5271
private:
@@ -72,8 +91,8 @@ class TextInputPlugin {
7291
// The MethodChannel used for communication with the Flutter engine.
7392
std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
7493

75-
// The associated |TextInputPluginDelegate|.
76-
TextInputPluginDelegate* delegate_;
94+
// The associated |FlutterWindowsEngine|.
95+
FlutterWindowsEngine* engine_;
7796

7897
// The active client id.
7998
int client_id_;
@@ -85,7 +104,7 @@ class TextInputPlugin {
85104
// as TextEditingDeltas or as one TextEditingValue.
86105
// For more information on the delta model, see:
87106
// https://master-api.flutter.dev/flutter/services/TextInputConfiguration/enableDeltaModel.html
88-
bool enable_delta_model;
107+
bool enable_delta_model = false;
89108

90109
// Keyboard type of the client. See available options:
91110
// https://api.flutter.dev/flutter/services/TextInputType-class.html

shell/platform/windows/text_input_plugin_delegate.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)