summaryrefslogtreecommitdiff
path: root/atspi/atspi-text.c
diff options
context:
space:
mode:
authorMike Gorse <mgorse@alum.wpi.edu>2019-05-05 11:15:19 -0500
committerMike Gorse <mgorse@alum.wpi.edu>2019-05-05 11:15:19 -0500
commit2e14dcd16f43144222385b01157ab408f0a02a4c (patch)
treec099672f85d2db66fb0443c97d7c8dffac9583fb /atspi/atspi-text.c
parent32599e8fa66df2c2c3add5dd19de3ffdea99aab5 (diff)
downloadat-spi2-core-2e14dcd16f43144222385b01157ab408f0a02a4c.tar.gz
Add atspi_text_notify_read_position
https://gitlab.gnome.org/GNOME/at-spi2-core/issues/10
Diffstat (limited to 'atspi/atspi-text.c')
-rw-r--r--atspi/atspi-text.c59
1 files changed, 59 insertions, 0 deletions
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)
{