*/
#include <string.h>
+#include <ctype.h>
#include <atk/atk.h>
#include <droute/droute.h>
+#include <atspi/atspi.h>
#include "bridge.h"
#include "accessible-register.h"
#include "common/spi-dbus.h"
+#include "event.h"
+#include "object.h"
static GArray *listener_ids = NULL;
/*---------------------------------------------------------------------------*/
-#define ITF_EVENT_OBJECT "org.freedesktop.atspi.Event.Object"
-#define ITF_EVENT_WINDOW "org.freedesktop.atspi.Event.Window"
-#define ITF_EVENT_DOCUMENT "org.freedesktop.atspi.Event.Document"
-#define ITF_EVENT_FOCUS "org.freedesktop.atspi.Event.Focus"
+#define ITF_EVENT_OBJECT "org.a11y.atspi.Event.Object"
+#define ITF_EVENT_WINDOW "org.a11y.atspi.Event.Window"
+#define ITF_EVENT_DOCUMENT "org.a11y.atspi.Event.Document"
+#define ITF_EVENT_FOCUS "org.a11y.atspi.Event.Focus"
/*---------------------------------------------------------------------------*/
} SpiReentrantCallClosure;
static void
+switch_main_context (GMainContext *cnx)
+{
+/* This code won't work on dbus-glib earlier than 0.9.0 because of FDO#30574 */
+ if (spi_global_app_data->app_bus_addr [0] == '\0')
+ return;
+
+ GList *list;
+
+ atspi_dbus_server_setup_with_g_main (spi_global_app_data->server, cnx);
+ atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx);
+ for (list = spi_global_app_data->direct_connections; list; list = list->next)
+ atspi_dbus_connection_setup_with_g_main (list->data, cnx);
+}
+
+static void
set_reply (DBusPendingCall * pending, void *user_data)
{
SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
closure->reply = dbus_pending_call_steal_reply (pending);
+ dbus_pending_call_unref (pending);
+ switch_main_context (NULL);
g_main_loop_quit (closure->loop);
}
{
DBusPendingCall *pending;
SpiReentrantCallClosure closure;
+ GMainContext *main_context;
- if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
+ main_context = (g_getenv ("AT_SPI_CLIENT") ? NULL :
+ spi_global_app_data->main_context);
+ closure.loop = g_main_loop_new (main_context, FALSE);
+ switch_main_context (main_context);
+
+ if (!dbus_connection_send_with_reply (bus, message, &pending, -1) || !pending)
+ {
+ switch_main_context (NULL);
return NULL;
+ }
dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
- closure.loop = g_main_loop_new (NULL, FALSE);
-
g_main_loop_run (closure.loop);
g_main_loop_unref (closure.loop);
}
/*
+ * Converts names of the form "active-descendant-changed" to
+ * "ActiveDescendantChanged"
+ */
+static gchar *
+ensure_proper_format (const char *name)
+{
+ gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
+ gchar *p = ret;
+ gboolean need_upper = TRUE;
+
+ if (!ret)
+ return NULL;
+ while (*name)
+ {
+ if (need_upper)
+ {
+ *p++ = toupper (*name);
+ need_upper = FALSE;
+ }
+ else if (*name == '-')
+ need_upper = TRUE;
+ else if (*name == ':')
+ {
+ need_upper = TRUE;
+ *p++ = *name;
+ }
+ else
+ *p++ = *name;
+ name++;
+ }
+ *p = '\0';
+ return ret;
+}
+
+static gboolean
+signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor)
+{
+ gchar *data [4];
+ GList *iter;
+ event_data *evdata;
+ gboolean ret = FALSE;
+ GList *list;
+
+ if (!spi_global_app_data->events_initialized)
+ return TRUE;
+
+ data [0] = ensure_proper_format (klass + 21);
+ data [1] = ensure_proper_format (major);
+ data [2] = ensure_proper_format (minor);
+ data [3] = NULL;
+
+ /* Hack: events such as "object::text-changed::insert:system" as
+ generated by Gecko */
+ data [2][strcspn (data [2], ":")] = '\0';
+ for (list = spi_global_app_data->events; list; list = list->next)
+ {
+ evdata = list->data;
+ if (spi_event_is_subtype (data, evdata->data))
+ {
+ ret = TRUE;
+ break;
+ }
+ }
+
+ g_free (data [2]);
+ g_free (data [1]);
+ g_free (data [0]);
+ return ret;
+}
+
+/*
* Emits an AT-SPI event.
* AT-SPI events names are split into three parts:
* class:major:minor
void (*append_variant) (DBusMessageIter *, const char *, const void *))
{
DBusConnection *bus = spi_global_app_data->bus;
- const char *path = spi_register_object_to_path (spi_global_register,
- G_OBJECT (obj));
+ const char *path;
gchar *cname, *t;
DBusMessage *sig;
if (!minor) minor = "";
if (!type) type = "u";
+ if (!signal_is_needed (klass, major, minor))
+ return;
+
+ path = spi_register_object_to_path (spi_global_register, G_OBJECT (obj));
+
/*
* This is very annoying, but as '-' isn't a legal signal
* name in D-Bus (Why not??!?) The names need converting
*/
cname = signal_name_to_dbus (major);
sig = dbus_message_new_signal(path, klass, cname);
- g_free(cname);
dbus_message_iter_init_append(sig, &iter);
- spi_object_append_reference (&iter, spi_global_app_data->root);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
-
append_variant (&iter, type, val);
+ spi_object_append_reference (&iter, spi_global_app_data->root);
dbus_connection_send(bus, sig, NULL);
dbus_message_unref(sig);
+
+ if (g_strcmp0 (cname, "ChildrenChanged") != 0)
+ spi_object_lease_if_needed (G_OBJECT (obj));
+
+ g_free(cname);
+ g_free (path);
}
/*---------------------------------------------------------------------------*/
}
else if (strcmp (pname, "accessible-role") == 0)
{
- dbus_uint32_t role = atk_object_get_role (accessible);
+ i = atk_object_get_role (accessible);
emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
- DBUS_TYPE_UINT32_AS_STRING, role, append_basic);
+ DBUS_TYPE_UINT32_AS_STRING, GINT_TO_POINTER(i), append_basic);
}
else if (strcmp (pname, "accessible-table-summary") == 0)
{
AtkObject *child;
GSignalQuery signal_query;
const gchar *name, *minor;
- gchar *s;
gint detail1;
g_signal_query (signal_hint->signal_id, &signal_query);
emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, 0,
"(so)", child, append_object);
- g_free (s);
return TRUE;
}
/*
* Handles the ATK signal 'Gtk:AtkText:text-changed' and
* converts it to the AT-SPI signal - 'object:text-changed'
+ * This signal is deprecated by Gtk:AtkText:text-insert
+ * and Gtk:AtkText:text-remove
*
*/
static gboolean
emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
DBUS_TYPE_STRING_AS_STRING, selected, append_basic);
+ g_free (selected);
+
return TRUE;
}
+/*
+ * Handles the ATK signal 'Gtk:AtkText:text-insert' and
+ * converts it to the AT-SPI signal - 'object:text-changed'
+ *
+ */
+static gboolean
+text_insert_event_listener (GSignalInvocationHint * signal_hint,
+ guint n_param_values,
+ const GValue * param_values, gpointer data)
+{
+ AtkObject *accessible;
+ guint text_changed_signal_id;
+ GSignalQuery signal_query;
+ const gchar *name;
+ gchar *minor, *text;
+ gint detail1, detail2;
+
+ accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
+ /* Get signal name for 'Gtk:AtkText:text-changed' so
+ * we convert it to the AT-SPI signal - 'object:text-changed'
+ */
+ text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
+ g_signal_query (text_changed_signal_id, &signal_query);
+ name = signal_query.signal_name;
+
+
+ /* Add the insert and keep any detail coming from atk */
+ minor = g_quark_to_string (signal_hint->detail);
+ if (minor)
+ minor = g_strconcat ("insert:", minor, NULL);
+ else
+ minor = g_strdup ("insert");
+
+ if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
+ detail1 = g_value_get_int (¶m_values[1]);
+
+ if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
+ detail2 = g_value_get_int (¶m_values[2]);
+
+ if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
+ text = g_value_get_string (¶m_values[3]);
+
+ emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
+ DBUS_TYPE_STRING_AS_STRING, text, append_basic);
+ g_free (minor);
+ return TRUE;
+}
+
+/*
+ * Handles the ATK signal 'Gtk:AtkText:text-remove' and
+ * converts it to the AT-SPI signal - 'object:text-changed'
+ *
+ */
+static gboolean
+text_remove_event_listener (GSignalInvocationHint * signal_hint,
+ guint n_param_values,
+ const GValue * param_values, gpointer data)
+{
+ AtkObject *accessible;
+ guint text_changed_signal_id;
+ GSignalQuery signal_query;
+ const gchar *name;
+ gchar *minor, *text;
+ gint detail1, detail2;
+
+ accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
+ /* Get signal name for 'Gtk:AtkText:text-changed' so
+ * we convert it to the AT-SPI signal - 'object:text-changed'
+ */
+ text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
+ g_signal_query (text_changed_signal_id, &signal_query);
+ name = signal_query.signal_name;
+
+ minor = g_quark_to_string (signal_hint->detail);
+
+ /* Add the delete and keep any detail coming from atk */
+ minor = g_quark_to_string (signal_hint->detail);
+ if (minor)
+ minor = g_strconcat ("delete:", minor, NULL);
+ else
+ minor = g_strdup ("delete");
+
+ if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
+ detail1 = g_value_get_int (¶m_values[1]);
+
+ if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
+ detail2 = g_value_get_int (¶m_values[2]);
+
+ if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
+ text = g_value_get_string (¶m_values[3]);
+
+ emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
+ DBUS_TYPE_STRING_AS_STRING, text, append_basic);
+ g_free (minor);
+ return TRUE;
+}
+
+
/*---------------------------------------------------------------------------*/
/*
/*
* Children changed signal converter and forwarder.
*
- * Klass (Interface) org.freedesktop.atspi.Event.Object
+ * Klass (Interface) org.a11y.atspi.Event.Object
* Major is the signal name.
* Minor is 'add' or 'remove'
* detail1 is the index.
const gchar *name, *minor;
gint detail1, detail2 = 0;
- AtkObject *accessible, *ao;
+ AtkObject *accessible, *ao=NULL;
gpointer child;
g_signal_query (signal_hint->signal_id, &signal_query);
/*
* Generic signal converter and forwarder.
*
- * Klass (Interface) org.freedesktop.atspi.Event.Object
+ * Klass (Interface) org.a11y.atspi.Event.Object
* Major is the signal name.
* Minor is NULL.
* detail1 is 0.
"Gtk:AtkText:text-selection-changed");
add_signal_listener (text_changed_event_listener,
"Gtk:AtkText:text-changed");
+ add_signal_listener (text_insert_event_listener,
+ "Gtk:AtkText:text-insert");
+ add_signal_listener (text_remove_event_listener,
+ "Gtk:AtkText:text-remove");
add_signal_listener (link_selected_event_listener,
"Gtk:AtkHypertext:link-selected");
add_signal_listener (generic_event_listener,
}
}
+gboolean
+spi_event_is_subtype (gchar **needle, gchar **haystack)
+{
+ while (*haystack && **haystack)
+ {
+ if (g_strcmp0 (*needle, *haystack))
+ return FALSE;
+ needle++;
+ haystack++;
+ }
+ return TRUE;
+}
+
/*END------------------------------------------------------------------------*/