aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorSimon Wülker <simon.wuelker@arcor.de>2025-01-27 15:13:22 +0100
committerGitHub <noreply@github.com>2025-01-27 14:13:22 +0000
commit859cc6ab9b9da0bf92ff623f087ecd728cf120c2 (patch)
tree58ae026f06e7f648aba6bf13eccb10da29d44069 /components/script/script_thread.rs
parentcd93841ba188ac89fc18ef597c07d0f135615a7d (diff)
downloadservo-859cc6ab9b9da0bf92ff623f087ecd728cf120c2.tar.gz
servo-859cc6ab9b9da0bf92ff623f087ecd728cf120c2.zip
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>
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 13558b81832..c232fb9fe51 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -128,6 +128,7 @@ use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlanchorelement::HTMLAnchorElement;
use crate::dom::htmliframeelement::HTMLIFrameElement;
+use crate::dom::htmlslotelement::HTMLSlotElement;
use crate::dom::mutationobserver::MutationObserver;
use crate::dom::node::{Node, NodeTraits, ShadowIncluding};
use crate::dom::performanceentry::PerformanceEntry;
@@ -259,6 +260,9 @@ pub struct ScriptThread {
/// The unit of related similar-origin browsing contexts' list of MutationObserver objects
mutation_observers: DomRefCell<Vec<Dom<MutationObserver>>>,
+ /// <https://dom.spec.whatwg.org/#signal-slot-list>
+ signal_slots: DomRefCell<Vec<Dom<HTMLSlotElement>>>,
+
/// A handle to the WebGL thread
#[no_trace]
webgl_chan: Option<WebGLPipeline>,
@@ -508,6 +512,26 @@ impl ScriptThread {
})
}
+ pub(crate) fn add_signal_slot(observer: &HTMLSlotElement) {
+ with_script_thread(|script_thread| {
+ script_thread
+ .signal_slots
+ .borrow_mut()
+ .push(Dom::from_ref(observer));
+ })
+ }
+
+ pub(crate) fn take_signal_slots() -> Vec<DomRoot<HTMLSlotElement>> {
+ with_script_thread(|script_thread| {
+ script_thread
+ .signal_slots
+ .take()
+ .into_iter()
+ .map(|slot| slot.as_rooted())
+ .collect()
+ })
+ }
+
pub(crate) fn mark_document_with_no_blocked_loads(doc: &Document) {
with_script_thread(|script_thread| {
script_thread
@@ -914,6 +938,7 @@ impl ScriptThread {
closed_pipelines: DomRefCell::new(HashSet::new()),
mutation_observer_microtask_queued: Default::default(),
mutation_observers: Default::default(),
+ signal_slots: Default::default(),
system_font_service,
webgl_chan: state.webgl_chan,
#[cfg(feature = "webxr")]
@@ -3718,6 +3743,15 @@ impl ScriptThread {
)
}
}
+
+ /// <https://dom.spec.whatwg.org/#signal-a-slot-change>
+ pub(crate) fn signal_a_slot_change(slot: &HTMLSlotElement) {
+ // Step 1. Append slot to slot’s relevant agent’s signal slots.
+ ScriptThread::add_signal_slot(slot);
+
+ // Step 2. Queue a mutation observer microtask.
+ MutationObserver::queue_mutation_observer_microtask();
+ }
}
impl Drop for ScriptThread {