From 82664003c0b6194543fa70a9d1468da81d35acc9 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 26 Jul 2020 20:27:39 +0100 Subject: [PATCH] a11y: Allow setting the role post-construction Some widgets have different roles after they are constructed, so we need to allow changing the role defined by the class. We should still avoid setting a role after the GtkATContext has been created. --- gtk/gtkaccessible.c | 1 - gtk/gtkwidget.c | 16 ++++++++++++++-- testsuite/gtk/defaultvalue.c | 7 ++++++- testsuite/gtk/notify.c | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c index 2638abcd1c..09227b86e1 100644 --- a/gtk/gtkaccessible.c +++ b/gtk/gtkaccessible.c @@ -62,7 +62,6 @@ gtk_accessible_default_init (GtkAccessibleInterface *iface) GTK_TYPE_ACCESSIBLE_ROLE, GTK_ACCESSIBLE_ROLE_NONE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_interface_install_property (iface, pspec); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index b3e1c61e68..f6da8f46db 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -1721,7 +1721,19 @@ gtk_widget_set_property (GObject *object, gtk_widget_set_layout_manager (widget, g_value_dup_object (value)); break; case PROP_ACCESSIBLE_ROLE: - priv->accessible_role = g_value_get_enum (value); + if (priv->at_context == NULL) + { + priv->accessible_role = g_value_get_enum (value); + g_object_notify_by_pspec (object, pspec); + } + else + { + char *role_str = g_enum_to_string (GTK_TYPE_ACCESSIBLE_ROLE, priv->accessible_role); + g_critical ("Widget of type ā€œ%sā€ already has an accessible role of type ā€œ%sā€", + G_OBJECT_TYPE_NAME (object), + role_str); + g_free (role_str); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -8111,8 +8123,8 @@ gtk_widget_accessible_get_at_context (GtkAccessible *accessible) else role = class_priv->accessible_role; - priv->at_context = gtk_at_context_create (role, accessible); priv->accessible_role = role; + priv->at_context = gtk_at_context_create (role, accessible); } return priv->at_context; diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c index 3612ab84ba..d1bb4739bc 100644 --- a/testsuite/gtk/defaultvalue.c +++ b/testsuite/gtk/defaultvalue.c @@ -144,6 +144,11 @@ test_type (gconstpointer data) if ((pspec->flags & G_PARAM_READABLE) == 0) continue; + /* This is set via class_init, and we have a11y tests to verify it */ + if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) && + strcmp (pspec->name, "accessible-role") == 0) + continue; + /* This is set via construct property */ if (g_type_is_a (type, GTK_TYPE_BUILDER) && strcmp (pspec->name, "scope") == 0) @@ -387,7 +392,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS continue; if (g_type_is_a (type, GTK_TYPE_WIDGET) && - (strcmp (pspec->name, "name") == 0 || + (strcmp (pspec->name, "name") == 0 || strcmp (pspec->name, "display") == 0 || strcmp (pspec->name, "style") == 0)) continue; diff --git a/testsuite/gtk/notify.c b/testsuite/gtk/notify.c index 58527375cf..5dd4499577 100644 --- a/testsuite/gtk/notify.c +++ b/testsuite/gtk/notify.c @@ -522,6 +522,10 @@ test_type (gconstpointer data) g_str_equal (pspec->name, "vexpand"))) continue; + if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) && + g_str_equal (pspec->name, "accessible-role")) + continue; + if (pspec->owner_type == GTK_TYPE_ENTRY && g_str_equal (pspec->name, "im-module")) continue;