]> Pileus Git - ~andy/gtk/commitdiff
Improve a11y names for colors
authorMatthias Clasen <mclasen@redhat.com>
Sun, 12 Feb 2012 00:03:45 +0000 (19:03 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 14 Feb 2012 21:37:04 +0000 (16:37 -0500)
Only read alpha if it is != 1, and read percentages also for
'unnamed' palette colors.

gtk/gtkcolorchooserwidget.c

index ca44737bf46f279021c425649efa2b51eca9c804..fad55fa57706dd1916782b941bc73de2acf04a4e 100644 (file)
@@ -267,6 +267,32 @@ gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
 
 /* UI construction {{{1 */
 
+static guint
+scale_round (gdouble value, gdouble scale)
+{
+  value = floor (value * scale + 0.5);
+  value = MAX (value, 0);
+  value = MIN (value, scale);
+  return (guint)value;
+}
+
+gchar *
+accessible_color_name (GdkRGBA *color)
+{
+  if (color->alpha < 1.0)
+    return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"),
+                            scale_round (color->red, 100),
+                            scale_round (color->green, 100),
+                            scale_round (color->blue, 100),
+                            scale_round (color->alpha, 100));
+  else
+    return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"),
+                            scale_round (color->red, 100),
+                            scale_round (color->green, 100),
+                            scale_round (color->blue, 100));
+}
+
+
 static void
 add_palette (GtkColorChooserWidget  *cc,
              gboolean                horizontal,
@@ -300,10 +326,21 @@ add_palette (GtkColorChooserWidget  *cc,
   for (i = 0; i < n_colors; i++)
     {
       p = gtk_color_swatch_new ();
+      atk_obj = gtk_widget_get_accessible (p);
       if (names)
         {
-          atk_obj = gtk_widget_get_accessible (p);
-          atk_object_set_description (atk_obj, C_("Color name", names[i]));
+          atk_object_set_description (atk_obj,
+                                      g_dpgettext2 (GETTEXT_PACKAGE, "Color name", names[i]));
+        }
+      else
+        {
+          gchar *text, *name;
+
+          name = accessible_color_name (&colors[i]);
+          text = g_strdup_printf (_("Color: %s"), name);
+          atk_object_set_description (atk_obj, text);
+          g_free (text);
+          g_free (name);
         }
       gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &colors[i]);
       connect_swatch_signals (p, cc);
@@ -438,15 +475,6 @@ add_default_palette (GtkColorChooserWidget *cc)
   cc->priv->has_default_palette = TRUE;
 }
 
-static guint
-scale_round (gdouble value, gdouble scale)
-{
-  value = floor (value * scale + 0.5);
-  value = MAX (value, 0);
-  value = MIN (value, scale);
-  return (guint)value;
-}
-
 static void
 gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
 {
@@ -460,7 +488,7 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
   GVariantIter iter;
   gboolean selected;
   AtkObject *atk_obj;
-  gchar *text;
+  gchar *text, *name;
 
   cc->priv = G_TYPE_INSTANCE_GET_PRIVATE (cc, GTK_TYPE_COLOR_CHOOSER_WIDGET, GtkColorChooserWidgetPrivate);
 
@@ -502,13 +530,11 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
       gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &color);
       gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
       atk_obj = gtk_widget_get_accessible (p);
-      text = g_strdup_printf (_("Custom color %d: Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"), i,
-                              scale_round (color.red, 100),
-                              scale_round (color.green, 100),
-                              scale_round (color.blue, 100),
-                              scale_round (color.alpha, 100));
+      name = accessible_color_name (&color);
+      text = g_strdup_printf (_("Custom color %d: %s"), i, name);
       atk_object_set_description (atk_obj, text);
       g_free (text);
+      g_free (name);
       connect_custom_signals (p, cc);
       gtk_container_add (GTK_CONTAINER (box), p);