| 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/fl_text_input_view_delegate.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 *im_context, FlTextInputViewDelegate *view_delegate)
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 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
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: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_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().

## ◆ G_DECLARE_FINAL_TYPE()

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