aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2016-09-07 09:36:14 +0800
committerMs2ger <Ms2ger@gmail.com>2016-09-08 10:21:03 +0200
commit45af168a5cc8b3003e7a147e8e405787959b0a5f (patch)
tree9049e2567b5a76a6ac033125cba0c5af0b4d1234
parent8bfe978c7868e2873f365b4cae4531db4c49d6b9 (diff)
downloadservo-45af168a5cc8b3003e7a147e8e405787959b0a5f.tar.gz
servo-45af168a5cc8b3003e7a147e8e405787959b0a5f.zip
Handle @namespace rules when parsing them rather than afterwards.
This will avoid dealing with DOMRefCell when we add it around NamespaceRule.
-rw-r--r--components/style/stylesheets.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs
index 8cc832c1be8..c2de24847da 100644
--- a/components/style/stylesheets.rs
+++ b/components/style/stylesheets.rs
@@ -160,19 +160,7 @@ impl Stylesheet {
let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser);
while let Some(result) = iter.next() {
match result {
- Ok(rule) => {
- if let CSSRule::Namespace(ref rule) = rule {
- if let Some(ref prefix) = rule.prefix {
- iter.parser.context.selector_context.namespace_prefixes.insert(
- prefix.clone(), rule.url.clone());
- } else {
- iter.parser.context.selector_context.default_namespace =
- Some(rule.url.clone());
- }
- }
-
- rules.push(rule);
- }
+ Ok(rule) => rules.push(rule),
Err(range) => {
let pos = range.start;
let message = format!("Invalid rule: '{}'", iter.input.slice(range));
@@ -443,10 +431,21 @@ 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());
+ let prefix_result = input.try(|input| input.expect_ident());
let url = Namespace(Atom::from(try!(input.expect_url_or_string())));
+
+ let opt_prefix = if let Ok(prefix) = prefix_result {
+ let prefix: Atom = prefix.into();
+ self.context.selector_context.namespace_prefixes.insert(
+ prefix.clone(), url.clone());
+ Some(prefix)
+ } else {
+ self.context.selector_context.default_namespace = Some(url.clone());
+ None
+ };
+
return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace(Arc::new(NamespaceRule {
- prefix: prefix,
+ prefix: opt_prefix,
url: url,
}))))
} else {