LibWeb: Merge did_remove_attribute() into attribute_changed()

Instead of having two virtuals for attribute change notifications,
there is now only one. When the attribute is removed, the value is null.
This commit is contained in:
Andreas Kling 2023-07-03 17:31:17 +02:00
parent 5a74486b59
commit 21260ea2ef
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
18 changed files with 86 additions and 152 deletions

View file

@ -497,16 +497,30 @@ void HTMLInputElement::attribute_changed(DeprecatedFlyString const& name, Deprec
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::checked) {
// When the checked content attribute is added, if the control does not have dirty checkedness,
// the user agent must set the checkedness of the element to true
if (!m_dirty_checkedness)
set_checked(true, ChangeSource::Programmatic);
if (value.is_null()) {
// When the checked content attribute is removed, if the control does not have dirty checkedness,
// the user agent must set the checkedness of the element to false.
if (!m_dirty_checkedness)
set_checked(false, ChangeSource::Programmatic);
} else {
// When the checked content attribute is added, if the control does not have dirty checkedness,
// the user agent must set the checkedness of the element to true
if (!m_dirty_checkedness)
set_checked(true, ChangeSource::Programmatic);
}
} else if (name == HTML::AttributeNames::type) {
m_type = parse_type_attribute(value);
} else if (name == HTML::AttributeNames::value) {
if (!m_dirty_value) {
m_value = value_sanitization_algorithm(value);
update_placeholder_visibility();
if (value.is_null()) {
if (!m_dirty_value) {
m_value = DeprecatedString::empty();
update_placeholder_visibility();
}
} else {
if (!m_dirty_value) {
m_value = value_sanitization_algorithm(value);
update_placeholder_visibility();
}
}
} else if (name == HTML::AttributeNames::placeholder) {
if (m_placeholder_text_node)
@ -528,25 +542,6 @@ HTMLInputElement::TypeAttributeState HTMLInputElement::parse_type_attribute(Stri
return HTMLInputElement::TypeAttributeState::Text;
}
void HTMLInputElement::did_remove_attribute(DeprecatedFlyString const& name)
{
HTMLElement::did_remove_attribute(name);
if (name == HTML::AttributeNames::checked) {
// When the checked content attribute is removed, if the control does not have dirty checkedness,
// the user agent must set the checkedness of the element to false.
if (!m_dirty_checkedness)
set_checked(false, ChangeSource::Programmatic);
} else if (name == HTML::AttributeNames::value) {
if (!m_dirty_value) {
m_value = DeprecatedString::empty();
update_placeholder_visibility();
}
} else if (name == HTML::AttributeNames::placeholder) {
if (m_placeholder_text_node)
m_placeholder_text_node->set_data({});
}
}
DeprecatedString HTMLInputElement::type() const
{
switch (m_type) {
@ -1104,5 +1099,4 @@ bool HTMLInputElement::is_submit_button() const
return type_state() == TypeAttributeState::SubmitButton
|| type_state() == TypeAttributeState::ImageButton;
}
}