[gtk+] menu button: Improve accessibility



commit fec8a1ee7fb40a4739a6b12eb2bb211a60c69b08
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 13 18:38:18 2015 -0400

    menu button: Improve accessibility
    
    Rework the way we assign an accessible name to menu buttons,
    to make sure we pick up a label, should the button contain
    one, and only override the name with "Menu" as a fallback.

 gtk/a11y/gtkmenubuttonaccessible.c |   19 +++++++++++++++++++
 gtk/gtkmenubutton.c                |    5 -----
 po/POTFILES.in                     |    1 +
 3 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/gtk/a11y/gtkmenubuttonaccessible.c b/gtk/a11y/gtkmenubuttonaccessible.c
index c640fec..d4a9162 100644
--- a/gtk/a11y/gtkmenubuttonaccessible.c
+++ b/gtk/a11y/gtkmenubuttonaccessible.c
@@ -18,6 +18,7 @@
 #include "config.h"
 
 #include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
 #include "gtkmenubuttonaccessible.h"
 
 
@@ -84,11 +85,29 @@ gtk_menu_button_accessible_ref_child (AtkObject *obj,
   return accessible;
 }
 
+static const gchar *
+gtk_menu_button_accessible_get_name (AtkObject *obj)
+{
+  const gchar *name = NULL;
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  name = ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->get_name (obj);
+  if (name != NULL)
+    return name;
+
+  return _("Menu");
+}
+
 static void
 gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass)
 {
   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
 
+  class->get_name = gtk_menu_button_accessible_get_name;
   class->initialize = gtk_menu_button_accessible_initialize;
   class->get_n_children = gtk_menu_button_accessible_get_n_children;
   class->ref_child = gtk_menu_button_accessible_ref_child;
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index f30c76f..594d119 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -624,7 +624,6 @@ static void
 gtk_menu_button_init (GtkMenuButton *menu_button)
 {
   GtkMenuButtonPrivate *priv;
-  AtkObject *accessible;
 
   priv = gtk_menu_button_get_instance_private (menu_button);
   menu_button->priv = priv;
@@ -634,10 +633,6 @@ gtk_menu_button_init (GtkMenuButton *menu_button)
   add_arrow (menu_button);
 
   gtk_widget_set_sensitive (GTK_WIDGET (menu_button), FALSE);
-
-  accessible = gtk_widget_get_accessible (GTK_WIDGET (menu_button));
-  if (GTK_IS_ACCESSIBLE (accessible))
-    atk_object_set_name (accessible, _("Menu"));
 }
 
 /**
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 92c313c..96631d3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -30,6 +30,7 @@ gtk/a11y/gtkcomboboxaccessible.c
 gtk/a11y/gtkentryaccessible.c
 gtk/a11y/gtkexpanderaccessible.c
 gtk/a11y/gtkimageaccessible.c
+gtk/a11y/gtkmenubuttonaccessible.c
 gtk/a11y/gtkmenuitemaccessible.c
 gtk/a11y/gtkrenderercellaccessible.c
 gtk/a11y/gtkscalebuttonaccessible.c


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