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.
This commit is contained in:
Emilio Cobos Álvarez 2017-08-16 15:46:17 +02:00
parent b8159e659e
commit d1725b1f19
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
14 changed files with 413 additions and 198 deletions

View file

@ -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)
}
}
}
}