X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Fevent.c;h=81a0f340fbdfa124808cb43ff51d9481ed8cb66f;hb=f6a0fdcf50c5bcbab547996313161ee4200266e4;hp=34dcda30fe987d6502f3ecf22a0fc6b9641e158a;hpb=b3cf1376c388c7ff5cc84bca99e05833f326f919;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/event.c b/atk-adaptor/event.c index 34dcda3..81a0f34 100644 --- a/atk-adaptor/event.c +++ b/atk-adaptor/event.c @@ -53,11 +53,28 @@ typedef struct _SpiReentrantCallClosure } 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; + + dbus_server_setup_with_g_main (spi_global_app_data->server, cnx); + dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx); + for (list = spi_global_app_data->direct_connections; list; list = list->next) + 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,12 +83,19 @@ 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)) + 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); @@ -281,6 +305,77 @@ signal_name_to_dbus (const gchar *s) } /* + * 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 @@ -314,6 +409,9 @@ emit_event (AtkObject *obj, if (!minor) minor = ""; if (!type) type = "u"; + if (!signal_is_needed (klass, major, minor)) + return; + /* * This is very annoying, but as '-' isn't a legal signal * name in D-Bus (Why not??!?) The names need converting @@ -321,7 +419,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); @@ -333,6 +430,11 @@ emit_event (AtkObject *obj, 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); } /*---------------------------------------------------------------------------*/ @@ -1006,4 +1108,17 @@ spi_atk_tidy_windows (void) } } +gboolean +spi_event_is_subtype (gchar **needle, gchar **haystack) +{ + while (*haystack && **haystack) + { + if (g_strcmp0 (*needle, *haystack)) + return FALSE; + needle++; + haystack++; + } + return TRUE; +} + /*END------------------------------------------------------------------------*/