[gtk/ebassi/for-master: 5/9] a11y: Remove weak ref from atspi.Cache



commit 4c012459b001cd887316a5ddd6160752ea2539c1
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Nov 19 14:25:35 2020 +0000

    a11y: Remove weak ref from atspi.Cache
    
    The GtkAtSpiContext is responsible for removing itself from the root,
    which will remove itself from the cache. Any code path that leads to the
    GtkAtSpiContext instance being collected passes through the
    unrealization phase, which will also unregister the context from the
    accessibility bus and from the cache.

 gtk/a11y/gtkatspicache.c | 47 +++++++++++++++--------------------------------
 1 file changed, 15 insertions(+), 32 deletions(-)
---
diff --git a/gtk/a11y/gtkatspicache.c b/gtk/a11y/gtkatspicache.c
index 880a64cc5c..e9ea83cd57 100644
--- a/gtk/a11y/gtkatspicache.c
+++ b/gtk/a11y/gtkatspicache.c
@@ -191,9 +191,11 @@ emit_add_accessible (GtkAtSpiCache   *self,
 }
 
 static void
-emit_remove_accessible (GtkAtSpiCache *self,
-                        GVariant      *ref)
+emit_remove_accessible (GtkAtSpiCache   *self,
+                        GtkAtSpiContext *context)
 {
+  GVariant *ref = gtk_at_spi_context_to_ref (context);
+
   g_dbus_connection_emit_signal (self->connection,
                                  NULL,
                                  self->cache_path,
@@ -325,29 +327,6 @@ gtk_at_spi_cache_new (GDBusConnection *connection,
                        NULL);
 }
 
-static void
-context_weak_unref (gpointer  data,
-                    GObject  *stale_context)
-{
-  GtkAtSpiCache *self = data;
-
-  const char *path = g_hash_table_lookup (self->contexts_to_path, stale_context);
-  if (path == NULL)
-    return;
-
-  /* By the time we get here, the context has already been dropped,
-   * so we need to generate the reference ourselves
-   */
-  emit_remove_accessible (self, g_variant_new ("(so)",
-                                               g_dbus_connection_get_unique_name (self->connection),
-                                               path));
-
-  GTK_NOTE (A11Y, g_message ("Removing stale context '%s' from cache", path));
-
-  g_hash_table_remove (self->contexts_by_path, path);
-  g_hash_table_remove (self->contexts_to_path, stale_context);
-}
-
 void
 gtk_at_spi_cache_add_context (GtkAtSpiCache   *self,
                               GtkAtSpiContext *context)
@@ -362,15 +341,21 @@ gtk_at_spi_cache_add_context (GtkAtSpiCache   *self,
   if (g_hash_table_contains (self->contexts_by_path, path))
     return;
 
-  g_object_weak_ref (G_OBJECT (context), context_weak_unref, self);
-
   char *path_key = g_strdup (path);
   g_hash_table_insert (self->contexts_by_path, path_key, context);
   g_hash_table_insert (self->contexts_to_path, context, path_key);
 
-  emit_add_accessible (self, context);
-
   GTK_NOTE (A11Y, g_message ("Adding context '%s' to cache", path_key));
+
+  /* Do not emit AddAccessible for hidden elements; if an hidden element
+   * is set to "visible" later on, ATs will get a state change event
+   */
+  GtkATContext *at_context = GTK_AT_CONTEXT (context);
+  GtkAccessibleValue *value =
+    gtk_at_context_get_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN);
+
+  if (!gtk_boolean_accessible_value_get (value))
+    emit_add_accessible (self, context);
 }
 
 void
@@ -384,9 +369,7 @@ gtk_at_spi_cache_remove_context (GtkAtSpiCache   *self,
   if (!g_hash_table_contains (self->contexts_by_path, path))
     return;
 
-  emit_remove_accessible (self, gtk_at_spi_context_to_ref (context));
-
-  g_object_weak_unref (G_OBJECT (context), context_weak_unref, self);
+  emit_remove_accessible (self, context);
 
   /* The order is important: the value in contexts_by_path is the
    * key in contexts_to_path


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]