Auto merge of #18484 - emilio:per-origin-sheets, r=SimonSapin

style: Store stylesheets per origin

This is the first step that will allow us to cache UA sheets across documents.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18484)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-13 14:59:16 -05:00 committed by GitHub
commit d461347adf
8 changed files with 221 additions and 101 deletions

View file

@ -141,7 +141,7 @@ use style::selector_parser::{RestyleDamage, Snapshot};
use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard};
use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join};
use style::stylesheet_set::StylesheetSet;
use style::stylesheets::{Stylesheet, StylesheetContents, OriginSet};
use style::stylesheets::{Stylesheet, StylesheetContents, Origin, OriginSet};
use task_source::TaskSource;
use time;
use timers::OneshotTimerCallback;
@ -2435,7 +2435,7 @@ impl Document {
pub fn stylesheet_at(&self, index: usize) -> Option<Root<CSSStyleSheet>> {
let stylesheets = self.stylesheets.borrow();
stylesheets.get(index).and_then(|s| {
stylesheets.get(Origin::Author, index).and_then(|s| {
s.owner.upcast::<Node>().get_cssom_stylesheet()
})
}

View file

@ -242,8 +242,8 @@ impl VirtualMethods for HTMLLinkElement {
s.unbind_from_tree(context);
}
if let Some(ref s) = *self.stylesheet.borrow() {
document_from_node(self).remove_stylesheet(self.upcast(), s);
if let Some(s) = self.stylesheet.borrow_mut().take() {
document_from_node(self).remove_stylesheet(self.upcast(), &s);
}
}
}

View file

@ -196,8 +196,8 @@ impl VirtualMethods for HTMLMetaElement {
if context.tree_in_doc {
self.process_referrer_attribute();
if let Some(ref s) = *self.stylesheet.borrow() {
document_from_node(self).remove_stylesheet(self.upcast(), s);
if let Some(s) = self.stylesheet.borrow_mut().take() {
document_from_node(self).remove_stylesheet(self.upcast(), &s);
}
}
}

View file

@ -190,9 +190,8 @@ impl VirtualMethods for HTMLStyleElement {
}
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)
if let Some(s) = self.stylesheet.borrow_mut().take() {
document_from_node(self).remove_stylesheet(self.upcast(), &s)
}
}
}