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.
This commit is contained in:
sideshowbarker 2024-11-20 05:25:26 +09:00
parent 6ee54ca08a
commit 032396ba4d
No known key found for this signature in database

View file

@ -2383,6 +2383,13 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
if (is<HTML::HTMLInputElement>(*element)) {
auto& input = (const_cast<HTML::HTMLInputElement&>(static_cast<HTML::HTMLInputElement const&>(*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())