From 6ee54ca08a100acb192fc00b67ac5f06367f2c3e Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Tue, 19 Nov 2024 21:03:48 +0900 Subject: [PATCH 1/3] LibWeb: Fix accessible-name computation for table, fieldset, image input This change makes Ladybird conform to the requirements in the HTML-AAM spec at https://w3c.github.io/html-aam/#accname-computation for the cases of HTML table, fieldset, and input@type=image elements. Otherwise, without this change, Ladybird fails to expose the expected accessible names for those cases. --- Libraries/LibWeb/DOM/Node.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 9ba7017f060..753945589ba 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 @@ -2360,6 +2363,31 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con // HTMLLabelElement is already handled (by the code for step C. “Embedded Control” above) in conformance // with the spec requirements — and if not, then add handling for it here. } + // 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().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().value(); + return IterationDecision::Break; + }); + if (legend.has_value()) + return legend.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) { From 032396ba4d2f419ba91fa586235342fc887c5a3f Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Wed, 20 Nov 2024 05:25:26 +0900 Subject: [PATCH 2/3] LibWeb: Fix input@type=button|submit|reset accessible-name computation This change makes Ladybird conform to the requirements in the HTML-AAM spec at https://w3c.github.io/html-aam/#accname-computation for the cases of HTML input@type=button, input@type=submit, and input@type=reset elements. Otherwise, without this change, Ladybird fails to expose the expected accessible names for those cases. --- Libraries/LibWeb/DOM/Node.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 753945589ba..7c19fe41738 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -2383,6 +2383,13 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con if (is(*element)) { auto& input = (const_cast(static_cast(*element))); // https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation + // Otherwise use the value attribute. + if (input.type_state() == HTML::HTMLInputElement::TypeAttributeState::Button + || input.type_state() == HTML::HTMLInputElement::TypeAttributeState::SubmitButton + || input.type_state() == HTML::HTMLInputElement::TypeAttributeState::ResetButton) + if (auto value = input.get_attribute(HTML::AttributeNames::value); value.has_value()) + return value.value(); + // 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()) From 928101482ba12776b548485409407699e3e7ceff Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Tue, 19 Nov 2024 21:14:36 +0900 Subject: [PATCH 3/3] =?UTF-8?q?LibWeb:=20Fix=20accessible-name=20computati?= =?UTF-8?q?on=20for=20=E2=80=9Cencapsulation=E2=80=9D=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes Ladybird correctly handle all “encapsulation” tests in the https://wpt.fyi/results/accname/name/comp_host_language_label.html set of tests in WPT. Those all test the requirement that when computing the accessible name for a