Commit 2e14dcd1 authored by Mike Gorse's avatar Mike Gorse

Add atspi_text_notify_read_position

#10
parent 32599e8f
......@@ -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
......
......@@ -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_ */
......@@ -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;
}
......@@ -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)
{
......
......@@ -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_ */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment