Skip to content

Commit

Permalink
Make UA and user stylesheets static and shared by all Stylist instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tschneidereit committed Nov 7, 2015
1 parent 69e6eb4 commit f173504
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
6 changes: 3 additions & 3 deletions components/layout/layout_task.rs
Expand Up @@ -75,7 +75,7 @@ use style::computed_values::{self, filter, mix_blend_mode};
use style::media_queries::{Device, MediaQueryList, MediaType};
use style::properties::longhands::{display, position};
use style::properties::style_structs;
use style::selector_matching::Stylist;
use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
use style::stylesheets::{CSSRule, CSSRuleIteratorExt, Origin, Stylesheet};
use style::values::AuExtensionMethods;
use style::viewport::ViewportRule;
Expand Down Expand Up @@ -377,8 +377,8 @@ impl LayoutTask {

let stylist = box Stylist::new(device);
let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0));
for user_or_user_agent_stylesheet in stylist.stylesheets() {
add_font_face_rules(user_or_user_agent_stylesheet,
for stylesheet in &*USER_OR_USER_AGENT_STYLESHEETS {
add_font_face_rules(stylesheet,
&stylist.device,
&font_cache_task,
&font_cache_sender,
Expand Down
57 changes: 32 additions & 25 deletions components/style/selector_matching.rs
Expand Up @@ -26,6 +26,36 @@ use viewport::{MaybeNew, ViewportRuleCascade};
pub type DeclarationBlock = GenericDeclarationBlock<Vec<PropertyDeclaration>>;


lazy_static! {
pub static ref USER_OR_USER_AGENT_STYLESHEETS: Vec<Stylesheet> = {
let mut stylesheets = vec!();
// FIXME: presentational-hints.css should be at author origin with zero specificity.
// (Does it make a difference?)
for &filename in &["user-agent.css", "servo.css", "presentational-hints.css"] {
match read_resource_file(&[filename]) {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylesheets.push(ua_stylesheet);
}
Err(..) => {
error!("Failed to load UA stylesheet {}!", filename);
process::exit(1);
}
}
}
for &(ref contents, ref url) in &opts::get().user_stylesheets {
stylesheets.push(Stylesheet::from_bytes(
&contents, url.clone(), None, None, Origin::User));
}
stylesheets
};
}

pub struct Stylist {
// List of stylesheets (including all media rules)
stylesheets: Vec<Stylesheet>,
Expand All @@ -51,7 +81,7 @@ pub struct Stylist {
impl Stylist {
#[inline]
pub fn new(device: Device) -> Stylist {
let mut stylist = Stylist {
let stylist = Stylist {
stylesheets: vec!(),
device: device,
is_dirty: true,
Expand All @@ -63,29 +93,6 @@ impl Stylist {
state_deps: StateDependencySet::new(),
};
// FIXME: Add iso-8859-9.css when the document’s encoding is ISO-8859-8.
// FIXME: presentational-hints.css should be at author origin with zero specificity.
// (Does it make a difference?)
for &filename in &["user-agent.css", "servo.css", "presentational-hints.css"] {
match read_resource_file(&[filename]) {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
}
Err(..) => {
error!("Stylist::new() failed at loading {}!", filename);
process::exit(1);
}
}
}
for &(ref contents, ref url) in &opts::get().user_stylesheets {
stylist.add_stylesheet(Stylesheet::from_bytes(
&contents, url.clone(), None, None, Origin::User));
}
stylist
}

Expand All @@ -110,7 +117,7 @@ impl Stylist {
self.rules_source_order = 0;
self.state_deps.clear();

for stylesheet in &self.stylesheets {
for stylesheet in USER_OR_USER_AGENT_STYLESHEETS.iter().chain(&self.stylesheets) {
let (mut element_map, mut before_map, mut after_map) = match stylesheet.origin {
Origin::UserAgent => (
&mut self.element_map.user_agent,
Expand Down

0 comments on commit f173504

Please sign in to comment.