a11y: Add an accessible for widgets with children

We've started to turns containers into widgets which
just happen to have children, and some of these need
to be exposed to the a11y stack.

This adds a very minimal implementation, it does not
currently emit change notification when children are
added or removed.
This commit is contained in:
Matthias Clasen 2020-02-05 23:05:01 -05:00
parent b3f5243aeb
commit d01070d472
4 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,87 @@
/* GTK+ - accessibility implementations
* Copyright 2020 Red Hat, 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 "gtkcompositeaccessible.h"
#include <gtk/gtk.h>
#include "gtkwidgetprivate.h"
G_DEFINE_TYPE (GtkCompositeAccessible, gtk_composite_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
static int
gtk_composite_accessible_get_n_children (AtkObject *obj)
{
GtkWidget *widget;
GtkWidget *child;
int count = 0;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return 0;
for (child = gtk_widget_get_first_child (widget); child; child = gtk_widget_get_next_sibling (child))
count++;
return count;
}
static AtkObject *
gtk_composite_accessible_ref_child (AtkObject *obj,
int i)
{
GtkWidget *widget;
GtkWidget *child;
int pos;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return NULL;
for (child = gtk_widget_get_first_child (widget), pos = 0; child && pos < i; child = gtk_widget_get_next_sibling (child), pos++);
if (child)
return g_object_ref (gtk_widget_get_accessible (GTK_WIDGET (child)));
return NULL;
}
static void
gtk_composite_accessible_initialize (AtkObject *obj,
gpointer data)
{
ATK_OBJECT_CLASS (gtk_composite_accessible_parent_class)->initialize (obj, data);
obj->role = ATK_ROLE_FILLER;
}
static void
gtk_composite_accessible_class_init (GtkCompositeAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
class->initialize = gtk_composite_accessible_initialize;
class->get_n_children = gtk_composite_accessible_get_n_children;
class->ref_child = gtk_composite_accessible_ref_child;
}
static void
gtk_composite_accessible_init (GtkCompositeAccessible *composite)
{
}

View File

@ -0,0 +1,55 @@
/* GTK+ - accessibility implementations
* Copyright 2020 Red Hat, 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_COMPOSITE_ACCESSIBLE_H__
#define __GTK_COMPOSITE_ACCESSIBLE_H__
#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk-a11y.h> can be included directly."
#endif
#include <gtk/gtkwidget.h>
#include <gtk/a11y/gtkwidgetaccessible.h>
G_BEGIN_DECLS
#define GTK_TYPE_COMPOSITE_ACCESSIBLE (gtk_composite_accessible_get_type ())
#define GTK_COMPOSITE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMPOSITE_ACCESSIBLE, GtkCompositeAccessible))
#define GTK_COMPOSITE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COMPOSITE_ACCESSIBLE, GtkCompositeAccessibleClass))
#define GTK_IS_COMPOSITE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COMPOSITE_ACCESSIBLE))
#define GTK_IS_COMPOSITE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COMPOSITE_ACCESSIBLE))
#define GTK_COMPOSITE_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COMPOSITE_ACCESSIBLE, GtkCompositeAccessibleClass))
typedef struct _GtkCompositeAccessible GtkCompositeAccessible;
typedef struct _GtkCompositeAccessibleClass GtkCompositeAccessibleClass;
struct _GtkCompositeAccessible
{
GtkWidgetAccessible parent;
};
struct _GtkCompositeAccessibleClass
{
GtkWidgetAccessibleClass parent_class;
};
GDK_AVAILABLE_IN_ALL
GType gtk_composite_accessible_get_type (void);
G_END_DECLS
#endif /* __GTK_COMPOSITE_ACCESSIBLE_H__ */

View File

@ -7,6 +7,7 @@ a11y_sources = files([
'gtkcellaccessibleparent.c',
'gtkcolorswatchaccessible.c',
'gtkcomboboxaccessible.c',
'gtkcompositeaccessible.c',
'gtkcontaineraccessible.c',
'gtkcontainercellaccessible.c',
'gtkentryaccessible.c',
@ -58,6 +59,7 @@ a11y_headers = files([
'gtkcellaccessible.h',
'gtkcellaccessibleparent.h',
'gtkcomboboxaccessible.h',
'gtkcompositeaccessible.h',
'gtkcontaineraccessible.h',
'gtkcontainercellaccessible.h',
'gtkentryaccessible.h',

View File

@ -33,6 +33,7 @@
#include <gtk/a11y/gtkcellaccessible.h>
#include <gtk/a11y/gtkcellaccessibleparent.h>
#include <gtk/a11y/gtkcomboboxaccessible.h>
#include <gtk/a11y/gtkcompositeaccessible.h>
#include <gtk/a11y/gtkcontaineraccessible.h>
#include <gtk/a11y/gtkcontainercellaccessible.h>
#include <gtk/a11y/gtkentryaccessible.h>