mirror of
https://github.com/servo/servo.git
synced 2025-06-06 00:25:37 +00:00
Atomize namespace prefixes.
This commit is contained in:
parent
84fed1a62f
commit
6173e1d339
4 changed files with 19 additions and 9 deletions
|
@ -167,7 +167,7 @@ impl SelectorImpl for GeckoSelectorImpl {
|
|||
type Identifier = Atom;
|
||||
type ClassName = Atom;
|
||||
type LocalName = Atom;
|
||||
type NamespacePrefix = String;
|
||||
type NamespacePrefix = Atom;
|
||||
type NamespaceUrl = Namespace;
|
||||
type BorrowedNamespaceUrl = WeakNamespace;
|
||||
type BorrowedLocalName = WeakAtom;
|
||||
|
|
|
@ -145,7 +145,7 @@ impl SelectorImpl for ServoSelectorImpl {
|
|||
type Identifier = Atom;
|
||||
type ClassName = Atom;
|
||||
type LocalName = Atom;
|
||||
type NamespacePrefix = String;
|
||||
type NamespacePrefix = Atom;
|
||||
type NamespaceUrl = Namespace;
|
||||
type BorrowedLocalName = Atom;
|
||||
type BorrowedNamespaceUrl = Namespace;
|
||||
|
|
|
@ -58,7 +58,11 @@ pub struct Stylesheet {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum CSSRule {
|
||||
Charset(String),
|
||||
Namespace(Option<String>, Namespace),
|
||||
Namespace {
|
||||
/// `None` for the default Namespace
|
||||
prefix: Option<Atom>,
|
||||
url: Namespace,
|
||||
},
|
||||
Style(StyleRule),
|
||||
Media(MediaRule),
|
||||
FontFace(FontFaceRule),
|
||||
|
@ -143,13 +147,13 @@ impl Stylesheet {
|
|||
while let Some(result) = iter.next() {
|
||||
match result {
|
||||
Ok(rule) => {
|
||||
if let CSSRule::Namespace(ref prefix, ref namespace) = rule {
|
||||
if let CSSRule::Namespace { ref prefix, ref url } = rule {
|
||||
if let Some(prefix) = prefix.as_ref() {
|
||||
iter.parser.context.selector_context.namespace_prefixes.insert(
|
||||
prefix.clone(), namespace.clone());
|
||||
prefix.clone(), url.clone());
|
||||
} else {
|
||||
iter.parser.context.selector_context.default_namespace =
|
||||
Some(namespace.clone());
|
||||
Some(url.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,9 +439,12 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
|||
if self.state.get() <= State::Namespaces {
|
||||
self.state.set(State::Namespaces);
|
||||
|
||||
let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into_owned());
|
||||
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(prefix, url)))
|
||||
return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace {
|
||||
prefix: prefix,
|
||||
url: url,
|
||||
}))
|
||||
} else {
|
||||
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
||||
}
|
||||
|
|
|
@ -38,7 +38,10 @@ fn test_parse_stylesheet() {
|
|||
media: None,
|
||||
dirty_on_viewport_size_change: false,
|
||||
rules: vec![
|
||||
CSSRule::Namespace(None, NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
CSSRule::Namespace {
|
||||
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