Flutter Engine
 
Loading...
Searching...
No Matches
flutter::TextInputPlugin Class Reference

#include <text_input_plugin.h>

Inheritance diagram for flutter::TextInputPlugin:
flutter::KeyboardHookHandler

Public Member Functions

 TextInputPlugin (flutter::BinaryMessenger *messenger)
 
virtual ~TextInputPlugin ()
 
void KeyboardHook (GLFWwindow *window, int key, int scancode, int action, int mods) override
 
void CharHook (GLFWwindow *window, unsigned int code_point) override
 
 TextInputPlugin (flutter::BinaryMessenger *messenger, FlutterWindowsEngine *engine)
 
virtual ~TextInputPlugin ()
 
virtual void KeyboardHook (int key, int scancode, int action, char32_t character, bool extended, bool was_down)
 
virtual void TextHook (const std::u16string &text)
 
virtual void ComposeBeginHook ()
 
virtual void ComposeCommitHook ()
 
virtual void ComposeEndHook ()
 
virtual void ComposeChangeHook (const std::u16string &text, int cursor_pos)
 
- Public Member Functions inherited from flutter::KeyboardHookHandler
virtual ~KeyboardHookHandler ()=default
 

Friends

class TextInputPluginModifier
 

Detailed Description

Definition at line 24 of file text_input_plugin.h.

Constructor & Destructor Documentation

◆ TextInputPlugin() [1/2]

flutter::TextInputPlugin::TextInputPlugin ( flutter::BinaryMessenger messenger)
explicit

Definition at line 99 of file text_input_plugin.cc.

100 : channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
101 messenger,
104 active_model_(nullptr) {
105 channel_->SetMethodCallHandler(
106 [this](
108 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
109 HandleMethodCall(call, std::move(result));
110 });
111}
static NSString *const kChannelName
static const JsonMethodCodec & GetInstance()

◆ ~TextInputPlugin() [1/2]

flutter::TextInputPlugin::~TextInputPlugin ( )
virtualdefault

◆ TextInputPlugin() [2/2]

flutter::TextInputPlugin::TextInputPlugin ( flutter::BinaryMessenger messenger,
FlutterWindowsEngine engine 
)

Definition at line 108 of file text_input_plugin.cc.

110 : channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
111 messenger,
114 engine_(engine),
115 active_model_(nullptr) {
116 channel_->SetMethodCallHandler(
117 [this](
119 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
120 HandleMethodCall(call, std::move(result));
121 });
122}
FlutterEngine engine
Definition main.cc:84

◆ ~TextInputPlugin() [2/2]

virtual flutter::TextInputPlugin::~TextInputPlugin ( )
virtual

Member Function Documentation

◆ CharHook()

void flutter::TextInputPlugin::CharHook ( GLFWwindow *  window,
unsigned int  code_point 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 44 of file text_input_plugin.cc.

44 {
45 if (active_model_ == nullptr) {
46 return;
47 }
48 active_model_->AddCodePoint(code_point);
49 SendStateUpdate(*active_model_);
50}

◆ ComposeBeginHook()

void flutter::TextInputPlugin::ComposeBeginHook ( )
virtual

Definition at line 126 of file text_input_plugin.cc.

126 {
127 if (active_model_ == nullptr) {
128 return;
129 }
130 active_model_->BeginComposing();
131 if (enable_delta_model) {
132 std::string text = active_model_->GetText();
133 TextRange selection = active_model_->selection();
134 TextEditingDelta delta = TextEditingDelta(text);
135 SendStateUpdateWithDelta(*active_model_, &delta);
136 } else {
137 SendStateUpdate(*active_model_);
138 }
139}
std::u16string text

References text.

◆ ComposeChangeHook()

void flutter::TextInputPlugin::ComposeChangeHook ( const std::u16string &  text,
int  cursor_pos 
)
virtual

Definition at line 193 of file text_input_plugin.cc.

194 {
195 if (active_model_ == nullptr) {
196 return;
197 }
198 std::string text_before_change = active_model_->GetText();
199 TextRange composing_before_change = active_model_->composing_range();
200 active_model_->AddText(text);
201 active_model_->UpdateComposingText(text, TextRange(cursor_pos, cursor_pos));
202 std::string text_after_change = active_model_->GetText();
203 if (enable_delta_model) {
204 TextEditingDelta delta = TextEditingDelta(
205 fml::Utf8ToUtf16(text_before_change), composing_before_change, text);
206 SendStateUpdateWithDelta(*active_model_, &delta);
207 } else {
208 SendStateUpdate(*active_model_);
209 }
210}
std::u16string Utf8ToUtf16(const std::string_view string)

References text, and fml::Utf8ToUtf16().

◆ ComposeCommitHook()

void flutter::TextInputPlugin::ComposeCommitHook ( )
virtual

Definition at line 141 of file text_input_plugin.cc.

141 {
142 if (active_model_ == nullptr) {
143 return;
144 }
145 std::string text_before_change = active_model_->GetText();
146 TextRange selection_before_change = active_model_->selection();
147 TextRange composing_before_change = active_model_->composing_range();
148 std::string composing_text_before_change = text_before_change.substr(
149 composing_before_change.start(), composing_before_change.length());
150 active_model_->CommitComposing();
151
152 // We do not trigger SendStateUpdate here.
153 //
154 // Until a WM_IME_ENDCOMPOSING event, the user is still composing from the OS
155 // point of view. Commit events are always immediately followed by another
156 // composing event or an end composing event. However, in the brief window
157 // between the commit event and the following event, the composing region is
158 // collapsed. Notifying the framework of this intermediate state will trigger
159 // any framework code designed to execute at the end of composing, such as
160 // input formatters, which may try to update the text and send a message back
161 // to the engine with changes.
162 //
163 // This is a particular problem with Korean IMEs, which build up one
164 // character at a time in their composing region until a keypress that makes
165 // no sense for the in-progress character. At that point, the result
166 // character is committed and a compose event is immedidately received with
167 // the new composing region.
168 //
169 // In the case where this event is immediately followed by a composing event,
170 // the state will be sent in ComposeChangeHook.
171 //
172 // In the case where this event is immediately followed by an end composing
173 // event, the state will be sent in ComposeEndHook.
174}

References flutter::TextRange::length(), and flutter::TextRange::start().

◆ ComposeEndHook()

void flutter::TextInputPlugin::ComposeEndHook ( )
virtual

Definition at line 176 of file text_input_plugin.cc.

176 {
177 if (active_model_ == nullptr) {
178 return;
179 }
180 std::string text_before_change = active_model_->GetText();
181 TextRange selection_before_change = active_model_->selection();
182 active_model_->CommitComposing();
183 active_model_->EndComposing();
184 if (enable_delta_model) {
185 std::string text = active_model_->GetText();
186 TextEditingDelta delta = TextEditingDelta(text);
187 SendStateUpdateWithDelta(*active_model_, &delta);
188 } else {
189 SendStateUpdate(*active_model_);
190 }
191}

References text.

◆ KeyboardHook() [1/2]

void flutter::TextInputPlugin::KeyboardHook ( GLFWwindow *  window,
int  key,
int  scancode,
int  action,
int  mods 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 52 of file text_input_plugin.cc.

56 {
57 if (active_model_ == nullptr) {
58 return;
59 }
60 if (action == GLFW_PRESS || action == GLFW_REPEAT) {
61 switch (key) {
62 case GLFW_KEY_LEFT:
63 if (active_model_->MoveCursorBack()) {
64 SendStateUpdate(*active_model_);
65 }
66 break;
67 case GLFW_KEY_RIGHT:
68 if (active_model_->MoveCursorForward()) {
69 SendStateUpdate(*active_model_);
70 }
71 break;
72 case GLFW_KEY_END:
73 active_model_->MoveCursorToEnd();
74 SendStateUpdate(*active_model_);
75 break;
76 case GLFW_KEY_HOME:
77 active_model_->MoveCursorToBeginning();
78 SendStateUpdate(*active_model_);
79 break;
80 case GLFW_KEY_BACKSPACE:
81 if (active_model_->Backspace()) {
82 SendStateUpdate(*active_model_);
83 }
84 break;
85 case GLFW_KEY_DELETE:
86 if (active_model_->Delete()) {
87 SendStateUpdate(*active_model_);
88 }
89 break;
90 case GLFW_KEY_ENTER:
91 EnterPressed(active_model_.get());
92 break;
93 default:
94 break;
95 }
96 }
97}

References action, and key.

◆ KeyboardHook() [2/2]

void flutter::TextInputPlugin::KeyboardHook ( int  key,
int  scancode,
int  action,
char32_t  character,
bool  extended,
bool  was_down 
)
virtual

Definition at line 86 of file text_input_plugin.cc.

91 {
92 if (active_model_ == nullptr) {
93 return;
94 }
95 if (action == WM_KEYDOWN || action == WM_SYSKEYDOWN) {
96 // Most editing keys (arrow keys, backspace, delete, etc.) are handled in
97 // the framework, so don't need to be handled at this layer.
98 switch (key) {
99 case VK_RETURN:
100 EnterPressed(active_model_.get());
101 break;
102 default:
103 break;
104 }
105 }
106}

References action, and key.

◆ TextHook()

void flutter::TextInputPlugin::TextHook ( const std::u16string &  text)
virtual

Definition at line 68 of file text_input_plugin.cc.

68 {
69 if (active_model_ == nullptr) {
70 return;
71 }
72 std::u16string text_before_change =
73 fml::Utf8ToUtf16(active_model_->GetText());
74 TextRange selection_before_change = active_model_->selection();
75 active_model_->AddText(text);
76
77 if (enable_delta_model) {
78 TextEditingDelta delta =
79 TextEditingDelta(text_before_change, selection_before_change, text);
80 SendStateUpdateWithDelta(*active_model_, &delta);
81 } else {
82 SendStateUpdate(*active_model_);
83 }
84}

References text, and fml::Utf8ToUtf16().

Friends And Related Symbol Documentation

◆ TextInputPluginModifier

friend class TextInputPluginModifier
friend

Definition at line 75 of file text_input_plugin.h.


The documentation for this class was generated from the following files: