a11y: Implement new GtkAccessible vfuncs in GtkStack
authorLukáš Tyrychtr <lukastyrychtr@gmail.com>
Mon, 12 Sep 2022 15:23:29 +0000 (17:23 +0200)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 3 Feb 2023 10:49:17 +0000 (11:49 +0100)
Implement the virtual a11y children for GtkStack.

gtk/gtkstack.c

index 47e7f813245a2cec888d2a6b2a6bec396fc54f56..e191d1252d75e326d42ea1bfd755fbc28220f8ec 100644 (file)
@@ -165,9 +165,12 @@ typedef struct {
 } GtkStackPrivate;
 
 static void gtk_stack_buildable_interface_init (GtkBuildableIface *iface);
+static void gtk_stack_accessible_init (GtkAccessibleInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkStack, gtk_stack, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkStack)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE,
+                                                gtk_stack_accessible_init)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                 gtk_stack_buildable_interface_init))
 enum  {
@@ -253,11 +256,43 @@ gtk_stack_page_accessible_get_platform_state (GtkAccessible              *self,
   return FALSE;
 }
 
+static GtkAccessible *
+gtk_stack_page_accessible_get_parent (GtkAccessible *accessible) {
+  GtkStackPage *page = GTK_STACK_PAGE (accessible);
+
+  if (page->widget == NULL)
+    return NULL;
+  else
+  return GTK_ACCESSIBLE (gtk_widget_get_parent (page->widget));
+}
+
+static GtkAccessible *
+gtk_stack_page_accessible_get_child_at_index(GtkAccessible *accessible, guint index) {
+  GtkStackPage *page = GTK_STACK_PAGE (accessible);
+
+  if (index == 0 && page->widget != NULL)
+    return GTK_ACCESSIBLE (page->widget);
+  else
+    return NULL;
+}
+
+static gboolean
+gtk_stack_page_accessible_get_bounds (GtkAccessible *accessible, int *x, int *y, int *width, int *height) {
+  GtkStackPage *page = GTK_STACK_PAGE (accessible);
+  if (page->widget != NULL)
+    return gtk_accessible_get_bounds (GTK_ACCESSIBLE (page->widget), x, y, width, height);
+  else
+    return false;
+}
+
 static void
 gtk_stack_page_accessible_init (GtkAccessibleInterface *iface)
 {
   iface->get_at_context = gtk_stack_page_accessible_get_at_context;
   iface->get_platform_state = gtk_stack_page_accessible_get_platform_state;
+  iface->get_parent = gtk_stack_page_accessible_get_parent;
+  iface->get_child_at_index = gtk_stack_page_accessible_get_child_at_index;
+  iface->get_bounds = gtk_stack_page_accessible_get_bounds;
 }
 
 G_DEFINE_TYPE_WITH_CODE (GtkStackPage, gtk_stack_page, G_TYPE_OBJECT,
@@ -728,6 +763,21 @@ gtk_stack_buildable_interface_init (GtkBuildableIface *iface)
   iface->add_child = gtk_stack_buildable_add_child;
 }
 
+static GtkAccessible *
+gtk_stack_accessible_get_child_at_index (GtkAccessible *accessible, guint index)
+{
+  GtkStack *stack = GTK_STACK (accessible);
+  GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
+  GtkStackPage *page = g_list_nth_data (priv->children, index);
+  return GTK_ACCESSIBLE (page);
+}
+
+static void
+gtk_stack_accessible_init(GtkAccessibleInterface *iface)
+{
+  iface->get_child_at_index = gtk_stack_accessible_get_child_at_index;
+}
+
 static void stack_remove (GtkStack  *stack,
                           GtkWidget *child,
                           gboolean   in_dispose);