mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Make UA and user stylesheets static and shared by all Stylist instances
This commit is contained in:
parent
69e6eb4d91
commit
f173504ded
2 changed files with 35 additions and 28 deletions
|
@ -75,7 +75,7 @@ use style::computed_values::{self, filter, mix_blend_mode};
|
||||||
use style::media_queries::{Device, MediaQueryList, MediaType};
|
use style::media_queries::{Device, MediaQueryList, MediaType};
|
||||||
use style::properties::longhands::{display, position};
|
use style::properties::longhands::{display, position};
|
||||||
use style::properties::style_structs;
|
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::stylesheets::{CSSRule, CSSRuleIteratorExt, Origin, Stylesheet};
|
||||||
use style::values::AuExtensionMethods;
|
use style::values::AuExtensionMethods;
|
||||||
use style::viewport::ViewportRule;
|
use style::viewport::ViewportRule;
|
||||||
|
@ -377,8 +377,8 @@ impl LayoutTask {
|
||||||
|
|
||||||
let stylist = box Stylist::new(device);
|
let stylist = box Stylist::new(device);
|
||||||
let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0));
|
let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0));
|
||||||
for user_or_user_agent_stylesheet in stylist.stylesheets() {
|
for stylesheet in &*USER_OR_USER_AGENT_STYLESHEETS {
|
||||||
add_font_face_rules(user_or_user_agent_stylesheet,
|
add_font_face_rules(stylesheet,
|
||||||
&stylist.device,
|
&stylist.device,
|
||||||
&font_cache_task,
|
&font_cache_task,
|
||||||
&font_cache_sender,
|
&font_cache_sender,
|
||||||
|
|
|
@ -26,6 +26,36 @@ use viewport::{MaybeNew, ViewportRuleCascade};
|
||||||
pub type DeclarationBlock = GenericDeclarationBlock<Vec<PropertyDeclaration>>;
|
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 {
|
pub struct Stylist {
|
||||||
// List of stylesheets (including all media rules)
|
// List of stylesheets (including all media rules)
|
||||||
stylesheets: Vec<Stylesheet>,
|
stylesheets: Vec<Stylesheet>,
|
||||||
|
@ -51,7 +81,7 @@ pub struct Stylist {
|
||||||
impl Stylist {
|
impl Stylist {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(device: Device) -> Stylist {
|
pub fn new(device: Device) -> Stylist {
|
||||||
let mut stylist = Stylist {
|
let stylist = Stylist {
|
||||||
stylesheets: vec!(),
|
stylesheets: vec!(),
|
||||||
device: device,
|
device: device,
|
||||||
is_dirty: true,
|
is_dirty: true,
|
||||||
|
@ -63,29 +93,6 @@ impl Stylist {
|
||||||
state_deps: StateDependencySet::new(),
|
state_deps: StateDependencySet::new(),
|
||||||
};
|
};
|
||||||
// FIXME: Add iso-8859-9.css when the document’s encoding is ISO-8859-8.
|
// 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
|
stylist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +117,7 @@ impl Stylist {
|
||||||
self.rules_source_order = 0;
|
self.rules_source_order = 0;
|
||||||
self.state_deps.clear();
|
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 {
|
let (mut element_map, mut before_map, mut after_map) = match stylesheet.origin {
|
||||||
Origin::UserAgent => (
|
Origin::UserAgent => (
|
||||||
&mut self.element_map.user_agent,
|
&mut self.element_map.user_agent,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue