Do not cache window extents 62/285862/8
authorLukasz Oleksak <l.oleksak@samsung.com>
Wed, 21 Dec 2022 13:28:31 +0000 (14:28 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Thu, 22 Dec 2022 15:14:19 +0000 (16:14 +0100)
Because:
a) in multi-window model window geometry may change so we need fresh one
b) so far extents were used to identify window at point x,y but we change to
   resource_id for the purpose of window identification

Change-Id: I32fdf6aa5f4c5c2a4e27660754f0ba5945e0bb1b

include/keyboard_tracker.h
include/window_info.h
src/keyboard_tracker.c
src/navigator.c
src/window_tracker.c
tests2/wrappers/mocked_keyboard_tracker.cpp
tests2/wrappers/mocked_keyboard_tracker.h
tests2/wrappers/mocked_navigator.cpp
tests2/wrappers/mocked_navigator.h

index 37d9f32218be5448a6e3f50737cee91e549fd7f9..b9b455fc218cd9fef289bb512462c43dc3ecfc26 100644 (file)
@@ -22,44 +22,17 @@ KeyboardTrackerData* keyboard_tracker_init(void);
  */
 void keyboard_tracker_shutdown(KeyboardTrackerData *ktd);
 
-/*
- * @brief Sets keyboard geometry
- *
- * @param ktd internal data struct
- * @param x int coordinate of left top corner
- * @param y int coordinate of left top corner
- * @param width
- * @param height
- */
-void keyboard_geometry_set(KeyboardTrackerData *ktd, int x, int y, int width, int height);
-
-/*
- * @brief Gets keyboard geometry
- *
- * @param ktd internal keyboard tracker data struct
- * @param x int pointer to coordinate of left top corner
- * @param y int pointer to coordinate of left top corner
- * @param width int pointer
- * @param height int pointer
- *
- * @return EINA_TRUE on success, EINA_FALSE otherwise
- *
- * @note One cannot pass NULL as a parameter
- */
-Eina_Bool keyboard_geometry_get(const KeyboardTrackerData *ktd, int *x, int *y, int *width, int *height);
-
 /*
  * @brief Return EINA_TRUE if the top window is Quickpanel Window
  *
  * @param ktd internal keyboard tracker data struct
- * @param x int coordinate
- * @param y int coordinate
+ * @param resource_id uint32_t resource id of window
  *
  * @return Eina_Bool status
  *
  * @note If SCREEN_READER_TV is undefined returns EINA_FALSE
  */
-Eina_Bool keyboard_event_status(KeyboardTrackerData *ktd, int x, int y);
+Eina_Bool keyboard_event_status(KeyboardTrackerData *ktd, uint32_t resource_id);
 
 /*
  * @brief Emits signal to eldbus interface
index 514f3d3d1c6fe495bf9546d68c1b0babfa783e7e..a12ad9d37c15fd11aaafd21cfe640c1ba59f03a6 100644 (file)
@@ -13,7 +13,6 @@ typedef enum {
 
 typedef struct {
        AtspiAccessible *window;
-       AtspiRect *rect;
        Eina_Bool keyboard_window_is;
        Eina_Bool view_change_need; /* Would be not necessary, keep this for later usage */
        WindowActivateInfoType window_activate_info_type;
index f4e752a5d32e37526fa5d7529375b0cb1954060b..3f04dc72fe407fc17afc2f75e4393d6950001ff5 100644 (file)
@@ -28,10 +28,6 @@ struct _KeyboardTrackerData
        AtspiDeviceListener *async_listener;
        Eldbus_Connection *conn;
        Eldbus_Service_Interface *iface;
-       int keyboardX;
-       int keyboardY;
-       int keyboardW;
-       int keyboardH;
        int prev_keyboard_state;
        TopWindowInfoGetCb top_window_info_get;
        void *top_window_info_get_user_data;
@@ -136,10 +132,6 @@ KeyboardTrackerData* keyboard_tracker_init(void)
                return NULL;
        }
 
-       ktd->keyboardX = 0;
-       ktd->keyboardY = 0;
-       ktd->keyboardW = 0;
-       ktd->keyboardH = 0;
        ktd->prev_keyboard_state = VCONFKEY_ISF_INPUT_PANEL_STATE_HIDE;
        ktd->top_window_info_get = NULL;
        ktd->top_window_info_get_user_data = NULL;
@@ -201,33 +193,7 @@ void keyboard_tracker_shutdown(KeyboardTrackerData *ktd)
        free(ktd);
 }
 
-void keyboard_geometry_set(KeyboardTrackerData *ktd, int x, int y, int width, int height)
-{
-       if (!ktd)
-               return;
-
-       ktd->keyboardX = x;
-       ktd->keyboardY = y;
-       ktd->keyboardW = width;
-       ktd->keyboardH = height;
-}
-
-Eina_Bool keyboard_geometry_get(const KeyboardTrackerData *ktd, int *x, int *y, int *width, int *height)
-{
-       if (!ktd) {
-               ERROR("invalid parameter!");
-               return EINA_FALSE;
-       }
-
-       if (x) *x = ktd->keyboardX;
-       if (y) *y = ktd->keyboardY;
-       if (width) *width = ktd->keyboardW;
-       if (height) *height = ktd->keyboardH;
-
-       return EINA_TRUE;
-}
-
-Eina_Bool keyboard_event_status(KeyboardTrackerData *ktd, const int x, const int y)
+Eina_Bool keyboard_event_status(KeyboardTrackerData *ktd, uint32_t resource_id)
 {
 #ifndef SCREEN_READER_TV
        if (ktd->prev_keyboard_state == VCONFKEY_ISF_INPUT_PANEL_STATE_SHOW) {
@@ -245,18 +211,14 @@ Eina_Bool keyboard_event_status(KeyboardTrackerData *ktd, const int x, const int
                }
 
                gchar *name = atspi_accessible_get_name(top_win_info->window, NULL);
-               if (name && g_strcmp0(name, "ISF Popup")) {
-                       int kX = top_win_info->rect->x;
-                       int kY = top_win_info->rect->y;
-                       int kW = top_win_info->rect->width;
-                       int kH = top_win_info->rect->height;
-                       if ((y >= kY) && (y <= (kY + kH)) && (x >= kX) && (x <= (kX + kW))) {
-                               g_free(name);
-                               DEBUG("Event (%d, %d) on keyboard window", x, y);
+               Eina_Bool is_isf_popup = !g_strcmp0(name, "ISF Popup");
+               g_free(name);
+               if (!is_isf_popup) {
+                       if (top_win_info->resource_id == resource_id) {
+                               DEBUG("Event on keyboard window (resID = %d)", resource_id);
                                return EINA_TRUE;
                        }
                }
-               g_free(name);
        }
 #endif
        return EINA_FALSE;
index 27e4f2b652655e25b66c75d56ffea26b18c0aab1..a14bd9d3d4fb2012d23051a60e9b5c9bb37367c4 100644 (file)
@@ -298,7 +298,7 @@ TIZEN_PROD_STATIC void _send_highlighted_object_info(NavigatorData *nd, AtspiAcc
                g_object_unref(comp);
        }
 
-       keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->x_end, info->y_end);
+       keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->resource_id);
        if (keyboard_status) {
                highlighted_object_x = info->x_end;
                highlighted_object_y = info->y_end;
@@ -2291,7 +2291,7 @@ TIZEN_PROD_STATIC void on_gesture_detected(void *data, const Eldbus_Message *msg
                                return;
                        }
                        nd->last_hover_event_time = info->state != 1 ? -1 : info->event_time;
-                       keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->x_end, info->y_end);
+                       keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->resource_id);
                        if (keyboard_status) {
                                keyboard_signal_emit(nd->keyboard_tracker_data, info->type, info->x_end, info->y_end);
                                /*TODO: Check if break is necessary or not.
@@ -2346,7 +2346,7 @@ TIZEN_PROD_STATIC void on_gesture_detected(void *data, const Eldbus_Message *msg
                }
                break;
        case ONE_FINGER_SINGLE_TAP:
-               keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->x_end, info->y_end);
+               keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->resource_id);
                if (keyboard_status) {
                        keyboard_signal_emit(nd->keyboard_tracker_data, info->type, info->x_end, info->y_end);
                        /*TODO: Check if break is necessary or not.
@@ -2360,7 +2360,7 @@ TIZEN_PROD_STATIC void on_gesture_detected(void *data, const Eldbus_Message *msg
                        _focus_widget(nd, info);
                break;
        case ONE_FINGER_DOUBLE_TAP:
-               keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->x_end, info->y_end);
+               keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->resource_id);
                if (keyboard_status) {
                        keyboard_signal_emit(nd->keyboard_tracker_data, info->type, info->x_end, info->y_end);
                        if (!_current_highlight_on_keyboard_is(nd))
index 945c9d098f1333e45596e0dfbcbec73267afa994..90343ee6218111a14002c3ce6539f499acfcdc75 100644 (file)
@@ -128,7 +128,6 @@ static void _purge_windows_list(WindowTrackerData *wtd)
                                keyboard_window_is = wi->keyboard_window_is;
                        }
                        g_object_unref(wi->window);
-                       g_free(wi->rect);
                        g_free(wi);
                        wtd->window_infos = eina_list_remove_list(wtd->window_infos, l);
                        removed_index++;
@@ -156,6 +155,40 @@ 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)) {
+               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);
+       } else {
+               DEBUG("Window: %s (no extents available) view change need: %d, keyboard window: %d",
+                       id, wi->view_change_need, wi->keyboard_window_is);
+       }
+       g_free(id);
+}
+
 static void _window_stack_print(WindowTrackerData *wtd)
 {
        Eina_List *l;
@@ -163,11 +196,7 @@ static void _window_stack_print(WindowTrackerData *wtd)
 
        EINA_LIST_FOREACH(wtd->window_infos, l, wi) {
                if (!wi) continue;
-               gchar *id = atspi_accessible_get_unique_id(wi->window, NULL);
-               DEBUG("Window: %s (%d, %d, %d, %d) view change need: %d, keyboard window: %d",
-                         id, wi->rect->x, wi->rect->y, wi->rect->width, wi->rect->height,
-                         wi->view_change_need, wi->keyboard_window_is);
-               g_free(id);
+               _window_info_print(wi);
        }
 }
 
@@ -200,33 +229,18 @@ static void _window_append(WindowTrackerData *wtd, AtspiAccessible *window, Eina
                if (!wi) continue;
                if (atspi_accessible_is_equal(wi->window, window)) {
                        g_object_unref(wi->window);
-                       g_free(wi->rect);
                        g_free(wi);
                        wtd->window_infos = eina_list_remove_list(wtd->window_infos, l);
                        break;
                }
        }
 
-       AtspiRect *rect = NULL;
-       AtspiComponent *comp = NULL;
-       comp = atspi_accessible_get_component_iface(window);
-       if (!comp) {
-               DEBUG("window is not a component");
-               return;
-       }
-       /* should be ATSPI_COORD_TYPE_SCREEN, but it seems that evas_object_geometry
-       would be same with ecore_evas_geometry for window. so the value is doubled */
-       rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
-       g_object_unref(comp);
-
        wi = g_malloc0(sizeof(WindowInfo));
        if (!wi) {
                DEBUG("Memory allocation by g_malloc0 is failed");
-               g_free(rect);
                return;
        }
        wi->window = g_object_ref(window);
-       wi->rect = rect;
        wi->keyboard_window_is = keyboard_window_is;
        wi->view_change_need = view_change_need;
        wi->window_activate_info_type = window_activate_info_type;
@@ -274,7 +288,6 @@ static void _window_remove(WindowTrackerData *wtd, AtspiAccessible *window)
                        view_change_need = wi->view_change_need;
                        keyboard_window_is = wi->keyboard_window_is;
                        g_object_unref(wi->window);
-                       g_free(wi->rect);
                        g_free(wi);
                        wtd->window_infos = eina_list_remove_list(wtd->window_infos, l);
                        window_removed = EINA_TRUE;
@@ -546,7 +559,6 @@ void window_tracker_shutdown(WindowTrackerData *wtd)
        EINA_LIST_FREE(wtd->window_infos, wi) {
                if (!wi) continue;
                g_object_unref(wi->window);
-               g_free(wi->rect);
                g_free(wi);
        }
 
@@ -631,15 +643,11 @@ AtspiAccessible *window_tracker_at_point_window_get(WindowTrackerData *wtd, int
 
        EINA_LIST_REVERSE_FOREACH(wtd->window_infos, l, wi) {
                if (!wi) continue;
-               AtspiRect *rect = wi->rect;
-               gchar *id = atspi_accessible_get_unique_id(wi->window, NULL);
-               DEBUG("Window: %s (%d, %d, %d, %d), view change need: %d, keyboard window: %d, point: %d, %d",
-                         id, rect->x, rect->y, rect->width, rect->height,
-                         wi->view_change_need, wi->keyboard_window_is, x, y);
-               g_free(id);
-
-               if ((rect->x <= x && rect->x + rect->width >= x) &&
-                               (rect->y <= y && rect->y + rect->height >= y)) {
+               _window_info_print(wi);
+               AtspiRect extents;
+               if (!_window_extents_get(wi->window, &extents)) continue;
+               if ((extents.x <= x && extents.x + extents.width >= x) &&
+                       (extents.y <= y && extents.y + extents.height >= y)) {
                        return wi->window;
                }
        }
@@ -655,13 +663,7 @@ AtspiAccessible *window_tracker_resource_id_window_get(WindowTrackerData *wtd, u
 
        EINA_LIST_REVERSE_FOREACH(wtd->window_infos, l, wi) {
                if (!wi) continue;
-               AtspiRect *rect = wi->rect;
-               gchar *id = atspi_accessible_get_unique_id(wi->window, NULL);
-               DEBUG("Window: %s (%d, %d, %d, %d), view change need: %d, keyboard window: %d, resource id: %u",
-                         id, rect->x, rect->y, rect->width, rect->height,
-                         wi->view_change_need, wi->keyboard_window_is, wi->resource_id);
-               g_free(id);
-
+               _window_info_print(wi);
                if (wi->resource_id == resource_id) {
                        return wi->window;
                }
@@ -680,7 +682,6 @@ void window_tracker_keyboard_window_remove(WindowTrackerData *wtd)
                if (!wi) continue;
                if (wi->keyboard_window_is) {
                        g_object_unref(wi->window);
-                       g_free(wi->rect);
                        g_free(wi);
                        wtd->window_infos = eina_list_remove_list(wtd->window_infos, l);
                        break;
index e77be69f10e91c42c60d8202dbd05abd2666f9e9..27cc9890b472b09ab6ab8c7a2bd284f791db5dcc 100644 (file)
@@ -20,9 +20,7 @@ IMPLEMENT_FUNCTION_MOCK2(mock_flat_navi_get_object_in_relation, flat_navi_get_ob
 IMPLEMENT_FUNCTION_MOCK2(mock_flat_navi_is_valid, flat_navi_is_valid, FlatNaviContextValidity(FlatNaviContext *, AtspiAccessible *));
 IMPLEMENT_FUNCTION_MOCK3(mock_generate_what_to_read_and_speak, generate_what_to_read_and_speak, void(NavigatorData *, AtspiAccessible *, Eina_Bool));
 IMPLEMENT_FUNCTION_MOCK0(mock_get_pointer_to_service_data_struct, get_pointer_to_service_data_struct, Service_Data *());
-IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, const int, const int));
-IMPLEMENT_FUNCTION_MOCK5(mock_keyboard_geometry_get, keyboard_geometry_get, Eina_Bool(const KeyboardTrackerData *, int *, int *, int *, int *));
-IMPLEMENT_FUNCTION_MOCK5(mock_keyboard_geometry_set, keyboard_geometry_set, void(KeyboardTrackerData *, int, int, int, int));
+IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, uint32_t resource_id));
 IMPLEMENT_FUNCTION_MOCK4(mock_keyboard_signal_emit, keyboard_signal_emit, void(KeyboardTrackerData *, int, int, int));
 IMPLEMENT_FUNCTION_MOCK0(mock_keyboard_tracker_init, keyboard_tracker_init, KeyboardTrackerData *());
 IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_tracker_register_top_window_info_get, keyboard_tracker_register_top_window_info_get, void(KeyboardTrackerData *, TopWindowInfoGetCb, void *));
index eb0cff5e0be0f8cd46a4a0c50a7c4cb0a504687b..af7c2fc77aa8b8f30afe22a824d95b31db629627 100644 (file)
@@ -31,9 +31,7 @@ DECLARE_FUNCTION_MOCK2(mock_flat_navi_get_object_in_relation, flat_navi_get_obje
 DECLARE_FUNCTION_MOCK2(mock_flat_navi_is_valid, flat_navi_is_valid, FlatNaviContextValidity(FlatNaviContext *, AtspiAccessible *));
 DECLARE_FUNCTION_MOCK3(mock_generate_what_to_read_and_speak, generate_what_to_read_and_speak, void(NavigatorData *, AtspiAccessible *, Eina_Bool));
 DECLARE_FUNCTION_MOCK0(mock_get_pointer_to_service_data_struct, get_pointer_to_service_data_struct, Service_Data *());
-DECLARE_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, const int, const int));
-DECLARE_FUNCTION_MOCK5(mock_keyboard_geometry_get, keyboard_geometry_get, Eina_Bool(const KeyboardTrackerData *, int *, int *, int *, int *));
-DECLARE_FUNCTION_MOCK5(mock_keyboard_geometry_set, keyboard_geometry_set, void(KeyboardTrackerData *, int, int, int, int));
+DECLARE_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, uint32_t resource_id));
 DECLARE_FUNCTION_MOCK4(mock_keyboard_signal_emit, keyboard_signal_emit, void(KeyboardTrackerData *, int, int, int));
 DECLARE_FUNCTION_MOCK0(mock_keyboard_tracker_init, keyboard_tracker_init, KeyboardTrackerData *());
 DECLARE_FUNCTION_MOCK3(mock_keyboard_tracker_register_top_window_info_get, keyboard_tracker_register_top_window_info_get, void(KeyboardTrackerData *, TopWindowInfoGetCb, void *));
index 0e5b28746f93c0601a0801f90bfd1477bdb98578..c927d58dbba6c3677d1c65c47e45a1e6db1c9922 100644 (file)
@@ -99,9 +99,7 @@ IMPLEMENT_FUNCTION_MOCK0(mock_haptic_module_disconnect, haptic_module_disconnect
 IMPLEMENT_FUNCTION_MOCK0(mock_haptic_module_init, haptic_module_init, void());
 IMPLEMENT_FUNCTION_MOCK2(mock_haptic_vibrate_start, haptic_vibrate_start, void(int, int));
 IMPLEMENT_FUNCTION_MOCK0(mock_haptic_vibrate_stop, haptic_vibrate_stop, void());
-IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, const int, const int));
-IMPLEMENT_FUNCTION_MOCK5(mock_keyboard_geometry_get, keyboard_geometry_get, Eina_Bool(const KeyboardTrackerData *, int *, int *, int *, int *));
-IMPLEMENT_FUNCTION_MOCK5(mock_keyboard_geometry_set, keyboard_geometry_set, void(KeyboardTrackerData *, int, int, int, int));
+IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, uint32_t resource_id));
 IMPLEMENT_FUNCTION_MOCK4(mock_keyboard_signal_emit, keyboard_signal_emit, void(KeyboardTrackerData *, int, int, int));
 IMPLEMENT_FUNCTION_MOCK0(mock_keyboard_tracker_init, keyboard_tracker_init, KeyboardTrackerData *());
 IMPLEMENT_FUNCTION_MOCK3(mock_keyboard_tracker_register_top_window_info_get, keyboard_tracker_register_top_window_info_get, void(KeyboardTrackerData *, TopWindowInfoGetCb, void *));
index 3c9f06bf08ce27f018bcf80d17aca7ae2d5b99ca..53c9f6bc2f0e3a667cce4a2c4853133920f0afd4 100644 (file)
@@ -179,9 +179,7 @@ DECLARE_FUNCTION_MOCK0(mock_haptic_module_disconnect, haptic_module_disconnect,
 DECLARE_FUNCTION_MOCK0(mock_haptic_module_init, haptic_module_init, void());
 DECLARE_FUNCTION_MOCK2(mock_haptic_vibrate_start, haptic_vibrate_start, void(int, int));
 DECLARE_FUNCTION_MOCK0(mock_haptic_vibrate_stop, haptic_vibrate_stop, void());
-DECLARE_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, const int, const int));
-DECLARE_FUNCTION_MOCK5(mock_keyboard_geometry_get, keyboard_geometry_get, Eina_Bool(const KeyboardTrackerData *, int *, int *, int *, int *));
-DECLARE_FUNCTION_MOCK5(mock_keyboard_geometry_set, keyboard_geometry_set, void(KeyboardTrackerData *, int, int, int, int));
+DECLARE_FUNCTION_MOCK3(mock_keyboard_event_status, keyboard_event_status, Eina_Bool(KeyboardTrackerData *, uint32_t resource_id));
 DECLARE_FUNCTION_MOCK4(mock_keyboard_signal_emit, keyboard_signal_emit, void(KeyboardTrackerData *, int, int, int));
 DECLARE_FUNCTION_MOCK0(mock_keyboard_tracker_init, keyboard_tracker_init, KeyboardTrackerData *());
 DECLARE_FUNCTION_MOCK3(mock_keyboard_tracker_register_top_window_info_get, keyboard_tracker_register_top_window_info_get, void(KeyboardTrackerData *, TopWindowInfoGetCb, void *));