mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-09 18:30:08 +00:00
colorchooser: Improve accessibility
Set up missing accessible relations, labels and roles.
This commit is contained in:
parent
f20ef5a0fc
commit
c49c971f47
@ -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");
|
||||
|
27
gtk/gtkcolorchooserwidgetprivate.h
Normal file
27
gtk/gtkcolorchooserwidgetprivate.h
Normal file
@ -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
|
||||
|
@ -19,10 +19,13 @@
|
||||
|
||||
#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");
|
||||
}
|
||||
|
@ -61,6 +61,10 @@
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user