Flutter Engine
fl_text_input_plugin.h File Reference
#include <gdk/gdk.h>
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"

Go to the source code of this file.

Functions

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (FlTextInputPlugin, fl_text_input_plugin, FL, TEXT_INPUT_PLUGIN, GObject)
 
FlTextInputPlugin * fl_text_input_plugin_new (FlBinaryMessenger *messenger, FlView *view)
 
gboolean fl_text_input_plugin_filter_keypress (FlTextInputPlugin *plugin, GdkEventKey *event)
 

Function Documentation

◆ fl_text_input_plugin_filter_keypress()

gboolean fl_text_input_plugin_filter_keypress ( FlTextInputPlugin *  plugin,
GdkEventKey *  event 
)

fl_text_input_plugin_filter_keypress : an #FlTextInputPlugin. : a #GdkEventKey

Process a Gdk key event.

Returns: TRUE if the event was used.

Definition at line 491 of file fl_text_input_plugin.cc.

References kClientIdUnset, perform_action(), TRUE, and update_editing_state().

Referenced by fl_view_key_press_event(), and fl_view_key_release_event().

492  {
493  g_return_val_if_fail(FL_IS_TEXT_INPUT_PLUGIN(self), FALSE);
494 
495  if (self->client_id == kClientIdUnset) {
496  return FALSE;
497  }
498 
499  if (gtk_im_context_filter_keypress(self->im_context, event)) {
500  return TRUE;
501  }
502 
503  // Handle the enter/return key.
504  gboolean do_action = FALSE;
505  // Handle navigation keys.
506  gboolean changed = FALSE;
507  if (event->type == GDK_KEY_PRESS) {
508  switch (event->keyval) {
509  case GDK_KEY_BackSpace:
510  changed = self->text_model->Backspace();
511  break;
512  case GDK_KEY_Delete:
513  case GDK_KEY_KP_Delete:
514  // Already handled inside Flutter.
515  break;
516  case GDK_KEY_End:
517  case GDK_KEY_KP_End:
518  changed = self->text_model->MoveCursorToEnd();
519  break;
520  case GDK_KEY_Return:
521  case GDK_KEY_KP_Enter:
522  case GDK_KEY_ISO_Enter:
523  if (self->input_multiline == TRUE) {
524  self->text_model->AddCodePoint('\n');
525  changed = TRUE;
526  }
527  do_action = TRUE;
528  break;
529  case GDK_KEY_Home:
530  case GDK_KEY_KP_Home:
531  changed = self->text_model->MoveCursorToBeginning();
532  break;
533  case GDK_KEY_Left:
534  case GDK_KEY_KP_Left:
535  // Already handled inside Flutter.
536  break;
537  case GDK_KEY_Right:
538  case GDK_KEY_KP_Right:
539  // Already handled inside Flutter.
540  break;
541  }
542  }
543 
544  if (changed) {
545  update_editing_state(self);
546  }
547  if (do_action) {
548  perform_action(self);
549  }
550 
551  return FALSE;
552 }
static void update_editing_state(FlTextInputPlugin *self)
static void perform_action(FlTextInputPlugin *self)
static constexpr int64_t kClientIdUnset
GdkEventButton * event
Definition: fl_view.cc:62
return TRUE
Definition: fl_view.cc:107

◆ fl_text_input_plugin_new()

FlTextInputPlugin* fl_text_input_plugin_new ( FlBinaryMessenger *  messenger,
FlView *  view 
)

FlTextInputPlugin:

#FlTextInputPlugin is a plugin that implements the shell side of SystemChannels.textInput from the Flutter services library. fl_text_input_plugin_new: : an #FlBinaryMessenger. : the #FlView with which the text input plugin is associated.

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

Returns: a new #FlTextInputPlugin.

Definition at line 473 of file fl_text_input_plugin.cc.

References fl_json_method_codec_new(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), kChannelName, method_call_cb(), _FlTextInputPlugin::view, and view_weak_notify_cb().

Referenced by fl_view_constructed().

474  {
475  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
476 
477  FlTextInputPlugin* self = FL_TEXT_INPUT_PLUGIN(
478  g_object_new(fl_text_input_plugin_get_type(), nullptr));
479 
480  g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
481  self->channel =
482  fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
484  nullptr);
485  self->view = view;
486  g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
487 
488  return self;
489 }
static void view_weak_notify_cb(gpointer user_data, GObject *object)
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
static constexpr char kChannelName[]
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)

◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE ( FlTextInputPlugin  ,
fl_text_input_plugin  ,
FL  ,
TEXT_INPUT_PLUGIN  ,
GObject   
)