From 2d638485a89dba1cbd4928512fc43681c92c3581 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Mon, 9 Dec 2024 17:01:54 +0900 Subject: [PATCH] =?UTF-8?q?LibWeb:=20Assign=20=E2=80=9Corphaned=E2=80=9D?= =?UTF-8?q?=20li=20elements=20the=20default=20ARIA=20role=20=E2=80=9Cnone?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes Ladybird conform to the current requirements at https://w3c.github.io/core-aam/#roleMappingComputedRole in the “Core Accessibility API Mappings” spec for the case of “orphaned” li elements; that is, any li element which doesn’t have a role=list ancestor. The core-aam spec requires that in such cases, the li element must not be assigned the “listitem” role but instead must be treated as if it had no role at all. --- Libraries/LibWeb/HTML/HTMLLIElement.h | 17 +++++++++++++-- .../html-aam/roles-generic.tentative.txt | 6 ++++++ .../html-aam/roles-generic.tentative.html | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html diff --git a/Libraries/LibWeb/HTML/HTMLLIElement.h b/Libraries/LibWeb/HTML/HTMLLIElement.h index d03e391104f..362b162dcdc 100644 --- a/Libraries/LibWeb/HTML/HTMLLIElement.h +++ b/Libraries/LibWeb/HTML/HTMLLIElement.h @@ -6,8 +6,10 @@ #pragma once -#include +#include #include +#include +#include #include namespace Web::HTML { @@ -20,7 +22,18 @@ public: virtual ~HTMLLIElement() override; // https://www.w3.org/TR/html-aria/#el-li - virtual Optional default_role() const override { return ARIA::Role::listitem; } + virtual Optional default_role() const override + { + for (auto const* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) { + if (ancestor->role_or_default() == ARIA::Role::list) + return ARIA::Role::listitem; + } + // https://w3c.github.io/core-aam/#roleMappingComputedRole + // When an element has a role but is not contained in the required context (for example, an orphaned listitem + // without the required accessible parent of role list), User Agents MUST ignore the role token, and return the + // computedrole as if the ignored role token had not been included. + return ARIA::Role::none; + } WebIDL::Long value(); void set_value(WebIDL::Long value) diff --git a/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt new file mode 100644 index 00000000000..43ee599a269 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass el-li-orphaned \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html new file mode 100644 index 00000000000..150ea5a9ae1 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html @@ -0,0 +1,21 @@ + + + + Tentative: HTML-AAM Generic Role Verification Tests + + + + + + + + + +
  • x
  • + + + + + \ No newline at end of file