diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-08-16 15:46:17 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-08-18 14:31:35 +0200 |
commit | d1725b1f195652bf947d5ce00622807597bc0b9c (patch) | |
tree | 5c0416212d033bcbbf19574134ff7fc74531a17a /components/script/dom/htmlstyleelement.rs | |
parent | b8159e659e787c1e792d13b0939bb88e978ae84e (diff) | |
download | servo-d1725b1f195652bf947d5ce00622807597bc0b9c.tar.gz servo-d1725b1f195652bf947d5ce00622807597bc0b9c.zip |
style: Replicate the list of stylesheets on the layout thread.
This is a patch that unifies a bit how Gecko and Stylo stylesheets work, in
order to be able to eventually move the stylesheets into the stylist, and be
able to incrementally update the invalidation map.
Diffstat (limited to 'components/script/dom/htmlstyleelement.rs')
-rw-r--r-- | components/script/dom/htmlstyleelement.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 9c6f34ba7bd..222f25a9b1d 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -20,7 +20,6 @@ use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use net_traits::ReferrerPolicy; -use script_layout_interface::message::Msg; use servo_arc::Arc; use std::cell::Cell; use style::media_queries::parse_media_query_list; @@ -109,10 +108,18 @@ impl HTMLStyleElement { self.upcast::<EventTarget>().fire_event(atom!("load")); } - win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap(); - *self.stylesheet.borrow_mut() = Some(sheet); + self.set_stylesheet(sheet); + } + + // FIXME(emilio): This is duplicated with HTMLLinkElement::set_stylesheet. + pub fn set_stylesheet(&self, s: Arc<Stylesheet>) { + let doc = document_from_node(self); + if let Some(ref s) = *self.stylesheet.borrow() { + doc.remove_stylesheet(self.upcast(), s) + } + *self.stylesheet.borrow_mut() = Some(s.clone()); self.cssom_stylesheet.set(None); - doc.invalidate_stylesheets(); + doc.add_stylesheet(self.upcast(), s); } pub fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> { @@ -180,8 +187,12 @@ impl VirtualMethods for HTMLStyleElement { s.unbind_from_tree(context); } - let doc = document_from_node(self); - doc.invalidate_stylesheets(); + if context.tree_in_doc { + if let Some(ref s) = *self.stylesheet.borrow() { + let doc = document_from_node(self); + doc.remove_stylesheet(self.upcast(), s) + } + } } } |