From ab7592ee4f8ded4c3990cff5daf7f28ef26ac41f Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 6 Dec 2023 14:34:43 +0100 Subject: [PATCH] a11y: Add article and comment roles Add new accessible roles GTK_ACCESSIBLE_ROLE_ARTICLE and GTK_ACCESSIBLE_ROLE_COMMENT. ARIA has corresponding roles as well [1] [2], with the article role being the superclass role of the comment role. Acccording to the ARIA spec, the article role has the document role as superclass role and the name can be set by the author. For the comment role, the name can be set by the author or come from the content. The ARIA spec for the comment contains this sentence [2]: > If the author has not explicitly declared aria-level, aria-posinset, or > aria-setsize for a comment element, user agents MUST automatically > compute the missing values and expose them to assistive technologies. However, these properties are not listed as "Required States and Properties" in the following table for that role. Potentially the above requirement only applies for the first of the two possible described cases of how the relationship between comments and the commented content can be set, so don't hard-require these attributes in the a11y overlay's `check_widget_accessibility_errors` either. [1] https://w3c.github.io/aria/#article [2] https://w3c.github.io/aria/#comment --- gtk/a11y/gtkatspiutils.c | 6 ++++++ gtk/gtkaccessible.c | 4 ++++ gtk/gtkatcontext.c | 2 ++ gtk/gtkenums.h | 10 +++++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gtk/a11y/gtkatspiutils.c b/gtk/a11y/gtkatspiutils.c index 6bf2d44549..1d2a91a376 100644 --- a/gtk/a11y/gtkatspiutils.c +++ b/gtk/a11y/gtkatspiutils.c @@ -48,6 +48,9 @@ gtk_accessible_role_to_atspi_role (GtkAccessibleRole role) case GTK_ACCESSIBLE_ROLE_APPLICATION: return ATSPI_ROLE_FRAME; + case GTK_ACCESSIBLE_ROLE_ARTICLE: + return ATSPI_ROLE_ARTICLE; + case GTK_ACCESSIBLE_ROLE_BANNER: break; @@ -75,6 +78,9 @@ gtk_accessible_role_to_atspi_role (GtkAccessibleRole role) case GTK_ACCESSIBLE_ROLE_COMMAND: break; + case GTK_ACCESSIBLE_ROLE_COMMENT: + return ATSPI_ROLE_COMMENT; + case GTK_ACCESSIBLE_ROLE_COMPOSITE: break; diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c index 5242855ed5..b14a947aac 100644 --- a/gtk/gtkaccessible.c +++ b/gtk/gtkaccessible.c @@ -834,6 +834,8 @@ static const char *role_names[] = { [GTK_ACCESSIBLE_ROLE_APPLICATION] = NC_("accessibility", "application"), [GTK_ACCESSIBLE_ROLE_PARAGRAPH] = NC_("accessibility", "paragraph"), [GTK_ACCESSIBLE_ROLE_BLOCK_QUOTE] = NC_("accessibility", "block quote"), + [GTK_ACCESSIBLE_ROLE_ARTICLE] = NC_("accessibility", "article"), + [GTK_ACCESSIBLE_ROLE_COMMENT] = NC_("accessibility", "comment"), }; /*< private > @@ -950,6 +952,8 @@ static struct { { GTK_ACCESSIBLE_ROLE_ALERT, GTK_ACCESSIBLE_ROLE_ALERT_DIALOG }, { GTK_ACCESSIBLE_ROLE_STATUS, GTK_ACCESSIBLE_ROLE_TIMER }, { GTK_ACCESSIBLE_ROLE_DIALOG, GTK_ACCESSIBLE_ROLE_ALERT_DIALOG }, + { GTK_ACCESSIBLE_ROLE_DOCUMENT, GTK_ACCESSIBLE_ROLE_ARTICLE }, + { GTK_ACCESSIBLE_ROLE_ARTICLE, GTK_ACCESSIBLE_ROLE_COMMENT }, }; gboolean diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index 9d4188a1aa..3c87ca840c 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -1025,6 +1025,7 @@ gtk_at_context_get_accessible_relation (GtkATContext *self, static guint8 naming[] = { [GTK_ACCESSIBLE_ROLE_ALERT] = NAME_FROM_AUTHOR, [GTK_ACCESSIBLE_ROLE_ALERT_DIALOG] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED, + [GTK_ACCESSIBLE_ROLE_ARTICLE] = NAME_FROM_AUTHOR, [GTK_ACCESSIBLE_ROLE_BANNER] = GTK_ACCESSIBLE_NAME_PROHIBITED, [GTK_ACCESSIBLE_ROLE_BLOCK_QUOTE] = NAME_FROM_AUTHOR, [GTK_ACCESSIBLE_ROLE_BUTTON] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED, @@ -1034,6 +1035,7 @@ static guint8 naming[] = { [GTK_ACCESSIBLE_ROLE_COLUMN_HEADER] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED, [GTK_ACCESSIBLE_ROLE_COMBO_BOX] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED, [GTK_ACCESSIBLE_ROLE_COMMAND] = GTK_ACCESSIBLE_NAME_PROHIBITED, + [GTK_ACCESSIBLE_ROLE_COMMENT] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT, [GTK_ACCESSIBLE_ROLE_COMPOSITE] = GTK_ACCESSIBLE_NAME_PROHIBITED, [GTK_ACCESSIBLE_ROLE_DIALOG] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED, [GTK_ACCESSIBLE_ROLE_DOCUMENT] = NAME_FROM_AUTHOR, diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index 07da78551f..aa166dd26a 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -1367,6 +1367,12 @@ typedef enum { * @GTK_ACCESSIBLE_ROLE_BLOCK_QUOTE: A section of content that is quoted * from another source. * Since: 4.14 + * @GTK_ACCESSIBLE_ROLE_ARTICLE: A section of a page that consists of a + * composition that forms an independent part of a document, page, or site. + * Since: 4.14 + * @GTK_ACCESSIBLE_ROLE_COMMENT: A comment contains content expressing reaction + * to other content. + * Since: 4.14 * * The accessible role for a [iface@Accessible] implementation. * @@ -1455,7 +1461,9 @@ typedef enum { GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON GDK_AVAILABLE_ENUMERATOR_IN_4_10, GTK_ACCESSIBLE_ROLE_APPLICATION GDK_AVAILABLE_ENUMERATOR_IN_4_12, GTK_ACCESSIBLE_ROLE_PARAGRAPH GDK_AVAILABLE_ENUMERATOR_IN_4_14, - GTK_ACCESSIBLE_ROLE_BLOCK_QUOTE GDK_AVAILABLE_ENUMERATOR_IN_4_14 + GTK_ACCESSIBLE_ROLE_BLOCK_QUOTE GDK_AVAILABLE_ENUMERATOR_IN_4_14, + GTK_ACCESSIBLE_ROLE_ARTICLE GDK_AVAILABLE_ENUMERATOR_IN_4_14, + GTK_ACCESSIBLE_ROLE_COMMENT GDK_AVAILABLE_ENUMERATOR_IN_4_14 } GtkAccessibleRole; /**