Flutter Windows Embedder
flutter::TextInputPlugin Class Reference

#include <text_input_plugin.h>

Public Member Functions

 TextInputPlugin (flutter::BinaryMessenger *messenger, TextInputPluginDelegate *delegate)
 
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,
TextInputPluginDelegate delegate 
)
explicit

Definition at line 106 of file text_input_plugin.cc.

108  : channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
109  messenger,
110  kChannelName,
112  delegate_(delegate),
113  active_model_(nullptr) {
114  channel_->SetMethodCallHandler(
115  [this](
117  std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
118  HandleMethodCall(call, std::move(result));
119  });
120 }

◆ ~TextInputPlugin()

flutter::TextInputPlugin::~TextInputPlugin ( )
virtualdefault

Member Function Documentation

◆ ComposeBeginHook()

void flutter::TextInputPlugin::ComposeBeginHook ( )
virtual

Definition at line 124 of file text_input_plugin.cc.

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

References text.

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

◆ ComposeChangeHook()

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

Definition at line 191 of file text_input_plugin.cc.

192  {
193  if (active_model_ == nullptr) {
194  return;
195  }
196  std::string text_before_change = active_model_->GetText();
197  TextRange composing_before_change = active_model_->composing_range();
198  active_model_->AddText(text);
199  cursor_pos += active_model_->composing_range().start();
200  active_model_->UpdateComposingText(text);
201  active_model_->SetSelection(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 }

References text.

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

◆ ComposeCommitHook()

void flutter::TextInputPlugin::ComposeCommitHook ( )
virtual

Definition at line 139 of file text_input_plugin.cc.

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

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

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

◆ ComposeEndHook()

void flutter::TextInputPlugin::ComposeEndHook ( )
virtual

Definition at line 174 of file text_input_plugin.cc.

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

References text.

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

◆ KeyboardHook()

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

Definition at line 84 of file text_input_plugin.cc.

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

References action, and key.

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

◆ TextHook()

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

Definition at line 66 of file text_input_plugin.cc.

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

References text.


The documentation for this class was generated from the following files:
flutter::MethodChannel
Definition: method_channel.h:33
flutter::JsonMethodCodec::GetInstance
static const JsonMethodCodec & GetInstance()
Definition: json_method_codec.cc:36
kChannelName
static constexpr char kChannelName[]
Definition: text_input_plugin.cc:56
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