mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Make ARIAMixin::to_element return a reference
Let's avoid confusion on whether this method can return null. It can't. This also adds a non-const override, as that will be needed soon.
This commit is contained in:
parent
88b41d4d76
commit
a7b1f2c800
Notes:
github-actions[bot]
2025-04-25 00:21:34 +00:00
Author: https://github.com/trflynn89
Commit: a7b1f2c800
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4460
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 18 additions and 16 deletions
|
@ -42,84 +42,84 @@ Optional<Role> ARIAMixin::role_from_role_attribute_value() const
|
||||||
// without the required accessible parent of role list), User Agents MUST ignore the role token, and return the
|
// 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.
|
// computedrole as if the ignored role token had not been included.
|
||||||
if (role == ARIA::Role::columnheader) {
|
if (role == ARIA::Role::columnheader) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::row)
|
if (ancestor->role_or_default() == ARIA::Role::row)
|
||||||
return ARIA::Role::columnheader;
|
return ARIA::Role::columnheader;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::gridcell) {
|
if (role == ARIA::Role::gridcell) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::row)
|
if (ancestor->role_or_default() == ARIA::Role::row)
|
||||||
return ARIA::Role::gridcell;
|
return ARIA::Role::gridcell;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::listitem) {
|
if (role == ARIA::Role::listitem) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::directory, ARIA::Role::list))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::directory, ARIA::Role::list))
|
||||||
return ARIA::Role::listitem;
|
return ARIA::Role::listitem;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::menuitem) {
|
if (role == ARIA::Role::menuitem) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
||||||
return ARIA::Role::menuitem;
|
return ARIA::Role::menuitem;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::menuitemcheckbox) {
|
if (role == ARIA::Role::menuitemcheckbox) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
||||||
return ARIA::Role::menuitemcheckbox;
|
return ARIA::Role::menuitemcheckbox;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::menuitemradio) {
|
if (role == ARIA::Role::menuitemradio) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::menu, ARIA::Role::menubar))
|
||||||
return ARIA::Role::menuitemradio;
|
return ARIA::Role::menuitemradio;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::option) {
|
if (role == ARIA::Role::option) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::listbox)
|
if (ancestor->role_or_default() == ARIA::Role::listbox)
|
||||||
return ARIA::Role::option;
|
return ARIA::Role::option;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::row) {
|
if (role == ARIA::Role::row) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::table, ARIA::Role::grid, ARIA::Role::treegrid))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::table, ARIA::Role::grid, ARIA::Role::treegrid))
|
||||||
return ARIA::Role::row;
|
return ARIA::Role::row;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::rowgroup) {
|
if (role == ARIA::Role::rowgroup) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::table, ARIA::Role::grid, ARIA::Role::treegrid))
|
if (first_is_one_of(ancestor->role_or_default(), ARIA::Role::table, ARIA::Role::grid, ARIA::Role::treegrid))
|
||||||
return ARIA::Role::rowgroup;
|
return ARIA::Role::rowgroup;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::rowheader) {
|
if (role == ARIA::Role::rowheader) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::row)
|
if (ancestor->role_or_default() == ARIA::Role::row)
|
||||||
return ARIA::Role::rowheader;
|
return ARIA::Role::rowheader;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::tab) {
|
if (role == ARIA::Role::tab) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::tablist)
|
if (ancestor->role_or_default() == ARIA::Role::tablist)
|
||||||
return ARIA::Role::tab;
|
return ARIA::Role::tab;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (role == ARIA::Role::treeitem) {
|
if (role == ARIA::Role::treeitem) {
|
||||||
for (auto ancestor = to_element()->parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
for (auto ancestor = to_element().parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
if (ancestor->role_or_default() == ARIA::Role::tree)
|
if (ancestor->role_or_default() == ARIA::Role::tree)
|
||||||
return ARIA::Role::treeitem;
|
return ARIA::Role::treeitem;
|
||||||
}
|
}
|
||||||
|
@ -131,13 +131,13 @@ Optional<Role> ARIAMixin::role_from_role_attribute_value() const
|
||||||
// had been provided. If a valid fallback role had been specified, or if the element had an implicit ARIA role,
|
// had been provided. If a valid fallback role had been specified, or if the element had an implicit ARIA role,
|
||||||
// then user agents would continue to expose that role, instead.
|
// then user agents would continue to expose that role, instead.
|
||||||
if ((role == ARIA::Role::form || role == ARIA::Role::region)
|
if ((role == ARIA::Role::form || role == ARIA::Role::region)
|
||||||
&& to_element()->accessible_name(to_element()->document(), DOM::ShouldComputeRole::No).value().is_empty())
|
&& to_element().accessible_name(to_element().document(), DOM::ShouldComputeRole::No).value().is_empty())
|
||||||
continue;
|
continue;
|
||||||
if (role == ARIA::Role::none || role == ARIA::Role::presentation) {
|
if (role == ARIA::Role::none || role == ARIA::Role::presentation) {
|
||||||
// https://w3c.github.io/aria/#conflict_resolution_presentation_none
|
// https://w3c.github.io/aria/#conflict_resolution_presentation_none
|
||||||
// If an element is focusable, user agents MUST ignore the none/presentation
|
// If an element is focusable, user agents MUST ignore the none/presentation
|
||||||
// role and expose the element with its implicit role.
|
// role and expose the element with its implicit role.
|
||||||
if (to_element()->is_focusable())
|
if (to_element().is_focusable())
|
||||||
continue;
|
continue;
|
||||||
// If an element has global WAI-ARIA states or properties, user agents MUST
|
// If an element has global WAI-ARIA states or properties, user agents MUST
|
||||||
// ignore the none/presentation role and instead expose the element's implicit role.
|
// ignore the none/presentation role and instead expose the element's implicit role.
|
||||||
|
|
|
@ -28,7 +28,8 @@ public:
|
||||||
// https://www.w3.org/TR/html-aria/#docconformance
|
// https://www.w3.org/TR/html-aria/#docconformance
|
||||||
virtual Optional<Role> default_role() const { return {}; }
|
virtual Optional<Role> default_role() const { return {}; }
|
||||||
|
|
||||||
virtual DOM::Element const* to_element() const { return {}; }
|
virtual DOM::Element& to_element() = 0;
|
||||||
|
virtual DOM::Element const& to_element() const = 0;
|
||||||
|
|
||||||
Optional<Role> role_from_role_attribute_value() const;
|
Optional<Role> role_from_role_attribute_value() const;
|
||||||
Optional<Role> role_or_default() const;
|
Optional<Role> role_or_default() const;
|
||||||
|
|
|
@ -330,7 +330,8 @@ public:
|
||||||
|
|
||||||
virtual bool include_in_accessibility_tree() const override;
|
virtual bool include_in_accessibility_tree() const override;
|
||||||
|
|
||||||
virtual Element const* to_element() const override { return this; }
|
virtual Element& to_element() override { return *this; }
|
||||||
|
virtual Element const& to_element() const override { return *this; }
|
||||||
|
|
||||||
bool is_hidden() const;
|
bool is_hidden() const;
|
||||||
bool has_hidden_ancestor() const;
|
bool has_hidden_ancestor() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue