diff --git a/components/script/dom/csskeyframesrule.rs b/components/script/dom/csskeyframesrule.rs index bda3ee2ea20..41d7beeaf80 100644 --- a/components/script/dom/csskeyframesrule.rs +++ b/components/script/dom/csskeyframesrule.rs @@ -19,7 +19,7 @@ use parking_lot::RwLock; use std::sync::Arc; use style::keyframes::{Keyframe, KeyframeSelector}; use style::parser::ParserContextExtraData; -use style::stylesheets::{KeyframesRule, Origin}; +use style::stylesheets::KeyframesRule; use style_traits::ToCss; #[dom_struct] @@ -83,8 +83,7 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule { fn AppendRule(&self, rule: DOMString) { let global = self.global(); let window = global.as_window(); - let doc = window.Document(); - let rule = Keyframe::parse(&rule, Origin::Author, doc.url().clone(), + let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(), ParserContextExtraData::default()); if let Ok(rule) = rule { self.keyframesrule.write().keyframes.push(rule); diff --git a/components/script/dom/cssrulelist.rs b/components/script/dom/cssrulelist.rs index 643cce9a944..e51ae3c78be 100644 --- a/components/script/dom/cssrulelist.rs +++ b/components/script/dom/cssrulelist.rs @@ -84,10 +84,10 @@ impl CSSRuleList { let global = self.global(); let window = global.as_window(); - let doc = window.Document(); let index = idx as usize; - let new_rule = css_rules.insert_rule(rule, doc.url().clone(), index, nested)?; + let parent_stylesheet = self.parent_stylesheet.style_stylesheet(); + let new_rule = css_rules.insert_rule(rule, parent_stylesheet, index, nested)?; let parent_stylesheet = &*self.parent_stylesheet; let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule); diff --git a/components/script/dom/cssstylesheet.rs b/components/script/dom/cssstylesheet.rs index 2e643f3e8a2..93aefa8f852 100644 --- a/components/script/dom/cssstylesheet.rs +++ b/components/script/dom/cssstylesheet.rs @@ -67,6 +67,10 @@ impl CSSStyleSheet { self.global().as_window().Document().invalidate_stylesheets(); } } + + pub fn style_stylesheet(&self) -> &StyleStyleSheet { + &self.style_stylesheet + } } impl CSSStyleSheetMethods for CSSStyleSheet { diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 7c9b969a210..831627d42c3 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -9,11 +9,10 @@ use parser::{ParserContext, ParserContextExtraData, log_css_error}; use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock}; use properties::PropertyDeclarationParseResult; use properties::animated_properties::TransitionProperty; -use servo_url::ServoUrl; use std::fmt; use std::sync::Arc; use style_traits::ToCss; -use stylesheets::{MemoryHoleReporter, Origin}; +use stylesheets::{MemoryHoleReporter, Stylesheet}; /// A number from 1 to 100, indicating the percentage of the animation where /// this keyframe should run. @@ -108,11 +107,11 @@ impl ToCss for Keyframe { impl Keyframe { - pub fn parse(css: &str, origin: Origin, - base_url: ServoUrl, - extra_data: ParserContextExtraData) -> Result>, ()> { + pub fn parse(css: &str, parent_stylesheet: &Stylesheet, extra_data: ParserContextExtraData) + -> Result>, ()> { let error_reporter = Box::new(MemoryHoleReporter); - let context = ParserContext::new_with_extra_data(origin, &base_url, + let context = ParserContext::new_with_extra_data(parent_stylesheet.origin, + &parent_stylesheet.base_url, error_reporter, extra_data); let mut input = Parser::new(css); diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 1529a2e77ef..f05cd4a7df6 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -88,7 +88,7 @@ impl CssRules { } // https://drafts.csswg.org/cssom/#insert-a-css-rule - pub fn insert_rule(&self, rule: &str, base_url: ServoUrl, index: usize, nested: bool) + pub fn insert_rule(&self, rule: &str, parent_stylesheet: &Stylesheet, index: usize, nested: bool) -> Result { let mut rules = self.0.write(); @@ -108,7 +108,7 @@ impl CssRules { // Step 3, 4 // XXXManishearth should we also store the namespace map? - let (new_rule, new_state) = try!(CssRule::parse(&rule, Origin::Author, base_url, + let (new_rule, new_state) = try!(CssRule::parse(&rule, parent_stylesheet, ParserContextExtraData::default(), state)); // Step 5 @@ -282,13 +282,15 @@ impl CssRule { // input state is None for a nested rule // Returns a parsed CSS rule and the final state of the parser - pub fn parse(css: &str, origin: Origin, - base_url: ServoUrl, - extra_data: ParserContextExtraData, - state: Option) -> Result<(Self, State), SingleRuleParseError> { + pub fn parse(css: &str, + parent_stylesheet: &Stylesheet, + extra_data: ParserContextExtraData, + state: Option) + -> Result<(Self, State), SingleRuleParseError> { let error_reporter = Box::new(MemoryHoleReporter); - let mut namespaces = Namespaces::default(); - let context = ParserContext::new_with_extra_data(origin, &base_url, + let mut namespaces = parent_stylesheet.namespaces.write(); + let context = ParserContext::new_with_extra_data(parent_stylesheet.origin, + &parent_stylesheet.base_url, error_reporter.clone(), extra_data); let mut input = Parser::new(css); @@ -296,7 +298,7 @@ impl CssRule { // nested rules are in the body state let state = state.unwrap_or(State::Body); let mut rule_parser = TopLevelRuleParser { - stylesheet_origin: origin, + stylesheet_origin: parent_stylesheet.origin, context: context, state: Cell::new(state), namespaces: &mut namespaces,