elm_focus: added new focus move policy and elm_object_focus_move_policy_set/get 34/48234/3
authorWooHyun Jung <wh0705.jung@samsung.com>
Tue, 2 Jun 2015 04:42:00 +0000 (13:42 +0900)
committerJaehwan Kim <jae.hwan.kim@samsung.com>
Wed, 16 Sep 2015 13:54:08 +0000 (06:54 -0700)
New focus move policy, ELM_FOCUS_MOVE_POLICY_KEY_ONLY, is added.
If you set this policy as base focus move policy, objects cannot steal
focus by using mouse click or mouse in. Only keyboard input (such as Left,
Right, Up, Down, ...) can make focus be moved.
Additaionally, an object can have its own focus move policy by using
elm_object_focus_move_policy_set API.

@feature

Change-Id: Iaa64ce2e92b2a376d000907e2986873fa542e655
origin: upstream

src/bin/Makefile.am
src/bin/test.c
src/lib/elm_config.h
src/lib/elm_focus.h
src/lib/elm_main.c
src/lib/elm_widget.c
src/lib/elm_widget.eo
src/lib/elm_widget.h

index 73c7df394aeaf6a1caa504bfaa8fe81442447019..473218973b1e00e2f85c50ff715120ac80af7f6a 100644 (file)
@@ -64,6 +64,7 @@ test_flipselector.c \
 test_floating.c \
 test_focus.c \
 test_focus_custom_chain.c \
+test_focus_policy.c \
 test_focus_style.c \
 test_gengrid.c \
 test_genlist.c \
index d03b1845a3785b82d4e1466d40c4b426c8c9bbf8..692914ddb873567d25ea0c1b8938e674da9d8622 100644 (file)
@@ -204,6 +204,7 @@ void test_focus_style(void *data, Evas_Object *obj, void *event_info);
 void test_focus_part(void *data, Evas_Object *obj, void *event_info);
 void test_focus3(void *data, Evas_Object *obj, void *event_info);
 void test_focus_object_style(void *data, Evas_Object *obj, void *event_info);
+void test_focus_object_policy(void *data, Evas_Object *obj, void *event_info);
 void test_flipselector(void *data, Evas_Object *obj, void *event_info);
 void test_diskselector(void *data, Evas_Object *obj, void *event_info);
 void test_colorselector(void *data, Evas_Object *obj, void *event_info);
@@ -796,6 +797,7 @@ add_tests:
    ADD_TEST(NULL, "Focus", "Focus On Part", test_focus_part);
    ADD_TEST(NULL, "Focus", "Focus 3", test_focus3);
    ADD_TEST(NULL, "Focus", "Focus Object Style", test_focus_object_style);
+   ADD_TEST(NULL, "Focus", "Focus Object Policy", test_focus_object_policy);
 
    //------------------------------//
    ADD_TEST(NULL, "Naviframe", "Naviframe", test_naviframe);
index 322e62143b996852aece6b6b427dd9db26196383..ad91710ac856409e46435855ccecca15afa1f409 100644 (file)
@@ -1406,7 +1406,8 @@ EAPI void elm_config_focus_highlight_clip_disabled_set(Eina_Bool disable);
 typedef enum
 {
    ELM_FOCUS_MOVE_POLICY_CLICK, /**< move focus by mouse click or touch. Elementary focus is set on mouse click and this is checked at mouse up time. (default) */
-   ELM_FOCUS_MOVE_POLICY_IN /**< move focus by mouse in. Elementary focus is set on mouse move when the mouse pointer is moved into an object. */
+   ELM_FOCUS_MOVE_POLICY_IN, /**< move focus by mouse in. Elementary focus is set on mouse move when the mouse pointer is moved into an object. */
+   ELM_FOCUS_MOVE_POLICY_KEY_ONLY /**< move focus by key. Elementary focus is set on key input like Left, Right, Up, Down, Tab, or Shift+Tab.*/
 } Elm_Focus_Move_Policy;
 
 /**
index 3aad5e94c64b8ce931e4c8937d6574065494214d..29883f784f518fb753b6e14c6be8602c3b3f9ba0 100644 (file)
@@ -335,3 +335,39 @@ EAPI const char  *elm_object_focus_highlight_style_get(const Evas_Object *obj);
  * @since 1.10
  */
 EAPI Elm_Object_Item             *elm_object_focused_item_get(const Evas_Object *obj);
+
+/**
+ * Set the focus movement policy to a given Elementary object.
+ *
+ * @param obj The Elementary object to operate on
+ * @param policy A policy to apply for the focus movement
+ *
+ * @see elm_object_focus_move_policy_get
+ *
+ * @since 1.15
+ *
+ * @ingroup Focus
+ */
+EAPI void                 elm_object_focus_move_policy_set(Evas_Object *obj, Elm_Focus_Move_Policy policy);
+
+/**
+ * Get the focus movement policy from a given Elementary objet.
+ *
+ * @param obj The Elementary widget to get the information from
+ * @return The focus movement policy
+ *
+ * Get how the focus is moved to the give Elemenray object. It can be
+ * #ELM_FOCUS_MOVE_POLICY_CLICK, #ELM_FOCUS_MOVE_POLICY_IN,
+ * or #ELM_FOCUS_MOVE_POLICY_KEY_ONLY.
+ * The first means elementary focus is moved on elementary object click.
+ * The second means elementary focus is moved on elementary object mouse in.
+ * The last means elementary focus is moved only by key input like Left,
+ * Right, Up, Down, Tab, or Shift+Tab.
+ *
+ * @see elm_object_focus_move_policy_set
+ *
+ * @since 1.15
+ *
+ * @ingroup Focus
+ */
+EAPI Elm_Focus_Move_Policy  elm_object_focus_move_policy_get(Evas_Object *obj);
index 4bb135e6f5abde1c383a181801a08333779d0098..30e0286f8b8f56d86c87dbe4a308c93bc716956c 100644 (file)
@@ -1484,6 +1484,21 @@ elm_object_tree_focus_allow_get(const Evas_Object *obj)
    return !elm_widget_tree_unfocusable_get(obj);
 }
 
+EAPI void
+elm_object_focus_move_policy_set(Evas_Object *obj,
+                                 Elm_Focus_Move_Policy policy)
+{
+   EINA_SAFETY_ON_NULL_RETURN(obj);
+   elm_widget_focus_move_policy_set(obj, policy);
+}
+
+EAPI Elm_Focus_Move_Policy
+elm_object_focus_move_policy_get(Evas_Object *obj)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
+   return elm_widget_focus_move_policy_get(obj);
+}
+
 EAPI void
 elm_object_scroll_hold_push(Evas_Object *obj)
 {
index 3ad7e667bfb1fa98862c3f54fc2a64170b435bee..9dd9390b6c07e621e53fd87b6032531a4766812d 100644 (file)
@@ -352,19 +352,20 @@ _obj_mouse_up(void *data,
 {
    ELM_WIDGET_DATA_GET(data, sd);
    if (sd->still_in &&
-       (_elm_config->focus_move_policy == ELM_FOCUS_MOVE_POLICY_CLICK))
+       (sd->focus_move_policy == ELM_FOCUS_MOVE_POLICY_CLICK))
      elm_widget_focus_mouse_up_handle(obj);
 
    sd->still_in = EINA_FALSE;
 }
 
 static void
-_obj_mouse_in(void *data EINA_UNUSED,
+_obj_mouse_in(void *data,
               Evas *e EINA_UNUSED,
               Evas_Object *obj,
               void *event_info EINA_UNUSED)
 {
-   if (_elm_config->focus_move_policy == ELM_FOCUS_MOVE_POLICY_IN)
+   ELM_WIDGET_DATA_GET(data, sd);
+   if (sd->focus_move_policy == ELM_FOCUS_MOVE_POLICY_IN)
      elm_widget_focus_mouse_up_handle(obj);
 }
 
@@ -377,6 +378,7 @@ _elm_widget_evas_object_smart_add(Eo *obj, Elm_Widget_Smart_Data *priv)
                                           * settings */
    elm_widget_can_focus_set(obj, EINA_TRUE);
    priv->is_mirrored = elm_config_mirrored_get();
+   priv->focus_move_policy = _elm_config->focus_move_policy;
 
    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
                                   _obj_mouse_down, obj);
@@ -4104,6 +4106,36 @@ _elm_widget_orientation_set(Eo *obj, Elm_Widget_Smart_Data *sd, int orient_mode)
      }
 }
 
+/**
+ * @internal
+ *
+ * Returns the widget's focus move policy.
+ *
+ * @param obj The widget.
+ * @return focus move policy of the object.
+ *
+ **/
+EOLIAN static Elm_Focus_Move_Policy
+_elm_widget_focus_move_policy_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
+{
+   return sd->focus_move_policy;
+}
+
+/**
+ * @internal
+ *
+ * Sets the widget's focus move policy.
+ *
+ * @param obj The widget.
+ * @param policy Elm_Focus_Momve_Policy to set object's focus move policy.
+ */
+
+EOLIAN static void
+_elm_widget_focus_move_policy_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Focus_Move_Policy policy)
+{
+   if (sd->focus_move_policy == policy) return;
+   sd->focus_move_policy = policy;
+}
 static void
 _track_obj_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
 
index 53e3c4fd8cfb0eb3ce311eea8e11fcff42929c34..cf40e1b31287639589b5c5a89ffab29c3cef46cf 100644 (file)
@@ -434,6 +434,17 @@ abstract Elm_Widget (Evas.Object_Smart, Elm_Interface_Atspi_Accessible, Elm_Inte
             const(char)* label;
          }
       }
+      focus_move_policy {
+         set {
+            /*@ No description supplied by the EAPI. */
+         }
+         get {
+            /*@ No description supplied by the EAPI. */
+         }
+         values {
+            Elm_Focus_Move_Policy policy;
+         }
+      }
    }
    methods {
       newest_focus_order_get @const {
index 84c3442d086b099f8338dc3cbefa0639ddd1fac1..e118af4a1431324a4fead8c168941c887fc3a2e0 100644 (file)
@@ -419,6 +419,7 @@ typedef struct _Elm_Widget_Smart_Data
                                                  Evas_Object *obj);
 
    int                           orient_mode; /* -1 is disabled */
+   Elm_Focus_Move_Policy         focus_move_policy;
 
    Eina_Bool                     drag_x_locked : 1;
    Eina_Bool                     drag_y_locked : 1;
@@ -774,6 +775,8 @@ EAPI void             elm_widget_orientation_mode_disabled_set(Evas_Object *obj,
 EAPI Eina_Bool        elm_widget_orientation_mode_disabled_get(const Evas_Object *obj);
 EAPI void             elm_widget_focus_highlight_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
 void                  _elm_widget_item_highlight_in_theme(Evas_Object *obj, Elm_Object_Item *it);
+EAPI void             elm_widget_focus_move_policy_set(Evas_Object *obj, Elm_Focus_Move_Policy policy);
+EAPI Elm_Focus_Move_Policy elm_widget_focus_move_policy_get(const Evas_Object *obj);
 
 /**
  * Function to operate on a given widget's scrollabe children when necessary.