LibWeb: Port handle_readonly_attribute from DeprecatedFlyString

It's a little awkward that one caller of this is passing through an
Optional<String> and another an Optional<DeprecatedString>, but that
should be fixed some point in the future with further DeprecatedString
porting.
This commit is contained in:
Shannon Booth 2023-11-05 12:17:24 +13:00 committed by Andreas Kling
parent 22f6abe5d6
commit f2e77f7778
Notes: sideshowbarker 2024-07-16 19:17:47 +09:00
2 changed files with 5 additions and 9 deletions

View file

@ -447,10 +447,10 @@ static bool is_allowed_to_be_readonly(HTML::HTMLInputElement::TypeAttributeState
} }
// https://html.spec.whatwg.org/multipage/input.html#attr-input-readonly // https://html.spec.whatwg.org/multipage/input.html#attr-input-readonly
void HTMLInputElement::handle_readonly_attribute(DeprecatedFlyString const& value) 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. // 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.
m_is_mutable = !(!value.is_null() && is_allowed_to_be_readonly(m_type)); m_is_mutable = !maybe_value.has_value() || !is_allowed_to_be_readonly(m_type);
if (m_text_node) if (m_text_node)
m_text_node->set_always_editable(m_is_mutable); m_text_node->set_always_editable(m_is_mutable);
@ -563,11 +563,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
// NOTE: file upload state is mutable, but we don't allow the text node to be modifed // NOTE: file upload state is mutable, but we don't allow the text node to be modifed
m_text_node->set_always_editable(false); m_text_node->set_always_editable(false);
} else { } else {
auto readonly = attribute(HTML::AttributeNames::readonly); handle_readonly_attribute(attribute(HTML::AttributeNames::readonly));
if (readonly.has_value())
handle_readonly_attribute(readonly->to_deprecated_string());
else
handle_readonly_attribute({});
} }
m_text_node->set_editable_text_node_owner(Badge<HTMLInputElement> {}, *this); m_text_node->set_editable_text_node_owner(Badge<HTMLInputElement> {}, *this);
@ -671,7 +667,7 @@ void HTMLInputElement::attribute_changed(FlyString const& name, Optional<Depreca
m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value.value_or("")))); m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value.value_or(""))));
} else if (name == HTML::AttributeNames::readonly) { } else if (name == HTML::AttributeNames::readonly) {
if (value.has_value()) if (value.has_value())
handle_readonly_attribute(*value); handle_readonly_attribute(MUST(String::from_deprecated_string(*value)));
else else
handle_readonly_attribute({}); handle_readonly_attribute({});
} }

View file

@ -174,7 +174,7 @@ private:
WebIDL::ExceptionOr<void> run_input_activation_behavior(); WebIDL::ExceptionOr<void> run_input_activation_behavior();
void set_checked_within_group(); void set_checked_within_group();
void handle_readonly_attribute(DeprecatedFlyString const& value); void handle_readonly_attribute(Optional<String> const& value);
// https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm // https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm
DeprecatedString value_sanitization_algorithm(DeprecatedString) const; DeprecatedString value_sanitization_algorithm(DeprecatedString) const;