atcontext: Update name computation

Implement this sentence from the "Accessible Name
and Description Computation 1.2" spec:

    If the root node's role prohibits naming,
    return the empty string ("").

See https://www.w3.org/TR/accname-1.2/
This commit is contained in:
Matthias Clasen 2023-06-11 08:06:14 -04:00
parent 2349f13f45
commit 22548785b0

View File

@ -1150,6 +1150,13 @@ gtk_at_context_get_description_accumulate (GtkATContext *self,
}
}
static GtkAccessibleRole name_forbidden[] = {
GTK_ACCESSIBLE_ROLE_CAPTION,
GTK_ACCESSIBLE_ROLE_GENERIC,
GTK_ACCESSIBLE_ROLE_PRESENTATION,
GTK_ACCESSIBLE_ROLE_NONE,
};
/*< private >
* gtk_at_context_get_name:
* @self: a `GtkATContext`
@ -1165,6 +1172,12 @@ gtk_at_context_get_name (GtkATContext *self)
{
g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL);
for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++)
{
if (self->accessible_role == name_forbidden[i])
return g_strdup ("");
}
GPtrArray *names = g_ptr_array_new ();
gtk_at_context_get_name_accumulate (self, names, TRUE);
@ -1204,6 +1217,12 @@ gtk_at_context_get_description (GtkATContext *self)
{
g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL);
for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++)
{
if (self->accessible_role == name_forbidden[i])
return g_strdup ("");
}
GPtrArray *names = g_ptr_array_new ();
gtk_at_context_get_description_accumulate (self, names, TRUE);