From afbcbb8404b6f0795e7e3696b0b03f95bae7c8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tyrychtr?= Date: Wed, 19 Apr 2023 11:18:48 +0200 Subject: [PATCH] a11y: When a menu item opens a submenu, set its expandable state To help distinguish submenu opening items, mark them as expandable. Previously, they only indicated that they had a popup, which is too general. --- gtk/gtkmodelbutton.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c index 064583623a..d0a65ca65f 100644 --- a/gtk/gtkmodelbutton.c +++ b/gtk/gtkmodelbutton.c @@ -560,12 +560,21 @@ static void update_accessible_properties (GtkModelButton *button) { if (button->menu_name || button->popover) - gtk_accessible_update_property (GTK_ACCESSIBLE (button), - GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE, - -1); + { + gtk_accessible_update_state (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); + gtk_accessible_update_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE, + -1); + } else - gtk_accessible_reset_property (GTK_ACCESSIBLE (button), - GTK_ACCESSIBLE_PROPERTY_HAS_POPUP); + { + gtk_accessible_reset_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_HAS_POPUP); + gtk_accessible_reset_state (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_STATE_EXPANDED); + } if (button->popover) gtk_accessible_update_relation (GTK_ACCESSIBLE (button), @@ -1043,7 +1052,12 @@ switch_menu (GtkModelButton *button) stack = gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK); if (stack != NULL) - gtk_stack_set_visible_child_name (GTK_STACK (stack), button->menu_name); + { + gtk_stack_set_visible_child_name (GTK_STACK (stack), button->menu_name); + gtk_accessible_update_state (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_STATE_EXPANDED, TRUE, + -1); + } } static void @@ -1063,6 +1077,10 @@ gtk_model_button_clicked (GtkModelButton *self) gtk_popover_popup (GTK_POPOVER (submenu)); gtk_popover_menu_set_open_submenu (menu, submenu); gtk_popover_menu_set_parent_menu (GTK_POPOVER_MENU (submenu), GTK_WIDGET (menu)); + + gtk_accessible_update_state (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_STATE_EXPANDED, TRUE, + -1); } else if (!self->keep_open) { @@ -1071,6 +1089,10 @@ gtk_model_button_clicked (GtkModelButton *self) popover = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_POPOVER); if (popover) gtk_popover_popdown (GTK_POPOVER (popover)); + + gtk_accessible_update_state (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); } if (self->action_helper)