a11y: Set an accessible role for GtkTextView

Use the text-box accessible role for GtkTextView
and set properties as appropriate.

Update the documentation and add a test.
This commit is contained in:
Matthias Clasen 2020-07-29 18:18:04 -04:00
parent 9722bb4d9e
commit c68fe1053a
4 changed files with 61 additions and 9 deletions

View File

@ -60,7 +60,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
| `SEPARATOR` | A divider that separates sections of content or groups of items | #GtkSeparator |
| `SPIN_BUTTON` | A range control that allows seelcting among discrete choices | #GtkSpinButton |
| `SWITCH` | A control that represents on/off values | #GtkSwitch |
| `TEXT_BOX` | A type of input that allows free-form text as its value. | #GtkEntry, #GtkPasswordEntry |
| `TEXT_BOX` | A type of input that allows free-form text as its value. | #GtkEntry, #GtkPasswordEntry, #GtkTextView |
| `WINDOW` | An application window | #GtkWindow |
| `...` | … |

View File

@ -89,9 +89,12 @@
*
* If a context menu is opened, the window node will appear as a subnode
* of the main node.
*
* # Accessibility
*
* GtkTextView uses the #GTK_ACCESSIBLE_ROLE_TEXT_BOX role.
*/
/* How scrolling, validation, exposes, etc. work.
*
* The expose_event handler has the invariant that the onscreen lines
@ -1801,6 +1804,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
"(i)", GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_css_name (widget_class, I_("textview"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TEXT_BOX);
quark_text_selection_data = g_quark_from_static_string ("gtk-text-view-text-selection-data");
quark_gtk_signal = g_quark_from_static_string ("gtk-signal");
@ -1942,6 +1946,10 @@ gtk_text_view_init (GtkTextView *text_view)
gtk_widget_action_set_enabled (GTK_WIDGET (text_view), "text.can-redo", FALSE);
gtk_widget_action_set_enabled (GTK_WIDGET (text_view), "text.can-undo", FALSE);
gtk_accessible_update_property (GTK_ACCESSIBLE (widget),
GTK_ACCESSIBLE_PROPERTY_MULTI_LINE, TRUE,
-1);
}
GtkCssNode *
@ -3096,6 +3104,10 @@ gtk_text_view_set_editable (GtkTextView *text_view,
gtk_text_layout_default_style_changed (priv->layout);
}
gtk_accessible_update_property (GTK_ACCESSIBLE (text_view),
GTK_ACCESSIBLE_PROPERTY_READ_ONLY, !setting,
-1);
g_object_notify (G_OBJECT (text_view), "editable");
}
}

View File

@ -24,6 +24,7 @@ tests = [
{ 'name': 'separator' },
{ 'name': 'spinbutton' },
{ 'name': 'switch' },
{ 'name': 'textview' },
{ 'name': 'window' },
]

39
testsuite/a11y/textview.c Normal file
View File

@ -0,0 +1,39 @@
#include <gtk/gtk.h>
static void
textview_role (void)
{
GtkWidget *widget = gtk_text_view_new ();
g_object_ref_sink (widget);
gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_TEXT_BOX);
g_object_unref (widget);
}
static void
textview_properties (void)
{
GtkWidget *widget = gtk_text_view_new ();
g_object_ref_sink (widget);
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_MULTI_LINE, TRUE);
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_READ_ONLY, FALSE);
gtk_text_view_set_editable (GTK_TEXT_VIEW (widget), FALSE);
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_READ_ONLY, TRUE);
g_object_unref (widget);
}
int
main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
g_test_add_func ("/a11y/textview/role", textview_role);
g_test_add_func ("/a11y/textview/properties", textview_properties);
return g_test_run ();
}