From 131556a889dba259618f631e56cc9aec737abbdf Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 17 Aug 2015 15:19:21 -0700 Subject: [PATCH] Bug 1013814 - add inIDOMUtils.getRelativeRuleLine; r=heycam,pbrosset --- dom/base/nsIStyleSheetLinkingElement.h | 12 +++- dom/base/nsStyleLinkElement.cpp | 6 ++ dom/base/nsStyleLinkElement.h | 1 + layout/inspector/inDOMUtils.cpp | 28 ++++++++ layout/inspector/inIDOMUtils.idl | 12 +++- layout/inspector/tests/mochitest.ini | 1 + .../tests/test_getRelativeRuleLine.html | 67 +++++++++++++++++++ toolkit/devtools/server/actors/csscoverage.js | 5 +- toolkit/devtools/server/actors/stylesheets.js | 47 ------------- 9 files changed, 127 insertions(+), 52 deletions(-) create mode 100644 layout/inspector/tests/test_getRelativeRuleLine.html diff --git a/dom/base/nsIStyleSheetLinkingElement.h b/dom/base/nsIStyleSheetLinkingElement.h index 948cdf9c4524..77eaebf6096f 100644 --- a/dom/base/nsIStyleSheetLinkingElement.h +++ b/dom/base/nsIStyleSheetLinkingElement.h @@ -13,8 +13,8 @@ class nsICSSLoaderObserver; class nsIURI; #define NS_ISTYLESHEETLINKINGELEMENT_IID \ -{ 0xe5855604, 0x8a9a, 0x4181, \ - { 0xbe, 0x41, 0xdd, 0xf7, 0x08, 0x70, 0x3f, 0xbe } } +{ 0xa8b79f3b, 0x9d18, 0x4f9c, \ + { 0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad } } namespace mozilla { class CSSStyleSheet; @@ -97,6 +97,14 @@ public: // some types of linking elements, but it's a better place than // anywhere else. virtual void SetLineNumber(uint32_t aLineNumber) = 0; + + /** + * Get the line number, as previously set by SetLineNumber. + * + * @return the line number of this element; or 1 if no line number + * was set + */ + virtual uint32_t GetLineNumber() = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleSheetLinkingElement, diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index 11164c5d86f7..c7a175c021d2 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -119,6 +119,12 @@ nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber) mLineNumber = aLineNumber; } +/* virtual */ uint32_t +nsStyleLinkElement::GetLineNumber() +{ + return mLineNumber; +} + /* static */ bool nsStyleLinkElement::IsImportEnabled() { diff --git a/dom/base/nsStyleLinkElement.h b/dom/base/nsStyleLinkElement.h index 9cd5f71d9022..1d7dd5d3744b 100644 --- a/dom/base/nsStyleLinkElement.h +++ b/dom/base/nsStyleLinkElement.h @@ -52,6 +52,7 @@ public: virtual void OverrideBaseURI(nsIURI* aNewBaseURI) override; virtual void SetLineNumber(uint32_t aLineNumber) override; + virtual uint32_t GetLineNumber() override; enum RelValue { ePREFETCH = 0x00000001, diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index 9989be817f3d..f2ff3247f74c 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -12,6 +12,7 @@ #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsString.h" +#include "nsIStyleSheetLinkingElement.h" #include "nsIDOMElement.h" #include "nsIDocument.h" #include "nsIPresShell.h" @@ -290,6 +291,33 @@ inDOMUtils::GetRuleColumn(nsIDOMCSSRule* aRule, uint32_t* _retval) return NS_OK; } +NS_IMETHODIMP +inDOMUtils::GetRelativeRuleLine(nsIDOMCSSRule* aRule, uint32_t* _retval) +{ + NS_ENSURE_ARG_POINTER(aRule); + + Rule* rule = aRule->GetCSSRule(); + if (!rule) { + return NS_ERROR_FAILURE; + } + + uint32_t lineNumber = rule->GetLineNumber(); + CSSStyleSheet* sheet = rule->GetStyleSheet(); + if (sheet) { + nsINode* owningNode = sheet->GetOwnerNode(); + if (owningNode) { + nsCOMPtr link = + do_QueryInterface(owningNode); + if (link) { + lineNumber -= link->GetLineNumber() - 1; + } + } + } + + *_retval = lineNumber; + return NS_OK; +} + NS_IMETHODIMP inDOMUtils::GetCSSLexer(const nsAString& aText, JSContext* aCx, JS::MutableHandleValue aResult) diff --git a/layout/inspector/inIDOMUtils.idl b/layout/inspector/inIDOMUtils.idl index f9ea98c5100a..1488f219b716 100644 --- a/layout/inspector/inIDOMUtils.idl +++ b/layout/inspector/inIDOMUtils.idl @@ -17,7 +17,7 @@ interface nsIDOMFontFaceList; interface nsIDOMRange; interface nsIDOMCSSStyleSheet; -[scriptable, uuid(60b4cbf7-2a08-4419-8937-6ef495417824)] +[scriptable, uuid(d67c0463-592e-4d7c-b67e-923ee3f6c643)] interface inIDOMUtils : nsISupports { // CSS utilities @@ -28,6 +28,16 @@ interface inIDOMUtils : nsISupports unsigned long getRuleLine(in nsIDOMCSSRule aRule); unsigned long getRuleColumn(in nsIDOMCSSRule aRule); + /** + * Like getRuleLine, but if the rule is in a + + + + + +

Test inDOMUtils::getRelativeRuleLine

+

+ +
+
+ + diff --git a/toolkit/devtools/server/actors/csscoverage.js b/toolkit/devtools/server/actors/csscoverage.js index 18b04568708e..3107d06c008d 100644 --- a/toolkit/devtools/server/actors/csscoverage.js +++ b/toolkit/devtools/server/actors/csscoverage.js @@ -564,8 +564,9 @@ function getImportedSheets(stylesheet) { * @see deconstructRuleId(ruleId) */ function ruleToId(rule) { - let loc = stylesheets.getRuleLocation(rule); - return sheetToUrl(rule.parentStyleSheet) + "|" + loc.line + "|" + loc.column; + let line = DOMUtils.getRelativeRuleLine(rule); + let column = DOMUtils.getRuleColumn(rule); + return sheetToUrl(rule.parentStyleSheet) + "|" + line + "|" + column; } /** diff --git a/toolkit/devtools/server/actors/stylesheets.js b/toolkit/devtools/server/actors/stylesheets.js index 6a277fadf35e..b2e453952263 100644 --- a/toolkit/devtools/server/actors/stylesheets.js +++ b/toolkit/devtools/server/actors/stylesheets.js @@ -932,53 +932,6 @@ let StyleSheetActor = protocol.ActorClass({ } }) -/** - * Find the line/column for a rule. - * This is like DOMUtils.getRule[Line|Column] except for inline