Skip to content
Permalink
Browse files

Tweak list of shadow roots attached to doc

  • Loading branch information...
ferjm committed Mar 6, 2019
1 parent b8925a0 commit 0313e38074d4fb768c914bfe6e73ae959e098394
Showing with 14 additions and 10 deletions.
  1. +4 −1 components/layout_thread/dom_wrapper.rs
  2. +4 −7 components/script/dom/document.rs
  3. +6 −2 components/script/dom/element.rs
@@ -430,7 +430,10 @@ impl<'ld> ServoLayoutDocument<'ld> {
self.document
.shadow_roots()
.iter()
.map(|sr| ServoShadowRoot::from_layout_js(*sr))
.map(|sr| {
debug_assert!(sr.upcast::<Node>().get_flag(NodeFlags::IS_CONNECTED));
ServoShadowRoot::from_layout_js(*sr)
})
.collect()
}
}
@@ -377,7 +377,7 @@ pub struct Document {
/// 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>>>,
shadow_roots: DomRefCell<HashSet<Dom<ShadowRoot>>>,
/// Whether any of the shadow roots need the stylesheets flushed.
shadow_roots_styles_changed: Cell<bool>,
}
@@ -2674,7 +2674,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()),
shadow_roots: DomRefCell::new(HashSet::new()),
shadow_roots_styles_changed: Cell::new(false),
}
}
@@ -3132,16 +3132,13 @@ impl Document {
pub fn register_shadow_root(&self, shadow_root: &ShadowRoot) {
self.shadow_roots
.borrow_mut()
.push(Dom::from_ref(shadow_root));
.insert(Dom::from_ref(shadow_root));
self.invalidate_shadow_roots_stylesheets();
}

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);
}
shadow_roots.remove(&Dom::from_ref(shadow_root));
}

pub fn invalidate_shadow_roots_stylesheets(&self) {
@@ -489,7 +489,9 @@ impl Element {
.shadow_root
.or_init(|| ShadowRoot::new(self, &*self.node.owner_doc()));

self.node.owner_doc().register_shadow_root(&*shadow_root);
if self.is_connected() {
self.node.owner_doc().register_shadow_root(&*shadow_root);
}

Ok(shadow_root)
}
@@ -2802,7 +2804,10 @@ impl VirtualMethods for Element {
f.bind_form_control_to_tree();
}

let doc = document_from_node(self);

if let Some(shadow_root) = self.rare_data.shadow_root.get() {
doc.register_shadow_root(&shadow_root);
let shadow_root = shadow_root.upcast::<Node>();
shadow_root.set_flag(NodeFlags::IS_CONNECTED, context.tree_connected);
for node in shadow_root.children() {
@@ -2815,7 +2820,6 @@ impl VirtualMethods for Element {
return;
}

let doc = document_from_node(self);
if let Some(ref value) = *self.id_attribute.borrow() {
if let Some(shadow_root) = self.upcast::<Node>().owner_shadow_root() {
shadow_root.register_named_element(self, value.clone());

0 comments on commit 0313e38

Please sign in to comment.
You can’t perform that action at this time.