mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add a separate NamespaceRule type
This commit is contained in:
parent
a5a3a74262
commit
94d5b28fe9
2 changed files with 18 additions and 14 deletions
|
@ -67,11 +67,7 @@ pub enum CSSRule {
|
||||||
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
||||||
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
||||||
|
|
||||||
Namespace {
|
Namespace(NamespaceRule),
|
||||||
/// `None` for the default Namespace
|
|
||||||
prefix: Option<Atom>,
|
|
||||||
url: Namespace,
|
|
||||||
},
|
|
||||||
Style(StyleRule),
|
Style(StyleRule),
|
||||||
Media(MediaRule),
|
Media(MediaRule),
|
||||||
FontFace(FontFaceRule),
|
FontFace(FontFaceRule),
|
||||||
|
@ -80,6 +76,14 @@ pub enum CSSRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub struct NamespaceRule {
|
||||||
|
/// `None` for the default Namespace
|
||||||
|
pub prefix: Option<Atom>,
|
||||||
|
pub url: Namespace,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct KeyframesRule {
|
pub struct KeyframesRule {
|
||||||
|
@ -156,13 +160,13 @@ impl Stylesheet {
|
||||||
while let Some(result) = iter.next() {
|
while let Some(result) = iter.next() {
|
||||||
match result {
|
match result {
|
||||||
Ok(rule) => {
|
Ok(rule) => {
|
||||||
if let CSSRule::Namespace { ref prefix, ref url } = rule {
|
if let CSSRule::Namespace(ref rule) = rule {
|
||||||
if let Some(prefix) = prefix.as_ref() {
|
if let Some(ref prefix) = rule.prefix {
|
||||||
iter.parser.context.selector_context.namespace_prefixes.insert(
|
iter.parser.context.selector_context.namespace_prefixes.insert(
|
||||||
prefix.clone(), url.clone());
|
prefix.clone(), rule.url.clone());
|
||||||
} else {
|
} else {
|
||||||
iter.parser.context.selector_context.default_namespace =
|
iter.parser.context.selector_context.default_namespace =
|
||||||
Some(url.clone());
|
Some(rule.url.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,10 +444,10 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
||||||
|
|
||||||
let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into());
|
let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into());
|
||||||
let url = Namespace(Atom::from(try!(input.expect_url_or_string())));
|
let url = Namespace(Atom::from(try!(input.expect_url_or_string())));
|
||||||
return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace {
|
return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace(NamespaceRule {
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
url: url,
|
url: url,
|
||||||
}))
|
})))
|
||||||
} else {
|
} else {
|
||||||
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use style::parser::ParserContextExtraData;
|
||||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands};
|
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands};
|
||||||
use style::properties::Importance;
|
use style::properties::Importance;
|
||||||
use style::properties::longhands::animation_play_state;
|
use style::properties::longhands::animation_play_state;
|
||||||
use style::stylesheets::{Stylesheet, CSSRule, StyleRule, KeyframesRule, Origin};
|
use style::stylesheets::{Stylesheet, NamespaceRule, CSSRule, StyleRule, KeyframesRule, Origin};
|
||||||
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
|
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -65,10 +65,10 @@ fn test_parse_stylesheet() {
|
||||||
media: None,
|
media: None,
|
||||||
dirty_on_viewport_size_change: false,
|
dirty_on_viewport_size_change: false,
|
||||||
rules: vec![
|
rules: vec![
|
||||||
CSSRule::Namespace {
|
CSSRule::Namespace(NamespaceRule {
|
||||||
prefix: None,
|
prefix: None,
|
||||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||||
},
|
}),
|
||||||
CSSRule::Style(StyleRule {
|
CSSRule::Style(StyleRule {
|
||||||
selectors: vec![
|
selectors: vec![
|
||||||
Selector {
|
Selector {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue