Commit f200eebf authored by Matthias Clasen's avatar Matthias Clasen

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.
parent 8a12a88b
......@@ -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 \
......
/* 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)
{
}
/* 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__ */
......@@ -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>
......
......@@ -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
......
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment