Use stylesheet’s base URL and ns prefixes in CSSOM insert/appendRule.

This commit is contained in:
Simon Sapin 2016-11-28 17:48:32 +01:00
parent f1d49d3773
commit 70b250fe2a
5 changed files with 24 additions and 20 deletions

View file

@ -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<Arc<RwLock<Self>>, ()> {
pub fn parse(css: &str, parent_stylesheet: &Stylesheet, extra_data: ParserContextExtraData)
-> Result<Arc<RwLock<Self>>, ()> {
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);

View file

@ -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<CssRule, RulesMutateError> {
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<State>) -> Result<(Self, State), SingleRuleParseError> {
pub fn parse(css: &str,
parent_stylesheet: &Stylesheet,
extra_data: ParserContextExtraData,
state: Option<State>)
-> 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,