X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Faccessible-cache.c;h=4d5cdb357bb59a1a574eb333723ba0cd84ec83ee;hb=770fcb6cf42143eebe5ebd9660a1c8737edaca6b;hp=c449657c32b2c296ea0cbf4a500431782670a22c;hpb=a01ba9992ad0c33c6c9ba02c4c416a5cf05d68ec;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/accessible-cache.c b/atk-adaptor/accessible-cache.c index c449657..4d5cdb3 100644 --- a/atk-adaptor/accessible-cache.c +++ b/atk-adaptor/accessible-cache.c @@ -21,6 +21,7 @@ */ #include +#include #include "accessible-cache.h" #include "accessible-register.h" @@ -46,6 +47,9 @@ add_object (SpiCache * cache, GObject * gobj); static void add_subtree (SpiCache *cache, AtkObject * accessible); +static gboolean +add_pending_items (gpointer data); + /*---------------------------------------------------------------------------*/ static void @@ -106,6 +110,7 @@ static void spi_cache_init (SpiCache * cache) { cache->objects = g_hash_table_new (g_direct_hash, g_direct_equal); + cache->add_traversal = g_queue_new (); #ifdef SPI_ATK_DEBUG if (g_thread_supported ()) @@ -120,8 +125,8 @@ spi_cache_init (SpiCache * cache) add_subtree (cache, spi_global_app_data->root); - atk_add_global_event_listener (child_added_listener, - "Gtk:AtkObject:children-changed"); + cache->child_added_listener = atk_add_global_event_listener (child_added_listener, + "Gtk:AtkObject:children-changed"); g_signal_connect (G_OBJECT (spi_global_app_data->root), "children-changed::add", @@ -133,7 +138,18 @@ spi_cache_finalize (GObject * object) { SpiCache *cache = SPI_CACHE (object); - g_free (cache->objects); + while (!g_queue_is_empty (cache->add_traversal)) + g_object_unref (G_OBJECT (g_queue_pop_head (cache->add_traversal))); + g_queue_free (cache->add_traversal); + g_hash_table_unref (cache->objects); + + g_signal_handlers_disconnect_by_func (spi_global_register, + (GCallback) remove_object, cache); + + g_signal_handlers_disconnect_by_func (G_OBJECT (spi_global_app_data->root), + (GCallback) toplevel_added_listener, NULL); + + atk_remove_global_event_listener (cache->child_added_listener); G_OBJECT_CLASS (spi_cache_parent_class)->finalize (object); } @@ -155,6 +171,11 @@ remove_object (GObject * source, GObject * gobj, gpointer data) if (spi_cache_in (cache, gobj)) { +#ifdef SPI_ATK_DEBUG + g_debug ("CACHE REM - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)), + atk_object_get_role (ATK_OBJECT (gobj)), + spi_register_object_to_path (spi_global_register, gobj)); +#endif g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj); g_hash_table_remove (cache->objects, gobj); } @@ -168,7 +189,7 @@ add_object (SpiCache * cache, GObject * gobj) g_hash_table_insert (cache->objects, gobj, NULL); #ifdef SPI_ATK_DEBUG - g_debug ("CACHE - %s - %d - %s", atk_object_get_name (ATK_OBJECT (gobj)), + g_debug ("CACHE ADD - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)), atk_object_get_role (ATK_OBJECT (gobj)), spi_register_object_to_path (spi_global_register, gobj)); #endif @@ -235,32 +256,37 @@ append_children (AtkObject * accessible, GQueue * traversal) static void add_subtree (SpiCache *cache, AtkObject * accessible) { + g_return_if_fail (ATK_IS_OBJECT (accessible)); + + g_object_ref (accessible); + g_queue_push_tail (cache->add_traversal, accessible); + add_pending_items (cache); +} + +static gboolean +add_pending_items (gpointer data) +{ + SpiCache *cache = SPI_CACHE (data); AtkObject *current; - GQueue *traversal; GQueue *to_add; - g_return_if_fail (ATK_IS_OBJECT (accessible)); - - traversal = g_queue_new (); to_add = g_queue_new (); - g_object_ref (accessible); - g_queue_push_tail (traversal, accessible); - - while (!g_queue_is_empty (traversal)) + while (!g_queue_is_empty (cache->add_traversal)) { AtkStateSet *set; - current = g_queue_pop_head (traversal); + current = g_queue_pop_head (cache->add_traversal); set = atk_object_ref_state_set (current); if (!atk_state_set_contains_state (set, ATK_STATE_TRANSIENT)) { g_queue_push_tail (to_add, current); if (!spi_cache_in (cache, G_OBJECT (current)) && - !atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS)) + !atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS) && + !atk_state_set_contains_state (set, ATK_STATE_DEFUNCT)) { - append_children (current, traversal); + append_children (current, cache->add_traversal); } } @@ -270,12 +296,18 @@ add_subtree (SpiCache *cache, AtkObject * accessible) while (!g_queue_is_empty (to_add)) { current = g_queue_pop_head (to_add); + + /* Make sure object is registerd so we are notified if it goes away */ + g_free (spi_register_object_to_path (spi_global_register, + G_OBJECT (current))); + add_object (cache, G_OBJECT(current)); g_object_unref (G_OBJECT (current)); } - g_queue_free (traversal); g_queue_free (to_add); + cache->add_pending_idle = 0; + return FALSE; } /*---------------------------------------------------------------------------*/ @@ -312,7 +344,7 @@ child_added_listener (GSignalInvocationHint * signal_hint, if (signal_hint->detail) detail = g_quark_to_string (signal_hint->detail); - if (!g_strcmp0 (detail, "add")) + if (detail && !strncmp (detail, "add", 3)) { gpointer child; int index = g_value_get_uint (param_values + 1); @@ -322,7 +354,11 @@ child_added_listener (GSignalInvocationHint * signal_hint, { child = atk_object_ref_accessible_child (accessible, index); } - add_subtree (cache, child); + g_object_ref (child); + g_queue_push_tail (cache->add_traversal, child); + + if (cache->add_pending_idle == 0) + cache->add_pending_idle = g_idle_add (add_pending_items, cache); } #ifdef SPI_ATK_DEBUG recursion_check_unset (); @@ -358,7 +394,13 @@ toplevel_added_listener (AtkObject * accessible, { child = atk_object_ref_accessible_child (accessible, index); } - add_subtree (cache, child); + else + g_object_ref (child); + + g_queue_push_tail (cache->add_traversal, child); + + if (cache->add_pending_idle == 0) + cache->add_pending_idle = g_idle_add (add_pending_items, cache); #ifdef SPI_ATK_DEBUG recursion_check_unset (); #endif