efl_ui_focus_manager_calc: performe the second stage later
authorMarcel Hollerbach <marcel@osg.samsung.com>
Sun, 10 Dec 2017 20:03:17 +0000 (21:03 +0100)
committerMarcel Hollerbach <marcel@osg.samsung.com>
Mon, 11 Dec 2017 09:46:52 +0000 (10:46 +0100)
the second stage is not meant to be a transition in both ways, only
because the one item is closer does not mean a other one is closer.

src/lib/elementary/efl_ui_focus_manager_calc.c

index 8e0490c..8f771da 100644 (file)
@@ -305,13 +305,18 @@ _min_max_gen(Dimension dim, Eina_Rect rect, int *min, int *max)
 }
 
 static inline void
-_calculate_node_stage1(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *node, Eina_Rect rect, Dimension dim, Eina_List **pos, Eina_List **neg)
+_calculate_node(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *node, Dimension dim, Eina_List **pos, Eina_List **neg)
 {
    int dim_min, dim_max, cur_pos_min = 0, cur_neg_min = 0;
    Efl_Ui_Focus_Object *op;
    Eina_Iterator *nodes;
+   Eina_Rect rect;
    Node *n;
 
+   *pos = NULL;
+   *neg = NULL;
+
+   rect = efl_ui_focus_object_focus_geometry_get(node);
    nodes = eina_hash_iterator_data_new(pd->node_hash);
    _min_max_gen(dim, rect, &dim_min, &dim_max);
 
@@ -431,13 +436,15 @@ _direction_to_outside(Efl_Ui_Focus_Direction direction)
 }
 
 static inline void
-_calculate_node_stage2(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *node, Eina_Rect rect, Efl_Ui_Focus_Direction direction, Eina_List **lst)
+_calculate_node_indirection(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *node, Efl_Ui_Focus_Direction direction, Eina_List **lst)
 {
    Efl_Ui_Focus_Object *op;
    Eina_Iterator *nodes;
    int min_distance = 0;
    Node *n;
+   Eina_Rect rect;
 
+   rect = efl_ui_focus_object_focus_geometry_get(node);
    nodes = eina_hash_iterator_data_new(pd->node_hash);
 
    EINA_ITERATOR_FOREACH(nodes, n)
@@ -476,39 +483,6 @@ _calculate_node_stage2(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *
      }
 }
 
-static inline void
-_calculate_node(Efl_Ui_Focus_Manager_Calc_Data *pd, Efl_Ui_Focus_Object *node, Dimension dim, Eina_List **pos, Eina_List **neg)
-{
-   Eina_Rect rect;
-   Efl_Ui_Focus_Direction direction;
-
-   rect = efl_ui_focus_object_focus_geometry_get(node);
-
-   *pos = NULL;
-   *neg = NULL;
-
-   _calculate_node_stage1(pd, node, rect, dim, pos, neg);
-
-  if (!*pos)
-    {
-       if (dim == DIMENSION_Y)
-         direction = EFL_UI_FOCUS_DIRECTION_DOWN;
-       else
-         direction = EFL_UI_FOCUS_DIRECTION_RIGHT;
-       _calculate_node_stage2(pd, node, rect, direction, pos);
-    }
-
-  if (!*neg)
-    {
-       if (dim == DIMENSION_Y)
-         direction = EFL_UI_FOCUS_DIRECTION_UP;
-       else
-         direction = EFL_UI_FOCUS_DIRECTION_LEFT;
-
-     _calculate_node_stage2(pd, node, rect, direction, neg);
-     }
-}
-
 #ifdef CALC_DEBUG
 static void
 _debug_node(Node *node)
@@ -576,6 +550,33 @@ dirty_flush_node(Efl_Ui_Focus_Manager *obj EINA_UNUSED, Efl_Ui_Focus_Manager_Cal
    convert_border_set(obj, pd, node, y_partners_neg, EFL_UI_FOCUS_DIRECTION_UP);
    convert_border_set(obj, pd, node, y_partners_pos, EFL_UI_FOCUS_DIRECTION_DOWN);
 
+   /*
+    * Stage 2: if there is still no relation in a special direction,
+    *          just take every single node that is in the given direction
+    *          and take the one with the shortest direction
+    */
+   for(int i = EFL_UI_FOCUS_DIRECTION_UP; i < EFL_UI_FOCUS_DIRECTION_LAST; i++)
+     {
+        if (!DIRECTION_ACCESS(node, i).partners)
+          {
+             Eina_List *tmp = NULL;
+             Efl_Ui_Focus_Object *focusable;
+
+             _calculate_node_indirection(pd, node->focusable, i, &tmp);
+
+             EINA_LIST_FREE(tmp, focusable)
+               {
+                  Border *b;
+                  Node *n;
+
+                  b = &DIRECTION_ACCESS(node, i);
+                  n = node_get(obj, pd, focusable);
+                  b->partners = eina_list_append(b->partners, n);
+               }
+
+          }
+     }
+
 #ifdef CALC_DEBUG
    _debug_node(node);
 #endif