mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-18 14:09:42 +00:00
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:
parent
1228063a85
commit
cac2ee41b9
Notes:
github-actions[bot]
2025-08-14 15:07:22 +00:00
Author: https://github.com/skyz1
Commit: cac2ee41b9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5812
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/trflynn89
10 changed files with 171 additions and 63 deletions
|
@ -893,13 +893,6 @@ void HTMLInputElement::handle_maxlength_attribute()
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#attr-input-readonly
|
||||
void HTMLInputElement::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() || !is_allowed_to_be_readonly(m_type));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:attr-input-placeholder-3
|
||||
static bool is_allowed_to_have_placeholder(HTML::HTMLInputElement::TypeAttributeState state)
|
||||
{
|
||||
|
@ -1066,7 +1059,6 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
MUST(element->append_child(*m_inner_text_element));
|
||||
|
||||
m_text_node = realm().create<DOM::Text>(document(), move(initial_value));
|
||||
handle_readonly_attribute(attribute(HTML::AttributeNames::readonly));
|
||||
if (type_state() == TypeAttributeState::Password)
|
||||
m_text_node->set_is_password_input({}, true);
|
||||
handle_maxlength_attribute();
|
||||
|
@ -1414,8 +1406,6 @@ void HTMLInputElement::form_associated_element_attribute_changed(FlyString const
|
|||
m_placeholder_text_node->set_data(Utf16String::from_utf8(placeholder()));
|
||||
update_placeholder_visibility();
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::readonly) {
|
||||
handle_readonly_attribute(value);
|
||||
} else if (name == HTML::AttributeNames::src) {
|
||||
handle_src_attribute(value.value_or({})).release_value_but_fixme_should_propagate_errors();
|
||||
} else if (name == HTML::AttributeNames::alt) {
|
||||
|
@ -3563,4 +3553,16 @@ void HTMLInputElement::set_is_open(bool is_open)
|
|||
invalidate_style(DOM::StyleInvalidationReason::HTMLInputElementSetIsOpen);
|
||||
}
|
||||
|
||||
bool HTMLInputElement::is_mutable() const
|
||||
{
|
||||
return
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:concept-fe-mutable-3
|
||||
// A select element that is not disabled is mutable.
|
||||
enabled()
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-readonly-attribute:concept-fe-mutable
|
||||
// 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.
|
||||
&& !(has_attribute(AttributeNames::readonly) && is_allowed_to_be_readonly(m_type));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue