[gtk/wip/ebassi/a11y-2: 423/442] a11y: Drop notify_gtk() from GtkRangeAccessible



commit f5ed59b7f2e1c2eb5726b29fccb7f6fa28032903
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 23 20:16:31 2020 +0100

    a11y: Drop notify_gtk() from GtkRangeAccessible
    
    Let the GtkRange notify the accessible instance when the adjustment
    changes.

 gtk/a11y/gtkrangeaccessible.c | 75 ++++++++++++++++++++++++-------------------
 gtk/a11y/gtkrangeaccessible.h |  6 ++--
 gtk/gtkrange.c                |  9 ++++++
 3 files changed, 54 insertions(+), 36 deletions(-)
---
diff --git a/gtk/a11y/gtkrangeaccessible.c b/gtk/a11y/gtkrangeaccessible.c
index 93cfb62a7e..5675e08c4b 100644
--- a/gtk/a11y/gtkrangeaccessible.c
+++ b/gtk/a11y/gtkrangeaccessible.c
@@ -21,10 +21,12 @@
 #include <gtk/gtk.h>
 #include "gtkrangeaccessible.h"
 
-struct _GtkRangeAccessiblePrivate
+typedef struct
 {
   GtkAdjustment *adjustment;
-};
+
+  gulong value_changed_id;
+} GtkRangeAccessiblePrivate;
 
 static void atk_value_interface_init  (AtkValueIface  *iface);
 
@@ -42,35 +44,44 @@ gtk_range_accessible_value_changed (GtkAdjustment *adjustment,
 static void
 gtk_range_accessible_widget_set (GtkAccessible *accessible)
 {
-  GtkRangeAccessiblePrivate *priv = GTK_RANGE_ACCESSIBLE (accessible)->priv;
+  GtkRangeAccessible *self = GTK_RANGE_ACCESSIBLE (accessible);
+  GtkRangeAccessiblePrivate *priv = gtk_range_accessible_get_instance_private (self);
   GtkWidget *range;
   GtkAdjustment *adj;
 
   range = gtk_accessible_get_widget (accessible);
   adj = gtk_range_get_adjustment (GTK_RANGE (range));
-  if (adj)
+  if (adj != NULL)
     {
-      priv->adjustment = adj;
-      g_object_ref (priv->adjustment);
-      g_signal_connect (priv->adjustment, "value-changed",
-                        G_CALLBACK (gtk_range_accessible_value_changed),
-                        accessible);
+      priv->adjustment = g_object_ref (adj);
+      priv->value_changed_id =
+        g_signal_connect (priv->adjustment, "value-changed",
+                          G_CALLBACK (gtk_range_accessible_value_changed),
+                          self);
     }
 }
 
 static void
 gtk_range_accessible_widget_unset (GtkAccessible *accessible)
 {
-  GtkRangeAccessiblePrivate *priv = GTK_RANGE_ACCESSIBLE (accessible)->priv;
+  GtkRangeAccessible *self = GTK_RANGE_ACCESSIBLE (accessible);
+  GtkRangeAccessiblePrivate *priv = gtk_range_accessible_get_instance_private (self);
 
-  if (priv->adjustment)
+  if (priv->adjustment != NULL &&
+      priv->value_changed_id != 0)
     {
-      g_signal_handlers_disconnect_by_func (priv->adjustment,
-                                            G_CALLBACK (gtk_range_accessible_value_changed),
-                                            accessible);
-      g_object_unref (priv->adjustment);
-      priv->adjustment = NULL;
+      g_signal_handler_disconnect (priv->adjustment, priv->value_changed_id);
+      priv->value_changed_id = 0;
     }
+
+  g_clear_object (&priv->adjustment);
+}
+
+void
+gtk_range_accessible_update_adjustment (GtkRangeAccessible *self)
+{
+  gtk_range_accessible_widget_unset (GTK_ACCESSIBLE (self));
+  gtk_range_accessible_widget_set (GTK_ACCESSIBLE (self));
 }
 
 static void
@@ -82,42 +93,40 @@ gtk_range_accessible_initialize (AtkObject *obj,
 }
 
 static void
-gtk_range_accessible_notify_gtk (GObject    *obj,
-                                 GParamSpec *pspec)
+gtk_range_accessible_dispose (GObject *gobject)
 {
-  GtkWidget *widget = GTK_WIDGET (obj);
-  AtkObject *range;
+  GtkRangeAccessible *self = GTK_RANGE_ACCESSIBLE (gobject);
+  GtkRangeAccessiblePrivate *priv = gtk_range_accessible_get_instance_private (self);
 
-  if (strcmp (pspec->name, "adjustment") == 0)
+  if (priv->adjustment != NULL && priv->value_changed_id != 0)
     {
-      range = gtk_widget_get_accessible (widget);
-      gtk_range_accessible_widget_unset (GTK_ACCESSIBLE (range));
-      gtk_range_accessible_widget_set (GTK_ACCESSIBLE (range));
+      g_signal_handler_disconnect (priv->adjustment, priv->value_changed_id);
+      priv->value_changed_id = 0;
     }
-  else
-    GTK_WIDGET_ACCESSIBLE_CLASS (gtk_range_accessible_parent_class)->notify_gtk (obj, pspec);
-}
 
+  g_clear_object (&priv->adjustment);
+
+  G_OBJECT_CLASS (gtk_range_accessible_parent_class)->dispose (gobject);
+}
 
 static void
 gtk_range_accessible_class_init (GtkRangeAccessibleClass *klass)
 {
-  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  AtkObjectClass *atkobject_class = ATK_OBJECT_CLASS (klass);
   GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
-  GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
 
-  class->initialize = gtk_range_accessible_initialize;
+  gobject_class->dispose = gtk_range_accessible_dispose;
+
+  atkobject_class->initialize = gtk_range_accessible_initialize;
 
   accessible_class->widget_set = gtk_range_accessible_widget_set;
   accessible_class->widget_unset = gtk_range_accessible_widget_unset;
-
-  widget_class->notify_gtk = gtk_range_accessible_notify_gtk;
 }
 
 static void
 gtk_range_accessible_init (GtkRangeAccessible *range)
 {
-  range->priv = gtk_range_accessible_get_instance_private (range);
 }
 
 static void
diff --git a/gtk/a11y/gtkrangeaccessible.h b/gtk/a11y/gtkrangeaccessible.h
index 4d0352628a..8779fb8eae 100644
--- a/gtk/a11y/gtkrangeaccessible.h
+++ b/gtk/a11y/gtkrangeaccessible.h
@@ -35,13 +35,10 @@ G_BEGIN_DECLS
 
 typedef struct _GtkRangeAccessible        GtkRangeAccessible;
 typedef struct _GtkRangeAccessibleClass   GtkRangeAccessibleClass;
-typedef struct _GtkRangeAccessiblePrivate GtkRangeAccessiblePrivate;
 
 struct _GtkRangeAccessible
 {
   GtkWidgetAccessible parent;
-
-  GtkRangeAccessiblePrivate *priv;
 };
 
 struct _GtkRangeAccessibleClass
@@ -52,6 +49,9 @@ struct _GtkRangeAccessibleClass
 GDK_AVAILABLE_IN_ALL
 GType gtk_range_accessible_get_type (void);
 
+/*< private >*/
+void    gtk_range_accessible_update_adjustment  (GtkRangeAccessible *self);
+
 G_END_DECLS
 
 #endif /* __GTK_RANGE_ACCESSIBLE_H__ */
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 916b63e2fc..f36fe248b2 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -673,6 +673,15 @@ gtk_range_set_adjustment (GtkRange      *range,
 
       gtk_range_adjustment_changed (adjustment, range);
       gtk_range_adjustment_value_changed (adjustment, range);
+
+      {
+        GtkRangeAccessible *accessible =
+          GTK_RANGE_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (range)));
+
+        if (accessible != NULL)
+          gtk_range_accessible_update_adjustment (accessible);
+      }
+
       g_object_notify_by_pspec (G_OBJECT (range), properties[PROP_ADJUSTMENT]);
     }
 }


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