From 28e1f288c3e27bb8d412341e17285840cc72065b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 18 Jun 2023 13:00:06 -0400 Subject: [PATCH] infobar: Improve a11y labelling Treat the close button the same way we treat the window close button, wrt. to accessibility. --- gtk/deprecated/gtkinfobar.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gtk/deprecated/gtkinfobar.c b/gtk/deprecated/gtkinfobar.c index e5eb224af9..6e9e378114 100644 --- a/gtk/deprecated/gtkinfobar.c +++ b/gtk/deprecated/gtkinfobar.c @@ -37,6 +37,7 @@ #include "gtkbox.h" #include "gtklabel.h" #include "gtkbutton.h" +#include "gtkimage.h" #include "gtkenums.h" #include "deprecated/gtkdialog.h" #include "gtkrevealer.h" @@ -46,6 +47,8 @@ #include "gtkbinlayout.h" #include "gtkgestureclick.h" +#include + G_GNUC_BEGIN_IGNORE_DEPRECATIONS /** @@ -456,6 +459,7 @@ gtk_info_bar_init (GtkInfoBar *info_bar) GtkWidget *widget = GTK_WIDGET (info_bar); GtkWidget *main_box; GtkGesture *gesture; + GtkWidget *image; /* message-type is a CONSTRUCT property, so we init to a value * different from its default to trigger its property setter @@ -478,11 +482,23 @@ gtk_info_bar_init (GtkInfoBar *info_bar) gtk_widget_set_valign (info_bar->action_area, GTK_ALIGN_CENTER); gtk_box_append (GTK_BOX (main_box), info_bar->action_area); - info_bar->close_button = gtk_button_new_from_icon_name ("window-close-symbolic"); + info_bar->close_button = gtk_button_new (); + /* The icon is not relevant for accessibility purposes */ + image = g_object_new (GTK_TYPE_IMAGE, + "accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION, + "icon-name", "window-close-symbolic", + "use-fallback", TRUE, + NULL); + gtk_button_set_child (GTK_BUTTON (info_bar->close_button), image); gtk_widget_hide (info_bar->close_button); gtk_widget_set_valign (info_bar->close_button, GTK_ALIGN_CENTER); gtk_widget_add_css_class (info_bar->close_button, "close"); gtk_box_append (GTK_BOX (main_box), info_bar->close_button); + gtk_accessible_update_property (GTK_ACCESSIBLE (info_bar->close_button), + GTK_ACCESSIBLE_PROPERTY_LABEL, _("Close"), + GTK_ACCESSIBLE_PROPERTY_DESCRIPTION, _("Close the infobar"), + -1); + g_signal_connect (info_bar->close_button, "clicked", G_CALLBACK (close_button_clicked_cb), info_bar); -- 2.30.2