From: Matthias Clasen Date: Sat, 10 Jun 2023 14:25:02 +0000 (-0400) Subject: button: Improve accessible setup X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~160^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=cf30a4f30454dce47148b17eedd60dcb231ad768;p=gtk4.git button: Improve accessible setup With the current approach, we get duplicate labels in the accessible name: _Cancel Cancel. Change things around to always set the labelled-by accessible relation if we have a label, and not the label accessible property. --- diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 763b9a50ce..8b92cac301 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -842,7 +842,7 @@ gtk_button_finish_activate (GtkButton *button, * This will also clear any previously set labels. */ void -gtk_button_set_label (GtkButton *button, +gtk_button_set_label (GtkButton *button, const char *label) { GtkButtonPrivate *priv = gtk_button_get_instance_private (button); @@ -853,13 +853,18 @@ gtk_button_set_label (GtkButton *button, if (priv->child_type != LABEL_CHILD || priv->child == NULL) { child = gtk_label_new (NULL); + gtk_button_set_child (button, child); if (priv->use_underline) { gtk_label_set_use_underline (GTK_LABEL (child), priv->use_underline); gtk_label_set_mnemonic_widget (GTK_LABEL (child), GTK_WIDGET (button)); } - - gtk_button_set_child (button, child); + else + { + gtk_accessible_update_relation (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, child, NULL, + -1); + } } gtk_label_set_label (GTK_LABEL (priv->child), label); @@ -869,10 +874,6 @@ gtk_button_set_label (GtkButton *button, gtk_button_set_child_type (button, LABEL_CHILD); - gtk_accessible_update_property (GTK_ACCESSIBLE (button), - GTK_ACCESSIBLE_PROPERTY_LABEL, label, - -1); - g_object_notify_by_pspec (G_OBJECT (button), props[PROP_LABEL]); } diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c index 5d7f3fa157..4c747a3937 100644 --- a/gtk/gtkfontchooserdialog.c +++ b/gtk/gtkfontchooserdialog.c @@ -36,6 +36,7 @@ #include "gtkheaderbar.h" #include "gtkactionable.h" #include "gtkeventcontrollerkey.h" +#include "gtkaccessible.h" G_GNUC_BEGIN_IGNORE_DEPRECATIONS @@ -189,6 +190,10 @@ setup_tweak_button (GtkFontChooserDialog *dialog) gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_button_set_icon_name (GTK_BUTTON (button), "emblem-system-symbolic"); gtk_widget_set_tooltip_text (button, _("Change Font Features")); + gtk_accessible_update_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_LABEL, + _("Change Font Features"), + -1); header = gtk_dialog_get_header_bar (GTK_DIALOG (dialog)); gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button); diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui index 9b0fc90313..e1ccdd932c 100644 --- a/gtk/ui/gtkfontchooserwidget.ui +++ b/gtk/ui/gtkfontchooserwidget.ui @@ -63,19 +63,29 @@ 1 Search font name + + Search font name + + + Filters + pan-down-symbolic + Filters 1 6 + + filter_by_label + - + Filter by 20 10 diff --git a/testsuite/a11y/button.c b/testsuite/a11y/button.c index 105e424f0c..b32682f755 100644 --- a/testsuite/a11y/button.c +++ b/testsuite/a11y/button.c @@ -20,7 +20,8 @@ button_label (void) GtkWidget *button = gtk_button_new_with_label ("Hello"); g_object_ref_sink (button); - gtk_test_accessible_assert_property (button, GTK_ACCESSIBLE_PROPERTY_LABEL, "Hello"); + gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, gtk_widget_get_first_child (button), NULL); g_object_unref (button); } @@ -58,7 +59,8 @@ linkbutton_label (void) GtkWidget *button = gtk_link_button_new ("Hello"); g_object_ref_sink (button); - gtk_test_accessible_assert_property (button, GTK_ACCESSIBLE_PROPERTY_LABEL, "Hello"); + gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, gtk_widget_get_first_child (button), NULL); g_object_unref (button); }