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 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
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) {
543 text_before_change, selection_before_change, text);
545 } else {
547 }
548 }
549 if (do_action) {
551 }
552
553 return changed;
554}
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:321
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 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}

References self.

Referenced by TEST(), TEST(), TEST(), TEST(), and 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}

References self.

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 =
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}
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:338

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 setup_keyboard(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), 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;
469 gtk_widget_get_window(self->widget));
470}
void gtk_im_context_set_client_window(GtkIMContext *context, GdkWindow *window)
Definition mock_gtk.cc:303
GdkWindow * gtk_widget_get_window(GtkWidget *widget)
Definition mock_gtk.cc:298

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

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   
)