diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index fa2fe7846c15..4a59d2f58123 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -100,6 +100,8 @@ impl HTMLMetaElement { *self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet { rules: vec![CssRule::Viewport(Arc::new(RwLock::new(translated_rule)))].into(), origin: Origin::Author, + base_url: window_from_node(self).get_url(), + namespaces: Default::default(), media: Default::default(), // Viewport constraints are always recomputed on resize; they don't need to // force all styles to be recomputed. diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 5756504e63b2..1529a2e77ef8 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -44,7 +44,7 @@ pub enum Origin { User, } -#[derive(Default)] +#[derive(Default, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct Namespaces { pub default: Option, @@ -166,6 +166,8 @@ pub struct Stylesheet { /// List of media associated with the Stylesheet. pub media: Arc>, pub origin: Origin, + pub base_url: ServoUrl, + pub namespaces: RwLock, pub dirty_on_viewport_size_change: AtomicBool, pub disabled: AtomicBool, } @@ -435,37 +437,40 @@ impl Stylesheet { error_reporter: Box, extra_data: ParserContextExtraData) -> Stylesheet { let mut namespaces = Namespaces::default(); - let rule_parser = TopLevelRuleParser { - stylesheet_origin: origin, - namespaces: &mut namespaces, - context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(), - extra_data), - state: Cell::new(State::Start), - }; - let mut input = Parser::new(css); - input.look_for_viewport_percentages(); - let mut rules = vec![]; + let dirty_on_viewport_size_change; { - let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser); - while let Some(result) = iter.next() { - match result { - Ok(rule) => rules.push(rule), - Err(range) => { - let pos = range.start; - let message = format!("Invalid rule: '{}'", iter.input.slice(range)); - let context = ParserContext::new(origin, &base_url, error_reporter.clone()); - log_css_error(iter.input, pos, &*message, &context); + let rule_parser = TopLevelRuleParser { + stylesheet_origin: origin, + namespaces: &mut namespaces, + context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter, extra_data), + state: Cell::new(State::Start), + }; + let mut input = Parser::new(css); + input.look_for_viewport_percentages(); + { + let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser); + while let Some(result) = iter.next() { + match result { + Ok(rule) => rules.push(rule), + Err(range) => { + let pos = range.start; + let message = format!("Invalid rule: '{}'", iter.input.slice(range)); + log_css_error(iter.input, pos, &*message, &iter.parser.context); + } } } } + dirty_on_viewport_size_change = input.seen_viewport_percentages(); } Stylesheet { origin: origin, + base_url: base_url, + namespaces: RwLock::new(namespaces), rules: rules.into(), media: Arc::new(RwLock::new(media)), - dirty_on_viewport_size_change: AtomicBool::new(input.seen_viewport_percentages()), + dirty_on_viewport_size_change: AtomicBool::new(dirty_on_viewport_size_change), disabled: AtomicBool::new(false), } } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 629bef96d282..1d7fb34fc988 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -19,7 +19,8 @@ use style::parser::ParserContextExtraData; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands}; use style::properties::Importance; use style::properties::longhands::animation_play_state; -use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, StyleRule, KeyframesRule, Origin}; +use style::stylesheets::{Origin, Namespaces}; +use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, StyleRule, KeyframesRule}; use style::values::specified::{LengthOrPercentageOrAuto, Percentage}; #[test] @@ -50,12 +51,16 @@ fn test_parse_stylesheet() { } }"; let url = ServoUrl::parse("about::test").unwrap(); - let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent, Default::default(), + let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(), Box::new(CSSErrorReporterTest), ParserContextExtraData::default()); + let mut namespaces = Namespaces::default(); + namespaces.default = Some(ns!(html)); let expected = Stylesheet { origin: Origin::UserAgent, media: Default::default(), + namespaces: RwLock::new(namespaces), + base_url: url, dirty_on_viewport_size_change: AtomicBool::new(false), disabled: AtomicBool::new(false), rules: vec![