Bug 887741 - Allow CSS at-rules in declaration lists. r=dbaron
authorSimon Sapin <simon.sapin@exyr.org>
Thu, 25 Jul 2013 09:43:29 -0400
changeset 152297 0f097f7ae11df698b091d00480af0931c90c390f
parent 152296 658e5f8a8daf1e3168a5edd3634d1a3edb3e6978
child 152298 cf03ffaa23cce203eedcf7301e99f0b9c0bdbce2
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs887741
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 887741 - Allow CSS at-rules in declaration lists. r=dbaron
layout/style/nsCSSParser.cpp
layout/style/test/Makefile.in
layout/style/test/test_bug887741_at-rules_in_declaration_lists.html
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -4699,16 +4699,21 @@ CSSParserImpl::ParseDeclaration(css::Dec
       // dangling semicolons are skipped
       continue;
     }
 
     if (!tk->IsSymbol('}')) {
       REPORT_UNEXPECTED_TOKEN(PEParseDeclarationDeclExpected);
       REPORT_UNEXPECTED(PEDeclSkipped);
       OUTPUT_ERROR();
+
+      if (eCSSToken_AtKeyword == tk->mType) {
+        SkipAtRule(checkForBraces);
+        return true;  // Not a declaration, but don’t skip until ';'
+      }
     }
     // Not a declaration...
     UngetToken();
     return false;
   }
 
   // Don't report property parse errors if we're inside a failing @supports
   // rule.
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -81,16 +81,17 @@ MOCHITEST_FILES =	test_acid3_test46.html
 		test_bug645998.html \
 		file_bug645998-1.css \
 		file_bug645998-2.css \
 		test_bug716226.html \
 		test_bug765590.html \
 		test_bug798567.html \
 		test_bug829816.html \
 		file_bug829816.css \
+		test_bug887741_at-rules_in_declaration_lists.html \
 		test_cascade.html \
 		test_ch_ex_no_infloops.html \
 		test_compute_data_with_start_struct.html \
 		test_computed_style.html \
 		test_computed_style_no_pseudo.html \
 		test_condition_text.html \
 		test_condition_text_assignment.html \
 		test_default_computed_style.html \
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_bug887741_at-rules_in_declaration_lists.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=887741
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 887741: at-rules in declaration lists</title>
+      <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <style>
+    #foo {
+        color: red;
+        @invalid-rule {
+            ignored: ignored;
+        }
+        /* No semicolon */
+        color: green;
+    }
+    @page {
+        margin-top: 0;
+        @bottom-center {
+            content: counter(page);
+        }
+        /* No semicolon */
+        margin-top: 5cm;
+    }
+    @keyframes dummy-animation {
+      12% {
+        color: red;
+        @invalid-rule {}
+        /* No semicolon */
+        color: green;
+      }
+    }
+    /* TODO: other at-rules that use declaration syntax? */
+  </style>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=887741">Mozilla Bug 887741</a>
+<p id="display"></p>
+<div id="content" style="display: none; color: red;
+                         @invalid-rule{} /* No semicolon */ color: green;">
+
+</div>
+<pre id="test">
+  <script type="application/javascript">
+
+  /** Test for Bug 887741 **/
+
+  var style = document.getElementById('content').style;
+  is(style.display, 'none', 'Sanity check: we have the right element');
+  is(style.color, 'green', 'Support at-rules in style attributes');
+
+  style.cssText = 'display: none; color: red; @invalid-rule{} /* No semicolon */ color: lime;';
+  is(style.color, 'lime', 'Support at-rules in CSSStyleDeclaration.cssText');
+
+  var rules = document.styleSheets[0].cssRules;
+  var style_rule = rules[0];
+  is(style_rule.selectorText, '#foo', 'Sanity check: we have the right style rule');
+  is(style_rule.style.color, 'green', 'Support at-rules in style rules');
+
+  var page_rule = rules[1];
+  is(page_rule.type, page_rule.PAGE_RULE, 'Sanity check: we have the right style rule');
+  is(page_rule.style.marginTop, '5cm', 'Support at-rules in @page rules');
+
+  var keyframe_rule = rules[2].cssRules[0];
+  is(keyframe_rule.keyText, '12%', 'Sanity check: we have the right keyframe rule');
+  is(keyframe_rule.style.color, 'green', 'Support at-rules in keyframe rules')
+
+  </script>
+</pre>
+</body>
+</html>