Bug 1350175 - stylo: Support getting line / column number of CSS rules. Part 4: NamespaceRule. r=xidorn
authorFernando Jimenez Moreno <ferjmoreno@gmail.com>
Tue, 25 Apr 2017 16:24:39 +0200
changeset 568555 420f0ce9dcf78103612512ec17cf2b9938bf4768
parent 568554 fb495a865fa38a0507968af60a3795056375e97b
child 568556 99d71a3c9719c62ee095fd5d9dd89058306b15a4
push id55899
push userferjmoreno@gmail.com
push dateWed, 26 Apr 2017 09:27:14 +0000
reviewersxidorn
bugs1350175
milestone55.0a1
Bug 1350175 - stylo: Support getting line / column number of CSS rules. Part 4: NamespaceRule. r=xidorn MozReview-Commit-ID: FSRr7fXJ7Wp
servo/components/style/stylesheets.rs
--- a/servo/components/style/stylesheets.rs
+++ b/servo/components/style/stylesheets.rs
@@ -455,16 +455,17 @@ impl ToCssWithGuard for CssRule {
 }
 
 #[derive(Debug, PartialEq)]
 #[allow(missing_docs)]
 pub struct NamespaceRule {
     /// `None` for the default Namespace
     pub prefix: Option<Prefix>,
     pub url: Namespace,
+    pub source_location: SourceLocation,
 }
 
 impl ToCssWithGuard for NamespaceRule {
     // https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSNamespaceRule
     fn to_css<W>(&self, _guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
     where W: fmt::Write {
         try!(dest.write_str("@namespace "));
         if let Some(ref prefix) = self.prefix {
@@ -980,32 +981,38 @@ impl<'a> AtRuleParser for TopLevelRulePa
                     self.state.set(State::Invalid);
                     return Err(())  // "@import must be before any rule but @charset"
                 }
             },
             "namespace" => {
                 if self.state.get() <= State::Namespaces {
                     self.state.set(State::Namespaces);
 
+                    let location = input.current_source_location();
+
                     let prefix_result = input.try(|input| input.expect_ident());
                     let url = Namespace::from(try!(input.expect_url_or_string()));
 
                     let opt_prefix = if let Ok(prefix) = prefix_result {
                         let prefix = Prefix::from(prefix);
                         self.namespaces.prefixes.insert(prefix.clone(), url.clone());
                         Some(prefix)
                     } else {
                         self.namespaces.default = Some(url.clone());
                         None
                     };
 
                     return Ok(AtRuleType::WithoutBlock(CssRule::Namespace(Arc::new(
                         self.shared_lock.wrap(NamespaceRule {
                             prefix: opt_prefix,
                             url: url,
+                            source_location: SourceLocation {
+                                line: location.line + self.context.line_number_offset as usize - 1,
+                                column: location.column,
+                            },
                         })
                     ))))
                 } else {
                     self.state.set(State::Invalid);
                     return Err(())  // "@namespace must be before any rule but @charset and @import"
                 }
             },
             // @charset is removed by rust-cssparser if it’s the first rule in the stylesheet