diff --git a/components/style/gecko_selector_impl.rs b/components/style/gecko_selector_impl.rs index 3944d21f959..98f52f34cc0 100644 --- a/components/style/gecko_selector_impl.rs +++ b/components/style/gecko_selector_impl.rs @@ -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; diff --git a/components/style/servo_selector_impl.rs b/components/style/servo_selector_impl.rs index c287823f2d5..f69b1cb9e12 100644 --- a/components/style/servo_selector_impl.rs +++ b/components/style/servo_selector_impl.rs @@ -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; diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 25bb03174e0..8d234540adc 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -58,7 +58,11 @@ pub struct Stylesheet { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum CSSRule { Charset(String), - Namespace(Option, Namespace), + Namespace { + /// `None` for the default Namespace + prefix: Option, + 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" } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index e476fb22533..a816c747876 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -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 {