diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 0d25b535593..3c02d76e7d0 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -379,6 +379,8 @@ pub struct Document { completely_loaded: Cell<bool>, /// List of shadow roots bound to the document tree. shadow_roots: DomRefCell<Vec<Dom<ShadowRoot>>>, + /// Whether any of the shadow roots need the stylesheets flushed. + shadow_roots_styles_changed: Cell<bool>, } #[derive(JSTraceable, MallocSizeOf)] @@ -2431,6 +2433,8 @@ pub trait LayoutDocumentHelpers { unsafe fn quirks_mode(&self) -> QuirksMode; unsafe fn style_shared_lock(&self) -> &StyleSharedRwLock; unsafe fn shadow_roots(&self) -> Vec<LayoutDom<ShadowRoot>>; + unsafe fn shadow_roots_styles_changed(&self) -> bool; + unsafe fn flush_shadow_roots_stylesheets(&self); } #[allow(unsafe_code)] @@ -2485,6 +2489,16 @@ impl LayoutDocumentHelpers for LayoutDom<Document> { .map(|sr| sr.to_layout()) .collect() } + + #[inline] + unsafe fn shadow_roots_styles_changed(&self) -> bool { + (*self.unsafe_get()).shadow_roots_styles_changed() + } + + #[inline] + unsafe fn flush_shadow_roots_stylesheets(&self) { + (*self.unsafe_get()).flush_shadow_roots_stylesheets() + } } // https://html.spec.whatwg.org/multipage/#is-a-registrable-domain-suffix-of-or-is-equal-to @@ -2694,6 +2708,7 @@ impl Document { script_and_layout_blockers: Cell::new(0), delayed_tasks: Default::default(), shadow_roots: DomRefCell::new(Vec::new()), + shadow_roots_styles_changed: Cell::new(false), } } @@ -3151,6 +3166,7 @@ impl Document { self.shadow_roots .borrow_mut() .push(Dom::from_ref(shadow_root)); + self.invalidate_shadow_roots_stylesheets(); } pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) { @@ -3160,6 +3176,21 @@ impl Document { shadow_roots.remove(index); } } + + pub fn invalidate_shadow_roots_stylesheets(&self) { + self.shadow_roots_styles_changed.set(true); + } + + pub fn shadow_roots_styles_changed(&self) -> bool { + self.shadow_roots_styles_changed.get() + } + + pub fn flush_shadow_roots_stylesheets(&self) { + if !self.shadow_roots_styles_changed.get() { + return; + } + self.shadow_roots_styles_changed.set(false); + } } impl Element { |