Flutter Windows Embedder
flutter::TextInputPlugin Class Reference

#include <text_input_plugin.h>

Public Member Functions

 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)
 

Detailed Description

Definition at line 28 of file text_input_plugin.h.

Constructor & Destructor Documentation

◆ TextInputPlugin()

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,
111  kChannelName,
113  engine_(engine),
114  active_model_(nullptr) {
115  channel_->SetMethodCallHandler(
116  [this](
118  std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
119  HandleMethodCall(call, std::move(result));
120  });
121 }

◆ ~TextInputPlugin()

flutter::TextInputPlugin::~TextInputPlugin ( )
virtualdefault

Member Function Documentation

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

References text.

Referenced by flutter::testing::TEST_F().

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

References text.

Referenced by flutter::testing::TEST_F().

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

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

Referenced by flutter::testing::TEST_F().

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

References text.

Referenced by flutter::testing::TEST_F().

◆ KeyboardHook()

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 }

References action, and key.

Referenced by flutter::testing::TEST_F().

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

References text.


The documentation for this class was generated from the following files:
flutter::MethodChannel
Definition: method_channel.h:34
flutter::JsonMethodCodec::GetInstance
static const JsonMethodCodec & GetInstance()
Definition: json_method_codec.cc:36
kChannelName
static constexpr char kChannelName[]
Definition: text_input_plugin.cc:57
text
std::u16string text
Definition: keyboard_unittests.cc:332
flutter::MethodCall
Definition: method_call.h:18
flutter::MethodResult
Definition: method_result.h:17
action
int action
Definition: keyboard_key_handler_unittests.cc:116
key
int key
Definition: keyboard_key_handler_unittests.cc:114