summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2020-11-12 20:57:56 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2020-11-12 21:46:06 +0000
commitabc9b403f85a34bcc39c055d337b29d10ebb3a46 (patch)
tree30c289a0ba51ec990a960d6ad87faad5f3509c2c
parentb9ad3172a4a67cbcf2a663dde4770e5604330550 (diff)
downloadgtk+-abc9b403f85a34bcc39c055d337b29d10ebb3a46.tar.gz
a11y: Implement atspi.Text.ScrollSubstringTo for GtkTextView
We reuse the existing implementation in GTK3.
-rw-r--r--gtk/a11y/gtkatspiprivate.h9
-rw-r--r--gtk/a11y/gtkatspitext.c93
2 files changed, 101 insertions, 1 deletions
diff --git a/gtk/a11y/gtkatspiprivate.h b/gtk/a11y/gtkatspiprivate.h
index 036a41ef27..ee3c51c4f6 100644
--- a/gtk/a11y/gtkatspiprivate.h
+++ b/gtk/a11y/gtkatspiprivate.h
@@ -263,5 +263,14 @@ typedef enum {
ATSPI_COMPONENT_LAYER_WINDOW
} AtspiComponentLayer;
+typedef enum {
+ ATSPI_SCROLL_TOP_LEFT,
+ ATSPI_SCROLL_BOTTOM_RIGHT,
+ ATSPI_SCROLL_TOP_EDGE,
+ ATSPI_SCROLL_BOTTOM_EDGE,
+ ATSPI_SCROLL_LEFT_EDGE,
+ ATSPI_SCROLL_RIGHT_EDGE,
+ ATSPI_SCROLL_ANYWHERE
+} AtspiScrollType;
G_END_DECLS
diff --git a/gtk/a11y/gtkatspitext.c b/gtk/a11y/gtkatspitext.c
index 59dccb752d..6c6fd79a46 100644
--- a/gtk/a11y/gtkatspitext.c
+++ b/gtk/a11y/gtkatspitext.c
@@ -1110,7 +1110,98 @@ text_view_handle_method (GDBusConnection *connection,
}
else if (g_strcmp0 (method_name, "ScrollSubstringTo") == 0)
{
- g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, "");
+ GtkTextBuffer *buffer = buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+ GtkTextIter iter;
+ int start_offset = 0;
+ int end_offset = 0;
+ int offset = 0;
+ double x_align = -1.0, y_align = -1.0;
+ AtspiScrollType scroll_type;
+ gboolean is_rtl = FALSE, use_align = TRUE;
+ gboolean ret = FALSE;
+
+ g_variant_get (parameters, "(iiu)", &start_offset, &end_offset, &scroll_type);
+
+ if (end_offset < start_offset)
+ {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_INVALID_ARGS,
+ "Negative offset is not supported");
+ return;
+ }
+
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ is_rtl = TRUE;
+
+ switch (scroll_type)
+ {
+ case ATSPI_SCROLL_TOP_LEFT:
+ offset = (is_rtl) ? end_offset : start_offset;
+ x_align = 0.0;
+ y_align = 0.0;
+ break;
+
+ case ATSPI_SCROLL_BOTTOM_RIGHT:
+ offset = (is_rtl) ? start_offset : end_offset;
+ x_align = 1.0;
+ y_align = 1.0;
+ break;
+
+ case ATSPI_SCROLL_TOP_EDGE:
+ offset = start_offset;
+ y_align = 0.0;
+ break;
+
+ case ATSPI_SCROLL_BOTTOM_EDGE:
+ offset = end_offset;
+ y_align = 1.0;
+ break;
+
+ case ATSPI_SCROLL_LEFT_EDGE:
+ offset = (is_rtl) ? end_offset : start_offset;
+ x_align = 0.0;
+ break;
+
+ case ATSPI_SCROLL_RIGHT_EDGE:
+ offset = (is_rtl) ? start_offset : end_offset;
+ x_align = 1.0;
+ break;
+
+ case ATSPI_SCROLL_ANYWHERE:
+ offset = start_offset;
+ use_align = FALSE;
+ x_align = 0.0;
+ y_align = 0.0;
+ break;
+
+ default:
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_INVALID_ARGS,
+ "Invalid scroll type");
+ return;
+ }
+
+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
+
+ if (use_align && (x_align != -1.0 || y_align != -1.0))
+ {
+ GdkRectangle visible_rect, iter_rect;
+
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (widget), &visible_rect);
+ gtk_text_view_get_iter_location (GTK_TEXT_VIEW (widget), &iter, &iter_rect);
+
+ if (x_align == -1.0)
+ x_align = ((double) (iter_rect.x - visible_rect.x)) / (visible_rect.width - 1);
+ if (y_align == -1.0)
+ y_align = ((double) (iter_rect.y - visible_rect.y)) / (visible_rect.height - 1);
+ }
+
+ ret = gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (widget), &iter,
+ 0.0,
+ use_align,
+ x_align, y_align);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", ret));
}
else if (g_strcmp0 (method_name, "ScrollSubstringToPoint") == 0)
{