a11y: Add an accessible for widgets with children
authorMatthias Clasen <mclasen@redhat.com>
Thu, 6 Feb 2020 04:05:01 +0000 (23:05 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 6 Feb 2020 21:54:59 +0000 (16:54 -0500)
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.

gtk/a11y/gtkcompositeaccessible.c [new file with mode: 0644]
gtk/a11y/gtkcompositeaccessible.h [new file with mode: 0644]
gtk/a11y/meson.build
gtk/gtk-a11y.h

diff --git a/gtk/a11y/gtkcompositeaccessible.c b/gtk/a11y/gtkcompositeaccessible.c
new file mode 100644 (file)
index 0000000..8e8a629
--- /dev/null
@@ -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 (file)
index 0000000..bc6a2bb
--- /dev/null
@@ -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__ */
index 550e4e7173b583bde38058a1648a01f81ede6d3f..d8f330e0161de72e5d02bdcb00a1e27ba675707d 100644 (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',
index 7afaf753dedcfe99218eb208b4285a59572ef20a..05a0cb21bc84f119b3fb01542d21811888bb2be0 100644 (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>