GtkShortcutsWindow: Allow a screen reader user to browse the available shortcuts
authorLukáš Tyrychtr <lukastyrychtr@gmail.com>
Wed, 21 Sep 2022 13:34:17 +0000 (15:34 +0200)
committerLukáš Tyrychtr <lukastyrychtr@gmail.com>
Wed, 21 Sep 2022 13:34:17 +0000 (15:34 +0200)
That required making the shortcuts focusable and with a meaningful
accessibility labels.

gtk/gtkshortcutlabel.c
gtk/gtkshortcutsshortcut.c

index 53a227ab006731c9048d69bfce666421773030fa..9ae12e8ed46e10e13c6038f8af50c8c722b89334 100644 (file)
@@ -357,6 +357,9 @@ parse_range (GtkShortcutLabel *self,
 static void
 clear_children (GtkShortcutLabel *self)
 {
+                                 gtk_accessible_reset_relation (GTK_ACCESSIBLE (self),
+                                                                GTK_ACCESSIBLE_RELATION_LABELLED_BY);
+
   GtkWidget *child;
 
   child = gtk_widget_get_first_child (GTK_WIDGET (self));
@@ -376,6 +379,10 @@ gtk_shortcut_label_rebuild (GtkShortcutLabel *self)
 {
   char **accels;
   int k;
+  GtkAccessibleRelation relation = GTK_ACCESSIBLE_RELATION_LABELLED_BY;
+  GValue value = G_VALUE_INIT;
+  GList *parts = NULL;
+  GtkWidget *child;
 
   clear_children (self);
 
@@ -402,6 +409,19 @@ gtk_shortcut_label_rebuild (GtkShortcutLabel *self)
         }
     }
   g_strfreev (accels);
+
+  /* All of the child labels are a part of our a11y label */
+  for(child = gtk_widget_get_last_child (GTK_WIDGET (self));
+      child != NULL;
+      child = gtk_widget_get_prev_sibling (child))
+    {
+      parts = g_list_prepend (parts, child);
+        }
+  gtk_accessible_relation_init_value (relation, &value);
+  g_value_set_pointer (&value, parts);
+  gtk_accessible_update_relation_value (GTK_ACCESSIBLE (self),
+                                        1, &relation, &value);
+
 }
 
 static void
index cf685d33c3005ada5e2046e0073e71f7539e0c94..11510eda03ed05f1377d9f8b2c5a31ccabb870ea 100644 (file)
@@ -712,12 +712,18 @@ gtk_shortcuts_shortcut_class_init (GtkShortcutsShortcutClass *klass)
 
   g_object_class_install_properties (object_class, LAST_PROP, properties);
   gtk_widget_class_set_css_name (widget_class, I_("shortcut"));
-  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP);
+  /* It is semantically a label, but the label role has such specific meaning in Orca
+   * as to be unusable in this context.
+   */
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_WIDGET);
 }
 
 static void
 gtk_shortcuts_shortcut_init (GtkShortcutsShortcut *self)
 {
+  gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
+
+
   self->box = g_object_new (GTK_TYPE_BOX,
                             "orientation", GTK_ORIENTATION_HORIZONTAL,
                             "spacing", 12,
@@ -760,4 +766,9 @@ gtk_shortcuts_shortcut_init (GtkShortcutsShortcut *self)
                                  NULL);
   gtk_widget_add_css_class (GTK_WIDGET (self->subtitle), "dim-label");
   gtk_box_append (GTK_BOX (self->title_box), GTK_WIDGET (self->subtitle));
+
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (self),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->title, NULL,
+                                  GTK_ACCESSIBLE_RELATION_DESCRIBED_BY, self->accelerator, NULL,
+                                  -1);
 }