[gtk+] Improve menubutton a11y
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Improve menubutton a11y
- Date: Fri, 20 Dec 2013 18:31:36 +0000 (UTC)
commit f200eebfd65886a535898aab0fd2a34661925680
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 20 10:58:32 2013 -0500
Improve menubutton a11y
The button now claims its menu as a child for a11y purposes,
which makes it possible for ATs to see it when the navigate
the tree top-down.
Update the a11y test to match.
gtk/a11y/Makefile.am | 2 +
gtk/a11y/gtkmenubuttonaccessible.c | 100 ++++++++++++++++++++++++++++++++++++
gtk/a11y/gtkmenubuttonaccessible.h | 57 ++++++++++++++++++++
gtk/gtk-a11y.h | 1 +
gtk/gtkmenubutton.c | 3 +
testsuite/a11y/menubutton.txt | 15 +++++
6 files changed, 178 insertions(+), 0 deletions(-)
---
diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am
index 8b29ae7..b32099e 100644
--- a/gtk/a11y/Makefile.am
+++ b/gtk/a11y/Makefile.am
@@ -31,6 +31,7 @@ gtka11y_c_sources = \
gtklistboxrowaccessible.c \
gtklockbuttonaccessible.c \
gtkmenuaccessible.c \
+ gtkmenubuttonaccessible.c \
gtkmenushellaccessible.c \
gtkmenuitemaccessible.c \
gtknotebookaccessible.c \
@@ -82,6 +83,7 @@ gtka11yinclude_HEADERS = \
gtklistboxrowaccessible.h \
gtklockbuttonaccessible.h \
gtkmenuaccessible.h \
+ gtkmenubuttonaccessible.h \
gtkmenuitemaccessible.h \
gtkmenushellaccessible.h \
gtknotebookaccessible.h \
diff --git a/gtk/a11y/gtkmenubuttonaccessible.c b/gtk/a11y/gtkmenubuttonaccessible.c
new file mode 100644
index 0000000..c5c8977
--- /dev/null
+++ b/gtk/a11y/gtkmenubuttonaccessible.c
@@ -0,0 +1,100 @@
+/* GTK+ - accessibility implementations
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include "gtkmenubuttonaccessible.h"
+
+
+G_DEFINE_TYPE (GtkMenuButtonAccessible, gtk_menu_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE)
+
+static void
+gtk_menu_button_accessible_initialize (AtkObject *accessible,
+ gpointer data)
+{
+ ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->initialize (accessible, data);
+}
+
+static gint
+gtk_menu_button_accessible_get_n_children (AtkObject* obj)
+{
+ GtkWidget *widget;
+ GtkWidget *submenu;
+ gint count = 0;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+ if (widget == NULL)
+ return count;
+
+ submenu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget));
+ if (submenu)
+ {
+ GList *children;
+
+ children = gtk_container_get_children (GTK_CONTAINER (submenu));
+ count = g_list_length (children);
+ g_list_free (children);
+ }
+ return count;
+}
+
+static AtkObject *
+gtk_menu_button_accessible_ref_child (AtkObject *obj,
+ gint i)
+{
+ AtkObject *accessible;
+ GtkWidget *widget;
+ GtkWidget *submenu;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+ if (widget == NULL)
+ return NULL;
+
+ submenu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget));
+ if (submenu)
+ {
+ GList *children;
+ GList *tmp_list;
+
+ children = gtk_container_get_children (GTK_CONTAINER (submenu));
+ tmp_list = g_list_nth (children, i);
+ if (tmp_list)
+ {
+ accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
+ g_object_ref (accessible);
+ }
+ g_list_free (children);
+ }
+
+ return accessible;
+}
+
+static void
+gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass)
+{
+ AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+ 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;
+}
+
+static void
+gtk_menu_button_accessible_init (GtkMenuButtonAccessible *menu_button)
+{
+}
diff --git a/gtk/a11y/gtkmenubuttonaccessible.h b/gtk/a11y/gtkmenubuttonaccessible.h
new file mode 100644
index 0000000..059f209
--- /dev/null
+++ b/gtk/a11y/gtkmenubuttonaccessible.h
@@ -0,0 +1,57 @@
+/* GTK+ - accessibility implementations
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_MENU_BUTTON_ACCESSIBLE_H__
+#define __GTK_MENU_BUTTON_ACCESSIBLE_H__
+
+#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk-a11y.h> can be included directly."
+#endif
+
+#include <gtk/a11y/gtktogglebuttonaccessible.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_MENU_BUTTON_ACCESSIBLE (gtk_menu_button_accessible_get_type ())
+#define GTK_MENU_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessible))
+#define GTK_MENU_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessibleClass))
+#define GTK_IS_MENU_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_TYPE_MENU_BUTTON_ACCESSIBLE))
+#define GTK_IS_MENU_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_TYPE_MENU_BUTTON_ACCESSIBLE))
+#define GTK_MENU_BUTTON_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessibleClass))
+
+typedef struct _GtkMenuButtonAccessible GtkMenuButtonAccessible;
+typedef struct _GtkMenuButtonAccessibleClass GtkMenuButtonAccessibleClass;
+typedef struct _GtkMenuButtonAccessiblePrivate GtkMenuButtonAccessiblePrivate;
+
+struct _GtkMenuButtonAccessible
+{
+ GtkToggleButtonAccessible parent;
+
+ GtkMenuButtonAccessiblePrivate *priv;
+};
+
+struct _GtkMenuButtonAccessibleClass
+{
+ GtkToggleButtonAccessibleClass parent_class;
+};
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_menu_button_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_MENU_BUTTON_ACCESSIBLE_H__ */
diff --git a/gtk/gtk-a11y.h b/gtk/gtk-a11y.h
index 8e395a6..6be98e6 100644
--- a/gtk/gtk-a11y.h
+++ b/gtk/gtk-a11y.h
@@ -52,6 +52,7 @@
#include <gtk/a11y/gtklistboxrowaccessible.h>
#include <gtk/a11y/gtklockbuttonaccessible.h>
#include <gtk/a11y/gtkmenuaccessible.h>
+#include <gtk/a11y/gtkmenubuttonaccessible.h>
#include <gtk/a11y/gtkmenuitemaccessible.h>
#include <gtk/a11y/gtkmenushellaccessible.h>
#include <gtk/a11y/gtknotebookaccessible.h>
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 2ccb26e..bef59c4 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -149,6 +149,7 @@
#include "gtkwindow.h"
#include "gtkmain.h"
#include "gtkaccessible.h"
+#include "a11y/gtkmenubuttonaccessible.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@@ -562,6 +563,8 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
GTK_TYPE_ARROW_TYPE,
GTK_ARROW_DOWN,
G_PARAM_READWRITE));
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_MENU_BUTTON_ACCESSIBLE);
}
static void
diff --git a/testsuite/a11y/menubutton.txt b/testsuite/a11y/menubutton.txt
index d61eb72..27a20fd 100644
--- a/testsuite/a11y/menubutton.txt
+++ b/testsuite/a11y/menubutton.txt
@@ -22,3 +22,18 @@ window1
<AtkAction>
action 0 name: click
action 0 description: Clicks the button
+ imagemenuitem
+ "menu item"
+ parent: menu
+ index: 0
+ name: New
+ state: enabled selectable sensitive visible
+ toolkit: gtk
+ <AtkComponent>
+ layer: popup
+ alpha: 1
+ <AtkAction>
+ action 0 name: click
+ action 0 description: Clicks the menuitem
+ action 0 keybinding: n;;
+ <AtkSelection>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]