LibWeb: Fire slotchange events when a slot is changed

This commit is contained in:
Shannon Booth 2025-03-08 16:03:54 +13:00 committed by Tim Flynn
commit b543523717
Notes: github-actions[bot] 2025-03-10 18:38:25 +00:00
7 changed files with 717 additions and 5 deletions

View file

@ -28,6 +28,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/CustomElements/CustomElementDefinition.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/HTMLSlotElement.h>
#include <LibWeb/HTML/Location.h>
#include <LibWeb/HTML/PromiseRejectionEvent.h>
#include <LibWeb/HTML/Scripting/Agent.h>
@ -677,9 +678,9 @@ void queue_mutation_observer_microtask(DOM::Document const& document)
for (auto& observer : surrounding_agent.mutation_observers)
notify_set.append(&observer);
// FIXME: 3. Let signalSet be a clone of the surrounding agents signal slots.
// FIXME: 4. Empty the surrounding agents signal slots.
// 3. Let signalSet be a clone of the surrounding agents signal slots.
// 4. Empty the surrounding agents signal slots.
auto signal_set = move(surrounding_agent.signal_slots);
// 5. For each mo of notifySet:
for (auto& mutation_observer : notify_set) {
@ -716,7 +717,12 @@ void queue_mutation_observer_microtask(DOM::Document const& document)
}
}
// FIXME: 6. For each slot of signalSet, fire an event named slotchange, with its bubbles attribute set to true, at slot.
// 6. For each slot of signalSet, fire an event named slotchange, with its bubbles attribute set to true, at slot.
for (auto& slot : signal_set) {
DOM::EventInit event_init;
event_init.bubbles = true;
slot->dispatch_event(DOM::Event::create(slot->realm(), HTML::EventNames::slotchange, event_init));
}
}));
}

View file

@ -206,7 +206,8 @@ void assign_a_slot(Slottable const& slottable)
// https://dom.spec.whatwg.org/#signal-a-slot-change
void signal_a_slot_change(GC::Ref<HTML::HTMLSlotElement> slottable)
{
// FIXME: 1. Append slot to slots relevant agents signal slots.
// 1. Append slot to slots relevant agents signal slots.
HTML::relevant_agent(slottable).signal_slots.append(slottable);
// 2. Queue a mutation observer microtask.
Bindings::queue_mutation_observer_microtask(slottable->document());

View file

@ -32,6 +32,10 @@ struct Agent {
// Each similar-origin window agent has a custom element reactions stack, which is initially empty.
CustomElementReactionsStack custom_element_reactions_stack {};
// https://dom.spec.whatwg.org/#signal-slot-list
// Each similar-origin window agent has signal slots (a set of slots), which is initially empty. [HTML]
Vector<GC::Root<HTML::HTMLSlotElement>> signal_slots;
// https://html.spec.whatwg.org/multipage/custom-elements.html#current-element-queue
// A similar-origin window agent's current element queue is the element queue at the top of its custom element reactions stack.
Vector<GC::Root<DOM::Element>>& current_element_queue() { return custom_element_reactions_stack.element_queue_stack.last(); }