mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Use stylesheet’s base URL and ns prefixes in CSSOM insert/appendRule.
This commit is contained in:
parent
f1d49d3773
commit
70b250fe2a
5 changed files with 24 additions and 20 deletions
|
@ -19,7 +19,7 @@ use parking_lot::RwLock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::keyframes::{Keyframe, KeyframeSelector};
|
use style::keyframes::{Keyframe, KeyframeSelector};
|
||||||
use style::parser::ParserContextExtraData;
|
use style::parser::ParserContextExtraData;
|
||||||
use style::stylesheets::{KeyframesRule, Origin};
|
use style::stylesheets::KeyframesRule;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -83,8 +83,7 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
||||||
fn AppendRule(&self, rule: DOMString) {
|
fn AppendRule(&self, rule: DOMString) {
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let window = global.as_window();
|
let window = global.as_window();
|
||||||
let doc = window.Document();
|
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(),
|
||||||
let rule = Keyframe::parse(&rule, Origin::Author, doc.url().clone(),
|
|
||||||
ParserContextExtraData::default());
|
ParserContextExtraData::default());
|
||||||
if let Ok(rule) = rule {
|
if let Ok(rule) = rule {
|
||||||
self.keyframesrule.write().keyframes.push(rule);
|
self.keyframesrule.write().keyframes.push(rule);
|
||||||
|
|
|
@ -84,10 +84,10 @@ impl CSSRuleList {
|
||||||
|
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let window = global.as_window();
|
let window = global.as_window();
|
||||||
let doc = window.Document();
|
|
||||||
let index = idx as usize;
|
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 parent_stylesheet = &*self.parent_stylesheet;
|
||||||
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);
|
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);
|
||||||
|
|
|
@ -67,6 +67,10 @@ impl CSSStyleSheet {
|
||||||
self.global().as_window().Document().invalidate_stylesheets();
|
self.global().as_window().Document().invalidate_stylesheets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn style_stylesheet(&self) -> &StyleStyleSheet {
|
||||||
|
&self.style_stylesheet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSSStyleSheetMethods for CSSStyleSheet {
|
impl CSSStyleSheetMethods for CSSStyleSheet {
|
||||||
|
|
|
@ -9,11 +9,10 @@ use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
||||||
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use properties::PropertyDeclarationParseResult;
|
use properties::PropertyDeclarationParseResult;
|
||||||
use properties::animated_properties::TransitionProperty;
|
use properties::animated_properties::TransitionProperty;
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style_traits::ToCss;
|
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
|
/// A number from 1 to 100, indicating the percentage of the animation where
|
||||||
/// this keyframe should run.
|
/// this keyframe should run.
|
||||||
|
@ -108,11 +107,11 @@ impl ToCss for Keyframe {
|
||||||
|
|
||||||
|
|
||||||
impl Keyframe {
|
impl Keyframe {
|
||||||
pub fn parse(css: &str, origin: Origin,
|
pub fn parse(css: &str, parent_stylesheet: &Stylesheet, extra_data: ParserContextExtraData)
|
||||||
base_url: ServoUrl,
|
-> Result<Arc<RwLock<Self>>, ()> {
|
||||||
extra_data: ParserContextExtraData) -> Result<Arc<RwLock<Self>>, ()> {
|
|
||||||
let error_reporter = Box::new(MemoryHoleReporter);
|
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,
|
error_reporter,
|
||||||
extra_data);
|
extra_data);
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl CssRules {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#insert-a-css-rule
|
// 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> {
|
-> Result<CssRule, RulesMutateError> {
|
||||||
let mut rules = self.0.write();
|
let mut rules = self.0.write();
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ impl CssRules {
|
||||||
|
|
||||||
// Step 3, 4
|
// Step 3, 4
|
||||||
// XXXManishearth should we also store the namespace map?
|
// 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));
|
ParserContextExtraData::default(), state));
|
||||||
|
|
||||||
// Step 5
|
// Step 5
|
||||||
|
@ -282,13 +282,15 @@ impl CssRule {
|
||||||
|
|
||||||
// input state is None for a nested rule
|
// input state is None for a nested rule
|
||||||
// Returns a parsed CSS rule and the final state of the parser
|
// Returns a parsed CSS rule and the final state of the parser
|
||||||
pub fn parse(css: &str, origin: Origin,
|
pub fn parse(css: &str,
|
||||||
base_url: ServoUrl,
|
parent_stylesheet: &Stylesheet,
|
||||||
extra_data: ParserContextExtraData,
|
extra_data: ParserContextExtraData,
|
||||||
state: Option<State>) -> Result<(Self, State), SingleRuleParseError> {
|
state: Option<State>)
|
||||||
|
-> Result<(Self, State), SingleRuleParseError> {
|
||||||
let error_reporter = Box::new(MemoryHoleReporter);
|
let error_reporter = Box::new(MemoryHoleReporter);
|
||||||
let mut namespaces = Namespaces::default();
|
let mut namespaces = parent_stylesheet.namespaces.write();
|
||||||
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.clone(),
|
error_reporter.clone(),
|
||||||
extra_data);
|
extra_data);
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
@ -296,7 +298,7 @@ impl CssRule {
|
||||||
// nested rules are in the body state
|
// nested rules are in the body state
|
||||||
let state = state.unwrap_or(State::Body);
|
let state = state.unwrap_or(State::Body);
|
||||||
let mut rule_parser = TopLevelRuleParser {
|
let mut rule_parser = TopLevelRuleParser {
|
||||||
stylesheet_origin: origin,
|
stylesheet_origin: parent_stylesheet.origin,
|
||||||
context: context,
|
context: context,
|
||||||
state: Cell::new(state),
|
state: Cell::new(state),
|
||||||
namespaces: &mut namespaces,
|
namespaces: &mut namespaces,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue