Skip to content

Commit

Permalink
LibWeb: Support the ARIA “sectionheader” & “sectionfooter” roles
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshowbarker authored and trflynn89 committed Dec 16, 2024
1 parent 203267f commit 1b165d8
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 4 deletions.
92 changes: 92 additions & 0 deletions Libraries/LibWeb/ARIA/AriaRoles.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,98 @@
"childrenArePresentational": false,
"implicitValueForRole": {}
},
"SectionFooter": {
"specLink": "https://w3c.github.io/aria/#sectionfooter",
"description": "A set of user interface objects and information representing information about its closest ancestral content group.",
"superClassRoles": [
"Section"
],
"supportedStates": [
"aria-busy",
"aria-current",
"aria-disabled",
"aria-grabbed",
"aria-hidden",
"aria-invalid"
],
"supportedProperties": [
"aria-atomic",
"aria-braillelabel",
"aria-brailleroledescription",
"aria-controls",
"aria-describedby",
"aria-description",
"aria-details",
"aria-dropeffect",
"aria-dropeffect",
"aria-errormessage",
"aria-flowto",
"aria-haspopup",
"aria-keyshortcuts",
"aria-label",
"aria-labelledby",
"aria-live",
"aria-owns",
"aria-relevant",
"aria-roledescription"
],
"requiredStates": [],
"requiredProperties": [],
"prohibitedStates": [],
"prohibitedProperties": [],
"requiredContextRoles": [],
"requiredOwnedElements": [],
"nameFromSource": "Author",
"accessibleNameRequired": false,
"childrenArePresentational": false,
"implicitValueForRole": {}
},
"SectionHeader": {
"specLink": "https://w3c.github.io/aria/#sectionheader",
"description": "A set of user interface objects and information that represents a collection of introductory items for the element's closest ancestral content group.",
"superClassRoles": [
"Section"
],
"supportedStates": [
"aria-busy",
"aria-current",
"aria-disabled",
"aria-grabbed",
"aria-hidden",
"aria-invalid"
],
"supportedProperties": [
"aria-atomic",
"aria-braillelabel",
"aria-brailleroledescription",
"aria-controls",
"aria-describedby",
"aria-description",
"aria-details",
"aria-dropeffect",
"aria-dropeffect",
"aria-errormessage",
"aria-flowto",
"aria-haspopup",
"aria-keyshortcuts",
"aria-label",
"aria-labelledby",
"aria-live",
"aria-owns",
"aria-relevant",
"aria-roledescription"
],
"requiredStates": [],
"requiredProperties": [],
"prohibitedStates": [],
"prohibitedProperties": [],
"requiredContextRoles": [],
"requiredOwnedElements": [],
"nameFromSource": "Author",
"accessibleNameRequired": false,
"childrenArePresentational": false,
"implicitValueForRole": {}
},
"Input": {
"specLink": "https://www.w3.org/TR/wai-aria-1.2/#input",
"description": "A generic type of widget that allows user input.",
Expand Down
4 changes: 4 additions & 0 deletions Libraries/LibWeb/ARIA/RoleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ ErrorOr<NonnullOwnPtr<RoleType>> RoleType::build_role_object(Role role, bool foc
return adopt_nonnull_own_or_enomem(new (nothrow) Search(data));
case Role::searchbox:
return adopt_nonnull_own_or_enomem(new (nothrow) SearchBox(data));
case Role::sectionfooter:
return adopt_nonnull_own_or_enomem(new (nothrow) SectionFooter(data));
case Role::sectionheader:
return adopt_nonnull_own_or_enomem(new (nothrow) SectionHeader(data));
case Role::separator:
if (focusable)
return adopt_nonnull_own_or_enomem(new (nothrow) FocusableSeparator(data));
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWeb/ARIA/Roles.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ namespace Web::ARIA {
__ENUMERATE_ARIA_ROLE(search) \
__ENUMERATE_ARIA_ROLE(searchbox) \
__ENUMERATE_ARIA_ROLE(section) \
__ENUMERATE_ARIA_ROLE(sectionfooter) \
__ENUMERATE_ARIA_ROLE(sectionhead) \
__ENUMERATE_ARIA_ROLE(sectionheader) \
__ENUMERATE_ARIA_ROLE(select) \
__ENUMERATE_ARIA_ROLE(separator) \
__ENUMERATE_ARIA_ROLE(slider) \
Expand Down
14 changes: 10 additions & 4 deletions Libraries/LibWeb/HTML/HTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,16 @@ Optional<ARIA::Role> HTMLElement::default_role() const
// complementary, main, navigation or region then (footer) role=contentinfo (header) role=banner. Otherwise,
// role=generic.
for (auto const* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) {
if (first_is_one_of(ancestor->local_name(), TagNames::article, TagNames::aside, TagNames::main, TagNames::nav, TagNames::section))
return ARIA::Role::generic;
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::article, ARIA::Role::complementary, ARIA::Role::main, ARIA::Role::navigation, ARIA::Role::region))
return ARIA::Role::generic;
if (first_is_one_of(ancestor->local_name(), TagNames::article, TagNames::aside, TagNames::main, TagNames::nav, TagNames::section)) {
if (local_name() == TagNames::footer)
return ARIA::Role::sectionfooter;
return ARIA::Role::sectionheader;
}
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::article, ARIA::Role::complementary, ARIA::Role::main, ARIA::Role::navigation, ARIA::Role::region)) {
if (local_name() == TagNames::footer)
return ARIA::Role::sectionfooter;
return ARIA::Role::sectionheader;
}
}
// then (footer) role=contentinfo.
if (local_name() == TagNames::footer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Harness status: OK

Found 4 tests

4 Pass
Pass el-footer
Pass el-footer-ancestormain
Pass el-header
Pass el-header-ancestormain
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<title>Tentative: HTML-AAM Contextual-Specific Role Verification Tests</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/testdriver.js"></script>
<script src="../resources/testdriver-vendor.js"></script>
<script src="../resources/testdriver-actions.js"></script>
<script src="../wai-aria/scripts/aria-utils.js"></script>
</head>
<body>

<!--
New sectionheader and sectionfooter roles.
See https://github.com/w3c/aria/pull/1931
-->
<nav>
<footer data-testname="el-footer" aria-label="x" data-expectedrole="sectionfooter" class="ex">x</aside>
</nav>
<main>
<footer data-testname="el-footer-ancestormain" data-expectedrole="sectionfooter" class="ex">x</footer>
</main>
<nav>
<header data-testname="el-header" aria-label="x" data-expectedrole="sectionheader" class="ex">x</header>
</nav>
<main>
<header data-testname="el-header-ancestormain" data-expectedrole="sectionheader" class="ex">x</header>
</main>

<script>
AriaUtils.verifyRolesBySelector(".ex");
</script>

</body>
</html>

0 comments on commit 1b165d8

Please sign in to comment.