atcontext: Update name computation
authorMatthias Clasen <mclasen@redhat.com>
Sun, 11 Jun 2023 12:06:14 +0000 (08:06 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 12 Jun 2023 00:27:22 +0000 (20:27 -0400)
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/

gtk/gtkatcontext.c

index 7db5c95fe7ea6454bbefd04d44351c6228645b0c..d12a5be9bdca92693ba1190bc5a81aeb3b84a795 100644 (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);