diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 741fbe3f4aa..ef1cf3eb5e8 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -36,11 +36,14 @@ #include #include #include +#include #include #include +#include #include #include #include +#include #include #include #include @@ -2381,6 +2384,31 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con if (auto title_attribute = element->get_attribute_ns(Namespace::XLink, XLink::AttributeNames::title); title_attribute.has_value()) return title_attribute.release_value(); } + // https://w3c.github.io/html-aam/#table-element-accessible-name-computation + // if the table element has a child that is a caption element, then use the subtree of the first such element + if (is(*element)) + if (auto& table = (const_cast(static_cast(*element))); table.caption()) + return table.caption()->text_content().release_value(); + // https://w3c.github.io/html-aam/#table-element-accessible-name-computation + // if the fieldset element has a child that is a legend element, then use the subtree of the first such element + if (is(*element)) { + Optional legend; + auto& fieldset = (const_cast(static_cast(*element))); + fieldset.for_each_child_of_type([&](HTML::HTMLLegendElement const& element) mutable { + legend = element.text_content().release_value(); + return IterationDecision::Break; + }); + if (legend.has_value()) + return legend.release_value(); + } + if (is(*element)) { + auto& input = (const_cast(static_cast(*element))); + // https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation + // Otherwise use alt attribute if present and its value is not the empty string. + if (input.type_state() == HTML::HTMLInputElement::TypeAttributeState::ImageButton) + if (auto alt = element->get_attribute(HTML::AttributeNames::alt); alt.has_value()) + return alt.release_value(); + } // F. Otherwise, if the current node's role allows name from content, or if the current node is referenced by aria-labelledby, aria-describedby, or is a native host language text alternative element (e.g. label in HTML), or is a descendant of a native host language text alternative element: if ((role.has_value() && ARIA::allows_name_from_content(role.value())) || is_referenced || is_descendant == IsDescendant::Yes) {