colorchooser: Improve accessibility
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 17:59:32 +0000 (13:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 10 Jun 2023 17:59:32 +0000 (13:59 -0400)
Set up missing accessible relations, labels and roles.

gtk/gtkcolorchooserwidget.c
gtk/gtkcolorchooserwidgetprivate.h [new file with mode: 0644]
gtk/gtkcoloreditor.c
gtk/ui/gtkcoloreditor.ui

index 7edd262714438fec2c6a3f343b42ff840c555724..c380f1f93698c15e46b874c7d3e8303ccc713ac9 100644 (file)
@@ -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 (file)
index 0000000..2c59ddd
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+char *accessible_color_name (const GdkRGBA *color);
+
+G_END_DECLS
+
index f818382dd8045a74037ebe64092c180481f9d598..be6fbfa1518087afddf388eb6250ae0a913650af 100644 (file)
 
 #include "gtkcoloreditorprivate.h"
 
+#include <glib/gi18n-lib.h>
+
 #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");
 }
index c957169322c4d24cbac103091acfa2ba3af876a6..cffdb04e23f48a1aa2fdc9f29970dc1c6f245b37 100644 (file)
                 <property name="selectable">False</property>
                 <property name="has-menu">False</property>
                 <property name="can-focus">False</property>
+                <property name="accessible-role">img</property>
+                <accessibility>
+                  <property name="description" translatable="1">The current color</property>
+                </accessibility>
                 <layout>
                   <property name="column">1</property>
                   <property name="row">0</property>