| 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 492 of file fl_text_input_handler.cc.

493 {
494 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), FALSE);
495
496 if (self->client_id == kClientIdUnset) {
497 return FALSE;
498 }
499
500 if (gtk_im_context_filter_keypress(
501 self->im_context,
502 reinterpret_cast<GdkEventKey*>(fl_key_event_get_origin(event)))) {
503 return TRUE;
504 }
505
506 std::string text_before_change = self->text_model->GetText();
507 flutter::TextRange selection_before_change = self->text_model->selection();
508 std::string text = self->text_model->GetText();
509
510 // Handle the enter/return key.
511 gboolean do_action = FALSE;
512 // Handle navigation keys.
513 gboolean changed = FALSE;
514 if (fl_key_event_get_is_press(event)) {
515 switch (fl_key_event_get_keyval(event)) {
516 case GDK_KEY_End:
517 case GDK_KEY_KP_End:
518 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
519 changed = self->text_model->SelectToEnd();
520 } else {
521 changed = self->text_model->MoveCursorToEnd();
522 }
523 break;
524 case GDK_KEY_Return:
525 case GDK_KEY_KP_Enter:
526 case GDK_KEY_ISO_Enter:
527 if (self->input_type == FL_TEXT_INPUT_TYPE_MULTILINE &&
528 strcmp(self->input_action, kNewlineInputAction) == 0) {
529 self->text_model->AddCodePoint('\n');
530 text = "\n";
531 changed = TRUE;
532 }
533 do_action = TRUE;
534 break;
535 case GDK_KEY_Home:
536 case GDK_KEY_KP_Home:
537 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
538 changed = self->text_model->SelectToBeginning();
539 } else {
540 changed = self->text_model->MoveCursorToBeginning();
541 }
542 break;
543 case GDK_KEY_BackSpace:
544 case GDK_KEY_Delete:
545 case GDK_KEY_KP_Delete:
546 case GDK_KEY_Left:
547 case GDK_KEY_KP_Left:
548 case GDK_KEY_Right:
549 case GDK_KEY_KP_Right:
550 // Already handled inside the framework in RenderEditable.
551 break;
552 }
553 }
554
555 if (changed) {
556 if (self->enable_delta_model) {
557 flutter::TextEditingDelta delta = flutter::TextEditingDelta(
558 text_before_change, selection_before_change, text);
559 update_editing_state_with_delta(self, &delta);
560 } else {
561 update_editing_state(self);
562 }
563 }
564 if (do_action) {
565 perform_action(self);
566 }
567
568 return changed;
569 }
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:91
update_editing_state_with_delta
static void update_editing_state_with_delta(FlTextInputHandler *self, flutter::TextEditingDelta *delta)
Definition: fl_text_input_handler.cc:107
kNewlineInputAction
static constexpr char kNewlineInputAction[]
Definition: fl_text_input_handler.cc:13
kClientIdUnset
static constexpr int64_t kClientIdUnset
Definition: fl_text_input_handler.cc:17
perform_action
static void perform_action(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:137
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 474 of file fl_text_input_handler.cc.

474 {
475 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
476 return self->im_context;
477 }

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 487 of file fl_text_input_handler.cc.

487 {
488 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
489 return self->widget;
490 }

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 437 of file fl_text_input_handler.cc.

437 {
438 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
439
440 FlTextInputHandler* self = FL_TEXT_INPUT_HANDLER(
441 g_object_new(fl_text_input_handler_get_type(), nullptr));
442
443 self->channel =
444 fl_text_input_channel_new(messenger, &text_input_vtable, self);
445
446 self->im_context = GTK_IM_CONTEXT(gtk_im_multicontext_new());
447
448 // On Wayland, this call sets up the input method so it can be enabled
449 // immediately when required. Without it, on-screen keyboard's don't come up
450 // the first time a text field is focused.
451 gtk_im_context_focus_out(self->im_context);
452
453 g_signal_connect_object(self->im_context, "preedit-start",
454 G_CALLBACK(im_preedit_start_cb), self,
455 G_CONNECT_SWAPPED);
456 g_signal_connect_object(self->im_context, "preedit-end",
457 G_CALLBACK(im_preedit_end_cb), self,
458 G_CONNECT_SWAPPED);
459 g_signal_connect_object(self->im_context, "preedit-changed",
460 G_CALLBACK(im_preedit_changed_cb), self,
461 G_CONNECT_SWAPPED);
462 g_signal_connect_object(self->im_context, "commit", G_CALLBACK(im_commit_cb),
463 self, G_CONNECT_SWAPPED);
464 g_signal_connect_object(self->im_context, "retrieve-surrounding",
465 G_CALLBACK(im_retrieve_surrounding_cb), self,
466 G_CONNECT_SWAPPED);
467 g_signal_connect_object(self->im_context, "delete-surrounding",
468 G_CALLBACK(im_delete_surrounding_cb), self,
469 G_CONNECT_SWAPPED);
470
471 return self;
472 }
fl_text_input_channel_new
FlTextInputChannel * fl_text_input_channel_new(FlBinaryMessenger *messenger, FlTextInputChannelVTable *vtable, gpointer user_data)
Definition: fl_text_input_channel.cc:313
im_delete_surrounding_cb
static gboolean im_delete_surrounding_cb(FlTextInputHandler *self, gint offset, gint n_chars)
Definition: fl_text_input_handler.cc:226
im_preedit_end_cb
static void im_preedit_end_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:205
im_retrieve_surrounding_cb
static gboolean im_retrieve_surrounding_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:217
im_preedit_start_cb
static void im_preedit_start_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:148
text_input_vtable
static FlTextInputChannelVTable text_input_vtable
Definition: fl_text_input_handler.cc:426
im_commit_cb
static void im_commit_cb(FlTextInputHandler *self, const gchar *text)
Definition: fl_text_input_handler.cc:180
im_preedit_changed_cb
static void im_preedit_changed_cb(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:153

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 479 of file fl_text_input_handler.cc.

480 {
481 g_return_if_fail(FL_IS_TEXT_INPUT_HANDLER(self));
482 self->widget = widget;
483 gtk_im_context_set_client_window(self->im_context,
484 gtk_widget_get_window(self->widget));
485 }

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 |
| ) |  |