Move _window_extents_get() to utils 43/285943/5 accepted/tizen/unified/20221227.170636
authorArtur Świgoń <a.swigon@samsung.com>
Thu, 22 Dec 2022 15:35:05 +0000 (16:35 +0100)
committerArtur Świgoń <a.swigon@samsung.com>
Fri, 23 Dec 2022 10:18:19 +0000 (11:18 +0100)
There are a few usages of atspi_accessible_get_component_iface() and
atspi_component_get_extents(), followed by error checking and freeing the
resources, that can all be replaced by a call to object_get_extents()
(previously known as _window_extents_get()).

Change-Id: I38952ccf5868e3e99fc1b9227c3772e5c2c382ee

include/utils.h
src/app_tracker.c
src/flat_navi.c
src/navigator.c
src/utils.c
src/window_tracker.c

index 7820b2dcd5c80218691211353c64a79d328af8b2..8c90bd4f175be70aec22c0616e33a3570d0b8116 100644 (file)
@@ -23,6 +23,8 @@
 
 #define MAX_ACCURACY 3
 
+#define INVALID_EXTENTS ((AtspiRect){ .x = -1, .y = -1, .width = -1, .height = -1 })
+
 #ifndef TIZEN_GTEST
 #define TIZEN_PROD_STATIC static
 #else
@@ -126,6 +128,7 @@ Eldbus_Connection *utils_a11y_bus_connection_get(void);
 Eina_Bool object_has_modal_role(AtspiRole role);
 Eina_Bool object_has_defunct_state(AtspiAccessible *obj);
 Eina_Bool object_has_highlighted_state(AtspiAccessible *obj);
+Eina_Bool object_get_extents(AtspiAccessible *object, AtspiRect *extents);
 
 int get_percent_value(double value, double lower, double upper);
 
index e68ef2f768f8dae9d004f3d548b04c1dccea1267..3b3f0146f92114ed595c4d96ec230979dd8684a4 100644 (file)
@@ -208,10 +208,8 @@ static void _object_needs_scroll_gesture_send(App_Tracker_Data *atd, AtspiAccess
        Eldbus_Connection *conn;
        Eldbus_Object *dobj;
        Eldbus_Proxy *proxy;
-       AtspiRect *rect = NULL;
-       AtspiComponent *comp = NULL;
-       int highlighted_object_x = -1;
-       int highlighted_object_y = -1;
+       int highlighted_object_x = INVALID_EXTENTS.x;
+       int highlighted_object_y = INVALID_EXTENTS.y;
 
        if (!atd->scroll_gesture_required_obj && !(obj))
                return;
@@ -230,12 +228,10 @@ static void _object_needs_scroll_gesture_send(App_Tracker_Data *atd, AtspiAccess
        }
 
        if (obj) {
-               comp = atspi_accessible_get_component_iface(obj);
-               rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
-               g_object_unref(comp);
-               highlighted_object_x = rect->x + rect->width / 2;
-               highlighted_object_y = rect->y + rect->height / 2;
-               g_free(rect);
+               AtspiRect extents;
+               object_get_extents(obj, &extents);
+               highlighted_object_x = extents.x + extents.width / 2;
+               highlighted_object_y = extents.y + extents.height / 2;
        }
        atd->scroll_gesture_required_obj = obj;
 
index 281f6073ed8a3bf228bf62e7333f7ae357b95ec9..fff67d4d7cb03f2191c0ed352a3115d997a481ea 100644 (file)
@@ -198,8 +198,6 @@ static Eina_Bool _accept_object(AtspiAccessible *obj)
        }
        Eina_Bool ret = EINA_FALSE;
        AtspiStateSet *ss = NULL;
-       AtspiComponent *component;
-       AtspiRect *extent;
        gchar *role = NULL;
 
        AtspiRole r = atspi_accessible_get_role(obj, NULL);
@@ -266,18 +264,13 @@ static Eina_Bool _accept_object(AtspiAccessible *obj)
                                }
                        }
                } else {
+                       AtspiRect extents;
                        /* Extent of candidate object could be 0 */
-                       component = atspi_accessible_get_component_iface(obj);
-                       extent = atspi_component_get_extents(component, ATSPI_COORD_TYPE_SCREEN, NULL);
-                       g_object_unref(component);
-
-                       if (extent->width <= 0 || extent->height <= 0) {
-                               g_free(extent);
+                       if (!object_get_extents(obj, &extents) || extents.width <= 0 || extents.height <= 0) {
                                g_object_unref(ss);
                                DEBUG("END - object rejected because of size = 0");
                                return EINA_FALSE;
                        }
-                       g_free(extent);
 
                        //When content is not in scroller
                        ret = atspi_state_set_contains(ss, ATSPI_STATE_SHOWING);
index a14bd9d3d4fb2012d23051a60e9b5c9bb37367c4..e5d5a5de0ab4d04999e050e4b0ad08c7c5538436 100644 (file)
@@ -269,8 +269,8 @@ TIZEN_PROD_STATIC void _send_highlighted_object_info(NavigatorData *nd, AtspiAcc
        Eldbus_Connection *conn;
        Eldbus_Object *dobj;
        Eldbus_Proxy *proxy;
-       int highlighted_object_x = -1;
-       int highlighted_object_y = -1;
+       int highlighted_object_x = INVALID_EXTENTS.x;
+       int highlighted_object_y = INVALID_EXTENTS.y;
        AtspiRole role = -1;
 
        if (!(conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM))) {
@@ -288,14 +288,10 @@ TIZEN_PROD_STATIC void _send_highlighted_object_info(NavigatorData *nd, AtspiAcc
        role = atspi_accessible_get_role(obj, NULL);
        /* when you change this condition, check _current_highlight_object_set */
        if (role != ATSPI_ROLE_POPUP_MENU && role != ATSPI_ROLE_DIALOG) { /* ctxpopup outline does not show highlight frame */
-               AtspiComponent *comp = atspi_accessible_get_component_iface(obj);
-               AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
-
-               highlighted_object_x = rect->x + rect->width / 2;
-               highlighted_object_y = rect->y + rect->height / 2;
-
-               g_boxed_free(ATSPI_TYPE_RECT, rect);
-               g_object_unref(comp);
+               AtspiRect extents;
+               object_get_extents(obj, &extents);
+               highlighted_object_x = extents.x + extents.width / 2;
+               highlighted_object_y = extents.y + extents.height / 2;
        }
 
        keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->resource_id);
@@ -1987,32 +1983,28 @@ TIZEN_PROD_STATIC void _move_slider(NavigatorData *nd, Gesture_Info *gi)
        }
 
        if (gi->state == 0) {
-               AtspiComponent *comp = atspi_accessible_get_component_iface(obj);
-               if (!comp) {
-                       ERROR("that slider do not have component interface");
+               AtspiRect extents;
+               if (!object_get_extents(obj, &extents)) {
+                       ERROR("that slider do not have component interface or extents");
                        nd->prepared = false;
                        g_object_unref(obj);
                        return;
                }
 
-               AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
-
-               DEBUG("Current object is in:%d %d", rect->x, rect->y);
-               DEBUG("Current object has size:%d %d", rect->width, rect->height);
+               DEBUG("Current object is in:%d %d", extents.x, extents.y);
+               DEBUG("Current object has size:%d %d", extents.width, extents.height);
                AtspiValue *value_interface = atspi_accessible_get_value_iface(obj);
                gdouble max = atspi_value_get_maximum_value(value_interface, NULL);
                gdouble min = atspi_value_get_minimum_value(value_interface, NULL);
-               if (rect->width > rect->height)
-                       total_distance = rect->width;
+               if (extents.width > extents.height)
+                       total_distance = extents.width;
                else
-                       total_distance = rect->height;
+                       total_distance = extents.height;
                if (total_distance)
                        nd->slider_offset = ((max - min) / total_distance);
                else
                        nd->slider_offset = 0.0;
                g_object_unref(value_interface);
-               g_free(rect);
-               g_object_unref(comp);
        }
 
        if (gi->state == 1) {
@@ -2799,4 +2791,3 @@ Eina_Bool navigator_get_is_text_selection_mode(NavigatorData *nd) {
        if (!nd) { ERROR("NavigatorData is NULL!"); }
        return nd ? nd->is_text_selection_mode : EINA_FALSE;
 }
-
index df4337788de9e5f48ceef6e41f9b20c2d4376a31..e07f7a6689c010aae0e0c557e18516599d736ee7 100644 (file)
@@ -233,6 +233,32 @@ Eina_Bool object_has_highlighted_state(AtspiAccessible *obj)
        return ret;
 }
 
+Eina_Bool object_get_extents(AtspiAccessible *object, AtspiRect *extents)
+{
+       if (!object || !extents)
+               return EINA_FALSE;
+
+       *extents = INVALID_EXTENTS;
+
+       AtspiComponent *comp = atspi_accessible_get_component_iface(object);
+       if (!comp) {
+               DEBUG("object is not a component");
+               return EINA_FALSE;
+       }
+
+       AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+       g_object_unref(comp);
+       if (!rect) {
+               DEBUG("object has no extents");
+               return EINA_FALSE;
+       }
+
+       *extents = *rect;
+       g_free(rect);
+
+       return EINA_TRUE;
+}
+
 int get_percent_value(double value, double lower, double upper)
 {
        double add_for_rounding = 0.5f;
index eaf4ccab5bfa386aef020b97530f1e25171d7153..2741dbb1b90e5d2e7626e669a713871542224fcf 100644 (file)
@@ -95,20 +95,13 @@ static Eina_Bool _window_need_to_be_purged(WindowInfo *wi)
                DEBUG("purging %p because of defunct state or window doesn't exist", wi->window);
                return EINA_TRUE;
        }
-       AtspiComponent *comp = atspi_accessible_get_component_iface(wi->window);
-       if (!comp) {
-               DEBUG("purging %p because of not component", wi->window);
-               return EINA_TRUE;
-       }
-       GError *err = NULL;
-       AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, &err);
-       g_object_unref(comp);
-       GERROR_CHECK(err);
-       if (!rect) {
-               DEBUG("purging because failed to get extents");
+
+       AtspiRect extents;
+       if (!object_get_extents(wi->window, &extents)) {
+               DEBUG("purging %p because failed to get extents", wi->window);
                return EINA_TRUE;
        }
-       g_free(rect);
+
        return EINA_FALSE;
 }
 
@@ -155,30 +148,12 @@ static void _purge_windows_list(WindowTrackerData *wtd)
        }
 }
 
-static bool _window_extents_get(AtspiAccessible *window, AtspiRect *extents)
-{
-       AtspiComponent *comp = atspi_accessible_get_component_iface(window);
-       if (!comp) {
-               DEBUG("window is not a component");
-               return false;
-       }
-       AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
-       g_object_unref(comp);
-       if (!rect) {
-               DEBUG("window has no extents");
-               return false;
-       }
-       *extents = *rect;
-       g_free(rect);
-       return true;
-}
-
 static void _window_info_print(WindowInfo *wi)
 {
        if (!wi) return;
        gchar *id = atspi_accessible_get_unique_id(wi->window, NULL);
        AtspiRect extents;
-       if (_window_extents_get(wi->window, &extents)) {
+       if (object_get_extents(wi->window, &extents)) {
                DEBUG("Window: %s (%d, %d, %d, %d) view change need: %d, keyboard window: %d",
                        id, extents.x, extents.y, extents.width, extents.height,
                        wi->view_change_need, wi->keyboard_window_is);
@@ -650,7 +625,7 @@ AtspiAccessible *window_tracker_at_point_window_get(WindowTrackerData *wtd, int
                if (!wi) continue;
                _window_info_print(wi);
                AtspiRect extents;
-               if (!_window_extents_get(wi->window, &extents)) continue;
+               if (!object_get_extents(wi->window, &extents)) continue;
                if ((extents.x <= x && extents.x + extents.width >= x) &&
                        (extents.y <= y && extents.y + extents.height >= y)) {
                        return wi->window;