1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LibWeb: Implement Document named properties with light caching

We now cache potentially named elements on the Document when elements
are inserted and removed. This allows us to do lookup of what names are
supported much faster than if we had to iterate the tree every time.

This first cut doesn't implement the rules for 'exposed' object and
embed elements.
This commit is contained in:
Andrew Kaster 2024-02-15 14:43:44 -07:00 committed by Tim Flynn
parent faaf5b9652
commit 94149db073
6 changed files with 285 additions and 8 deletions

View file

@ -466,12 +466,14 @@ void Element::attribute_changed(FlyString const& name, Optional<String> const& v
else
m_id = value_or_empty;
document().element_id_changed({});
document().element_id_changed({}, *this);
} else if (name == HTML::AttributeNames::name) {
if (!value.has_value())
m_name = {};
else
m_name = value_or_empty;
document().element_name_changed({}, *this);
} else if (name == HTML::AttributeNames::class_) {
auto new_classes = value_or_empty.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
m_classes.clear();
@ -1033,7 +1035,10 @@ void Element::inserted()
Base::inserted();
if (m_id.has_value())
document().element_with_id_was_added_or_removed({});
document().element_with_id_was_added({}, *this);
if (m_name.has_value())
document().element_with_name_was_added({}, *this);
}
void Element::removed_from(Node* node)
@ -1041,7 +1046,10 @@ void Element::removed_from(Node* node)
Base::removed_from(node);
if (m_id.has_value())
document().element_with_id_was_added_or_removed({});
document().element_with_id_was_removed({}, *this);
if (m_name.has_value())
document().element_with_name_was_removed({}, *this);
}
void Element::children_changed()