[gtk/4.0-backports: 3/53] a11y: Make GtkATContext realization lazier




commit 5fb3dafa7d389035db37577e0cb7ee4759209f7c
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jan 21 16:39:22 2021 +0000

    a11y: Make GtkATContext realization lazier
    
    We only realize the ATContext on the top level, which will create an
    GtkAtSpiRoot object and the corresponding GtkAtSpiCache object. Whenever
    an AT connects to the accessibility bus, and asks for the various
    objects, all the ATContext will be realized on demand.

 gtk/gtkwidget.c        | 26 +++++++++++++-------------
 gtk/gtkwidgetprivate.h |  3 +++
 gtk/gtkwindow.c        |  4 ++++
 3 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 5ac8b9ac84..217293cd23 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2374,7 +2374,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   priv->at_context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (widget));
 }
 
-static void
+void
 gtk_widget_realize_at_context (GtkWidget *self)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (self);
@@ -2383,10 +2383,6 @@ gtk_widget_realize_at_context (GtkWidget *self)
   if (priv->at_context == NULL || gtk_at_context_is_realized (priv->at_context))
     return;
 
-  /* Realize the root ATContext first */
-  if (!GTK_IS_ROOT (self))
-    gtk_widget_realize_at_context (GTK_WIDGET (priv->root));
-
   /* Reset the accessible role to its current value */
   if (role == GTK_ACCESSIBLE_ROLE_WIDGET)
     {
@@ -2400,6 +2396,18 @@ gtk_widget_realize_at_context (GtkWidget *self)
   gtk_at_context_realize (priv->at_context);
 }
 
+void
+gtk_widget_unrealize_at_context (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
+  if (priv->at_context != NULL)
+    {
+      gtk_at_context_set_display (priv->at_context, gdk_display_get_default ());
+      gtk_at_context_unrealize (priv->at_context);
+    }
+}
+
 void
 gtk_widget_root (GtkWidget *widget)
 {
@@ -2428,8 +2436,6 @@ gtk_widget_root (GtkWidget *widget)
   if (priv->layout_manager)
     gtk_layout_manager_set_root (priv->layout_manager, priv->root);
 
-  gtk_widget_realize_at_context (widget);
-
   GTK_WIDGET_GET_CLASS (widget)->root (widget);
 
   if (!GTK_IS_ROOT (widget))
@@ -2454,12 +2460,6 @@ gtk_widget_unroot (GtkWidget *widget)
 
   GTK_WIDGET_GET_CLASS (widget)->unroot (widget);
 
-  if (priv->at_context != NULL)
-    {
-      gtk_at_context_set_display (priv->at_context, gdk_display_get_default ());
-      gtk_at_context_unrealize (priv->at_context);
-    }
-
   if (priv->context)
     gtk_style_context_set_display (priv->context, gdk_display_get_default ());
 
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index eb6959fe7c..9848d4038f 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -373,6 +373,9 @@ gboolean gtk_widget_focus_self       (GtkWidget        *widget,
 void    gtk_widget_update_orientation   (GtkWidget      *widget,
                                          GtkOrientation  orientation);
 
+void    gtk_widget_realize_at_context   (GtkWidget *widget);
+void    gtk_widget_unrealize_at_context (GtkWidget *widget);
+
 /* inline getters */
 
 static inline GtkWidget *
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index d704f497b1..06835dc99c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -3806,6 +3806,8 @@ gtk_window_map (GtkWidget *widget)
 
   if (priv->application)
     gtk_application_handle_window_map (priv->application, window);
+
+  gtk_widget_realize_at_context (widget);
 }
 
 static void
@@ -3818,6 +3820,8 @@ gtk_window_unmap (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_window_parent_class)->unmap (widget);
   gdk_surface_hide (priv->surface);
 
+  gtk_widget_unrealize_at_context (widget);
+
   if (priv->title_box != NULL)
     gtk_widget_unmap (priv->title_box);
 


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