Skip to content
Permalink
Browse files

Added a mapping between nodes and stylesheets

Changed stylesheets into_iter to iter
  • Loading branch information...
cbrewster committed Mar 26, 2016
1 parent 3c00aff commit f727444a147851c36bbb09eba3e5a2c8f54e391f
Showing with 9 additions and 8 deletions.
  1. +8 −7 components/script/dom/document.rs
  2. +1 −1 components/script/dom/window.rs
@@ -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>,
@@ -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>() {
@@ -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
@@ -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,

0 comments on commit f727444

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