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.
This commit is contained in:
Emmanuele Bassi 2020-07-26 20:27:39 +01:00
parent b9a1cb74a1
commit 82664003c0
4 changed files with 24 additions and 4 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;