LibWeb/HTML: Correctly compute whether element is mutable

This adapts the implementation of `is_mutable` to align more closely
with the spec. Specifically, it is now also taken into account whether
the element is enabled.
This commit is contained in:
Glenn Skrzypczak 2025-08-10 00:29:35 +02:00 committed by Tim Flynn
commit cac2ee41b9
Notes: github-actions[bot] 2025-08-14 15:07:22 +00:00
10 changed files with 171 additions and 63 deletions

View file

@ -376,7 +376,6 @@ void HTMLTextAreaElement::create_shadow_tree_if_needed()
MUST(element->append_child(*m_inner_text_element));
m_text_node = realm().create<DOM::Text>(document(), Utf16String {});
handle_readonly_attribute(attribute(HTML::AttributeNames::readonly));
// NOTE: If `children_changed()` was called before now, `m_raw_value` will hold the text content.
// Otherwise, it will get filled in whenever that does get called.
m_text_node->set_text_content(m_raw_value);
@ -386,13 +385,6 @@ void HTMLTextAreaElement::create_shadow_tree_if_needed()
update_placeholder_visibility();
}
// https://html.spec.whatwg.org/multipage/input.html#attr-input-readonly
void HTMLTextAreaElement::handle_readonly_attribute(Optional<String> const& maybe_value)
{
// The readonly attribute is a boolean attribute that controls whether or not the user can edit the form control. When specified, the element is not mutable.
set_is_mutable(!maybe_value.has_value());
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-maxlength
void HTMLTextAreaElement::handle_maxlength_attribute()
{
@ -442,8 +434,6 @@ void HTMLTextAreaElement::form_associated_element_attribute_changed(FlyString co
if (name == HTML::AttributeNames::placeholder) {
if (m_placeholder_text_node)
m_placeholder_text_node->set_data(Utf16String::from_utf8(value.value_or(String {})));
} else if (name == HTML::AttributeNames::readonly) {
handle_readonly_attribute(value);
} else if (name == HTML::AttributeNames::maxlength) {
handle_maxlength_attribute();
}
@ -489,4 +479,11 @@ bool HTMLTextAreaElement::suffering_from_being_missing() const
return has_attribute(HTML::AttributeNames::required) && is_mutable() && value().is_empty();
}
// https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
bool HTMLTextAreaElement::is_mutable() const
{
// A textarea element is mutable if it is neither disabled nor has a readonly attribute specified.
return enabled() && !has_attribute(AttributeNames::readonly);
}
}