diff --git a/docs/reference/gtk/section-accessibility.md b/docs/reference/gtk/section-accessibility.md index 4c9b158732..c3b965da82 100644 --- a/docs/reference/gtk/section-accessibility.md +++ b/docs/reference/gtk/section-accessibility.md @@ -45,14 +45,13 @@ Each role name is part of the #GtkAccessibleRole enumeration. | Role name | Description | Related GTK widget | |-----------|-------------|--------------------| -| `ALERT` | A message with important information | - | | `BUTTON` | A control that performs an action when pressed | #GtkButton, #GtkLinkButton, #GtkExpander | | `CHECKBOX` | A control that has three possible value: `true`, `false`, or `undefined` | #GtkCheckButton | -| `COLUMNHEADER` | The header of a column in a list or grid | - | | `COMBOBOX` | A control that can be expanded to show a list of possible values to select | #GtkComboBox | | `DIALOG` | A dialog that prompts the user to enter information or require a response | #GtkDialog and subclasses | | `IMG` | An image | #GtkImage, #GtkPicture | -| `LABEL` | A visible name or caption for a user interface component. | #GtkLabel | +| `LABEL` | A visible name or caption for a user interface component | #GtkLabel | +| `METER` | Represents a value within a known range | #GtkLevelBar | | `PROGRESS_BAR` | An element that display progress | #GtkProgressBar | | `RADIO` | A checkable input in a group of radio roles | #GtkRadioButton | | `SCROLLBAR` | A graphical object controlling the scolling of content | #GtkScrollbar | diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index 23add4f560..d8dbe725b0 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -1194,7 +1194,7 @@ typedef enum { * @GTK_ACCESSIBLE_ROLE_MAIN: Unused * @GTK_ACCESSIBLE_ROLE_MARQUEE: Unused * @GTK_ACCESSIBLE_ROLE_MATH: Unused - * @GTK_ACCESSIBLE_ROLE_METER: Unused + * @GTK_ACCESSIBLE_ROLE_METER: An element that represents a value within a known range. * @GTK_ACCESSIBLE_ROLE_MENU: Unused * @GTK_ACCESSIBLE_ROLE_MENU_BAR: Unused * @GTK_ACCESSIBLE_ROLE_MENU_ITEM: Unused diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c index b0e286fff3..c324bf7fdc 100644 --- a/gtk/gtklevelbar.c +++ b/gtk/gtklevelbar.c @@ -116,6 +116,10 @@ * * In horizontal orientation, the nodes are always arranged from left to right, * regardless of text direction. + * + * # Accessibility + * + * GtkLevelBar uses the #GTK_ACCESSIBLE_ROLE_METER role. */ #include "config.h" @@ -1007,6 +1011,7 @@ gtk_level_bar_class_init (GtkLevelBarClass *klass) gtk_widget_class_set_layout_manager_type (wclass, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_set_css_name (wclass, I_("levelbar")); + gtk_widget_class_set_accessible_role (wclass, GTK_ACCESSIBLE_ROLE_METER); } static void @@ -1041,6 +1046,12 @@ gtk_level_bar_init (GtkLevelBar *self) update_mode_style_classes (self); update_block_nodes (self); update_level_style_classes (self); + + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, 1.0, + GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, 0.0, + GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 0.0, + -1); } /** @@ -1163,6 +1174,12 @@ gtk_level_bar_set_min_value (GtkLevelBar *self, update_block_nodes (self); update_level_style_classes (self); + + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, self->min_value, + GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, self->cur_value, + -1); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_VALUE]); } @@ -1194,6 +1211,12 @@ gtk_level_bar_set_max_value (GtkLevelBar *self, gtk_level_bar_ensure_offsets_in_range (self); update_block_nodes (self); update_level_style_classes (self); + + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, self->max_value, + GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, self->cur_value, + -1); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_VALUE]); } @@ -1216,6 +1239,10 @@ gtk_level_bar_set_value (GtkLevelBar *self, gtk_level_bar_set_value_internal (self, value); update_level_style_classes (self); + + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, self->cur_value, + -1); } /** diff --git a/testsuite/a11y/levelbar.c b/testsuite/a11y/levelbar.c new file mode 100644 index 0000000000..de7e391f09 --- /dev/null +++ b/testsuite/a11y/levelbar.c @@ -0,0 +1,50 @@ +#include + +static void +level_bar_role (void) +{ + GtkWidget *widget = gtk_level_bar_new (); + g_object_ref_sink (widget); + + gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_METER); + + g_object_unref (widget); +} + +static void +level_bar_properties (void) +{ + GtkWidget *widget = gtk_level_bar_new (); + g_object_ref_sink (widget); + + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, 1.); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, 0.); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 0.); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT, NULL); + + gtk_level_bar_set_max_value (GTK_LEVEL_BAR (widget), 100.0); + gtk_level_bar_set_min_value (GTK_LEVEL_BAR (widget), 10.0); + + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, 100.0); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, 10.0); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 10.0); + + gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), 40.0); + + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MAX, 100.0); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_MIN, 10.0); + gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, 40.0); + + g_object_unref (widget); +} + +int +main (int argc, char *argv[]) +{ + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/a11y/levelbar/role", level_bar_role); + g_test_add_func ("/a11y/levelbar/properties", level_bar_properties); + + return g_test_run (); +} diff --git a/testsuite/a11y/meson.build b/testsuite/a11y/meson.build index 1244a521f8..bed847ec91 100644 --- a/testsuite/a11y/meson.build +++ b/testsuite/a11y/meson.build @@ -18,6 +18,7 @@ tests = [ { 'name': 'expander' }, { 'name': 'image' }, { 'name': 'label' }, + { 'name': 'levelbar' }, { 'name': 'passwordentry' }, { 'name': 'progressbar' }, { 'name': 'scrollbar' },