From 758bcd5343df497af3cf97954db09f4b6bae30b7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 21 Oct 2020 16:34:16 -0400 Subject: [PATCH] popovermenubar: Initial accessibility setup Set roles, properties and relations according to the ARIA authoring practices document. This is not quite complete. --- gtk/gtkpopovermenubar.c | 43 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/gtk/gtkpopovermenubar.c b/gtk/gtkpopovermenubar.c index 1f172e3088..1401c998eb 100644 --- a/gtk/gtkpopovermenubar.c +++ b/gtk/gtkpopovermenubar.c @@ -45,6 +45,12 @@ * * The item whose popover is currently open gets the .active * style class. + * + * # Accessibility + * + * GtkPopoverMenuBar uses the #GTK_ACCESSIBLE_ROLE_MENU_BAR role, + * the menu items use the #GTK_ACCESSIBLE_ROLE_MENU_ITEM role and + * the menus use the #GTK_ACCESSIBLE_ROLE_MENU role. */ @@ -126,7 +132,12 @@ set_active_item (GtkPopoverMenuBar *bar, was_popup = FALSE; if (was_popup && changed) - gtk_popover_popdown (bar->active_item->popover); + { + gtk_accessible_update_state (GTK_ACCESSIBLE (bar->active_item), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); + gtk_popover_popdown (bar->active_item->popover); + } if (changed) { @@ -142,7 +153,12 @@ set_active_item (GtkPopoverMenuBar *bar, if (bar->active_item) { if (popup || (was_popup && changed)) - gtk_popover_popup (bar->active_item->popover); + { + gtk_popover_popup (bar->active_item->popover); + gtk_accessible_update_state (GTK_ACCESSIBLE (bar->active_item), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); + } else if (changed) gtk_widget_grab_focus (GTK_WIDGET (bar->active_item)); } @@ -316,6 +332,22 @@ gtk_popover_menu_bar_item_activate (GtkPopoverMenuBarItem *item) set_active_item (bar, item, TRUE); } +static void +gtk_popover_menu_bar_item_root (GtkWidget *widget) +{ + GtkPopoverMenuBarItem *item = GTK_POPOVER_MENU_BAR_ITEM (widget); + + GTK_WIDGET_CLASS (gtk_popover_menu_bar_item_parent_class)->root (widget); + + gtk_accessible_update_relation (GTK_ACCESSIBLE (widget), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, g_list_append (NULL, item->label), + GTK_ACCESSIBLE_RELATION_CONTROLS, g_list_append (NULL, item->popover), + -1); + gtk_accessible_update_property (GTK_ACCESSIBLE (widget), + GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE, + -1); +} + static void gtk_popover_menu_bar_item_class_init (GtkPopoverMenuBarItemClass *klass) { @@ -325,6 +357,7 @@ gtk_popover_menu_bar_item_class_init (GtkPopoverMenuBarItemClass *klass) object_class->dispose = gtk_popover_menu_bar_item_dispose; object_class->finalize = gtk_popover_menu_bar_item_finalize; + widget_class->root = gtk_popover_menu_bar_item_root; widget_class->measure = gtk_popover_menu_bar_item_measure; widget_class->size_allocate = gtk_popover_menu_bar_item_size_allocate; @@ -340,6 +373,7 @@ gtk_popover_menu_bar_item_class_init (GtkPopoverMenuBarItemClass *klass) G_TYPE_NONE, 0); gtk_widget_class_set_css_name (widget_class, I_("item")); + gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_ITEM); } enum { @@ -552,6 +586,10 @@ gtk_popover_menu_bar_root (GtkWidget *widget) toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); add_to_window (GTK_WINDOW (toplevel), bar); + + gtk_accessible_update_property (GTK_ACCESSIBLE (bar), + GTK_ACCESSIBLE_PROPERTY_ORIENTATION, GTK_ORIENTATION_HORIZONTAL, + -1); } static void @@ -598,6 +636,7 @@ gtk_popover_menu_bar_class_init (GtkPopoverMenuBarClass *klass) gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT); gtk_widget_class_set_css_name (widget_class, I_("menubar")); + gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_BAR); } static void