Skip to content

Truly independent web browser

LibWeb: Preserve accessible names with display contents

Andreas Kling8d9b1f47689a
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index b727a8dbfd1..8de51ba82dd 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -4995,13 +4995,27 @@ ENUMERATE_ARIA_ATTRIBUTES
bool Element::is_hidden(Layout::BegunRead const& read) const
{
- if (layout_node(read) == nullptr)
+ // https://drafts.csswg.org/css-display-3/#valdef-display-contents
+ // The element itself does not generate any boxes, but its children and pseudo-elements still generate boxes and text sequences as normal.
+ if (!layout_node(read) && !has_display_contents())
return true;
- if (layout_node(read)->visibility() == CSS::Visibility::Hidden || layout_node(read)->visibility() == CSS::Visibility::Collapse || layout_node(read)->content_visibility() == CSS::ContentVisibility::Hidden)
+ auto const* inherited_box_values = style_group<CSS::ComputedValues::InheritedBoxValues>();
+ if (inherited_box_values
+ && (static_cast<CSS::Visibility>(inherited_box_values->visibility) != CSS::Visibility::Visible
+ || static_cast<CSS::ContentVisibility>(inherited_box_values->content_visibility) == CSS::ContentVisibility::Hidden))
return true;
for (ParentNode const* self_or_ancestor = this; self_or_ancestor; self_or_ancestor = self_or_ancestor->parent_or_shadow_host()) {
if (self_or_ancestor->is_element()) {
- auto aria_hidden = static_cast<DOM::Element const*>(self_or_ancestor)->aria_hidden();
+ auto const& element = static_cast<DOM::Element const&>(*self_or_ancestor);
+ // NB: A boxless display:contents element can also be inside an undisplayed subtree.
+ auto const* box_values = element.style_group<CSS::ComputedValues::BoxValues>();
+ if (box_values && CSS::display_from_ffi_display(box_values->display).is_none())
+ return true;
+ auto const* ancestor_inherited_box_values = element.style_group<CSS::ComputedValues::InheritedBoxValues>();
+ if (ancestor_inherited_box_values
+ && static_cast<CSS::ContentVisibility>(ancestor_inherited_box_values->content_visibility) == CSS::ContentVisibility::Hidden)
+ return true;
+ auto aria_hidden = element.aria_hidden();
if (aria_hidden.has_value() && aria_hidden->utf16_view() == u"true"sv)
return true;
}
diff --git a/Tests/LibWeb/Text/expected/css/display-contents-accessible-name.txt b/Tests/LibWeb/Text/expected/css/display-contents-accessible-name.txt
index aeea882f5b0..bb7e24963fe 100644
--- a/Tests/LibWeb/Text/expected/css/display-contents-accessible-name.txt
+++ b/Tests/LibWeb/Text/expected/css/display-contents-accessible-name.txt
@@ -1,6 +1,6 @@
-visible:
+visible: label
visibility hidden:
ancestor display none:
ancestor content visibility hidden:
aria hidden:
-visible again:
+visible again: label
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-display/accessibility/display-contents-role-and-label.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-display/accessibility/display-contents-role-and-label.txt
index f807ff4e193..b8618496cca 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-display/accessibility/display-contents-role-and-label.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-display/accessibility/display-contents-role-and-label.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 112 tests
-98 Pass
-14 Fail
+112 Pass
Pass tr with display: contents, within table with display: flex, has row role
Pass td as child of tr with display: contents, within table with display: flex, has cell role
Pass tr with display: contents, within table with role=table with display: flex, has row role
@@ -61,16 +60,16 @@ Pass Label: button with display: contents is labelled via aria-label
Pass Label: div with role group with display: contents is labelled via aria-label
Pass Label: button with display: contents is labelled via label for/id association
Pass Label: g element with display: contents, as child of svg, is labelled via title element
-Fail Label: link with display: contents is labelled via name from contents
-Fail Label: button with display: contents is labelled via name from contents
-Fail Label: h3 with display: contents is labelled via name from contents
-Fail Label: button with display: contents has button role
-Fail Label: button with explicit button role and display: contents has button role
-Fail Label: div with button role and display: contents has button role
-Fail Label: div with button role, tabindex=0 and display: contents has button role
-Fail Label: h3 with display: contents has heading role
-Fail Label: div with heading role, aria-level=3 and display: contents has heading role
-Fail Label: span with heading role, aria-level=1 and display: contents has heading role
+Pass Label: link with display: contents is labelled via name from contents
+Pass Label: button with display: contents is labelled via name from contents
+Pass Label: h3 with display: contents is labelled via name from contents
+Pass Label: button with display: contents has button role
+Pass Label: button with explicit button role and display: contents has button role
+Pass Label: div with button role and display: contents has button role
+Pass Label: div with button role, tabindex=0 and display: contents has button role
+Pass Label: h3 with display: contents has heading role
+Pass Label: div with heading role, aria-level=3 and display: contents has heading role
+Pass Label: span with heading role, aria-level=1 and display: contents has heading role
Pass Label: nav with display: contents and aria-label has navigation role
Pass Label: aside with display: contents and aria-label has complementary role
Pass Label: form with display: contents has form role
@@ -80,10 +79,10 @@ Pass Label: div with role complementary, aria-label and display: contents has co
Pass Label: div with role form, aria-label and display: contents has form role
Pass Label: div with role search and display: contents has search role
Pass Label: div with role region, aria-label and display: contents has region role
-Fail Label: link with display: contents has link role
-Fail Label: link with explicit link role and display: contents has link role
-Fail Label: div with link role and display: contents has link role
-Fail Label: div with link role, tabindex=0 and display: contents has link role
+Pass Label: link with display: contents has link role
+Pass Label: link with explicit link role and display: contents has link role
+Pass Label: div with link role and display: contents has link role
+Pass Label: div with link role, tabindex=0 and display: contents has link role
Pass Role: button with display: contents is labelled via referenced hidden span
Pass Role: link with display: contents is labelled via aria-labelledby
Pass Role: nav with display: contents is labelled via aria-labelledby