summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-02-05 23:05:01 -0500
committerMatthias Clasen <mclasen@redhat.com>2020-02-06 16:54:59 -0500
commitd01070d4728e79153fbb0f4555adc26652b42ccb (patch)
treeb1692ab87e2f287716a5c918b6d29dc0a89f5f60
parentb3f5243aeb6a2b06d66b11b8cebcbb8770b2151e (diff)
downloadgtk+-d01070d4728e79153fbb0f4555adc26652b42ccb.tar.gz
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.
-rw-r--r--gtk/a11y/gtkcompositeaccessible.c87
-rw-r--r--gtk/a11y/gtkcompositeaccessible.h55
-rw-r--r--gtk/a11y/meson.build2
-rw-r--r--gtk/gtk-a11y.h1
4 files changed, 145 insertions, 0 deletions
diff --git a/gtk/a11y/gtkcompositeaccessible.c b/gtk/a11y/gtkcompositeaccessible.c
new file mode 100644
index 0000000000..8e8a6297b3
--- /dev/null
+++ b/gtk/a11y/gtkcompositeaccessible.c
@@ -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)
+{
+}
diff --git a/gtk/a11y/gtkcompositeaccessible.h b/gtk/a11y/gtkcompositeaccessible.h
new file mode 100644
index 0000000000..bc6a2bbafc
--- /dev/null
+++ b/gtk/a11y/gtkcompositeaccessible.h
@@ -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__ */
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index 550e4e7173..d8f330e016 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -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',
diff --git a/gtk/gtk-a11y.h b/gtk/gtk-a11y.h
index 7afaf753de..05a0cb21bc 100644
--- a/gtk/gtk-a11y.h
+++ b/gtk/gtk-a11y.h
@@ -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>