From a62831562ff8a3935740ca2a89bdd61dfa70d821 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 4 Apr 2024 11:30:31 +0200 Subject: [PATCH] a11y atspi: Move helpers for coord translation to gtkatspiutils Move the (so far) local helper functions used for the AT-SPI Component method implementations, `translate_coordinates_from_accessible` and `translate_coordinates_to_accessible` to `gtkatspiutilsprivate` and add a "gtk_at_spi_" prefix to the function names. This will allow to reuse them elsewhere in upcoming commits. --- gtk/a11y/gtkatspicomponent.c | 117 ++------------------------------ gtk/a11y/gtkatspiutils.c | 109 +++++++++++++++++++++++++++++ gtk/a11y/gtkatspiutilsprivate.h | 17 +++++ 3 files changed, 130 insertions(+), 113 deletions(-) diff --git a/gtk/a11y/gtkatspicomponent.c b/gtk/a11y/gtkatspicomponent.c index 92149ff4cf..b3e006fdd0 100644 --- a/gtk/a11y/gtkatspicomponent.c +++ b/gtk/a11y/gtkatspicomponent.c @@ -48,114 +48,6 @@ find_first_accessible_non_socket (GtkAccessible *accessible) return NULL; } -static void -translate_coordinates_to_accessible (GtkAccessible *accessible, - AtspiCoordType coordtype, - int xi, - int yi, - int *xo, - int *yo) -{ - GtkAccessible *parent; - int x, y, width, height; - - if (coordtype == ATSPI_COORD_TYPE_SCREEN) - { - *xo = 0; - *yo = 0; - return; - } - - if (!gtk_accessible_get_bounds (accessible, &x, &y, &width, &height)) - { - *xo = xi; - *yo = yi; - return; - } - - // Transform coords to our parent, we will need that in any case - *xo = xi - x; - *yo = yi - y; - - // If that's what the caller requested, we're done - if (coordtype == ATSPI_COORD_TYPE_PARENT) - return; - - if (coordtype == ATSPI_COORD_TYPE_WINDOW) - { - parent = gtk_accessible_get_accessible_parent (accessible); - while (parent != NULL) - { - g_object_unref (parent); - - if (gtk_accessible_get_bounds (parent, &x, &y, &width, &height)) - { - *xo = *xo - x; - *yo = *yo - y; - parent = gtk_accessible_get_accessible_parent (parent); - } - else - break; - } - } - else - g_assert_not_reached (); -} - -static void -translate_coordinates_from_accessible (GtkAccessible *accessible, - AtspiCoordType coordtype, - int xi, - int yi, - int *xo, - int *yo) -{ - GtkAccessible *parent; - int x, y, width, height; - - if (coordtype == ATSPI_COORD_TYPE_SCREEN) - { - *xo = 0; - *yo = 0; - return; - } - - if (!gtk_accessible_get_bounds (accessible, &x, &y, &width, &height)) - { - *xo = xi; - *yo = yi; - return; - } - - // Transform coords to our parent, we will need that in any case - *xo = xi + x; - *yo = yi + y; - - // If that's what the caller requested, we're done - if (coordtype == ATSPI_COORD_TYPE_PARENT) - return; - - if (coordtype == ATSPI_COORD_TYPE_WINDOW) - { - parent = gtk_accessible_get_accessible_parent (accessible); - while (parent != NULL) - { - g_object_unref (parent); - - if (gtk_accessible_get_bounds (parent, &x, &y, &width, &height)) - { - *xo = *xo + x; - *yo = *yo + y; - parent = gtk_accessible_get_accessible_parent (parent); - } - else - break; - } - } - else - g_assert_not_reached (); -} - static GtkAccessible * accessible_at_point (GtkAccessible *parent, int x, @@ -209,7 +101,7 @@ component_handle_method (GDBusConnection *connection, g_variant_get (parameters, "(iiu)", &x, &y, &coordtype); - translate_coordinates_to_accessible (accessible, coordtype, x, y, &x, &y); + gtk_at_spi_translate_coordinates_to_accessible (accessible, coordtype, x, y, &x, &y); if (gtk_accessible_get_bounds (accessible, &bounds_x, &bounds_y, &width, &height)) ret = x >= 0 && x <= bounds_x && y >= 0 && y <= bounds_y; @@ -225,8 +117,7 @@ component_handle_method (GDBusConnection *connection, GtkAccessible *child; g_variant_get (parameters, "(iiu)", &x, &y, &coordtype); - - translate_coordinates_to_accessible (accessible, coordtype, x, y, &x, &y); + gtk_at_spi_translate_coordinates_to_accessible (accessible, coordtype, x, y, &x, &y); child = accessible_at_point (accessible, x, y, TRUE); if (!child) @@ -255,7 +146,7 @@ component_handle_method (GDBusConnection *connection, g_variant_get (parameters, "(u)", &coordtype); - translate_coordinates_from_accessible (accessible, coordtype, 0, 0, &x, &y); + gtk_at_spi_translate_coordinates_from_accessible (accessible, coordtype, 0, 0, &x, &y); g_dbus_method_invocation_return_value (invocation, g_variant_new ("((iiii))", x, y, width, height)); } @@ -266,7 +157,7 @@ component_handle_method (GDBusConnection *connection, g_variant_get (parameters, "(u)", &coordtype); - translate_coordinates_from_accessible (accessible, coordtype, 0, 0, &x, &y); + gtk_at_spi_translate_coordinates_from_accessible (accessible, coordtype, 0, 0, &x, &y); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(ii)", x, y)); } diff --git a/gtk/a11y/gtkatspiutils.c b/gtk/a11y/gtkatspiutils.c index 65a4fad0a8..4a91be47cd 100644 --- a/gtk/a11y/gtkatspiutils.c +++ b/gtk/a11y/gtkatspiutils.c @@ -367,3 +367,112 @@ gtk_at_spi_emit_children_changed (GDBusConnection *connection, g_variant_new ("(siiv@(so))", change, idx, 0, child_ref, sender_ref), NULL); } + + +void +gtk_at_spi_translate_coordinates_to_accessible (GtkAccessible *accessible, + AtspiCoordType coordtype, + int xi, + int yi, + int *xo, + int *yo) +{ + GtkAccessible *parent; + int x, y, width, height; + + if (coordtype == ATSPI_COORD_TYPE_SCREEN) + { + *xo = 0; + *yo = 0; + return; + } + + if (!gtk_accessible_get_bounds (accessible, &x, &y, &width, &height)) + { + *xo = xi; + *yo = yi; + return; + } + + // Transform coords to our parent, we will need that in any case + *xo = xi - x; + *yo = yi - y; + + // If that's what the caller requested, we're done + if (coordtype == ATSPI_COORD_TYPE_PARENT) + return; + + if (coordtype == ATSPI_COORD_TYPE_WINDOW) + { + parent = gtk_accessible_get_accessible_parent (accessible); + while (parent != NULL) + { + g_object_unref (parent); + + if (gtk_accessible_get_bounds (parent, &x, &y, &width, &height)) + { + *xo = *xo - x; + *yo = *yo - y; + parent = gtk_accessible_get_accessible_parent (parent); + } + else + break; + } + } + else + g_assert_not_reached (); +} + +void +gtk_at_spi_translate_coordinates_from_accessible (GtkAccessible *accessible, + AtspiCoordType coordtype, + int xi, + int yi, + int *xo, + int *yo) +{ + GtkAccessible *parent; + int x, y, width, height; + + if (coordtype == ATSPI_COORD_TYPE_SCREEN) + { + *xo = 0; + *yo = 0; + return; + } + + if (!gtk_accessible_get_bounds (accessible, &x, &y, &width, &height)) + { + *xo = xi; + *yo = yi; + return; + } + + // Transform coords to our parent, we will need that in any case + *xo = xi + x; + *yo = yi + y; + + // If that's what the caller requested, we're done + if (coordtype == ATSPI_COORD_TYPE_PARENT) + return; + + if (coordtype == ATSPI_COORD_TYPE_WINDOW) + { + parent = gtk_accessible_get_accessible_parent (accessible); + while (parent != NULL) + { + g_object_unref (parent); + + if (gtk_accessible_get_bounds (parent, &x, &y, &width, &height)) + { + *xo = *xo + x; + *yo = *yo + y; + parent = gtk_accessible_get_accessible_parent (parent); + } + else + break; + } + } + else + g_assert_not_reached (); +} diff --git a/gtk/a11y/gtkatspiutilsprivate.h b/gtk/a11y/gtkatspiutilsprivate.h index d54f5896c7..e5cf50191b 100644 --- a/gtk/a11y/gtkatspiutilsprivate.h +++ b/gtk/a11y/gtkatspiutilsprivate.h @@ -39,4 +39,21 @@ gtk_at_spi_emit_children_changed (GDBusConnection *connection, GVariant *child_ref, GVariant *sender_ref); +void +gtk_at_spi_translate_coordinates_to_accessible (GtkAccessible *accessible, + AtspiCoordType coordtype, + int xi, + int yi, + int *xo, + int *yo); + + +void +gtk_at_spi_translate_coordinates_from_accessible (GtkAccessible *accessible, + AtspiCoordType coordtype, + int xi, + int yi, + int *xo, + int *yo); + G_END_DECLS