Bug 1195978 - set line number when re-parsing sheet. r=heycam
authorTom Tromey <tromey@mozilla.com>
Fri, 04 Sep 2015 08:12:00 +0200
changeset 261130 8e33c66fc2ca55a6c77457e1b277795d760f56d1
parent 261129 14207bf8e5b8032142e60207fdfb9c09cfc69ae5
child 261131 e3bd50974b084168f081ed5a56e9d8ea07e8d997
push id29336
push usercbook@mozilla.com
push dateMon, 07 Sep 2015 10:01:38 +0000
treeherdermozilla-central@5fe9ed3edd68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1195978
milestone43.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 1195978 - set line number when re-parsing sheet. r=heycam
layout/inspector/tests/mochitest.ini
layout/inspector/tests/test_parseStyleSheet.html
layout/style/CSSStyleSheet.cpp
--- a/layout/inspector/tests/mochitest.ini
+++ b/layout/inspector/tests/mochitest.ini
@@ -16,9 +16,10 @@ support-files =
 [test_bug1006595.html]
 [test_color_to_rgba.html]
 [test_css_property_is_shorthand.html]
 [test_css_property_is_valid.html]
 [test_getRelativeRuleLine.html]
 [test_get_all_style_sheets.html]
 [test_is_valid_css_color.html]
 [test_isinheritableproperty.html]
+[test_parseStyleSheet.html]
 [test_selectormatcheselement.html]
new file mode 100644
--- /dev/null
+++ b/layout/inspector/tests/test_parseStyleSheet.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+    https://bugzilla.mozilla.org/show_bug.cgi?id=1195978
+-->
+  <head>
+    <title>Test for Bug 1195978</title>
+    <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+    <style>
+      body {
+        color: red;
+      }
+    </style>
+  </head>
+  <body>
+    <script type="application/javascript">
+var domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
+               .getService(SpecialPowers.Ci.inIDOMUtils);
+
+var sheet = document.styleSheets[1];
+is(domUtils.getRelativeRuleLine(sheet.cssRules[0]), 2,
+   "initial relative rule line");
+is(domUtils.getRuleLine(sheet.cssRules[0]), 11,
+   "initial rule line");
+
+domUtils.parseStyleSheet(sheet, "\nbody {\n  color: blue;\n}\n");
+is(domUtils.getRelativeRuleLine(sheet.cssRules[0]), 2,
+   "relative rule line after reparsing");
+is(domUtils.getRuleLine(sheet.cssRules[0]), 11,
+   "relative rule line after reparsing");
+    </script>
+  </body>
+</html>
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -42,16 +42,17 @@
 #include "nsRuleNode.h"
 #include "nsMediaFeatures.h"
 #include "nsDOMClassInfoID.h"
 #include "mozilla/Likely.h"
 #include "mozilla/dom/CSSStyleSheetBinding.h"
 #include "nsComponentManagerUtils.h"
 #include "nsNullPrincipal.h"
 #include "mozilla/RuleProcessorCache.h"
+#include "nsIStyleSheetLinkingElement.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // -------------------------------
 // Style Rule List for the DOM
 //
 class CSSRuleListImpl final : public CSSRuleList
@@ -2306,19 +2307,28 @@ CSSStyleSheet::ParseSheet(const nsAStrin
     child->mDocument = nullptr;
   }
   mInner->mFirstChild = nullptr;
   mInner->mNameSpaceMap = nullptr;
 
   // allow unsafe rules if the style sheet's principal is the system principal
   bool allowUnsafeRules = nsContentUtils::IsSystemPrincipal(mInner->mPrincipal);
 
+  uint32_t lineNumber = 1;
+  if (mOwningNode) {
+    nsCOMPtr<nsIStyleSheetLinkingElement> link = do_QueryInterface(mOwningNode);
+    if (link) {
+      lineNumber = link->GetLineNumber();
+    }
+  }
+
   nsCSSParser parser(loader, this);
   nsresult rv = parser.ParseSheet(aInput, mInner->mSheetURI, mInner->mBaseURI,
-                                  mInner->mPrincipal, 1, allowUnsafeRules);
+                                  mInner->mPrincipal, lineNumber,
+                                  allowUnsafeRules);
   DidDirty(); // we are always 'dirty' here since we always remove rules first
   NS_ENSURE_SUCCESS(rv, rv);
 
   // notify document of all new rules
   if (mDocument) {
     for (int32_t index = 0; index < mInner->mOrderedRules.Count(); ++index) {
       nsRefPtr<css::Rule> rule = mInner->mOrderedRules.ObjectAt(index);
       if (rule->GetType() == css::Rule::IMPORT_RULE &&