Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
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
 
virtual void KeyboardHook (GLFWwindow *window, int key, int scancode, int action, int mods)=0
 
virtual void CharHook (GLFWwindow *window, unsigned int code_point)=0
 

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](
109 HandleMethodCall(call, std::move(result));
110 });
111}
static const JsonMethodCodec & GetInstance()
GAsyncResult * result
static constexpr char kChannelName[]
def call(args)
Definition: dom.py:159

◆ ~TextInputPlugin() [1/2]

flutter::TextInputPlugin::~TextInputPlugin ( )
virtualdefault

◆ TextInputPlugin() [2/2]

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

Definition at line 107 of file text_input_plugin.cc.

109 : channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
110 messenger,
113 engine_(engine),
114 active_model_(nullptr) {
115 channel_->SetMethodCallHandler(
116 [this](
119 HandleMethodCall(call, std::move(result));
120 });
121}
FlutterEngine engine
Definition: main.cc:68
static constexpr char kChannelName[]

◆ ~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 125 of file text_input_plugin.cc.

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

◆ ComposeChangeHook()

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

Definition at line 192 of file text_input_plugin.cc.

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

◆ ComposeCommitHook()

void flutter::TextInputPlugin::ComposeCommitHook ( )
virtual

Definition at line 140 of file text_input_plugin.cc.

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

◆ ComposeEndHook()

void flutter::TextInputPlugin::ComposeEndHook ( )
virtual

Definition at line 175 of file text_input_plugin.cc.

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

◆ 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}

◆ 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 85 of file text_input_plugin.cc.

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

◆ TextHook()

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

Definition at line 67 of file text_input_plugin.cc.

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

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