Skip to content

Commit

Permalink
FlTextInputType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi authored and robert-ancell committed Jun 16, 2021
1 parent a07f7e3 commit df3aa14
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions shell/platform/linux/fl_text_input_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ static constexpr char kNoneInputType[] = "TextInputType.none";

static constexpr int64_t kClientIdUnset = -1;

typedef enum {
FL_TEXT_INPUT_TYPE_TEXT,
// Send newline when multi-line and enter is pressed.
FL_TEXT_INPUT_TYPE_MULTILINE,
// The input method is not shown at all.
FL_TEXT_INPUT_TYPE_NONE,
} FlTextInputType;

struct FlTextInputPluginPrivate {
GObject parent_instance;

Expand All @@ -56,11 +64,8 @@ struct FlTextInputPluginPrivate {
// Input action to perform when enter pressed.
gchar* input_action;

// Send newline when multi-line and enter is pressed.
gboolean input_multiline;

// The input method is not shown when the input type is "none".
gboolean input_none;
// The type of the input method.
FlTextInputType input_type;

// Input method.
GtkIMContext* im_context;
Expand Down Expand Up @@ -269,9 +274,8 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
priv->input_action = g_strdup(fl_value_get_string(input_action_value));
}

// Reset the input type flags, then set them only if appropriate.
priv->input_multiline = FALSE;
priv->input_none = FALSE;
// Reset the input type, then set only if appropriate.
priv->input_type = FL_TEXT_INPUT_TYPE_TEXT;
FlValue* input_type_value =
fl_value_lookup_string(config_value, kTextInputTypeKey);
if (fl_value_get_type(input_type_value) == FL_VALUE_TYPE_MAP) {
Expand All @@ -280,9 +284,9 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
if (fl_value_get_type(input_type_name) == FL_VALUE_TYPE_STRING) {
const gchar* input_type = fl_value_get_string(input_type_name);
if (g_strcmp0(input_type, kMultilineInputType) == 0) {
priv->input_multiline = TRUE;
priv->input_type = FL_TEXT_INPUT_TYPE_MULTILINE;
} else if (g_strcmp0(input_type, kNoneInputType) == 0) {
priv->input_none = TRUE;
priv->input_type = FL_TEXT_INPUT_TYPE_NONE;
}
}
}
Expand All @@ -303,7 +307,7 @@ static FlMethodResponse* hide(FlTextInputPlugin* self) {
static FlMethodResponse* show(FlTextInputPlugin* self) {
FlTextInputPluginPrivate* priv = static_cast<FlTextInputPluginPrivate*>(
fl_text_input_plugin_get_instance_private(self));
if (priv->input_none == TRUE) {
if (priv->input_type == FL_TEXT_INPUT_TYPE_NONE) {
return hide(self);
}

Expand Down Expand Up @@ -534,7 +538,7 @@ static gboolean fl_text_input_plugin_filter_keypress_default(
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
case GDK_KEY_ISO_Enter:
if (priv->input_multiline == TRUE) {
if (priv->input_type == FL_TEXT_INPUT_TYPE_MULTILINE) {
priv->text_model->AddCodePoint('\n');
changed = TRUE;
}
Expand Down Expand Up @@ -584,8 +588,7 @@ static void fl_text_input_plugin_init(FlTextInputPlugin* self) {

priv->client_id = kClientIdUnset;
priv->im_context = gtk_im_multicontext_new();
priv->input_multiline = FALSE;
priv->input_none = FALSE;
priv->input_type = FL_TEXT_INPUT_TYPE_TEXT;
g_signal_connect_object(priv->im_context, "preedit-start",
G_CALLBACK(im_preedit_start_cb), self,
G_CONNECT_SWAPPED);
Expand Down

0 comments on commit df3aa14

Please sign in to comment.