mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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:
parent
cd93841ba1
commit
859cc6ab9b
17 changed files with 152 additions and 119 deletions
|
@ -15,9 +15,11 @@ use crate::dom::bindings::codegen::Bindings::MutationObserverBinding::{
|
|||
MutationCallback, MutationObserverInit,
|
||||
};
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::mutationrecord::MutationRecord;
|
||||
use crate::dom::node::{Node, ShadowIncluding};
|
||||
use crate::dom::window::Window;
|
||||
|
@ -90,35 +92,57 @@ impl MutationObserver {
|
|||
|
||||
/// <https://dom.spec.whatwg.org/#queue-a-mutation-observer-compound-microtask>
|
||||
pub(crate) fn queue_mutation_observer_microtask() {
|
||||
// Step 1
|
||||
// Step 1. If the surrounding agent’s mutation observer microtask queued is true, then return.
|
||||
if ScriptThread::is_mutation_observer_microtask_queued() {
|
||||
return;
|
||||
}
|
||||
// Step 2
|
||||
|
||||
// Step 2. Set the surrounding agent’s mutation observer microtask queued to true.
|
||||
ScriptThread::set_mutation_observer_microtask_queued(true);
|
||||
// Step 3
|
||||
|
||||
// Step 3. Queue a microtask to notify mutation observers.
|
||||
ScriptThread::enqueue_microtask(Microtask::NotifyMutationObservers);
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#notify-mutation-observers>
|
||||
pub(crate) fn notify_mutation_observers() {
|
||||
// Step 1
|
||||
pub(crate) fn notify_mutation_observers(can_gc: CanGc) {
|
||||
// Step 1. Set the surrounding agent’s mutation observer microtask queued to false.
|
||||
ScriptThread::set_mutation_observer_microtask_queued(false);
|
||||
// Step 2
|
||||
|
||||
// Step 2. Let notifySet be a clone of the surrounding agent’s pending mutation observers.
|
||||
// TODO Step 3. Empty the surrounding agent’s pending mutation observers.
|
||||
let notify_list = ScriptThread::get_mutation_observers();
|
||||
// TODO: steps 3-4 (slots)
|
||||
// Step 5
|
||||
|
||||
// Step 4. Let signalSet be a clone of the surrounding agent’s signal slots.
|
||||
// Step 5. Empty the surrounding agent’s signal slots.
|
||||
let signal_set = ScriptThread::take_signal_slots();
|
||||
|
||||
// Step 6. For each mo of notifySet:
|
||||
for mo in ¬ify_list {
|
||||
// Step 6.1 Let records be a clone of mo’s record queue.
|
||||
let queue: Vec<DomRoot<MutationRecord>> = mo.record_queue.borrow().clone();
|
||||
|
||||
// Step 6.2 Empty mo’s record queue.
|
||||
mo.record_queue.borrow_mut().clear();
|
||||
// TODO: Step 5.3 Remove all transient registered observers whose observer is mo.
|
||||
|
||||
// TODO Step 6.3 For each node of mo’s node list, remove all transient registered observers
|
||||
// whose observer is mo from node’s registered observer list.
|
||||
|
||||
// Step 6.4 If records is not empty, then invoke mo’s callback with « records,
|
||||
// mo » and "report", and with callback this value mo.
|
||||
if !queue.is_empty() {
|
||||
let _ = mo
|
||||
.callback
|
||||
.Call_(&**mo, queue, mo, ExceptionHandling::Report);
|
||||
}
|
||||
}
|
||||
// TODO: Step 6 (slot signals)
|
||||
|
||||
// Step 6. For each slot of signalSet, fire an event named slotchange,
|
||||
// with its bubbles attribute set to true, at slot.
|
||||
for slot in signal_set {
|
||||
slot.upcast::<EventTarget>()
|
||||
.fire_event(atom!("slotchange"), can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#queueing-a-mutation-record>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue