X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Faccessible-cache.c;h=c997b4ada7c3530d1439d33bc58c17260864c79f;hb=55b85389cc9fab84ecf17e113747e1b9d7f4ec2c;hp=813d03fb5885460fc64c1df9ab90955d7003083e;hpb=38b14df983445e90257e6c5bfae8baf18f31da51;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/accessible-cache.c b/atk-adaptor/accessible-cache.c index 813d03f..c997b4a 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); } @@ -163,6 +179,8 @@ remove_object (GObject * source, GObject * gobj, gpointer data) g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj); g_hash_table_remove (cache->objects, gobj); } + else + g_queue_remove (cache->add_traversal, gobj); } static void @@ -240,47 +258,59 @@ 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)) + if (set && !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); } } - g_object_unref (set); + if (set) + g_object_unref (set); } 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; } /*---------------------------------------------------------------------------*/ @@ -291,9 +321,8 @@ child_added_listener (GSignalInvocationHint * signal_hint, const GValue * param_values, gpointer data) { SpiCache *cache = spi_global_cache; - + gboolean child_needs_ref = TRUE; AtkObject *accessible; - AtkObject *child; const gchar *detail = NULL; @@ -317,17 +346,23 @@ 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); child = g_value_get_pointer (param_values + 2); if (!ATK_IS_OBJECT (child)) - { - child = atk_object_ref_accessible_child (accessible, index); - } - add_subtree (cache, child); + { + child = atk_object_ref_accessible_child (accessible, index); + child_needs_ref = FALSE; + } + if (child_needs_ref) + 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 (); @@ -363,7 +398,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