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



commit 9d51aa14433ba315488ae53d4f9a0b82396eff3d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 23 20:08:18 2020 +0100

    a11y: Drop notify_gtk() from GtkButtonAccessible
    
    Make GtkButton notify the accessible state directly when updating the
    label.

 gtk/a11y/gtkbuttonaccessible.c | 25 +++++++++----------------
 gtk/a11y/gtkbuttonaccessible.h |  3 +++
 gtk/gtkbutton.c                |  9 +++++++++
 3 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/gtk/a11y/gtkbuttonaccessible.c b/gtk/a11y/gtkbuttonaccessible.c
index b8f30658e9..3c1385dc78 100644
--- a/gtk/a11y/gtkbuttonaccessible.c
+++ b/gtk/a11y/gtkbuttonaccessible.c
@@ -171,37 +171,30 @@ gtk_button_accessible_ref_state_set (AtkObject *obj)
   return state_set;
 }
 
-static void
-gtk_button_accessible_notify_gtk (GObject    *obj,
-                                  GParamSpec *pspec)
+void
+gtk_button_accessible_update_label (GtkButtonAccessible *self)
 {
-  GtkWidget *widget = GTK_WIDGET (obj);
-  AtkObject *atk_obj = gtk_widget_get_accessible (widget);
+  g_return_if_fail (GTK_IS_BUTTON_ACCESSIBLE (self));
 
-  if (strcmp (pspec->name, "label") == 0)
-    {
-      if (atk_obj->name == NULL)
-        g_object_notify (G_OBJECT (atk_obj), "accessible-name");
+  /* If we don't have an overridden name, we use the label as the
+   * accessible name
+   */
+  if (atk_object_get_name (ATK_OBJECT (self)) == NULL)
+    g_object_notify (G_OBJECT (self), "accessible-name");
 
-      g_signal_emit_by_name (atk_obj, "visible-data-changed");
-    }
-  else
-    GTK_WIDGET_ACCESSIBLE_CLASS (gtk_button_accessible_parent_class)->notify_gtk (obj, pspec);
+  g_signal_emit_by_name (self, "visible-data-changed");
 }
 
 static void
 gtk_button_accessible_class_init (GtkButtonAccessibleClass *klass)
 {
   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-  GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
 
   class->get_name = gtk_button_accessible_get_name;
   class->get_n_children = gtk_button_accessible_get_n_children;
   class->ref_child = gtk_button_accessible_ref_child;
   class->ref_state_set = gtk_button_accessible_ref_state_set;
   class->initialize = gtk_button_accessible_initialize;
-
-  widget_class->notify_gtk = gtk_button_accessible_notify_gtk;
 }
 
 static void
diff --git a/gtk/a11y/gtkbuttonaccessible.h b/gtk/a11y/gtkbuttonaccessible.h
index 077344007d..1c49c329b6 100644
--- a/gtk/a11y/gtkbuttonaccessible.h
+++ b/gtk/a11y/gtkbuttonaccessible.h
@@ -52,6 +52,9 @@ struct _GtkButtonAccessibleClass
 GDK_AVAILABLE_IN_ALL
 GType gtk_button_accessible_get_type (void);
 
+/*< private >*/
+void    gtk_button_accessible_update_label      (GtkButtonAccessible *self);
+
 G_END_DECLS
 
 #endif /* __GTK_BUTTON_ACCESSIBLE_H__ */
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index fd9cbf7abc..dc96c752b1 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -836,6 +836,15 @@ gtk_button_set_label (GtkButton   *button,
 
   gtk_label_set_label (GTK_LABEL (priv->child), label);
   gtk_button_set_child_type (button, LABEL_CHILD);
+
+  {
+    GtkButtonAccessible *accessible =
+      GTK_BUTTON_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (button)));
+
+    if (accessible != NULL)
+      gtk_button_accessible_update_label (accessible);
+  }
+
   g_object_notify_by_pspec (G_OBJECT (button), props[PROP_LABEL]);
 }
 


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