From c49c971f473b5ca5362fb5461b805761bfc7592e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 10 Jun 2023 13:59:32 -0400 Subject: [PATCH] colorchooser: Improve accessibility Set up missing accessible relations, labels and roles. --- gtk/gtkcolorchooserwidget.c | 8 ++++++-- gtk/gtkcolorchooserwidgetprivate.h | 27 +++++++++++++++++++++++++++ gtk/gtkcoloreditor.c | 29 +++++++++++++++++++++++------ gtk/ui/gtkcoloreditor.ui | 4 ++++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 gtk/gtkcolorchooserwidgetprivate.h 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/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 -- 2.30.2