From 7750a2c42362db7d2de7a0b05efd17372dcfc625 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 23 May 2022 15:54:13 +0100 Subject: [PATCH 1/2] a11y: Implement atspi.Text.GetCharacterExtents for GtkTextView Retrieve the location of a given offset in window-relative coordinate space. --- gtk/a11y/gtkatspitext.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/gtk/a11y/gtkatspitext.c b/gtk/a11y/gtkatspitext.c index 338357f6d3..5bac320813 100644 --- a/gtk/a11y/gtkatspitext.c +++ b/gtk/a11y/gtkatspitext.c @@ -1098,7 +1098,40 @@ text_view_handle_method (GDBusConnection *connection, } else if (g_strcmp0 (method_name, "GetCharacterExtents") == 0) { - g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, ""); + int offset = 0; + guint coords_type; + + g_variant_get (parameters, "(iu)", &offset, &coords_type); + + if (coords_type != ATSPI_COORD_TYPE_WINDOW) + { + g_dbus_method_invocation_return_error_literal (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Unsupported coordinate space"); + return; + } + + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); + + GtkTextIter iter; + gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset); + + GdkRectangle rect = { 0, }; + gtk_text_view_get_iter_location (GTK_TEXT_VIEW (widget), &iter, &rect); + + int x, y; + gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (widget), + GTK_TEXT_WINDOW_WIDGET, + rect.x, rect.y, + &x, &y); + + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(iiii)", + x, + y, + rect.width, + rect.height)); } else if (g_strcmp0 (method_name, "GetRangeExtents") == 0) { -- GitLab From e895f7dd7018e1af3f238c7f4fd0bd5f1fafe1df Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 2 Jun 2022 14:32:41 +0200 Subject: [PATCH 2/2] a11y: Transform GetCharacterExtents coords to native surface ones These coordinates are "window"-relative, so transform textview coordinates to the coordinate system of the GtkNative containing it. --- gtk/a11y/gtkatspitext.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gtk/a11y/gtkatspitext.c b/gtk/a11y/gtkatspitext.c index 5bac320813..e4a6140298 100644 --- a/gtk/a11y/gtkatspitext.c +++ b/gtk/a11y/gtkatspitext.c @@ -1126,6 +1126,13 @@ text_view_handle_method (GDBusConnection *connection, rect.x, rect.y, &x, &y); + double dx, dy; + gtk_widget_translate_coordinates (widget, + GTK_WIDGET (gtk_widget_get_native (widget)), + (double) x, (double) y, &dx, &dy); + x = floor (dx); + y = floor (dy); + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(iiii)", x, -- GitLab