From 94f5d2db0dfa81cc99a402970607f6beb81577e2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 18 Jun 2023 20:59:33 -0400 Subject: [PATCH] modelbutton: Set a11y shortcuts --- gtk/gtkmodelbutton.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c index cd8052fe84..853eeb3dd5 100644 --- a/gtk/gtkmodelbutton.c +++ b/gtk/gtkmodelbutton.c @@ -587,6 +587,17 @@ update_accessible_properties (GtkModelButton *button) gtk_accessible_update_relation (GTK_ACCESSIBLE (button), GTK_ACCESSIBLE_RELATION_LABELLED_BY, button->label, NULL, -1); + + if (button->accel_label) + { + const char *text = gtk_label_get_label (GTK_LABEL (button->accel_label)); + gtk_accessible_update_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_KEY_SHORTCUTS, text, + -1); + } + else + gtk_accessible_reset_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_KEY_SHORTCUTS); } static void @@ -831,6 +842,7 @@ update_accel (GtkModelButton *self, if (!self->accel_label) { self->accel_label = g_object_new (GTK_TYPE_LABEL, + "accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION, "css-name", "accelerator", NULL); gtk_widget_insert_before (self->accel_label, GTK_WIDGET (self), NULL); @@ -880,6 +892,8 @@ update_accel (GtkModelButton *self, self->controller = NULL; } } + + update_accessible_properties (self); } static void @@ -1481,7 +1495,7 @@ gtk_model_button_init (GtkModelButton *self) gtk_widget_set_focusable (GTK_WIDGET (self), TRUE); self->role = GTK_BUTTON_ROLE_NORMAL; - self->label = gtk_label_new (""); + self->label = g_object_new (GTK_TYPE_LABEL, "accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION, NULL); gtk_widget_set_halign (self->label, GTK_ALIGN_START); gtk_widget_set_parent (self->label, GTK_WIDGET (self));