efl.ui.textbox: add and use keyboard bindings
authorAli Alzyod <ali198724@gmail.com>
Sun, 2 Feb 2020 14:07:45 +0000 (14:07 +0000)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 11 Feb 2020 21:58:27 +0000 (06:58 +0900)
As other widgets, efl.ui.textbox will use keyboard bindings instead of listen to keyboard events

Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de>
Differential Revision: https://phab.enlightenment.org/D11236

data/elementary/config/default/base.src.in
data/elementary/config/mobile/base.src.in
data/elementary/config/standard/base.src.in
src/lib/elementary/efl_ui_textbox.c
src/lib/elementary/efl_ui_textbox.eo
src/lib/elementary/elm_config.c
src/lib/elementary/elm_priv.h

index f5c8ed8..fe886e7 100644 (file)
@@ -1,5 +1,5 @@
 group "Elm_Config" struct {
-  value "config_version" int: 131094;
+  value "config_version" int: 131095;
   value "entry_select_allow" uchar: 1;
   value "engine" string: "";
   value "vsync" uchar: 0;
@@ -3460,7 +3460,54 @@ group "Elm_Config" struct {
               value "action" string: "move";
               value "params" string: "next";
            }
-      }
-    }
+       }
+     }
+     group "Elm_Config_Bindings_Widget" struct {
+        value "name" string: "Efl.Ui.Textbox";
+        group "key_bindings" list {
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "c";
+              value "action" string: "copy";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "x";
+              value "action" string: "cut";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "v";
+              value "action" string: "paste";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "menu";
+              value "action" string: "menu";
+              value "params" string: "";
+           }
+        }
+     }
   }
 }
index 1797404..9770143 100644 (file)
@@ -1,5 +1,5 @@
 group "Elm_Config" struct {
-  value "config_version" int: 131094;
+  value "config_version" int: 131095;
   value "entry_select_allow" uchar: 1;
   value "engine" string: "";
   value "vsync" uchar: 0;
@@ -3446,7 +3446,54 @@ group "Elm_Config" struct {
               value "action" string: "move";
               value "params" string: "next";
            }
-      }
-    }
+       }
+     }
+     group "Elm_Config_Bindings_Widget" struct {
+        value "name" string: "Efl.Ui.Textbox";
+        group "key_bindings" list {
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "c";
+              value "action" string: "copy";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "x";
+              value "action" string: "cut";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "v";
+              value "action" string: "paste";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "menu";
+              value "action" string: "menu";
+              value "params" string: "";
+           }
+        }
+     }
   }
 }
index f0194d2..0d55e29 100644 (file)
@@ -1,5 +1,5 @@
 group "Elm_Config" struct {
-  value "config_version" int: 131094;
+  value "config_version" int: 131095;
   value "entry_select_allow" uchar: 1;
   value "engine" string: "";
   value "vsync" uchar: 0;
@@ -3443,7 +3443,54 @@ group "Elm_Config" struct {
               value "action" string: "move";
               value "params" string: "next";
            }
-      }
-    }
+       }
+     }
+     group "Elm_Config_Bindings_Widget" struct {
+        value "name" string: "Efl.Ui.Textbox";
+        group "key_bindings" list {
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "c";
+              value "action" string: "copy";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "x";
+              value "action" string: "cut";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "v";
+              value "action" string: "paste";
+              value "params" string: "";
+              group "modifiers" list {
+                 group "Elm_Config_Binding_Modifier" struct {
+                    value "mod" string: "Control";
+                    value "flag" uchar: 1;
+                 }
+              }
+           }
+           group "Elm_Config_Binding_Key" struct {
+              value "context" int: 0;
+              value "key" string: "menu";
+              value "action" string: "menu";
+              value "params" string: "";
+           }
+        }
+     }
   }
 }
index 3fdac1d..19727dd 100644 (file)
@@ -210,6 +210,19 @@ static Eina_Position2D _decoration_calc_offset(Efl_Ui_Textbox_Data *sd);
 static void _update_text_theme(Eo *obj, Efl_Ui_Textbox_Data *sd);
 static void _efl_ui_textbox_selection_paste_type(Eo *obj, Efl_Ui_Selection_Type type);
 
+static Eina_Bool _key_action_copy(Evas_Object *obj, const char *params);
+static Eina_Bool _key_action_paste(Evas_Object *obj, const char *params);
+static Eina_Bool _key_action_cut(Evas_Object *obj, const char *params);
+static Eina_Bool _key_action_menu(Evas_Object *obj, const char *params);
+
+static const Elm_Action key_actions[] = {
+   {"copy", _key_action_copy},
+   {"paste", _key_action_paste},
+   {"cut", _key_action_cut},
+   {"menu", _key_action_menu},
+   {NULL, NULL}
+};
+
 static void
 _efl_ui_textbox_guide_update(Evas_Object *obj,
                         Eina_Bool has_text)
@@ -1050,49 +1063,38 @@ _long_press_cb(void *data, const Efl_Event *ev EINA_UNUSED)
    sd->long_pressed = EINA_TRUE;
 }
 
-static void
-_key_down_cb(void *data, const Efl_Event *event)
+
+static Eina_Bool
+_key_action_copy(Evas_Object *obj, const char *params EINA_UNUSED)
 {
-   Efl_Input_Key_Data *ev = efl_data_scope_get(event->info, EFL_INPUT_KEY_CLASS);
-   Eina_Bool on_hold = EINA_FALSE;
+   efl_ui_textbox_selection_copy(obj);
+   return EINA_TRUE;
+}
 
-   /* First check if context menu disabled is false or not, and
-    * then check for key id */
-   if ((!_elm_config->context_menu_disabled) && !strcmp(ev->key, "Menu"))
-     {
-        _menu_call(data);
-        on_hold = EINA_TRUE;
-     }
-   else
-     {
-#if defined(__APPLE__) && defined(__MACH__)
-        Eina_Bool control = evas_key_modifier_is_set(ev->modifiers, "Super");
-#else
-        Eina_Bool control = evas_key_modifier_is_set(ev->modifiers, "Control");
-#endif
+static Eina_Bool
+_key_action_cut(Evas_Object *obj, const char *params EINA_UNUSED)
+{
+   efl_ui_textbox_selection_cut(obj);
+   return EINA_TRUE;
+}
 
-        /* Ctrl operations */
-        if (control)
-          {
-             if (!strncmp(ev->key, "c", 1))
-               {
-                  efl_ui_textbox_selection_copy(data);
-                  on_hold = EINA_TRUE;
-               }
-             else if (!strncmp(ev->key, "x", 1))
-               {
-                  efl_ui_textbox_selection_cut(data);
-                  on_hold = EINA_TRUE;
-               }
-             else if (!strncmp(ev->key, "v", 1))
-               {
-                  efl_ui_textbox_selection_paste(data);
-                  on_hold = EINA_TRUE;
-               }
-          }
-     }
+static Eina_Bool
+_key_action_paste(Evas_Object *obj, const char *params EINA_UNUSED)
+{
+   efl_ui_textbox_selection_paste(obj);
+   return EINA_TRUE;
+}
 
-   if (on_hold) ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+static Eina_Bool
+_key_action_menu(Evas_Object *obj, const char *params EINA_UNUSED)
+{
+   Eina_Bool b_ret = EINA_FALSE;
+   if (!_elm_config->context_menu_disabled)
+     {
+        _menu_call(obj);
+        b_ret = EINA_TRUE;
+     }
+   return b_ret;
 }
 
 static void
@@ -1699,8 +1701,6 @@ _efl_ui_textbox_efl_object_finalize(Eo *obj,
          _efl_ui_textbox_move_cb, obj);
 
    efl_event_callback_add
-     (sd->entry_edje, EFL_EVENT_KEY_DOWN, _key_down_cb, obj);
-   efl_event_callback_add
      (sd->entry_edje, EFL_EVENT_POINTER_DOWN, _mouse_down_cb, obj);
    efl_event_callback_add
      (sd->entry_edje, EFL_EVENT_POINTER_UP, _mouse_up_cb, obj);
@@ -3348,6 +3348,10 @@ _part_is_efl_ui_textbox_part(const Eo *obj EINA_UNUSED, const char *part)
    return EINA_FALSE;
 }
 
+/* Standard widget overrides */
+
+ELM_WIDGET_KEY_DOWN_DEFAULT_IMPLEMENT(efl_ui_textbox, Efl_Ui_Textbox_Data)
+
 ELM_PART_OVERRIDE_PARTIAL(efl_ui_textbox, EFL_UI_TEXTBOX, Efl_Ui_Textbox_Data, _part_is_efl_ui_textbox_part)
 ELM_PART_OVERRIDE_TEXT_SET(efl_ui_textbox, EFL_UI_TEXTBOX, Efl_Ui_Textbox_Data)
 ELM_PART_OVERRIDE_TEXT_GET(efl_ui_textbox, EFL_UI_TEXTBOX, Efl_Ui_Textbox_Data)
index c52f7c6..da38f89 100644 (file)
@@ -92,6 +92,7 @@ class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Click
       Efl.Canvas.Group.group_calculate;
       Efl.Ui.Widget.on_access_activate;
       Efl.Ui.Widget.theme_apply;
+      Efl.Ui.Widget.widget_input_event_handler;
       Efl.Ui.Focus.Object.on_focus_update;
       Efl.Ui.Widget.interest_region { get; }
       Efl.Ui.Widget.disabled {set;}
index 97a87ab..9ccbe24 100644 (file)
@@ -3166,6 +3166,12 @@ _config_update(void)
    tcfg = _config_system_load();
    IFCFGEND
 
+   IFCFG(0x0017)
+   _elm_key_bindings_copy_missing_bindings_of_widget(_elm_config, tcfg, "Efl.Ui.Textbox");
+   /* after this function call, the tcfg is partly invalidated, reload! */
+   _config_free(tcfg);
+   tcfg = _config_system_load();
+   IFCFGEND
    /**
     * Fix user config for current ELM_CONFIG_EPOCH here.
     **/
index 8965cc0..7a62034 100644 (file)
@@ -280,7 +280,7 @@ struct _Efl_Ui_Theme_Data
  * the users config doesn't need to be wiped - simply new values need
  * to be put in
  */
-# define ELM_CONFIG_FILE_GENERATION 0x0016
+# define ELM_CONFIG_FILE_GENERATION 0x0017
 # define ELM_CONFIG_VERSION_EPOCH_OFFSET 16
 # define ELM_CONFIG_VERSION         ((ELM_CONFIG_EPOCH << ELM_CONFIG_VERSION_EPOCH_OFFSET) | \
                                      ELM_CONFIG_FILE_GENERATION)