summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Tyrychtr <lukastyrychtr@gmail.com>2022-09-21 15:34:17 +0200
committerLukáš Tyrychtr <lukastyrychtr@gmail.com>2022-09-21 15:34:17 +0200
commit33e5d2c307a7634a31d617675e98b010864e65b2 (patch)
tree9224ef37cb12d2babe1dcfa4ffb2abc622dddac5
parenta012f5bddbc9bc0d2342c7d4f4512f632687ea8c (diff)
downloadgtk+-33e5d2c307a7634a31d617675e98b010864e65b2.tar.gz
GtkShortcutsWindow: Allow a screen reader user to browse the available shortcuts
That required making the shortcuts focusable and with a meaningful accessibility labels.
-rw-r--r--gtk/gtkshortcutlabel.c20
-rw-r--r--gtk/gtkshortcutsshortcut.c13
2 files changed, 32 insertions, 1 deletions
diff --git a/gtk/gtkshortcutlabel.c b/gtk/gtkshortcutlabel.c
index 53a227ab00..9ae12e8ed4 100644
--- a/gtk/gtkshortcutlabel.c
+++ b/gtk/gtkshortcutlabel.c
@@ -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
diff --git a/gtk/gtkshortcutsshortcut.c b/gtk/gtkshortcutsshortcut.c
index cf685d33c3..11510eda03 100644
--- a/gtk/gtkshortcutsshortcut.c
+++ b/gtk/gtkshortcutsshortcut.c
@@ -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);
}