summaryrefslogtreecommitdiff
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
parent32599e8fa66df2c2c3add5dd19de3ffdea99aab5 (diff)
downloadat-spi2-core-2e14dcd16f43144222385b01157ab408f0a02a4c.tar.gz
Add atspi_text_notify_read_position
https://gitlab.gnome.org/GNOME/at-spi2-core/issues/10
-rw-r--r--atspi/atspi-constants.h3
-rw-r--r--atspi/atspi-misc-private.h2
-rw-r--r--atspi/atspi-misc.c47
-rw-r--r--atspi/atspi-text.c59
-rw-r--r--atspi/atspi-text.h1
-rw-r--r--doc/libatspi/libatspi-sections.txt1
6 files changed, 113 insertions, 0 deletions
diff --git a/atspi/atspi-constants.h b/atspi/atspi-constants.h
index b9f41ef9..369235c7 100644
--- a/atspi/atspi-constants.h
+++ b/atspi/atspi-constants.h
@@ -1462,6 +1462,9 @@ typedef enum {
#define ATSPI_DBUS_INTERFACE_VALUE "org.a11y.atspi.Value"
#define ATSPI_DBUS_INTERFACE_SOCKET "org.a11y.atspi.Socket"
+#define ATSPI_DBUS_PATH_SCREEN_READER "/org/a11y/atspi/screenreader"
+#define ATSPI_DBUS_INTERFACE_SCREEN_READER "org.a11y.Atspi.ScreenReader"
+
#ifdef __cplusplus
}
#endif
diff --git a/atspi/atspi-misc-private.h b/atspi/atspi-misc-private.h
index 314746e1..a20b5c33 100644
--- a/atspi/atspi-misc-private.h
+++ b/atspi/atspi-misc-private.h
@@ -166,6 +166,8 @@ gboolean _atspi_get_allow_sync ();
gboolean _atspi_set_allow_sync (gboolean val);
void _atspi_set_error_no_sync (GError **error);
+
+gboolean _atspi_prepare_screen_reader_interface ();
G_END_DECLS
#endif /* _ATSPI_MISC_PRIVATE_H_ */
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index 9b97b18d..fdc25bb4 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -1849,3 +1849,50 @@ _atspi_set_error_no_sync (GError **error)
g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_SYNC_NOT_ALLOWED,
_("Attempted synchronous call where prohibited"));
}
+
+static const char *sr_introspection = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
+"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
+"<node name=\"/org/a11y/atspi/screenreader\">\n"
+" <interface name=\"org.a11y.Atspi.ScreenReader\">\n"
+" <signal name=\"ReadingPosition\">\n"
+" <arg type=\"i\"/>\n"
+" <arg type=\"i\"/>\n"
+" </signal>\n"
+" </interface>\n"
+"</node>";
+
+static DBusHandlerResult
+screen_reader_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE,
+ "Introspect"))
+ {
+ DBusMessage *reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &sr_introspection,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+gboolean
+_atspi_prepare_screen_reader_interface ()
+{
+ static gint initialized = 0;
+ DBusConnection *a11y_bus = _atspi_bus ();
+
+ if (initialized)
+ return (initialized > 0);
+
+ if (dbus_bus_request_name (a11y_bus, "org.a11y.Atspi.ScreenReader", 0, NULL) < 0)
+ {
+ initialized = -1;
+ return FALSE;
+ }
+
+ initialized = 1;
+ dbus_connection_add_filter (a11y_bus, screen_reader_filter, NULL, NULL);
+ return TRUE;
+}
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)
{
diff --git a/atspi/atspi-text.h b/atspi/atspi-text.h
index 05b99dc4..fcc4259c 100644
--- a/atspi/atspi-text.h
+++ b/atspi/atspi-text.h
@@ -141,6 +141,7 @@ gboolean atspi_text_scroll_substring_to (AtspiText *obj, gint start_offset, gint
gboolean atspi_text_scroll_substring_to_point (AtspiText *obj, gint start_offset, gint end_offset, AtspiCoordType coords, gint x, gint y, GError **error);
+void atspi_text_notify_read_position (AtspiText *obj, gint offset);
G_END_DECLS
#endif /* _ATSPI_TEXT_H_ */
diff --git a/doc/libatspi/libatspi-sections.txt b/doc/libatspi/libatspi-sections.txt
index f4a0eec1..951e8013 100644
--- a/doc/libatspi/libatspi-sections.txt
+++ b/doc/libatspi/libatspi-sections.txt
@@ -32,6 +32,7 @@ atspi_text_get_text_attribute_value
atspi_text_get_text_attributes
atspi_text_scroll_substring_to
atspi_text_scroll_substring_to_point
+atspi_text_notify_read_position
<SUBSECTION Standard>
ATSPI_TEXT
ATSPI_IS_TEXT