diff options
-rw-r--r-- | docs/reference/gtk/section-accessibility.md | 2 | ||||
-rw-r--r-- | gtk/gtktextview.c | 28 | ||||
-rw-r--r-- | testsuite/a11y/meson.build | 1 | ||||
-rw-r--r-- | testsuite/a11y/textview.c | 39 |
4 files changed, 61 insertions, 9 deletions
diff --git a/docs/reference/gtk/section-accessibility.md b/docs/reference/gtk/section-accessibility.md index 1885b928f8..4dd51c6a7e 100644 --- a/docs/reference/gtk/section-accessibility.md +++ b/docs/reference/gtk/section-accessibility.md @@ -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 | | `...` | … | diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 8be1e73a86..f59b259277 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -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 * @@ -3074,11 +3082,11 @@ gtk_text_view_set_editable (GtkTextView *text_view, if (priv->editable != setting) { if (!setting) - { - gtk_text_view_reset_im_context(text_view); - if (gtk_widget_has_focus (GTK_WIDGET (text_view))) - gtk_im_context_focus_out (priv->im_context); - } + { + gtk_text_view_reset_im_context (text_view); + if (gtk_widget_has_focus (GTK_WIDGET (text_view))) + gtk_im_context_focus_out (priv->im_context); + } priv->editable = setting; @@ -3090,12 +3098,16 @@ gtk_text_view_set_editable (GtkTextView *text_view, if (priv->layout && priv->layout->default_style) { - gtk_text_layout_set_overwrite_mode (priv->layout, - priv->overwrite_mode && priv->editable); + gtk_text_layout_set_overwrite_mode (priv->layout, + priv->overwrite_mode && priv->editable); priv->layout->default_style->editable = priv->editable; 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"); } } diff --git a/testsuite/a11y/meson.build b/testsuite/a11y/meson.build index 2d828e36bd..2c25837dbb 100644 --- a/testsuite/a11y/meson.build +++ b/testsuite/a11y/meson.build @@ -24,6 +24,7 @@ tests = [ { 'name': 'separator' }, { 'name': 'spinbutton' }, { 'name': 'switch' }, + { 'name': 'textview' }, { 'name': 'window' }, ] diff --git a/testsuite/a11y/textview.c b/testsuite/a11y/textview.c new file mode 100644 index 0000000000..cdbccda8e4 --- /dev/null +++ b/testsuite/a11y/textview.c @@ -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 (); +} |