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 committed by Jelle Raaijmakers
parent 12b7304876
commit 7a6813cdea
Notes: github-actions[bot] 2024-11-25 10:22:27 +00:00

View file

@ -2403,6 +2403,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-button-input-type-submit-and-input-type-reset-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.release_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)