[gtk/abolish-size-allocate: 1/7] Explicitly update widget a11y bounds when allocating



commit 9407473f6aa66552e12ddfc0228f1a1e65cf3f2e
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Apr 20 17:10:40 2020 +0100

    Explicitly update widget a11y bounds when allocating
    
    The a11y machinery is using signal subscription to get notified of size
    changes and notify listeners in turn. This is suboptimal for a couple of
    reasons:
    
     - if something connects to the GtkWidget::size-allocate signal we need
       to emit it; currently, we have an optimization in place that will
       skip the signal emission if there are no handlers, and it would be
       nice to go through the fast path
     - the accessibility implementation is part of GTK, and should not go
       through additional hoops like any out-of-tree API consumer

 gtk/a11y/gtkwidgetaccessible.c        | 35 +++++++++++++++++------------------
 gtk/a11y/gtkwidgetaccessibleprivate.h |  2 ++
 gtk/gtkwidget.c                       |  5 ++++-
 3 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/gtk/a11y/gtkwidgetaccessible.c b/gtk/a11y/gtkwidgetaccessible.c
index 84732dcda5..43b9c8cb9a 100644
--- a/gtk/a11y/gtkwidgetaccessible.c
+++ b/gtk/a11y/gtkwidgetaccessible.c
@@ -54,28 +54,28 @@ notify_cb (GObject    *obj,
     klass->notify_gtk (obj, pspec);
 }
 
-/* Translate GtkWidget::size-allocate to AtkComponent::bounds-changed */
-static void
-size_allocate_cb (GtkWidget *widget,
-                  int        width,
-                  int        height)
+/*< private >
+ * gtk_widget_accessible_update_bounds:
+ * @self: a #GtkWidgetAccessible
+ *
+ * Updates the bounds of the widget's accessible implementation using
+ * the widget's allocation.
+ */
+void
+gtk_widget_accessible_update_bounds (GtkWidgetAccessible *self)
 {
-  AtkObject* accessible;
+  GtkAllocation alloc;
   AtkRectangle rect;
 
-  accessible = gtk_widget_get_accessible (widget);
-  if (ATK_IS_COMPONENT (accessible))
-    {
-      GtkAllocation alloc;
-      gtk_widget_get_allocation (widget, &alloc);
+  GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (self));
+  gtk_widget_get_allocation (widget, &alloc);
 
-      rect.x = alloc.x;
-      rect.y = alloc.y;
-      rect.width = alloc.width;
-      rect.height = alloc.height;
+  rect.x = alloc.x;
+  rect.y = alloc.y;
+  rect.width = alloc.width;
+  rect.height = alloc.height;
 
-      g_signal_emit_by_name (accessible, "bounds-changed", &rect);
-    }
+  g_signal_emit_by_name (self, "bounds-changed", &rect);
 }
 
 /* Translate GtkWidget mapped state into AtkObject showing */
@@ -109,7 +109,6 @@ gtk_widget_accessible_initialize (AtkObject *obj,
   widget = GTK_WIDGET (data);
 
   g_signal_connect (widget, "notify", G_CALLBACK (notify_cb), NULL);
-  g_signal_connect (widget, "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
   g_signal_connect (widget, "map", G_CALLBACK (map_cb), NULL);
   g_signal_connect (widget, "unmap", G_CALLBACK (map_cb), NULL);
 
diff --git a/gtk/a11y/gtkwidgetaccessibleprivate.h b/gtk/a11y/gtkwidgetaccessibleprivate.h
index 9623429501..ac60f0e43d 100644
--- a/gtk/a11y/gtkwidgetaccessibleprivate.h
+++ b/gtk/a11y/gtkwidgetaccessibleprivate.h
@@ -25,6 +25,8 @@ G_BEGIN_DECLS
 void _gtk_widget_accessible_set_layer (GtkWidgetAccessible *accessible,
                                        AtkLayer             layer);
 
+void gtk_widget_accessible_update_bounds (GtkWidgetAccessible *self);
+
 G_END_DECLS
 
 #endif /* __GTK_WIDGET_ACCESSIBLE_PRIVATE_H__ */
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 8ee76a263d..6612183ebb 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -74,7 +74,7 @@
 #include "gtknativeprivate.h"
 #include "gtkconstraint.h"
 
-#include "a11y/gtkwidgetaccessible.h"
+#include "a11y/gtkwidgetaccessibleprivate.h"
 #include "inspector/window.h"
 
 #include "gdk/gdkeventsprivate.h"
@@ -4103,6 +4103,9 @@ gtk_widget_allocate (GtkWidget    *widget,
 
   gtk_widget_update_paintables (widget);
 
+  if (priv->accessible != NULL)
+    gtk_widget_accessible_update_bounds (GTK_WIDGET_ACCESSIBLE (priv->accessible));
+
 skip_allocate:
   if (size_changed || baseline_changed)
     gtk_widget_queue_draw (widget);


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