mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
a11y: Set an accessible role for GtkExpander
Use the button accessible role for GtkExpander and set attributes as appropriate. Update the documentation and add a test.
This commit is contained in:
parent
144114bf40
commit
c0de580d46
@ -46,7 +46,7 @@ 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 |
|
||||
| `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 |
|
||||
|
@ -106,6 +106,10 @@
|
||||
* GtkExpander has three CSS nodes, the main node with the name expander,
|
||||
* a subnode with name title and node below it with name arrow. The arrow of an
|
||||
* expander that is showing its child gets the :checked pseudoclass added to it.
|
||||
*
|
||||
* # Accessibility
|
||||
*
|
||||
* GtkExpander uses the #GTK_ACCESSIBLE_ROLE_BUTTON role.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@ -374,6 +378,7 @@ gtk_expander_class_init (GtkExpanderClass *klass)
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, I_("expander-widget"));
|
||||
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -420,6 +425,10 @@ gtk_expander_init (GtkExpander *expander)
|
||||
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
|
||||
GTK_PHASE_BUBBLE);
|
||||
gtk_widget_add_controller (GTK_WIDGET (expander->title_widget), GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
gtk_accessible_update_state (GTK_ACCESSIBLE (expander),
|
||||
GTK_ACCESSIBLE_STATE_EXPANDED, FALSE,
|
||||
-1);
|
||||
}
|
||||
|
||||
static GtkBuildableIface *parent_buildable_iface;
|
||||
@ -877,6 +886,10 @@ gtk_expander_set_expanded (GtkExpander *expander,
|
||||
gtk_expander_resize_toplevel (expander);
|
||||
}
|
||||
|
||||
gtk_accessible_update_state (GTK_ACCESSIBLE (expander),
|
||||
GTK_ACCESSIBLE_STATE_EXPANDED, expanded,
|
||||
-1);
|
||||
|
||||
g_object_notify (G_OBJECT (expander), "expanded");
|
||||
}
|
||||
|
||||
@ -1164,6 +1177,8 @@ void
|
||||
gtk_expander_set_child (GtkExpander *expander,
|
||||
GtkWidget *child)
|
||||
{
|
||||
GList *list = NULL;
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
||||
|
||||
@ -1188,6 +1203,13 @@ gtk_expander_set_child (GtkExpander *expander,
|
||||
}
|
||||
}
|
||||
|
||||
if (expander->child)
|
||||
list = g_list_append (list, expander->child);
|
||||
gtk_accessible_update_relation (GTK_ACCESSIBLE (expander),
|
||||
GTK_ACCESSIBLE_RELATION_CONTROLS, list,
|
||||
-1);
|
||||
g_list_free (list);
|
||||
|
||||
g_object_notify (G_OBJECT (expander), "child");
|
||||
}
|
||||
|
||||
|
57
testsuite/a11y/expander.c
Normal file
57
testsuite/a11y/expander.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static void
|
||||
expander_role (void)
|
||||
{
|
||||
GtkWidget *widget = gtk_expander_new ("Hello");
|
||||
g_object_ref_sink (widget);
|
||||
|
||||
gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_BUTTON);
|
||||
|
||||
g_object_unref (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
expander_state (void)
|
||||
{
|
||||
GtkWidget *widget = gtk_expander_new ("Hello");
|
||||
g_object_ref_sink (widget);
|
||||
|
||||
gtk_test_accessible_assert_state (widget, GTK_ACCESSIBLE_STATE_EXPANDED, FALSE);
|
||||
|
||||
gtk_expander_set_expanded (GTK_EXPANDER (widget), TRUE);
|
||||
|
||||
gtk_test_accessible_assert_state (widget, GTK_ACCESSIBLE_STATE_EXPANDED, TRUE);
|
||||
|
||||
g_object_unref (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
expander_relations (void)
|
||||
{
|
||||
GtkWidget *widget = gtk_expander_new ("Hello");
|
||||
GtkWidget *child = gtk_label_new ("Child");
|
||||
GList *list;
|
||||
|
||||
g_object_ref_sink (widget);
|
||||
|
||||
gtk_expander_set_child (GTK_EXPANDER (widget), child);
|
||||
|
||||
list = g_list_append (NULL, child);
|
||||
gtk_test_accessible_assert_relation (widget, GTK_ACCESSIBLE_RELATION_CONTROLS, list);
|
||||
g_list_free (list);
|
||||
|
||||
g_object_unref (widget);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/a11y/expander/role", expander_role);
|
||||
g_test_add_func ("/a11y/expander/state", expander_state);
|
||||
g_test_add_func ("/a11y/expander/relations", expander_relations);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -15,6 +15,7 @@ tests = [
|
||||
{ 'name': 'checkbutton' },
|
||||
{ 'name': 'dialog' },
|
||||
{ 'name': 'entry' },
|
||||
{ 'name': 'expander' },
|
||||
{ 'name': 'image' },
|
||||
{ 'name': 'label' },
|
||||
{ 'name': 'passwordentry' },
|
||||
|
Loading…
Reference in New Issue
Block a user