aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-01-07 10:56:02 +0100
committerGitHub <noreply@github.com>2025-01-07 09:56:02 +0000
commite42b4b793d52e756e79c8a408b3f7e99219493f5 (patch)
tree1346ec6841f8e37b00018c836a29fb227f026d41 /components/script/dom/node.rs
parent17e2ca3f013e2ff8e7d7bca08d93c6c723a2b71d (diff)
downloadservo-e42b4b793d52e756e79c8a408b3f7e99219493f5.tar.gz
servo-e42b4b793d52e756e79c8a408b3f7e99219493f5.zip
script: Expose `NodeTraits::owner_global` / `Window::as_global_scope` (#34843)
Expose two new helpers and start using them as much as possible. - `NodeTraits::owner_global`: which gets the `GlobalScope` that currenty owns a `Node`. This may be different than `.global()` in the case that the `Node` was adopted by a different `Document`. - `Window::as_global_scope`: A helper to avoid having to cast so much when treating a `Window` like a `GlobalScope`. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 7cb3cacd2ac..9ae38955a57 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -45,6 +45,7 @@ use style::stylesheets::{Stylesheet, UrlExtraData};
use uuid::Uuid;
use xml5ever::serialize as xml_serialize;
+use super::globalscope::GlobalScope;
use crate::document_loader::DocumentLoader;
use crate::dom::attr::Attr;
use crate::dom::bindings::cell::{DomRefCell, Ref, RefMut};
@@ -3346,6 +3347,10 @@ pub(crate) trait NodeTraits {
/// differ from the [`Document`] that the node was created in if it was adopted by a
/// different [`Document`] (the owner).
fn owner_window(&self) -> DomRoot<Window>;
+ /// Get the [`GlobalScope`] of the [`Document`] that owns this node. Note that this may
+ /// differ from the [`GlobalScope`] that the node was created in if it was adopted by a
+ /// different [`Document`] (the owner).
+ fn owner_global(&self) -> DomRoot<GlobalScope>;
/// If this [`Node`] is contained in a [`ShadowRoot`] return it, otherwise `None`.
fn containing_shadow_root(&self) -> Option<DomRoot<ShadowRoot>>;
/// Get the stylesheet owner for this node: either the [`Document`] or the [`ShadowRoot`]
@@ -3363,6 +3368,10 @@ impl<T: DerivedFrom<Node> + DomObject> NodeTraits for T {
DomRoot::from_ref(self.owner_document().window())
}
+ fn owner_global(&self) -> DomRoot<GlobalScope> {
+ DomRoot::from_ref(self.owner_window().upcast())
+ }
+
fn containing_shadow_root(&self) -> Option<DomRoot<ShadowRoot>> {
Node::containing_shadow_root(self.upcast())
}