aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index cb61bb393ef..12b47cf4d96 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -69,6 +69,7 @@ use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::range::Range;
use dom::servohtmlparser::{ParserRoot, ParserRef, MutNullableParserField};
+use dom::stylesheetlist::StyleSheetList;
use dom::text::Text;
use dom::touch::Touch;
use dom::touchevent::TouchEvent;
@@ -157,7 +158,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>,
@@ -1648,11 +1649,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>() {
@@ -1663,13 +1664,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
@@ -1736,6 +1738,11 @@ impl Element {
}
impl DocumentMethods for Document {
+ // https://drafts.csswg.org/cssom/#dom-document-stylesheets
+ fn StyleSheets(&self) -> Root<StyleSheetList> {
+ StyleSheetList::new(&self.window, JS::from_ref(&self))
+ }
+
// https://dom.spec.whatwg.org/#dom-document-implementation
fn Implementation(&self) -> Root<DOMImplementation> {
self.implementation.or_init(|| DOMImplementation::new(self))