From 2e14dcd16f43144222385b01157ab408f0a02a4c Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Sun, 5 May 2019 11:15:19 -0500 Subject: Add atspi_text_notify_read_position https://gitlab.gnome.org/GNOME/at-spi2-core/issues/10 --- atspi/atspi-text.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'atspi/atspi-text.c') diff --git a/atspi/atspi-text.c b/atspi/atspi-text.c index a360f56c..24095606 100644 --- a/atspi/atspi-text.c +++ b/atspi/atspi-text.c @@ -962,6 +962,65 @@ atspi_text_scroll_substring_to_point (AtspiText *obj, return retval; } +/** + * atspi_text_notify_read_position: + * @obj: the #AtspiText object being read. + * @offset: the offset of the text currently being read. + * + * Notifies interested listeners of the specific text that the screen + * reader is currently reading. This allows a magnifier to synchronize with + * the screen reader and highlight the text that is currently being read. + */ +void +atspi_text_notify_read_position (AtspiText *obj, + gint offset) +{ + DBusConnection *bus = _atspi_bus (); + DBusMessage *signal; + AtspiAccessible *accessible; + gint len; + static gint quark_text_len = 0; + gpointer plen; + DBusMessageIter iter, iter_struct; + gint remaining; + + g_return_if_fail (obj != NULL); + + accessible = ATSPI_ACCESSIBLE(obj); + + if (!_atspi_prepare_screen_reader_interface ()) + return; + + if (!quark_text_len) + quark_text_len = g_quark_from_string ("accessible-text-len"); + + plen = g_object_get_qdata (accessible, quark_text_len); + if (plen) + len = (gint)plen; + else + { + len = atspi_text_get_character_count (obj, NULL); + plen = (gpointer)len; + g_object_set_qdata (accessible, quark_text_len, plen); + } + + remaining = (len >= 0 ? len - offset : 0); + + signal = dbus_message_new_signal (ATSPI_DBUS_PATH_SCREEN_READER, + ATSPI_DBUS_INTERFACE_SCREEN_READER, + "ReadingPosition"); + dbus_message_iter_init_append (signal, &iter); + dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, + &iter_struct); + dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &accessible->parent.app->bus_name); + dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &accessible->parent.path); + dbus_message_iter_close_container (&iter, &iter_struct); + dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &offset); + dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &remaining); + dbus_connection_send (_atspi_bus (), signal, NULL); + dbus_message_unref (signal); +} + static void atspi_text_base_init (AtspiText *klass) { -- cgit v1.2.1