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
|
||||
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
||||
|
||||
Namespace {
|
||||
/// `None` for the default Namespace
|
||||
prefix: Option<Atom>,
|
||||
url: Namespace,
|
||||
},
|
||||
Namespace(NamespaceRule),
|
||||
Style(StyleRule),
|
||||
Media(MediaRule),
|
||||
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)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct KeyframesRule {
|
||||
|
@ -156,13 +160,13 @@ impl Stylesheet {
|
|||
while let Some(result) = iter.next() {
|
||||
match result {
|
||||
Ok(rule) => {
|
||||
if let CSSRule::Namespace { ref prefix, ref url } = rule {
|
||||
if let Some(prefix) = prefix.as_ref() {
|
||||
if let CSSRule::Namespace(ref rule) = rule {
|
||||
if let Some(ref prefix) = rule.prefix {
|
||||
iter.parser.context.selector_context.namespace_prefixes.insert(
|
||||
prefix.clone(), url.clone());
|
||||
prefix.clone(), rule.url.clone());
|
||||
} else {
|
||||
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 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,
|
||||
url: url,
|
||||
}))
|
||||
})))
|
||||
} else {
|
||||
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::Importance;
|
||||
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 url::Url;
|
||||
|
||||
|
@ -65,10 +65,10 @@ fn test_parse_stylesheet() {
|
|||
media: None,
|
||||
dirty_on_viewport_size_change: false,
|
||||
rules: vec![
|
||||
CSSRule::Namespace {
|
||||
CSSRule::Namespace(NamespaceRule {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
},
|
||||
}),
|
||||
CSSRule::Style(StyleRule {
|
||||
selectors: vec![
|
||||
Selector {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue