Skip to content

Commit

Permalink
Added a mapping between nodes and stylesheets
Browse files Browse the repository at this point in the history
Changed stylesheets into_iter to iter
  • Loading branch information
cbrewster committed Mar 31, 2016
1 parent 3c00aff commit f727444
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions components/script/dom/document.rs
Expand Up @@ -157,7 +157,7 @@ pub struct Document {
anchors: MutNullableHeap<JS<HTMLCollection>>,
applets: MutNullableHeap<JS<HTMLCollection>>,
/// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed.
stylesheets: DOMRefCell<Option<Vec<Arc<Stylesheet>>>>,
stylesheets: DOMRefCell<Option<Vec<(JS<Node>, Arc<Stylesheet>)>>>,
/// Whether the list of stylesheets has changed since the last reflow was triggered.
stylesheets_changed_since_reflow: Cell<bool>,
ready_state: Cell<DocumentReadyState>,
Expand Down Expand Up @@ -1635,11 +1635,11 @@ impl Document {
}

/// Returns the list of stylesheets associated with nodes in the document.
pub fn stylesheets(&self) -> Ref<Vec<Arc<Stylesheet>>> {
pub fn stylesheets(&self) -> Vec<Arc<Stylesheet>> {
{
let mut stylesheets = self.stylesheets.borrow_mut();
if stylesheets.is_none() {
let new_stylesheets: Vec<Arc<Stylesheet>> = self.upcast::<Node>()
*stylesheets = Some(self.upcast::<Node>()
.traverse_preorder()
.filter_map(|node| {
if let Some(node) = node.downcast::<HTMLStyleElement>() {
Expand All @@ -1650,13 +1650,14 @@ impl Document {
node.get_stylesheet()
} else {
None
}
}.map(|stylesheet| (JS::from_rooted(&node), stylesheet))
})
.collect();
*stylesheets = Some(new_stylesheets);
.collect());
};
}
Ref::map(self.stylesheets.borrow(), |t| t.as_ref().unwrap())
self.stylesheets.borrow().as_ref().unwrap().iter()
.map(|&(_, ref stylesheet)| stylesheet.clone())
.collect()
}

/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/window.rs
Expand Up @@ -996,7 +996,7 @@ impl Window {
page_clip_rect: self.page_clip_rect.get(),
},
document: self.Document().upcast::<Node>().to_trusted_node_address(),
document_stylesheets: document.stylesheets().clone(),
document_stylesheets: document.stylesheets(),
stylesheets_changed: stylesheets_changed,
window_size: window_size,
script_join_chan: join_chan,
Expand Down

0 comments on commit f727444

Please sign in to comment.