Fire slot change events when the slot content changes (#35137)

* Add the onslotchange attribute to ShadowRoot

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Add spec comments to MutationObserver::queue_mutation_observer_microtask

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Add DomRefCell::take

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Add spec comments to notify_mutation_observers

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Fire slotchange events when a slot changes

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* ./mach fmt

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Fix check for when to dispatch slot events

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Potentially fire slot change events in Node::remove

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* ./mach fmt

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Bump stylo

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move "signal a slot change" into ScriptThread impl

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-01-27 15:13:22 +01:00 committed by GitHub
parent cd93841ba1
commit 859cc6ab9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 152 additions and 119 deletions

View file

@ -32,6 +32,7 @@ use crate::dom::node::{Node, ShadowIncluding};
use crate::dom::text::Text;
use crate::dom::virtualmethods::VirtualMethods;
use crate::script_runtime::CanGc;
use crate::ScriptThread;
/// <https://html.spec.whatwg.org/multipage/#the-slot-element>
#[dom_struct]
@ -185,6 +186,10 @@ impl HTMLSlotElement {
)
}
pub(crate) fn has_assigned_nodes(&self) -> bool {
!self.assigned_nodes.borrow().is_empty()
}
/// <https://dom.spec.whatwg.org/#find-flattened-slotables>
fn find_flattened_slottables(&self, result: &mut RootedVec<Slottable>) {
// Step 1. Let result be an empty list.
@ -312,8 +317,12 @@ impl HTMLSlotElement {
rooted_vec!(let mut slottables);
self.find_slottables(&mut slottables);
// Step 2. TODO If slottables and slots assigned nodes are not identical,
// Step 2. If slottables and slots assigned nodes are not identical,
// then run signal a slot change for slot.
let slots_are_identical = self.assigned_nodes.borrow().iter().eq(slottables.iter());
if !slots_are_identical {
ScriptThread::signal_a_slot_change(self);
}
// Step 3. Set slots assigned nodes to slottables.
*self.assigned_nodes.borrow_mut() = slottables.iter().cloned().collect();