efl_ui_widget: unify tree number settings code
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Mon, 23 Mar 2020 16:12:25 +0000 (12:12 -0400)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 23 Mar 2020 21:28:21 +0000 (06:28 +0900)
Summary:
the internals of those two methods have been the same. Both setted the
internal numeric flag as either as 1 more or equal to the flag in the
parent object (depending on the internal state). Further details can be
found in the comment in code.
Depends on D11554

Reviewers: zmike

Reviewed By: zmike

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D11555

src/lib/elementary/efl_ui_widget.c

index 29427f1bf7dd03a33c9e0434e3c8e79ba655157b..d6e57b51a224ee6d46ac83ab587b8fef59cb4b30 100644 (file)
@@ -2018,6 +2018,51 @@ _tree_unfocusable_counter_get(Eo *widget)
    return pd->tree_unfocusable;
 }
 
+/**
+ * Evalulate tree number.
+ *
+ * This is here to support properties which are propagating through the widget tree. If this property is set to true,
+ * every widget in the subtree, will also be automatically true.
+ * When one of the widgets in the subtree then seperatly will be set to true, the unsetting on the original widget will not unset the flag automatically in this tree.
+ *
+ * The basic idea here is:
+ * - The numeric number beeing bigger than 0, means that the property is true
+ * - The differnce between the number of the parent, and the number of the object, represents the boolean flag
+ *   (0 means that the flag is equal to the one of the parent, 1 means that if the parent is false, this child is true).
+ */
+static int
+_calculate_tree_number(int self_counter, int parent_counter, Eina_Bool flag)
+{
+   int distance = self_counter - parent_counter;
+
+   if (flag)
+     self_counter ++;
+   else
+     self_counter --;
+
+   distance = self_counter - parent_counter;
+
+   if ((distance < 0) || (distance > 1))
+     {
+        distance = MAX(MIN(flag, 1), 0);
+        self_counter = parent_counter + distance;
+     }
+
+   return self_counter;
+}
+
+static void
+_propagate_bool_property(Elm_Widget_Smart_Data *pd, Eina_Bool flag, void (*property_setting)(Eo *obj, Eina_Bool flag))
+{
+   Efl_Ui_Widget *subs;
+   for (unsigned int i = 0; i < eina_array_count(pd->children); ++i)
+     {
+        subs = eina_array_data_get(pd->children, i);
+        if (efl_isa(subs, EFL_UI_WIDGET_CLASS))
+          property_setting(subs, flag);
+     }
+}
+
 /**
  * @internal
  *
@@ -2037,34 +2082,20 @@ EAPI void
 elm_widget_tree_unfocusable_set(Eo *obj, Eina_Bool tree_unfocusable)
 {
    /* TIZEN_ONLY(20190821): keep legacy focus logic
-   Efl_Ui_Widget *subs;
    Elm_Widget_Smart_Data *pd = efl_data_scope_safe_get(obj, MY_CLASS);
    EINA_SAFETY_ON_NULL_RETURN(pd);
-   int old_tree_unfocusable, distance, parent_counter = (pd->parent_obj ? _tree_unfocusable_counter_get(pd->parent_obj) : 0);
+   int old_tree_unfocusable;
 
    old_tree_unfocusable = pd->tree_unfocusable;
 
-   if (tree_unfocusable)
-     pd->tree_unfocusable ++;
-   else
-     pd->tree_unfocusable --;
-
-   distance = pd->tree_unfocusable - parent_counter;
+   pd->tree_unfocusable = _calculate_tree_number(pd->tree_unfocusable,
+                                                (pd->parent_obj ? _tree_unfocusable_counter_get(pd->parent_obj) : 0),
+                                                tree_unfocusable);
 
-   if ((distance < 0) || (distance > 1))
-     {
-        distance = MAX(MIN(tree_unfocusable, 1), 0);
-        pd->tree_unfocusable = parent_counter + distance;
-     }
    if (old_tree_unfocusable != pd->tree_unfocusable)
      {
         _full_eval(obj, pd);
-        for (unsigned int i = 0; i < eina_array_count(pd->children); ++i)
-          {
-             subs = eina_array_data_get(pd->children, i);
-             if (efl_isa(subs, EFL_UI_WIDGET_CLASS))
-               elm_widget_tree_unfocusable_set(subs, elm_widget_tree_unfocusable_get(obj));
-          }
+        _propagate_bool_property(pd, elm_widget_tree_unfocusable_get(obj), elm_widget_tree_unfocusable_set);
      }
 
    */
@@ -2808,22 +2839,11 @@ EOLIAN static void
 _efl_ui_widget_disabled_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *pd, Eina_Bool disabled)
 {
    Efl_Ui_Widget *subs;
-   int old_state, distance, parent_counter = (pd->parent_obj ? _disabled_counter_get(pd->parent_obj) : 0);
+   int old_state;
 
    old_state = pd->disabled;
 
-   if (disabled)
-     pd->disabled ++;
-   else
-     pd->disabled --;
-
-   distance = pd->disabled - parent_counter;
-
-   if ((distance < 0) || (distance > 1))
-     {
-        distance = MAX(MIN(disabled, 1), 0);
-        pd->disabled = parent_counter + distance;
-     }
+   pd->disabled = _calculate_tree_number(pd->disabled, (pd->parent_obj ? _disabled_counter_get(pd->parent_obj) : 0), disabled);
    if (old_state != pd->disabled)
      {
         //TIZEN_ONLY(20191028): Restore focus revert in disabled_set