1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 12:05:07 +00:00

LibWeb: Implement automatic slottable assignment

This implements automatic slottable assignment by way of hooking into
the element attribute change steps. When the `name` attribute of a slot
or the `slot` attribute of a slottable changes, assignment is performed.
This commit is contained in:
Timothy Flynn 2023-09-05 15:08:35 -04:00 committed by Andreas Kling
parent e9da74ebe0
commit b602ee7ddd
3 changed files with 85 additions and 4 deletions

View file

@ -15,6 +15,33 @@ namespace Web::HTML {
HTMLSlotElement::HTMLSlotElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
// https://dom.spec.whatwg.org/#ref-for-concept-element-attributes-change-ext
add_attribute_change_steps([this](auto const& local_name, auto const& old_value, auto const& value, auto const& namespace_) {
// 1. If element is a slot, localName is name, and namespace is null, then:
if (local_name == AttributeNames::name && namespace_.is_null()) {
// 1. If value is oldValue, then return.
if (value == old_value)
return;
// 2. If value is null and oldValue is the empty string, then return.
if (value.is_null() && old_value == DeprecatedString::empty())
return;
// 3. If value is the empty string and oldValue is null, then return.
if (value == DeprecatedString::empty() && old_value.is_null())
return;
// 4. If value is null or the empty string, then set elements name to the empty string.
if (value.is_empty())
set_slot_name({});
// 5. Otherwise, set elements name to value.
else
set_slot_name(MUST(String::from_deprecated_string(value)));
// 6. Run assign slottables for a tree with elements root.
DOM::assign_slottables_for_a_tree(root());
}
});
}
HTMLSlotElement::~HTMLSlotElement() = default;