Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_text_input_handler.h File Reference

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

500 {
501 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), FALSE);
502
503 if (self->client_id == kClientIdUnset) {
504 return FALSE;
505 }
506
508 self->im_context,
509 reinterpret_cast<GdkEventKey*>(fl_key_event_get_origin(event)))) {
510 return TRUE;
511 }
512
513 std::string text_before_change = self->text_model->GetText();
514 flutter::TextRange selection_before_change = self->text_model->selection();
515 std::string text = self->text_model->GetText();
516
517 // Handle the enter/return key.
518 gboolean do_action = FALSE;
519 // Handle navigation keys.
520 gboolean changed = FALSE;
521 if (fl_key_event_get_is_press(event)) {
522 switch (fl_key_event_get_keyval(event)) {
523 case GDK_KEY_End:
524 case GDK_KEY_KP_End:
525 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
526 changed = self->text_model->SelectToEnd();
527 } else {
528 changed = self->text_model->MoveCursorToEnd();
529 }
530 break;
531 case GDK_KEY_Return:
532 case GDK_KEY_KP_Enter:
533 case GDK_KEY_ISO_Enter:
534 if (self->input_type == FL_TEXT_INPUT_TYPE_MULTILINE &&
535 strcmp(self->input_action, kNewlineInputAction) == 0) {
536 self->text_model->AddCodePoint('\n');
537 text = "\n";
538 changed = TRUE;
539 }
540 do_action = TRUE;
541 break;
542 case GDK_KEY_Home:
543 case GDK_KEY_KP_Home:
544 if (fl_key_event_get_state(event) & GDK_SHIFT_MASK) {
545 changed = self->text_model->SelectToBeginning();
546 } else {
547 changed = self->text_model->MoveCursorToBeginning();
548 }
549 break;
550 case GDK_KEY_BackSpace:
551 case GDK_KEY_Delete:
552 case GDK_KEY_KP_Delete:
553 case GDK_KEY_Left:
554 case GDK_KEY_KP_Left:
555 case GDK_KEY_Right:
556 case GDK_KEY_KP_Right:
557 // Already handled inside the framework in RenderEditable.
558 break;
559 }
560 }
561
562 if (changed) {
563 if (self->enable_delta_model) {
565 text_before_change, selection_before_change, text);
567 } else {
569 }
570 }
571 if (do_action) {
573 }
574
575 return changed;
576}
return TRUE
gboolean fl_key_event_get_is_press(FlKeyEvent *self)
GdkEvent * fl_key_event_get_origin(FlKeyEvent *self)
GdkModifierType fl_key_event_get_state(FlKeyEvent *self)
guint fl_key_event_get_keyval(FlKeyEvent *self)
@ FL_TEXT_INPUT_TYPE_MULTILINE
static void update_editing_state(FlTextInputHandler *self)
static void update_editing_state_with_delta(FlTextInputHandler *self, flutter::TextEditingDelta *delta)
static constexpr char kNewlineInputAction[]
static constexpr int64_t kClientIdUnset
static void perform_action(FlTextInputHandler *self)
std::u16string text
gboolean gtk_im_context_filter_keypress(GtkIMContext *context, GdkEventKey *event)
Definition mock_gtk.cc:332
A change in the state of an input field.

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, gtk_im_context_filter_keypress(), kClientIdUnset, kNewlineInputAction, perform_action(), self, text, 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 480 of file fl_text_input_handler.cc.

480 {
481 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
482 return self->im_context;
483}

References self.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

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

494 {
495 g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr);
496 return self->widget;
497}

References self.

Referenced by fl_view_dispose(), setup_keyboard(), and TEST_F().

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

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

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

Referenced by FlTextInputHandlerTest::SetUp(), and setup_keyboard().

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

486 {
487 g_return_if_fail(FL_IS_TEXT_INPUT_HANDLER(self));
488 self->widget = widget;
490 self->im_context,
491 widget != nullptr ? gtk_widget_get_window(widget) : nullptr);
492}
void gtk_im_context_set_client_window(GtkIMContext *context, GdkWindow *window)
Definition mock_gtk.cc:314
GdkWindow * gtk_widget_get_window(GtkWidget *widget)
Definition mock_gtk.cc:309

References gtk_im_context_set_client_window(), gtk_widget_get_window(), and self.

Referenced by fl_view_dispose(), fl_view_focus_in_event(), setup_keyboard(), TEST_F(), and TEST_F().

◆ G_DECLARE_FINAL_TYPE()

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