Register/unregister shadow roots in documents when they are connected

This commit is contained in:
Fernando Jiménez Moreno 2019-02-12 12:44:44 +01:00
parent cd07574235
commit 18c1b8f690
2 changed files with 30 additions and 6 deletions

View file

@ -377,6 +377,8 @@ pub struct Document {
delayed_tasks: DomRefCell<Vec<Box<dyn TaskBox>>>,
/// https://html.spec.whatwg.org/multipage/#completely-loaded
completely_loaded: Cell<bool>,
/// List of shadow roots bound to the document tree.
shadow_roots: DomRefCell<Vec<Dom<ShadowRoot>>>,
}
#[derive(JSTraceable, MallocSizeOf)]
@ -2680,6 +2682,7 @@ impl Document {
completely_loaded: Cell::new(false),
script_and_layout_blockers: Cell::new(0),
delayed_tasks: Default::default(),
shadow_roots: DomRefCell::new(Vec::new()),
}
}
@ -3132,6 +3135,20 @@ impl Document {
}
}
}
pub fn register_shadow_root(&self, shadow_root: &ShadowRoot) {
self.shadow_roots
.borrow_mut()
.push(Dom::from_ref(shadow_root));
}
pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) {
let mut shadow_roots = self.shadow_roots.borrow_mut();
let position = shadow_roots.iter().position(|sr| **sr == *shadow_root);
if let Some(index) = position {
shadow_roots.remove(index);
}
}
}
impl Element {