[at-spi2-core] Add atspi_text_notify_read_position



commit 2e14dcd16f43144222385b01157ab408f0a02a4c
Author: Mike Gorse <mgorse alum wpi edu>
Date:   Sun May 5 11:15:19 2019 -0500

    Add atspi_text_notify_read_position
    
    https://gitlab.gnome.org/GNOME/at-spi2-core/issues/10

 atspi/atspi-constants.h            |  3 ++
 atspi/atspi-misc-private.h         |  2 ++
 atspi/atspi-misc.c                 | 47 ++++++++++++++++++++++++++++++
 atspi/atspi-text.c                 | 59 ++++++++++++++++++++++++++++++++++++++
 atspi/atspi-text.h                 |  1 +
 doc/libatspi/libatspi-sections.txt |  1 +
 6 files changed, 113 insertions(+)
---
diff --git a/atspi/atspi-constants.h b/atspi/atspi-constants.h
index b9f41ef..369235c 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 314746e..a20b5c3 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 9b97b18..fdc25bb 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 a360f56..2409560 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 05b99dc..fcc4259 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 f4a0eec..951e801 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]