X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Fevent.c;h=a616879edb131a6faab99ba2e760bbcc5d66032e;hb=18c287edd0e891221bb08037b42697bbe32f1634;hp=f843f4f16686ba2022f78297d488c4ee1c6c6412;hpb=9c0373ce0207bed7de428d3bb5a63b4d6db55700;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/event.c b/atk-adaptor/event.c index f843f4f..a616879 100644 --- a/atk-adaptor/event.c +++ b/atk-adaptor/event.c @@ -23,14 +23,18 @@ */ #include +#include #include #include +#include #include "bridge.h" #include "accessible-register.h" #include "common/spi-dbus.h" +#include "event.h" +#include "object.h" static GArray *listener_ids = NULL; @@ -53,11 +57,26 @@ typedef struct _SpiReentrantCallClosure } SpiReentrantCallClosure; static void +switch_main_context (GMainContext *cnx) +{ + GList *list; + +#ifndef DISABLE_P2P + atspi_dbus_server_setup_with_g_main (spi_global_app_data->server, cnx); +#endif + 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); } @@ -66,26 +85,20 @@ send_and_allow_reentry (DBusConnection * bus, DBusMessage * message) { DBusPendingCall *pending; SpiReentrantCallClosure closure; + GMainContext *main_context; - if (!dbus_connection_send_with_reply (bus, message, &pending, -1)) - return NULL; - dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL); - closure.loop = g_main_loop_new (NULL, FALSE); + 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); - /* TODO: Remove old AT_SPI_CLIENT name */ - if (getenv ("AT_SPI_CLIENT") || getenv ("AT_SPI_REENTER_G_MAIN_LOOP")) - { - g_main_loop_run (closure.loop); - } - else + if (!dbus_connection_send_with_reply (bus, message, &pending, -1) || !pending) { - closure.reply = NULL; - while (!closure.reply) - { - if (!dbus_connection_read_write_dispatch (spi_global_app_data->bus, 1000)) - return NULL; - } + switch_main_context (NULL); + return NULL; } + dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL); + g_main_loop_run (closure.loop); g_main_loop_unref (closure.loop); return closure.reply; @@ -215,7 +228,7 @@ convert_signal_name (const gchar * s) } static const void * -replace_null (const gint type, +validate_for_dbus (const gint type, const void *val) { switch (type) @@ -224,6 +237,11 @@ replace_null (const gint type, case DBUS_TYPE_OBJECT_PATH: if (!val) return ""; + else if (!g_utf8_validate (val, -1, NULL)) + { + g_warning ("atk-bridge: Received bad UTF-8 string when emitting event"); + return ""; + } else return val; default: @@ -240,7 +258,7 @@ append_basic (DBusMessageIter *iter, dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &sub); - val = replace_null ((int) *type, val); + val = validate_for_dbus ((int) *type, val); dbus_message_iter_append_basic(&sub, (int) *type, &val); dbus_message_iter_close_container(iter, &sub); @@ -345,6 +363,19 @@ signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor) data [2] = ensure_proper_format (minor); data [3] = NULL; + /* Hack: Always pass events that update the cache. + * TODO: FOr 2.2, have at-spi2-core define a special "cache listener" for + * this instead, so that we don't send these if no one is listening */ + if (!g_strcmp0 (data [1], "ChildrenChanged") || + !g_strcmp0 (data [1], "PropertyChange") || + !g_strcmp0 (data [1], "StateChanged")) + { + g_free (data [2]); + g_free (data [1]); + g_free (data [0]); + return TRUE; + } + /* Hack: events such as "object::text-changed::insert:system" as generated by Gecko */ data [2][strcspn (data [2], ":")] = '\0'; @@ -358,6 +389,9 @@ signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor) } } +#if 0 + g_print("event: %s %s %s: %d\n", data[0], data[1], data[2], ret); +#endif g_free (data [2]); g_free (data [1]); g_free (data [0]); @@ -386,8 +420,7 @@ emit_event (AtkObject *obj, 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; @@ -401,6 +434,8 @@ emit_event (AtkObject *obj, 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 @@ -408,7 +443,6 @@ emit_event (AtkObject *obj, */ cname = signal_name_to_dbus (major); sig = dbus_message_new_signal(path, klass, cname); - g_free(cname); dbus_message_iter_init_append(sig, &iter); @@ -423,6 +457,9 @@ emit_event (AtkObject *obj, if (g_strcmp0 (cname, "ChildrenChanged") != 0) spi_object_lease_if_needed (G_OBJECT (obj)); + + g_free(cname); + g_free (path); } /*---------------------------------------------------------------------------*/ @@ -744,6 +781,8 @@ link_selected_event_listener (GSignalInvocationHint * signal_hint, /* * 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 @@ -774,9 +813,109 @@ text_changed_event_listener (GSignalInvocationHint * signal_hint, 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; +} + + /*---------------------------------------------------------------------------*/ /* @@ -987,6 +1126,10 @@ spi_atk_register_event_listeners (void) "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,