1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

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
18 changed files with 86 additions and 152 deletions

View file

@ -233,15 +233,19 @@ void HTMLElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedS
Element::attribute_changed(name, value);
if (name == HTML::AttributeNames::contenteditable) {
if ((!value.is_null() && value.is_empty()) || value.equals_ignoring_ascii_case("true"sv)) {
// "true", an empty string or a missing value map to the "true" state.
m_content_editable_state = ContentEditableState::True;
} else if (value.equals_ignoring_ascii_case("false"sv)) {
// "false" maps to the "false" state.
m_content_editable_state = ContentEditableState::False;
} else {
// Having no such attribute or an invalid value maps to the "inherit" state.
if (value.is_null()) {
m_content_editable_state = ContentEditableState::Inherit;
} else {
if (value.is_empty() || value.equals_ignoring_ascii_case("true"sv)) {
// "true", an empty string or a missing value map to the "true" state.
m_content_editable_state = ContentEditableState::True;
} else if (value.equals_ignoring_ascii_case("false"sv)) {
// "false" maps to the "false" state.
m_content_editable_state = ContentEditableState::False;
} else {
// Having no such attribute or an invalid value maps to the "inherit" state.
m_content_editable_state = ContentEditableState::Inherit;
}
}
}
@ -256,14 +260,6 @@ void HTMLElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedS
#undef __ENUMERATE
}
void HTMLElement::did_remove_attribute(DeprecatedFlyString const& name)
{
Base::did_remove_attribute(name);
if (name == HTML::AttributeNames::contenteditable) {
m_content_editable_state = ContentEditableState::Inherit;
}
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-focus
void HTMLElement::focus()
{