a11y atspi: Don't require GtkWidget for GetOffsetAtPoint

Use the existing `gtk_at_spi_translate_coordinates_to_accessible`
to translate the coordinates passed as parameters to AT-SPI
Text's GetOffsetAtPoint method instead of having a
custom GtkWidget-specific translation.

This makes this work for non-GtkWidget GtkAccessibles
as well, and also adds support for parent-relative
coordinates (ATSPI_COORD_TYPE_PARENT).
This commit is contained in:
Michael Weghorn 2024-04-04 13:43:13 +02:00
parent 2101f880af
commit 0b27f39c2b

View File

@ -285,14 +285,13 @@ accessible_text_handle_method (GDBusConnection *connection,
{
int x, y;
guint coords_type;
GtkNative *native;
double nx, ny;
int nx, ny;
graphene_point_t p;
unsigned int offset;
g_variant_get (parameters, "(iiu)", &x, &y, &coords_type);
if (coords_type != ATSPI_COORD_TYPE_WINDOW)
if (coords_type != ATSPI_COORD_TYPE_PARENT && coords_type != ATSPI_COORD_TYPE_WINDOW)
{
g_dbus_method_invocation_return_error_literal (invocation,
G_DBUS_ERROR,
@ -301,14 +300,10 @@ accessible_text_handle_method (GDBusConnection *connection,
return;
}
native = gtk_widget_get_native (GTK_WIDGET (accessible));
gtk_native_get_surface_transform (native, &nx, &ny);
gtk_at_spi_translate_coordinates_to_accessible (accessible, coords_type, x, y, &nx, &ny);
if (!gtk_widget_compute_point (GTK_WIDGET (native),
GTK_WIDGET (accessible),
&GRAPHENE_POINT_INIT (x - nx, y - ny),
&p) ||
!gtk_accessible_text_get_offset (accessible_text, &p, &offset))
p = GRAPHENE_POINT_INIT (nx, ny);
if (!gtk_accessible_text_get_offset (accessible_text, &p, &offset))
{
g_dbus_method_invocation_return_error_literal (invocation,
G_DBUS_ERROR,