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/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c index 7edd262714..c380f1f936 100644 --- a/gtk/gtkcolorchooserwidget.c +++ b/gtk/gtkcolorchooserwidget.c @@ -20,6 +20,7 @@ #include "deprecated/gtkcolorchooserprivate.h" #include "deprecated/gtkcolorchooserwidget.h" +#include "gtkcolorchooserwidgetprivate.h" #include "gtkcoloreditorprivate.h" #include "gtkcolorswatchprivate.h" #include "gtkgrid.h" @@ -305,8 +306,8 @@ scale_round (double value, return (guint)value; } -static char * -accessible_color_name (GdkRGBA *color) +char * +accessible_color_name (const GdkRGBA *color) { if (color->alpha < 1.0) return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"), @@ -566,6 +567,9 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc) connect_button_signals (button, cc); gtk_color_swatch_set_icon (GTK_COLOR_SWATCH (button), "list-add-symbolic"); gtk_color_swatch_set_selectable (GTK_COLOR_SWATCH (button), FALSE); + gtk_accessible_update_property (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_PROPERTY_LABEL, _("Add Color"), + -1); gtk_box_append (GTK_BOX (box), button); cc->settings = g_settings_new ("org.gtk.gtk4.Settings.ColorChooser"); diff --git a/gtk/gtkcolorchooserwidgetprivate.h b/gtk/gtkcolorchooserwidgetprivate.h new file mode 100644 index 0000000000..2c59dddcbb --- /dev/null +++ b/gtk/gtkcolorchooserwidgetprivate.h @@ -0,0 +1,27 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2023 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +char *accessible_color_name (const GdkRGBA *color); + +G_END_DECLS + diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c index f818382dd8..be6fbfa151 100644 --- a/gtk/gtkcoloreditor.c +++ b/gtk/gtkcoloreditor.c @@ -19,10 +19,13 @@ #include "gtkcoloreditorprivate.h" +#include + #include "deprecated/gtkcolorchooserprivate.h" #include "gtkcolorplaneprivate.h" #include "gtkcolorscaleprivate.h" #include "gtkcolorswatchprivate.h" +#include "gtkcolorchooserwidgetprivate.h" #include "gtkcolorutils.h" #include "gtkcolorpickerprivate.h" #include "gtkgrid.h" @@ -158,6 +161,24 @@ entry_text_changed (GtkWidget *entry, editor->text_changed = TRUE; } +static void +update_color (GtkColorEditor *editor, + const GdkRGBA *color) +{ + char *name; + char *text; + name = accessible_color_name (color); + text = g_strdup_printf (_("Color: %s"), name); + gtk_accessible_update_property (GTK_ACCESSIBLE (editor->swatch), + GTK_ACCESSIBLE_PROPERTY_LABEL, text, + -1); + g_free (name); + g_free (text); + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->swatch), color); + gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->a_slider), color); + entry_set_rgba (editor, color); +} + static void hsv_changed (GtkColorEditor *editor) { @@ -172,9 +193,7 @@ hsv_changed (GtkColorEditor *editor) gtk_hsv_to_rgb (h, s, v, &color.red, &color.green, &color.blue); color.alpha = a; - gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->swatch), &color); - gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->a_slider), &color); - entry_set_rgba (editor, &color); + update_color (editor, &color); g_object_notify (G_OBJECT (editor), "rgba"); } @@ -586,9 +605,7 @@ gtk_color_editor_set_rgba (GtkColorChooser *chooser, gtk_adjustment_set_value (editor->v_adj, v); gtk_adjustment_set_value (editor->a_adj, color->alpha); - gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->swatch), color); - gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->a_slider), color); - entry_set_rgba (editor, color); + update_color (editor, color); g_object_notify (G_OBJECT (editor), "rgba"); } 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/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index e54d1f575d..598466d027 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -1594,6 +1594,9 @@ add_axis (GtkFontChooserWidget *fontchooser, (double)ax->max_value, 1.0, 10.0, 0.0); axis->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, axis->adjustment); + gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->scale), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL, + -1); gtk_scale_add_mark (GTK_SCALE (axis->scale), (double)ax->default_value, GTK_POS_TOP, NULL); gtk_widget_set_valign (axis->scale, GTK_ALIGN_BASELINE_FILL); gtk_widget_set_hexpand (axis->scale, TRUE); @@ -1601,6 +1604,9 @@ add_axis (GtkFontChooserWidget *fontchooser, gtk_scale_set_draw_value (GTK_SCALE (axis->scale), FALSE); gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->scale, 1, row, 1, 1); axis->spin = gtk_spin_button_new (axis->adjustment, 0, 0); + gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->spin), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL, + -1); g_signal_connect (axis->spin, "output", G_CALLBACK (output_cb), fontchooser); gtk_widget_set_valign (axis->spin, GTK_ALIGN_BASELINE_FILL); gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->spin, 2, row, 1, 1); @@ -2345,7 +2351,7 @@ add_enum_group (GtkFontChooserWidget *fontchooser, const char **tags, unsigned int n_tags) { - GtkWidget *label; + GtkWidget *label = NULL; GtkWidget *group; PangoAttrList *attrs; int i; @@ -2433,6 +2439,9 @@ add_radio_group (GtkFontChooserWidget *fontchooser, gtk_label_set_attributes (GTK_LABEL (label), attrs); pango_attr_list_unref (attrs); gtk_box_append (GTK_BOX (group), label); + gtk_accessible_update_relation (GTK_ACCESSIBLE (group), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL, + -1); for (i = 0; i < n_tags; i++) { diff --git a/gtk/ui/gtkcoloreditor.ui b/gtk/ui/gtkcoloreditor.ui index c957169322..cffdb04e23 100644 --- a/gtk/ui/gtkcoloreditor.ui +++ b/gtk/ui/gtkcoloreditor.ui @@ -61,6 +61,10 @@ False False False + img + + The current color + 1 0 diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui index 9b0fc90313..99b30e86a9 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 @@ -186,6 +196,9 @@ Preview Font + + Preview Font + horizontal @@ -215,6 +228,9 @@ 1 slider_adjustment 0 + + size_label + horizontal @@ -231,6 +247,9 @@ spin_adjustment 3 + + size_label + 2 @@ -252,6 +271,10 @@ 1 3 3 + alert + + no_fonts_label + @@ -266,7 +289,7 @@ - + No Fonts Found @@ -307,6 +330,9 @@ 12 3 0 + + Font Name + selection @@ -324,6 +350,9 @@ Preview Font + + Preview Font + @@ -346,6 +375,9 @@ 6 12 + + Font Variation Axes + Size @@ -362,6 +394,9 @@ 1 slider_adjustment 0 + + size_label2 + 1 0 @@ -373,6 +408,9 @@ spin_adjustment 3 + + size_label2 + 2 0 @@ -385,6 +423,9 @@ 1 12 + + Font Features + 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); }