Reading order handling updated with new feature.
authorTomasz Olszak <t.olszak@samsung.com>
Mon, 6 Jul 2015 14:27:46 +0000 (16:27 +0200)
committerTomasz Olszak <t.olszak@samsung.com>
Mon, 6 Jul 2015 14:27:46 +0000 (16:27 +0200)
If item has reading order >= INT_MAX/2 then it will be placed in reading
chain AFTER items with default (0) reading order.
Items with reading order > 0 and < INT_MAX/2 will behave the same so they
will still have higher priority than 0 (will be read before default ones).

Change-Id: I67e2e36f22574885a0b8bf3cde9e4ce53076652e
Signed-off-by: Tomasz Olszak <t.olszak@samsung.com>
src/position_sort.c

index cb9e7f1..5b0fdc1 100644 (file)
@@ -64,54 +64,41 @@ _sort_horizontally(const void *a, const void *b)
 static int
 _sort_index(const void *a, const void *b)
 {
-   AtspiAccessible *objA, *objB;
    int ia, ib;
 
-   objA = (AtspiAccessible*)a;
-   objB = (AtspiAccessible*)b;
-
-   DEBUG("objA:%s objB:%s", atspi_accessible_get_name(objA, NULL), atspi_accessible_get_name(objB, NULL));
-
-   AtspiComponent *comp1;
-   AtspiComponent *comp2;
-   comp1 = atspi_accessible_get_component_iface(objA);
-   comp2 = atspi_accessible_get_component_iface(objB);
+   AtspiComponent *comp1 = atspi_accessible_get_component_iface((AtspiAccessible*)a);
+   AtspiComponent *comp2 = atspi_accessible_get_component_iface((AtspiAccessible*)b);
 
    ia = atspi_component_get_highlight_index(comp1, NULL);
    ib = atspi_component_get_highlight_index(comp2, NULL);
+   g_object_unref(comp1);
+   g_object_unref(comp2);
 
-   DEBUG("ia:%d ib:%d", ia, ib);
-
-   if (ia == ib)
-      return 0;
-   else if (ia > ib)
-      return 1;
-   else
-      return -1;
+   return ia == ib ? 0 : ia > ib ? 1 : -1;
 }
 
-static Eina_List*
-_get_rest(const Eina_List *objs)
+static void
+_get_priorities(const Eina_List *objs, Eina_List **priority, Eina_List **candidates, Eina_List **priority_after)
 {
-   Eina_List *candidates = NULL;
    const Eina_List *l;
    AtspiAccessible *obj;
    AtspiComponent *comp;
-   int index = 0;
 
    EINA_LIST_FOREACH(objs, l, obj)
    {
       if ((comp = atspi_accessible_get_component_iface(obj)) != NULL)
          {
-            index = atspi_component_get_highlight_index(comp, NULL);
+            int index = atspi_component_get_highlight_index(comp, NULL);
+            g_clear_object(&comp);
             if (index == 0)
-               candidates = eina_list_append(candidates, obj);
-            else if (index < 0)
-               {
-                  DEBUG("Element [%s] [%s] has negative highlight index, will be skipped",
-                        atspi_accessible_get_name(obj, NULL),
-                        atspi_accessible_get_role_name(obj, NULL));
-               }
+               *candidates = eina_list_append(*candidates, obj);
+            else if (index > 0)
+              {
+                 if (index < INT_MAX/2)
+                    *priority = eina_list_append(*priority, obj);
+                 else
+                    *priority_after = eina_list_append(*priority_after, obj);
+              }
          }
       else
          DEBUG("No component interface: skipping %s %s",
@@ -119,31 +106,8 @@ _get_rest(const Eina_List *objs)
                atspi_accessible_get_role_name(obj, NULL));
    }
 
-   return candidates;
-}
-
-static Eina_List*
-_get_priorities(const Eina_List *objs)
-{
-   Eina_List *candidates = NULL;
-   const Eina_List *l;
-   AtspiAccessible *obj;
-   AtspiComponent *comp;
-
-   EINA_LIST_FOREACH(objs, l, obj)
-   {
-      if ((comp = atspi_accessible_get_component_iface(obj)) != NULL)
-         {
-            if (atspi_component_get_highlight_index(comp, NULL) > 0)
-               candidates = eina_list_append(candidates, obj);
-         }
-      else
-         DEBUG("No component interface: skipping %s %s",
-               atspi_accessible_get_name(obj, NULL),
-               atspi_accessible_get_role_name(obj, NULL));
-   }
-
-   return eina_list_sort(candidates, 0, _sort_index);
+   *priority = eina_list_sort(*priority, 0, _sort_index);
+   *priority_after = eina_list_sort(*priority_after, 0, _sort_index);
 }
 
 static Eina_List*
@@ -152,35 +116,29 @@ _get_zones(const Eina_List *objs)
    Eina_List *candidates = NULL;
    const Eina_List *l;
    AtspiAccessible *obj;
-   AtspiComponent *comp;
    const ObjectCache *oc;
 
    EINA_LIST_FOREACH(objs, l, obj)
    {
-      if ((comp = atspi_accessible_get_component_iface(obj)) != NULL)
-         {
-            oc = object_cache_get(obj);
-
-            if (!oc)
-               {
-                  ERROR("Cache is not ready yet");
-                  continue;
-               }
-            // some objects may implement AtspiCompoment interface, however
-            // they do not have valid sizes.
-            if (!oc->bounds || (oc->bounds->width < 0) || oc->bounds->height < 0)
-               {
-                  DEBUG("Invalid bounds. skipping from zone list: %s %s",
-                        atspi_accessible_get_name(obj, NULL),
-                        atspi_accessible_get_role_name(obj, NULL));
-                  continue;
-               }
-            candidates = eina_list_append(candidates, obj);
-         }
-      else
-         DEBUG("No component interface: skipping %s %s",
-               atspi_accessible_get_name(obj, NULL),
-               atspi_accessible_get_role_name(obj, NULL));
+
+        oc = object_cache_get(obj);
+
+        if (!oc)
+           {
+              ERROR("Cache is not ready yet");
+              continue;
+           }
+        // some objects may implement AtspiCompoment interface, however
+        // they do not have valid sizes.
+        if (!oc->bounds || (oc->bounds->width < 0) || oc->bounds->height < 0)
+           {
+              DEBUG("Invalid bounds. skipping from zone list: %s %s",
+                    atspi_accessible_get_name(obj, NULL),
+                    atspi_accessible_get_role_name(obj, NULL));
+              continue;
+           }
+        candidates = eina_list_append(candidates, obj);
+
    }
 
    // Sort object by y - coordinate
@@ -233,15 +191,12 @@ _get_lines(const Eina_List *objs)
 
 Eina_List *position_sort(const Eina_List *objs)
 {
-   Eina_List *l, *line, *zones, *priority, *lines = NULL;
+   Eina_List *l = NULL, *line = NULL, *zones = NULL, *priority = NULL, *priority_after = NULL, *lines = NULL;
    Eina_List *candidates = NULL;
    int i = 0;
 
-   priority = _get_priorities(objs);
+   _get_priorities(objs, &priority, &candidates, &priority_after);
    DEBUG("With positive index it is: %d", eina_list_count(priority));
-
-   candidates = _get_rest(objs);
-
    // Get list of objects occupying place on the screen
    DEBUG("PositionSort: Candidates; %d", eina_list_count(candidates));
    zones = _get_zones(candidates);
@@ -262,6 +217,9 @@ Eina_List *position_sort(const Eina_List *objs)
    if (eina_list_count(priority) > 0)
       lines = eina_list_prepend(lines, priority);
 
+   if (eina_list_count(priority_after) > 0)
+      lines = eina_list_append(lines, priority_after);
+
    if (zones) eina_list_free(zones);
 
    return lines;