| Flutter Linux Embedder |

Classes | Functions | Variables
fl_text_input_handler.cc File Reference
`#include "flutter/shell/platform/linux/fl_text_input_handler.h"`
`#include <gtk/gtk.h>`
`#include "flutter/shell/platform/common/text_editing_delta.h"`
`#include "flutter/shell/platform/common/text_input_model.h"`
`#include "flutter/shell/platform/linux/fl_text_input_channel.h"`

Go to the source code of this file.

## Classes
struct | _FlTextInputHandler

## Functions
static void | update_editing_state_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | update_editing_state_with_deltas_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | update_editing_state (FlTextInputHandler *self)
static void | update_editing_state_with_delta (FlTextInputHandler *self, flutter::TextEditingDelta *delta)
static void | perform_action_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | perform_action (FlTextInputHandler *self)
static void | im_preedit_start_cb (FlTextInputHandler *self)
static void | im_preedit_changed_cb (FlTextInputHandler *self)
static void | im_commit_cb (FlTextInputHandler *self, const gchar *text)
static void | im_preedit_end_cb (FlTextInputHandler *self)
static gboolean | im_retrieve_surrounding_cb (FlTextInputHandler *self)
static gboolean | im_delete_surrounding_cb (FlTextInputHandler *self, gint offset, gint n_chars)
static void | set_client (int64_t client_id, const gchar *input_action, gboolean enable_delta_model, FlTextInputType input_type, gpointer user_data)
static void | hide (gpointer user_data)
static void | show (gpointer user_data)
static void | set_editing_state (const gchar *text, int64_t selection_base, int64_t selection_extent, int64_t composing_base, int64_t composing_extent, gpointer user_data)
static void | clear_client (gpointer user_data)
static void | update_im_cursor_position (FlTextInputHandler *self)
static void | set_editable_size_and_transform (double *transform, gpointer user_data)
static void | set_marked_text_rect (double x, double y, double width, double height, gpointer user_data)
static void | fl_text_input_handler_dispose (GObject *object)
static void | fl_text_input_handler_class_init (FlTextInputHandlerClass *klass)
static void | fl_text_input_handler_init (FlTextInputHandler *self)
static void | init_im_context (FlTextInputHandler *self, GtkIMContext *im_context)
FlTextInputHandler * | fl_text_input_handler_new (FlBinaryMessenger *messenger, GtkIMContext *im_context, FlTextInputViewDelegate *view_delegate)
gboolean | fl_text_input_handler_filter_keypress (FlTextInputHandler *self, FlKeyEvent *event)

## Variables
static constexpr char | kNewlineInputAction [] = "TextInputAction.newline"
static constexpr int64_t | kClientIdUnset = -1
static FlTextInputChannelVTable | text_input_vtable

## Function Documentation

## ◆ clear_client()

static void clear_client | ( | gpointer | user_data | ) |
| static

Definition at line 305 of file fl_text_input_handler.cc.

305 {
306 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
307 self->client_id = kClientIdUnset;
308 }
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
kClientIdUnset
static constexpr int64_t kClientIdUnset
Definition: fl_text_input_handler.cc:15

References kClientIdUnset, and user_data.

## ◆ fl_text_input_handler_class_init()

static void fl_text_input_handler_class_init | ( | FlTextInputHandlerClass * | klass | ) |
| static

Definition at line 405 of file fl_text_input_handler.cc.

405 {
406 G_OBJECT_CLASS(klass)->dispose = fl_text_input_handler_dispose;
407 }
fl_text_input_handler_dispose
static void fl_text_input_handler_dispose(GObject *object)
Definition: fl_text_input_handler.cc:386

References fl_text_input_handler_dispose().

## ◆ fl_text_input_handler_dispose()

static void fl_text_input_handler_dispose | ( | GObject * | object | ) |
| static

Definition at line 386 of file fl_text_input_handler.cc.

386 {
387 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(object);
388
389 g_cancellable_cancel(self->cancellable);
390
391 g_clear_object(&self->channel);
392 g_clear_pointer(&self->input_action, g_free);
393 g_clear_object(&self->im_context);
394 if (self->text_model != nullptr) {
395 delete self->text_model;
396 self->text_model = nullptr;
397 }
398 g_weak_ref_clear(&self->view_delegate);
399 g_clear_object(&self->cancellable);
400
401 G_OBJECT_CLASS(fl_text_input_handler_parent_class)->dispose(object);
402 }

Referenced by fl_text_input_handler_class_init().

## ◆ fl_text_input_handler_filter_keypress()

gboolean fl_text_input_handler_filter_keypress | ( | FlTextInputHandler * | handler,
|  | FlKeyEvent * | event
| ) |  |

fl_text_input_handler_filter_keypress @handler: an #FlTextInputHandler. @event: a #FlKeyEvent

Process a Gdk key event.

Returns: TRUE if the event was used.

Definition at line 476 of file fl_text_input_handler.cc.

477 {
478 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), FALSE);
479
480 if (self->client_id == kClientIdUnset) {
481 return FALSE;
482 }
483
484 if (gtk_im_context_filter_keypress(
485 self->im_context,
486 reinterpret_cast<GdkEventKey*>(fl_key_event_get_origin(event)))) {
487 return TRUE;
488 }
489
490 std::string text_before_change = self->text_model->GetText();
491 flutter::TextRange selection_before_change = self->text_model->selection();
492 std::string text = self->text_model->GetText();
493
494 // Handle the enter/return key.
495 gboolean do_action = FALSE;
496 // Handle navigation keys.
497 gboolean changed = FALSE;
498 if (fl_key_event_get_is_press(event)) {
499 switch (fl_key_event_get_keyval(event)) {
500 case GDK_KEY_End:
501 case GDK_KEY_KP_End:
502 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
503 changed = self->text_model->SelectToEnd();
504 } else {
505 changed = self->text_model->MoveCursorToEnd();
506 }
507 break;
508 case GDK_KEY_Return:
509 case GDK_KEY_KP_Enter:
510 case GDK_KEY_ISO_Enter:
511 if (self->input_type == FL_TEXT_INPUT_TYPE_MULTILINE &&
512 strcmp(self->input_action, kNewlineInputAction) == 0) {
513 self->text_model->AddCodePoint('\n');
514 text = "\n";
515 changed = TRUE;
516 }
517 do_action = TRUE;
518 break;
519 case GDK_KEY_Home:
520 case GDK_KEY_KP_Home:
521 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
522 changed = self->text_model->SelectToBeginning();
523 } else {
524 changed = self->text_model->MoveCursorToBeginning();
525 }
526 break;
527 case GDK_KEY_BackSpace:
528 case GDK_KEY_Delete:
529 case GDK_KEY_KP_Delete:
530 case GDK_KEY_Left:
531 case GDK_KEY_KP_Left:
532 case GDK_KEY_Right:
533 case GDK_KEY_KP_Right:
534 // Already handled inside the framework in RenderEditable.
535 break;
536 }
537 }
538
539 if (changed) {
540 if (self->enable_delta_model) {
541 flutter::TextEditingDelta delta = flutter::TextEditingDelta(
542 text_before_change, selection_before_change, text);
543 update_editing_state_with_delta(self, &delta);
544 } else {
545 update_editing_state(self);
546 }
547 }
548 if (do_action) {
549 perform_action(self);
550 }
551
552 return changed;
553 }
flutter::TextRange
Definition: text_range.h:19
fl_key_event_get_origin
GdkEvent * fl_key_event_get_origin(FlKeyEvent *self)
Definition: fl_key_event.cc:109
fl_key_event_get_is_press
gboolean fl_key_event_get_is_press(FlKeyEvent *self)
Definition: fl_key_event.cc:84
fl_key_event_get_state
GdkModifierType fl_key_event_get_state(FlKeyEvent *self)
Definition: fl_key_event.cc:99
fl_key_event_get_keyval
guint fl_key_event_get_keyval(FlKeyEvent *self)
Definition: fl_key_event.cc:94
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
FL_TEXT_INPUT_TYPE_MULTILINE
@ FL_TEXT_INPUT_TYPE_MULTILINE
Definition: fl_text_input_channel.h:17
update_editing_state
static void update_editing_state(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:88
update_editing_state_with_delta
static void update_editing_state_with_delta(FlTextInputHandler *self, flutter::TextEditingDelta *delta)
Definition: fl_text_input_handler.cc:104
kNewlineInputAction
static constexpr char kNewlineInputAction[]
Definition: fl_text_input_handler.cc:13
perform_action
static void perform_action(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:134
flutter::TextEditingDelta
A change in the state of an input field.
Definition: text_editing_delta.h:16

References fl_key_event_get_is_press(), fl_key_event_get_keyval(), fl_key_event_get_origin(), fl_key_event_get_state(), FL_TEXT_INPUT_TYPE_MULTILINE, kClientIdUnset, kNewlineInputAction, perform_action(), TRUE, update_editing_state(), and update_editing_state_with_delta().

Referenced by fl_view_keyboard_delegate_iface_init(), and send_key_event().

## ◆ fl_text_input_handler_init()

static void fl_text_input_handler_init | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 410 of file fl_text_input_handler.cc.

410 {
411 self->client_id = kClientIdUnset;
412 self->input_type = FL_TEXT_INPUT_TYPE_TEXT;
413 self->text_model = new flutter::TextInputModel();
414 self->cancellable = g_cancellable_new();
415 }
flutter::TextInputModel
Definition: text_input_model.h:18
FL_TEXT_INPUT_TYPE_TEXT
@ FL_TEXT_INPUT_TYPE_TEXT
Definition: fl_text_input_channel.h:15

References FL_TEXT_INPUT_TYPE_TEXT, and kClientIdUnset.

## ◆ fl_text_input_handler_new()

FlTextInputHandler* fl_text_input_handler_new | ( | FlBinaryMessenger * | messenger,
|  | GtkIMContext * | im_context,
|  | FlTextInputViewDelegate * | view_delegate
| ) |  |

FlTextInputHandler:

#FlTextInputHandler is a handler that implements the shell side of SystemChannels.textInput from the Flutter services library. fl_text_input_handler_new: @messenger: an #FlBinaryMessenger. @im_context: (allow-none): a #GtkIMContext. @view_delegate: an #FlTextInputViewDelegate.

Creates a new handler that implements SystemChannels.textInput from the Flutter services library.

Returns: a new #FlTextInputHandler.

Definition at line 455 of file fl_text_input_handler.cc.

458 {
459 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
460 g_return_val_if_fail(GTK_IS_IM_CONTEXT(im_context), nullptr);
461 g_return_val_if_fail(FL_IS_TEXT_INPUT_VIEW_DELEGATE(view_delegate), nullptr);
462
463 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(
464 g_object_new(fl_text_input_handler_get_type(), nullptr));
465
466 self->channel =
467 fl_text_input_channel_new(messenger, &text_input_vtable, self);
468
469 init_im_context(self, im_context);
470
471 g_weak_ref_init(&self->view_delegate, view_delegate);
472
473 return self;
474 }
fl_text_input_channel_new
FlTextInputChannel * fl_text_input_channel_new(FlBinaryMessenger *messenger, FlTextInputChannelVTable *vtable, gpointer user_data)
Definition: fl_text_input_channel.cc:245
init_im_context
static void init_im_context(FlTextInputHandler *self, GtkIMContext *im_context)
Definition: fl_text_input_handler.cc:417
text_input_vtable
static FlTextInputChannelVTable text_input_vtable
Definition: fl_text_input_handler.cc:445

References fl_text_input_channel_new(), init_im_context(), and text_input_vtable.

Referenced by init_keyboard(), and TEST().

## ◆ hide()

static void hide | ( | gpointer | user_data | ) |
| static

Definition at line 256 of file fl_text_input_handler.cc.

256 {
257 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
258
259 gtk_im_context_focus_out(self->im_context);
260 }

References user_data.

Referenced by show().

## ◆ im_commit_cb()

static void im_commit_cb | ( | FlTextInputHandler * | self,
|  | const gchar * | text
| ) |  |
| static

Definition at line 177 of file fl_text_input_handler.cc.

177 {
178 std::string text_before_change = self->text_model->GetText();
179 flutter::TextRange composing_before_change =
180 self->text_model->composing_range();
181 flutter::TextRange selection_before_change = self->text_model->selection();
182 gboolean was_composing = self->text_model->composing();
183
184 self->text_model->AddText(text);
185 if (self->text_model->composing()) {
186 self->text_model->CommitComposing();
187 }
188
189 if (self->enable_delta_model) {
190 flutter::TextRange replace_range =
191 was_composing ? composing_before_change : selection_before_change;
192 std::unique_ptr<flutter::TextEditingDelta> delta =
193 std::make_unique<flutter::TextEditingDelta>(text_before_change,
194 replace_range, text);
195 update_editing_state_with_delta(self, delta.get());
196 } else {
197 update_editing_state(self);
198 }
199 }

References update_editing_state(), and update_editing_state_with_delta().

Referenced by init_im_context().

## ◆ im_delete_surrounding_cb()

static gboolean im_delete_surrounding_cb | ( | FlTextInputHandler * | self,
|  | gint | offset,
|  | gint | n_chars
| ) |  |
| static

Definition at line 223 of file fl_text_input_handler.cc.

225 {
226 std::string text_before_change = self->text_model->GetText();
227 if (self->text_model->DeleteSurrounding(offset, n_chars)) {
228 if (self->enable_delta_model) {
229 flutter::TextEditingDelta delta = flutter::TextEditingDelta(
230 text_before_change, self->text_model->composing_range(),
231 self->text_model->GetText());
232 update_editing_state_with_delta(self, &delta);
233 } else {
234 update_editing_state(self);
235 }
236 }
237 return TRUE;
238 }

References TRUE, update_editing_state(), and update_editing_state_with_delta().

Referenced by init_im_context().

## ◆ im_preedit_changed_cb()

static void im_preedit_changed_cb | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 150 of file fl_text_input_handler.cc.

150 {
151 std::string text_before_change = self->text_model->GetText();
152 flutter::TextRange composing_before_change =
153 self->text_model->composing_range();
154 g_autofree gchar* buf = nullptr;
155 gint cursor_offset = 0;
156 gtk_im_context_get_preedit_string(self->im_context, &buf, nullptr,
157 &cursor_offset);
158 if (self->text_model->composing()) {
159 cursor_offset += self->text_model->composing_range().start();
160 } else {
161 cursor_offset += self->text_model->selection().start();
162 }
163 self->text_model->UpdateComposingText(buf);
164 self->text_model->SetSelection(flutter::TextRange(cursor_offset));
165
166 if (self->enable_delta_model) {
167 std::string text(buf);
168 flutter::TextEditingDelta delta = flutter::TextEditingDelta(
169 text_before_change, composing_before_change, text);
170 update_editing_state_with_delta(self, &delta);
171 } else {
172 update_editing_state(self);
173 }
174 }

References update_editing_state(), and update_editing_state_with_delta().

Referenced by init_im_context().

## ◆ im_preedit_end_cb()

static void im_preedit_end_cb | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 202 of file fl_text_input_handler.cc.

202 {
203 self->text_model->EndComposing();
204 if (self->enable_delta_model) {
205 flutter::TextEditingDelta delta =
206 flutter::TextEditingDelta(self->text_model->GetText());
207 update_editing_state_with_delta(self, &delta);
208 } else {
209 update_editing_state(self);
210 }
211 }

References update_editing_state(), and update_editing_state_with_delta().

Referenced by init_im_context().

## ◆ im_preedit_start_cb()

static void im_preedit_start_cb | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 145 of file fl_text_input_handler.cc.

145 {
146 self->text_model->BeginComposing();
147 }

Referenced by init_im_context().

## ◆ im_retrieve_surrounding_cb()

static gboolean im_retrieve_surrounding_cb | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 214 of file fl_text_input_handler.cc.

214 {
215 auto text = self->text_model->GetText();
216 size_t cursor_offset = self->text_model->GetCursorOffset();
217 gtk_im_context_set_surrounding(self->im_context, text.c_str(), -1,
218 cursor_offset);
219 return TRUE;
220 }

References TRUE.

Referenced by init_im_context().

## ◆ init_im_context()

static void init_im_context | ( | FlTextInputHandler * | self,
|  | GtkIMContext * | im_context
| ) |  |
| static

Definition at line 417 of file fl_text_input_handler.cc.

418 {
419 self->im_context = GTK_IM_CONTEXT(g_object_ref(im_context));
420
421 // On Wayland, this call sets up the input method so it can be enabled
422 // immediately when required. Without it, on-screen keyboard's don't come up
423 // the first time a text field is focused.
424 gtk_im_context_focus_out(self->im_context);
425
426 g_signal_connect_object(self->im_context, "preedit-start",
427 G_CALLBACK(im_preedit_start_cb), self,
428 G_CONNECT_SWAPPED);
429 g_signal_connect_object(self->im_context, "preedit-end",
430 G_CALLBACK(im_preedit_end_cb), self,
431 G_CONNECT_SWAPPED);
432 g_signal_connect_object(self->im_context, "preedit-changed",
433 G_CALLBACK(im_preedit_changed_cb), self,
434 G_CONNECT_SWAPPED);
435 g_signal_connect_object(self->im_context, "commit", G_CALLBACK(im_commit_cb),
436 self, G_CONNECT_SWAPPED);
437 g_signal_connect_object(self->im_context, "retrieve-surrounding",
438 G_CALLBACK(im_retrieve_surrounding_cb), self,
439 G_CONNECT_SWAPPED);
440 g_signal_connect_object(self->im_context, "delete-surrounding",
441 G_CALLBACK(im_delete_surrounding_cb), self,
442 G_CONNECT_SWAPPED);
443 }
im_delete_surrounding_cb
static gboolean im_delete_surrounding_cb(FlTextInputHandler *self, gint offset, gint n_chars)
Definition: fl_text_input_handler.cc:223
im_preedit_end_cb
static void im_preedit_end_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:202
im_retrieve_surrounding_cb
static gboolean im_retrieve_surrounding_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:214
im_preedit_start_cb
static void im_preedit_start_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:145
im_commit_cb
static void im_commit_cb(FlTextInputHandler *self, const gchar *text)
Definition: fl_text_input_handler.cc:177
im_preedit_changed_cb
static void im_preedit_changed_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:150

References im_commit_cb(), im_delete_surrounding_cb(), im_preedit_changed_cb(), im_preedit_end_cb(), im_preedit_start_cb(), and im_retrieve_surrounding_cb().

Referenced by fl_text_input_handler_new().

## ◆ perform_action()

static void perform_action | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 134 of file fl_text_input_handler.cc.

134 {
135 g_return_if_fail(FL_IS_TEXT_INPUT_HANDLER(self));
136 g_return_if_fail(self->client_id != 0);
137 g_return_if_fail(self->input_action != nullptr);
138
139 fl_text_input_channel_perform_action(self->channel, self->client_id,
140 self->input_action, self->cancellable,
141 perform_action_response_cb, self);
142 }
fl_text_input_channel_perform_action
void fl_text_input_channel_perform_action(FlTextInputChannel *self, int64_t client_id, const gchar *input_action, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_text_input_channel.cc:384
perform_action_response_cb
static void perform_action_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_text_input_handler.cc:122

References fl_text_input_channel_perform_action(), and perform_action_response_cb().

Referenced by fl_text_input_handler_filter_keypress().

## ◆ perform_action_response_cb()

static void perform_action_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 122 of file fl_text_input_handler.cc.

124 {
125 g_autoptr(GError) error = nullptr;
126 if (!fl_text_input_channel_perform_action_finish(object, result, &error)) {
127 if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
128 g_warning("Failed to perform action: %s", error->message);
129 }
130 }
131 }
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_text_input_channel_perform_action_finish
gboolean fl_text_input_channel_perform_action_finish(GObject *object, GAsyncResult *result, GError **error)
Definition: fl_text_input_channel.cc:400

References error, and fl_text_input_channel_perform_action_finish().

Referenced by perform_action().

## ◆ set_client()

static void set_client | ( | int64_t | client_id,
|  | const gchar * | input_action,
|  | gboolean | enable_delta_model,
|  | FlTextInputType | input_type,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 241 of file fl_text_input_handler.cc.

245 {
246 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
247
248 self->client_id = client_id;
249 g_free(self->input_action);
250 self->input_action = g_strdup(input_action);
251 self->enable_delta_model = enable_delta_model;
252 self->input_type = input_type;
253 }

References user_data.

## ◆ set_editable_size_and_transform()

static void set_editable_size_and_transform | ( | double * | transform,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 355 of file fl_text_input_handler.cc.

356 {
357 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
358
359 for (size_t i = 0; i < 16; i++) {
360 self->editabletext_transform[i / 4][i % 4] = transform[i];
361 }
362 update_im_cursor_position(self);
363 }
i
int i
Definition: fl_socket_accessible.cc:18
update_im_cursor_position
static void update_im_cursor_position(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:318

References i, update_im_cursor_position(), and user_data.

## ◆ set_editing_state()

static void set_editing_state | ( | const gchar * | text,
|  | int64_t | selection_base,
|  | int64_t | selection_extent,
|  | int64_t | composing_base,
|  | int64_t | composing_extent,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 275 of file fl_text_input_handler.cc.

280 {
281 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
282
283 self->text_model->SetText(text);
284
285 // Flutter uses -1/-1 for invalid; translate that to 0/0 for the model.
286 if (selection_base == -1 && selection_extent == -1) {
287 selection_base = selection_extent = 0;
288 }
289
290 self->text_model->SetText(text);
291 self->text_model->SetSelection(
292 flutter::TextRange(selection_base, selection_extent));
293
294 if (composing_base == -1 && composing_extent == -1) {
295 self->text_model->EndComposing();
296 } else {
297 size_t composing_start = std::min(composing_base, composing_extent);
298 size_t cursor_offset = selection_base - composing_start;
299 self->text_model->SetComposingRange(
300 flutter::TextRange(composing_base, composing_extent), cursor_offset);
301 }
302 }

References user_data.

## ◆ set_marked_text_rect()

static void set_marked_text_rect | ( | double | x,
|  | double | y,
|  | double | width,
|  | double | height,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 371 of file fl_text_input_handler.cc.

375 {
376 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
377
378 self->composing_rect.x = x;
379 self->composing_rect.y = y;
380 self->composing_rect.width = width;
381 self->composing_rect.height = height;
382 update_im_cursor_position(self);
383 }
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38

References height, update_im_cursor_position(), user_data, and width.

## ◆ show()

static void show | ( | gpointer | user_data | ) |
| static

Definition at line 263 of file fl_text_input_handler.cc.

263 {
264 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(user_data);
265
266 if (self->input_type == FL_TEXT_INPUT_TYPE_NONE) {
267 hide(user_data);
268 return;
269 }
270
271 gtk_im_context_focus_in(self->im_context);
272 }
FL_TEXT_INPUT_TYPE_NONE
@ FL_TEXT_INPUT_TYPE_NONE
Definition: fl_text_input_channel.h:19
hide
static void hide(gpointer user_data)
Definition: fl_text_input_handler.cc:256

References FL_TEXT_INPUT_TYPE_NONE, hide(), and user_data.

## ◆ update_editing_state()

static void update_editing_state | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 88 of file fl_text_input_handler.cc.

88 {
89 int composing_base = -1;
90 int composing_extent = -1;
91 if (!self->text_model->composing_range().collapsed()) {
92 composing_base = self->text_model->composing_range().base();
93 composing_extent = self->text_model->composing_range().extent();
94 }
95 flutter::TextRange selection = self->text_model->selection();
96 fl_text_input_channel_update_editing_state(
97 self->channel, self->client_id, self->text_model->GetText().c_str(),
98 selection.base(), selection.extent(), FL_TEXT_AFFINITY_DOWNSTREAM, FALSE,
99 composing_base, composing_extent, self->cancellable,
100 update_editing_state_response_cb, self);
101 }
flutter::TextRange::base
size_t base() const
Definition: text_range.h:30
flutter::TextRange::extent
size_t extent() const
Definition: text_range.h:36
fl_text_input_channel_update_editing_state
void fl_text_input_channel_update_editing_state(FlTextInputChannel *self, int64_t client_id, const gchar *text, int64_t selection_base, int64_t selection_extent, FlTextAffinity selection_affinity, gboolean selection_is_directional, int64_t composing_base, int64_t composing_extent, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_text_input_channel.cc:266
FL_TEXT_AFFINITY_DOWNSTREAM
@ FL_TEXT_AFFINITY_DOWNSTREAM
Definition: fl_text_input_channel.h:24
update_editing_state_response_cb
static void update_editing_state_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_text_input_handler.cc:60

References flutter::TextRange::base(), flutter::TextRange::extent(), FL_TEXT_AFFINITY_DOWNSTREAM, fl_text_input_channel_update_editing_state(), and update_editing_state_response_cb().

Referenced by fl_text_input_handler_filter_keypress(), im_commit_cb(), im_delete_surrounding_cb(), im_preedit_changed_cb(), and im_preedit_end_cb().

## ◆ update_editing_state_response_cb()

static void update_editing_state_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 60 of file fl_text_input_handler.cc.

62 {
63 g_autoptr(GError) error = nullptr;
64 if (!fl_text_input_channel_update_editing_state_finish(object, result,
65 &error)) {
66 if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
67 g_warning("Failed to update editing state: %s", error->message);
68 }
69 }
70 }
fl_text_input_channel_update_editing_state_finish
gboolean fl_text_input_channel_update_editing_state_finish(GObject *object, GAsyncResult *result, GError **error)
Definition: fl_text_input_channel.cc:306

References error, and fl_text_input_channel_update_editing_state_finish().

Referenced by update_editing_state().

## ◆ update_editing_state_with_delta()

static void update_editing_state_with_delta | ( | FlTextInputHandler * | self,
|  | flutter::TextEditingDelta * | delta
| ) |  |
| static

Definition at line 104 of file fl_text_input_handler.cc.

105 {
106 flutter::TextRange selection = self->text_model->selection();
107 int composing_base = -1;
108 int composing_extent = -1;
109 if (!self->text_model->composing_range().collapsed()) {
110 composing_base = self->text_model->composing_range().base();
111 composing_extent = self->text_model->composing_range().extent();
112 }
113 fl_text_input_channel_update_editing_state_with_deltas(
114 self->channel, self->client_id, delta->old_text().c_str(),
115 delta->delta_text().c_str(), delta->delta_start(), delta->delta_end(),
116 selection.base(), selection.extent(), FL_TEXT_AFFINITY_DOWNSTREAM, FALSE,
117 composing_base, composing_extent, self->cancellable,
118 update_editing_state_with_deltas_response_cb, self);
119 }
fl_text_input_channel_update_editing_state_with_deltas
void fl_text_input_channel_update_editing_state_with_deltas(FlTextInputChannel *self, int64_t client_id, const gchar *old_text, const gchar *delta_text, int64_t delta_start, int64_t delta_end, int64_t selection_base, int64_t selection_extent, FlTextAffinity selection_affinity, gboolean selection_is_directional, int64_t composing_base, int64_t composing_extent, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_text_input_channel.cc:317
update_editing_state_with_deltas_response_cb
static void update_editing_state_with_deltas_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_text_input_handler.cc:74
flutter::TextEditingDelta::delta_text
std::string delta_text() const
Definition: text_editing_delta.h:39
flutter::TextEditingDelta::delta_start
int delta_start() const
Get the delta_start_ value.
Definition: text_editing_delta.h:42
flutter::TextEditingDelta::delta_end
int delta_end() const
Get the delta_end_ value.
Definition: text_editing_delta.h:45
flutter::TextEditingDelta::old_text
std::string old_text() const
Definition: text_editing_delta.h:34

References flutter::TextRange::base(), flutter::TextEditingDelta::delta_end(), flutter::TextEditingDelta::delta_start(), flutter::TextEditingDelta::delta_text(), flutter::TextRange::extent(), FL_TEXT_AFFINITY_DOWNSTREAM, fl_text_input_channel_update_editing_state_with_deltas(), flutter::TextEditingDelta::old_text(), and update_editing_state_with_deltas_response_cb().

Referenced by fl_text_input_handler_filter_keypress(), im_commit_cb(), im_delete_surrounding_cb(), im_preedit_changed_cb(), and im_preedit_end_cb().

## ◆ update_editing_state_with_deltas_response_cb()

static void update_editing_state_with_deltas_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 74 of file fl_text_input_handler.cc.

76 {
77 g_autoptr(GError) error = nullptr;
78 if (!fl_text_input_channel_update_editing_state_with_deltas_finish(
79 object, result, &error)) {
80 if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
81 g_warning("Failed to update editing state with deltas: %s",
82 error->message);
83 }
84 }
85 }
fl_text_input_channel_update_editing_state_with_deltas_finish
gboolean fl_text_input_channel_update_editing_state_with_deltas_finish(GObject *object, GAsyncResult *result, GError **error)
Definition: fl_text_input_channel.cc:372

References error, and fl_text_input_channel_update_editing_state_with_deltas_finish().

Referenced by update_editing_state_with_delta().

## ◆ update_im_cursor_position()

static void update_im_cursor_position | ( | FlTextInputHandler * | self | ) |
| static

Definition at line 318 of file fl_text_input_handler.cc.

318 {
319 g_autoptr(FlTextInputViewDelegate) view_delegate =
320 FL_TEXT_INPUT_VIEW_DELEGATE(g_weak_ref_get(&self->view_delegate));
321 if (view_delegate == nullptr) {
322 return;
323 }
324
325 // Skip update if not composing to avoid setting to position 0.
326 if (!self->text_model->composing()) {
327 return;
328 }
329
330 // Transform the x, y positions of the cursor from local coordinates to
331 // Flutter view coordinates.
332 gint x = self->composing_rect.x * self->editabletext_transform[0][0] +
333 self->composing_rect.y * self->editabletext_transform[1][0] +
334 self->editabletext_transform[3][0] + self->composing_rect.width;
335 gint y = self->composing_rect.x * self->editabletext_transform[0][1] +
336 self->composing_rect.y * self->editabletext_transform[1][1] +
337 self->editabletext_transform[3][1] + self->composing_rect.height;
338
339 // Transform from Flutter view coordinates to GTK window coordinates.
340 GdkRectangle preedit_rect = {};
341 fl_text_input_view_delegate_translate_coordinates(
342 view_delegate, x, y, &preedit_rect.x, &preedit_rect.y);
343
344 // Set the cursor location in window coordinates so that GTK can position
345 // any system input method windows.
346 gtk_im_context_set_cursor_location(self->im_context, &preedit_rect);
347 }
fl_text_input_view_delegate_translate_coordinates
void fl_text_input_view_delegate_translate_coordinates(FlTextInputViewDelegate *self, gint view_x, gint view_y, gint *window_x, gint *window_y)
Definition: fl_text_input_view_delegate.cc:14

References fl_text_input_view_delegate_translate_coordinates().

Referenced by set_editable_size_and_transform(), and set_marked_text_rect().

## Variable Documentation

## ◆ kClientIdUnset

constexpr int64_t kClientIdUnset = -1
| static constexpr

Definition at line 15 of file fl_text_input_handler.cc.

Referenced by clear_client(), fl_text_input_handler_filter_keypress(), and fl_text_input_handler_init().

## ◆ kNewlineInputAction

constexpr char kNewlineInputAction[] = "TextInputAction.newline"
| static constexpr

Definition at line 13 of file fl_text_input_handler.cc.

Referenced by fl_text_input_handler_filter_keypress().

## ◆ text_input_vtable

FlTextInputChannelVTable text_input_vtable
| static

Initial value:
= {
.set_client = set_client,
.hide = hide,
.show = show,
.set_editing_state = set_editing_state,
.clear_client = clear_client,
.set_editable_size_and_transform = set_editable_size_and_transform,
.set_marked_text_rect = set_marked_text_rect,
}
show
static void show(gpointer user_data)
Definition: fl_text_input_handler.cc:263
set_marked_text_rect
static void set_marked_text_rect(double x, double y, double width, double height, gpointer user_data)
Definition: fl_text_input_handler.cc:371
clear_client
static void clear_client(gpointer user_data)
Definition: fl_text_input_handler.cc:305
set_editable_size_and_transform
static void set_editable_size_and_transform(double *transform, gpointer user_data)
Definition: fl_text_input_handler.cc:355
set_editing_state
static void set_editing_state(const gchar *text, int64_t selection_base, int64_t selection_extent, int64_t composing_base, int64_t composing_extent, gpointer user_data)
Definition: fl_text_input_handler.cc:275
set_client
static void set_client(int64_t client_id, const gchar *input_action, gboolean enable_delta_model, FlTextInputType input_type, gpointer user_data)
Definition: fl_text_input_handler.cc:241

Definition at line 445 of file fl_text_input_handler.cc.

Referenced by fl_text_input_handler_new().