| Flutter Linux Embedder |

Functions
fl_text_input_handler.h File Reference
`#include <gtk/gtk.h>`
`#include "flutter/shell/platform/linux/fl_key_event.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"`

Go to the source code of this file.

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlTextInputHandler, fl_text_input_handler, FL, TEXT_INPUT_HANDLER, GObject)
FlTextInputHandler * | fl_text_input_handler_new (FlBinaryMessenger *messenger)
GtkIMContext * | fl_text_input_handler_get_im_context (FlTextInputHandler *handler)
void | fl_text_input_handler_set_widget (FlTextInputHandler *handler, GtkWidget *widget)
GtkWidget * | fl_text_input_handler_get_widget (FlTextInputHandler *handler)
gboolean | fl_text_input_handler_filter_keypress (FlTextInputHandler *handler, FlKeyEvent *event)

## Function Documentation

## ◆ 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 key event.

Returns: TRUE if the event was used.

Definition at line 477 of file fl_text_input_handler.cc.

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

## ◆ fl_text_input_handler_get_im_context()

GtkIMContext* fl_text_input_handler_get_im_context | ( | FlTextInputHandler * | handler | ) |

fl_text_input_handler_get_im_context: @handler: an #FlTextInputHandler.

Get the IM context that is being used. Provided for testing purposes.

Returns: a #GtkIMContext.

Definition at line 459 of file fl_text_input_handler.cc.

459 {
460 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
461 return self->im_context;
462 }

Referenced by TEST().

## ◆ fl_text_input_handler_get_widget()

GtkWidget* fl_text_input_handler_get_widget | ( | FlTextInputHandler * | handler | ) |

fl_text_input_handler_get_widget: @handler: an #FlTextInputHandler.

Get the widget that has input focus.

Returns: a #GtkWidget or NULL if none active.

Definition at line 472 of file fl_text_input_handler.cc.

472 {
473 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
474 return self->widget;
475 }

Referenced by setup_keyboard().

## ◆ fl_text_input_handler_new()

FlTextInputHandler* fl_text_input_handler_new | ( | FlBinaryMessenger * | messenger | ) |

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.

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

Returns: a new #FlTextInputHandler.

Definition at line 422 of file fl_text_input_handler.cc.

422 {
423 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
424
425 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(
426 g_object_new(fl_text_input_handler_get_type(), nullptr));
427
428 self->channel =
429 fl_text_input_channel_new(messenger, &text_input_vtable, self);
430
431 self->im_context = GTK_IM_CONTEXT(gtk_im_multicontext_new());
432
433 // On Wayland, this call sets up the input method so it can be enabled
434 // immediately when required. Without it, on-screen keyboard's don't come up
435 // the first time a text field is focused.
436 gtk_im_context_focus_out(self->im_context);
437
438 g_signal_connect_object(self->im_context, "preedit-start",
439 G_CALLBACK(im_preedit_start_cb), self,
440 G_CONNECT_SWAPPED);
441 g_signal_connect_object(self->im_context, "preedit-end",
442 G_CALLBACK(im_preedit_end_cb), self,
443 G_CONNECT_SWAPPED);
444 g_signal_connect_object(self->im_context, "preedit-changed",
445 G_CALLBACK(im_preedit_changed_cb), self,
446 G_CONNECT_SWAPPED);
447 g_signal_connect_object(self->im_context, "commit", G_CALLBACK(im_commit_cb),
448 self, G_CONNECT_SWAPPED);
449 g_signal_connect_object(self->im_context, "retrieve-surrounding",
450 G_CALLBACK(im_retrieve_surrounding_cb), self,
451 G_CONNECT_SWAPPED);
452 g_signal_connect_object(self->im_context, "delete-surrounding",
453 G_CALLBACK(im_delete_surrounding_cb), self,
454 G_CONNECT_SWAPPED);
455
456 return self;
457 }
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
im_delete_surrounding_cb
static gboolean im_delete_surrounding_cb(FlTextInputHandler *self, gint offset, gint n_chars)
Definition: fl_text_input_handler.cc:224
im_preedit_end_cb
static void im_preedit_end_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:203
im_retrieve_surrounding_cb
static gboolean im_retrieve_surrounding_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:215
im_preedit_start_cb
static void im_preedit_start_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:146
text_input_vtable
static FlTextInputChannelVTable text_input_vtable
Definition: fl_text_input_handler.cc:412
im_commit_cb
static void im_commit_cb(FlTextInputHandler *self, const gchar *text)
Definition: fl_text_input_handler.cc:178
im_preedit_changed_cb
static void im_preedit_changed_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:151

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

Referenced by setup_keyboard(), and TEST().

## ◆ fl_text_input_handler_set_widget()

void fl_text_input_handler_set_widget | ( | FlTextInputHandler * | handler,
|  | GtkWidget * | widget
| ) |  |

fl_text_input_handler_set_widget: @handler: an #FlTextInputHandler. @widget: the widget with keyboard focus.

Set the widget that has input focus.

Definition at line 464 of file fl_text_input_handler.cc.

465 {
466 g_return_if_fail(FL_IS_TEXT_INPUT_HANDLER(self));
467 self->widget = widget;
468 gtk_im_context_set_client_window(self->im_context,
469 gtk_widget_get_window(self->widget));
470 }

Referenced by fl_view_focus_in_event(), and setup_keyboard().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlTextInputHandler | ,
|  | fl_text_input_handler | ,
|  | FL | ,
|  | TEXT_INPUT_HANDLER | ,
|  | GObject |
| ) |  |