--- a/devtools/server/actors/stylesheets.js
+++ b/devtools/server/actors/stylesheets.js
@@ -20,18 +20,16 @@ const InspectorUtils = require("Inspecto
loader.lazyRequireGetter(this, "CssLogic", "devtools/shared/inspector/css-logic");
loader.lazyRequireGetter(this, "addPseudoClassLock",
"devtools/server/actors/highlighters/utils/markup", true);
loader.lazyRequireGetter(this, "removePseudoClassLock",
"devtools/server/actors/highlighters/utils/markup", true);
loader.lazyRequireGetter(this, "loadSheet", "devtools/shared/layout/utils", true);
-loader.lazyServiceGetter(this, "DOMUtils", "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
-
var TRANSITION_PSEUDO_CLASS = ":-moz-styleeditor-transitioning";
var TRANSITION_DURATION_MS = 500;
var TRANSITION_BUFFER_MS = 1000;
var TRANSITION_RULE_SELECTOR =
`:root${TRANSITION_PSEUDO_CLASS}, :root${TRANSITION_PSEUDO_CLASS} *`;
var TRANSITION_SHEET = "data:text/css;charset=utf-8," + encodeURIComponent(`
${TRANSITION_RULE_SELECTOR} {
@@ -536,17 +534,17 @@ var StyleSheetActor = protocol.ActorClas
* Update the style sheet in place with new text.
*
* @param {object} request
* 'text' - new text
* 'transition' - whether to do CSS transition for change.
* 'kind' - either UPDATE_PRESERVING_RULES or UPDATE_GENERAL
*/
update: function (text, transition, kind = UPDATE_GENERAL) {
- DOMUtils.parseStyleSheet(this.rawSheet, text);
+ InspectorUtils.parseStyleSheet(this.rawSheet, text);
modifiedStyleSheets.set(this.rawSheet, text);
this.text = text;
this._notifyPropertyChanged("ruleCount");
if (transition) {
--- a/dom/tests/mochitest/chrome/test_parsingMode.html
+++ b/dom/tests/mochitest/chrome/test_parsingMode.html
@@ -7,18 +7,16 @@
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function run() {
const Cc = Components.classes;
const Ci = Components.interfaces;
const sss = Cc["@mozilla.org/content/style-sheet-service;1"]
.getService(Ci.nsIStyleSheetService);
- const domutils = Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(Ci.inIDOMUtils);
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const userUrl = encodeURI("data:text/css,body { color: seagreen; -moz-window-transform: none }");
utils.loadSheetUsingURIString(userUrl, sss.USER_SHEET);
const agentUrl = encodeURI("data:text/css,body { color: tomato; }");
utils.loadSheetUsingURIString(agentUrl, sss.AGENT_SHEET);
@@ -43,17 +41,17 @@
continue;
} else {
// Ignore sheets we don't care about.
continue;
}
// Check that re-parsing preserves the mode.
let mode = sheet.parsingMode;
- domutils.parseStyleSheet(sheet, "body { color: chartreuse; }");
+ InspectorUtils.parseStyleSheet(sheet, "body { color: chartreuse; }");
is(sheet.parsingMode, mode,
"check that re-parsing preserved mode " + mode);
}
ok(results[sss.AGENT_SHEET] && results[sss.USER_SHEET] &&
results[sss.AUTHOR_SHEET],
"all sheets seen");
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -66,16 +66,17 @@ namespace InspectorUtils {
[NewObject, Throws] sequence<InspectorFontFace> getUsedFontFaces(Range range);
sequence<DOMString> getCSSPseudoElementNames();
void addPseudoClassLock(Element element,
DOMString pseudoClass,
optional boolean enabled = true);
void removePseudoClassLock(Element element, DOMString pseudoClass);
boolean hasPseudoClassLock(Element element, DOMString pseudoClass);
void clearPseudoClassLocks(Element element);
+ [Throws] void parseStyleSheet(CSSStyleSheet sheet, DOMString input);
};
dictionary PropertyNamesOptions {
boolean includeAliases = false;
};
dictionary InspectorRGBATuple {
/*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -242,16 +242,28 @@ public:
static void RemovePseudoClassLock(GlobalObject& aGlobal,
Element& aElement,
const nsAString& aPseudoClass);
static bool HasPseudoClassLock(GlobalObject& aGlobal,
Element& aElement,
const nsAString& aPseudoClass);
static void ClearPseudoClassLocks(GlobalObject& aGlobal, Element& aElement);
+ /**
+ * Parse CSS and update the style sheet in place.
+ *
+ * @param DOMCSSStyleSheet aSheet
+ * @param DOMString aInput
+ * The new source string for the style sheet.
+ */
+ static void ParseStyleSheet(GlobalObject& aGlobal,
+ StyleSheet& aSheet,
+ const nsAString& aInput,
+ ErrorResult& aRv);
+
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
};
} // namespace dom
} // namespace mozilla
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -1088,39 +1088,47 @@ InspectorUtils::HasPseudoClassLock(Globa
/* static */ void
InspectorUtils::ClearPseudoClassLocks(GlobalObject& aGlobalObject,
Element& aElement)
{
aElement.ClearStyleStateLocks();
}
+/* static */ void
+InspectorUtils::ParseStyleSheet(GlobalObject& aGlobalObject,
+ StyleSheet& aSheet,
+ const nsAString& aInput,
+ ErrorResult& aRv)
+{
+ RefPtr<CSSStyleSheet> geckoSheet = do_QueryObject(&aSheet);
+ if (geckoSheet) {
+ nsresult rv = geckoSheet->ReparseSheet(aInput);
+ if (NS_FAILED(rv)) {
+ aRv.Throw(rv);
+ }
+ return;
+ }
+
+ RefPtr<ServoStyleSheet> servoSheet = do_QueryObject(&aSheet);
+ if (servoSheet) {
+ nsresult rv = servoSheet->ReparseSheet(aInput);
+ if (NS_FAILED(rv)) {
+ aRv.Throw(rv);
+ }
+ return;
+ }
+
+ aRv.Throw(NS_ERROR_INVALID_POINTER);
+}
+
} // namespace dom
} // namespace mozilla
NS_IMETHODIMP
-inDOMUtils::ParseStyleSheet(nsIDOMCSSStyleSheet *aSheet,
- const nsAString& aInput)
-{
- RefPtr<CSSStyleSheet> geckoSheet = do_QueryObject(aSheet);
- if (geckoSheet) {
- NS_ENSURE_ARG_POINTER(geckoSheet);
- return geckoSheet->ReparseSheet(aInput);
- }
-
- RefPtr<ServoStyleSheet> servoSheet = do_QueryObject(aSheet);
- if (servoSheet) {
- NS_ENSURE_ARG_POINTER(servoSheet);
- return servoSheet->ReparseSheet(aInput);
- }
-
- return NS_ERROR_INVALID_POINTER;
-}
-
-NS_IMETHODIMP
inDOMUtils::ScrollElementIntoView(nsIDOMElement *aElement)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
NS_ENSURE_ARG_POINTER(content);
nsIPresShell* presShell = content->OwnerDoc()->GetShell();
if (!presShell) {
return NS_OK;
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -16,24 +16,16 @@ interface nsIDOMNodeList;
interface nsIDOMFontFaceList;
interface nsIDOMRange;
interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
/**
- * Parse CSS and update the style sheet in place.
- *
- * @param DOMCSSStyleSheet aSheet
- * @param DOMString aInput
- * The new source string for the style sheet.
- */
- void parseStyleSheet(in nsIDOMCSSStyleSheet aSheet, in DOMString aInput);
- /**
* Scroll an element completely into view, if possible.
* This is similar to ensureElementIsVisible but for all ancestors.
*
* @param DOMElement aElement
*/
void scrollElementIntoView(in nsIDOMElement aElement);
};
--- a/layout/inspector/tests/chrome/test_bug727834.xul
+++ b/layout/inspector/tests/chrome/test_bug727834.xul
@@ -12,30 +12,28 @@ http://creativecommons.org/publicdomain/
onload="RunTests();">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"><![CDATA[
/** Test for Bug 727834 - Add an API to (re)parse a style sheet in place **/
function RunTests() {
SimpleTest.waitForExplicitFinish();
- let DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
- .getService(Components.interfaces.inIDOMUtils);
let body = document.querySelector("body");
let testSheet = document.styleSheets[2];
let rule = document.styleSheets[2].cssRules[0];
is(testSheet.cssRules.length, 1,
"style sheet has 1 rule");
is(rule.style.paddingTop, "100px",
"original first rule has padding-top 100px");
is(window.getComputedStyle(body).paddingTop, "100px",
"original first rule applies");
- DOMUtils.parseStyleSheet(testSheet,
+ InspectorUtils.parseStyleSheet(testSheet,
"@import url(test_bug727834.css); body{background: red;}");
is(testSheet.cssRules.length, 2,
"style sheet now has 2 rules");
is(window.getComputedStyle(body).backgroundColor, "rgb(255, 0, 0)",
"background is now red");
let exceptionName;
@@ -50,28 +48,28 @@ function RunTests() {
is(window.getComputedStyle(body).paddingLeft, "0px",
"original rule does not apply to document");
rule = testSheet.cssRules[0];
is(rule.parentStyleSheet, testSheet,
"rule's parent style sheet is not null");
- DOMUtils.parseStyleSheet(testSheet,
+ InspectorUtils.parseStyleSheet(testSheet,
"body{background: lime;}");
is(testSheet.cssRules.length, 1,
"style sheet now has 1 rule");
is(window.getComputedStyle(body).backgroundColor, "rgb(0, 255, 0)",
"background is now lime");
is(rule.parentStyleSheet, null,
"detached rule's parent style sheet is null");
SimpleTest.executeSoon(function () {
- DOMUtils.parseStyleSheet(testSheet,
+ InspectorUtils.parseStyleSheet(testSheet,
"@import url(test_bug727834.css); body{background: blue;}");
is(testSheet.cssRules.length, 2,
"style sheet now has 2 rules");
is(window.getComputedStyle(body).backgroundColor, "rgb(0, 0, 255)",
"background is now blue");
is(testSheet.cssRules[0].parentStyleSheet, testSheet,
"parent style sheet is the test sheet");
--- a/layout/inspector/tests/chrome/test_parseStyleSheetObservers.html
+++ b/layout/inspector/tests/chrome/test_parseStyleSheetObservers.html
@@ -7,18 +7,16 @@
<style>
body { color: red; }
</style>
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
-let DOMUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(SpecialPowers.Ci.inIDOMUtils);
const Cu = SpecialPowers.Components.utils;
const { ContentTaskUtils } = Cu.import("resource://testing-common/ContentTaskUtils.jsm", {});
let sheet = document.styleSheets[1];
document.styleSheetChangeEventsEnabled = true;
let listenerOptions = {
"capture": false,
};
@@ -36,17 +34,17 @@ let countingAddListener = function() {
let countingRemoveListener = function() {
removeCount++;
}
function test1Setup() {
document.addEventListener("StyleRuleAdded", countingAddListener, listenerOptions);
document.addEventListener("StyleRuleRemoved", countingRemoveListener, listenerOptions);
- DOMUtils.parseStyleSheet(sheet, "body { color: blue; } p { color: green; }");
+ InspectorUtils.parseStyleSheet(sheet, "body { color: blue; } p { color: green; }");
is(sheet.cssRules.length, 2, "Test 1: Stylesheet now has 2 rules.");
SimpleTest.executeSoon(test1Result);
}
function test1Result() {
is(removeCount, 1, "Test 1: Removed expected number of rules.");
is(addCount, 2, "Test 1: Added expected number of rules.");
@@ -80,17 +78,17 @@ async function test2Setup() {
// Create a Promise to watch for two StyleRuleAdded events. The first invocation should
// be the style rule, and the second should be the import rule. We use the same processor
// for both events, but the processor will only return true (completing the Promise) when
// the import rule has been processed.
let gotAllStyleRuleAddedEvents = ContentTaskUtils.waitForEvent(document,
"StyleRuleAdded", true, styleFirstAddProcessor);
- DOMUtils.parseStyleSheet(sheet, "@import url('imported_no_op.css'); p {color: purple;}");
+ InspectorUtils.parseStyleSheet(sheet, "@import url('imported_no_op.css'); p {color: purple;}");
is(sheet.cssRules.length, 2, "Test 2: Stylesheet now has 2 rules.");
// Await and then process the events we expect to arrive.
await gotAllStyleRuleAddedEvents;
is(foundStyle, true, "Test 2: Got the style rule.");
is(foundImport, true, "Test 2: Got the import rule.");
--- a/layout/inspector/tests/test_parseStyleSheet.html
+++ b/layout/inspector/tests/test_parseStyleSheet.html
@@ -12,25 +12,22 @@
color: red;
}
</style>
</head>
<body>
<script type="application/javascript">
const InspectorUtils = SpecialPowers.InspectorUtils;
-var domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(SpecialPowers.Ci.inIDOMUtils);
-
var sheet = document.styleSheets[1];
is(InspectorUtils.getRelativeRuleLine(sheet.cssRules[0]), 2,
"initial relative rule line");
is(InspectorUtils.getRuleLine(sheet.cssRules[0]), 11,
"initial rule line");
-domUtils.parseStyleSheet(sheet, "\nbody {\n color: blue;\n}\n");
+InspectorUtils.parseStyleSheet(sheet, "\nbody {\n color: blue;\n}\n");
is(InspectorUtils.getRelativeRuleLine(sheet.cssRules[0]), 2,
"relative rule line after reparsing");
is(InspectorUtils.getRuleLine(sheet.cssRules[0]), 11,
"relative rule line after reparsing");
</script>
</body>
</html>
--- a/layout/inspector/tests/test_parseStyleSheetImport.html
+++ b/layout/inspector/tests/test_parseStyleSheetImport.html
@@ -9,70 +9,69 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
@import url('bug1202095.css');
@import url('bug1202095-2.css');
</style>
</head>
<body>
<script type="application/javascript">
-var domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(SpecialPowers.Ci.inIDOMUtils);
+const InspectorUtils = SpecialPowers.InspectorUtils;
function do_test() {
var sheet = document.styleSheets[1];
var importRule = sheet.cssRules[0];
is(importRule.type, SpecialPowers.Ci.nsIDOMCSSRule.IMPORT_RULE,
"initial sheet has @import rule");
var importedSheet = importRule.styleSheet;
importedSheet.deleteRule(0);
is(importedSheet.cssRules.length, 0, "imported sheet now has no rules");
// "suffixed" refers to the "-2".
var suffixedSheet = sheet.cssRules[1].styleSheet;
- domUtils.parseStyleSheet(suffixedSheet, "");
+ InspectorUtils.parseStyleSheet(suffixedSheet, "");
is(suffixedSheet.cssRules.length, 0, "second imported sheet now has no rules");
// Re-parse the style sheet, preserving the imports.
- domUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" +
- "@import url('bug1202095-2.css');");
+ InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" +
+ "@import url('bug1202095-2.css');");
is(sheet.cssRules[0].type, SpecialPowers.Ci.nsIDOMCSSRule.IMPORT_RULE,
"re-parsed sheet has @import rule");
is(sheet.cssRules[0].styleSheet, importedSheet,
"imported sheet has not changed");
is(sheet.cssRules[1].styleSheet, suffixedSheet,
"second imported sheet has not changed");
// Re-parse the style sheet, preserving both imports, but changing
// the order.
- domUtils.parseStyleSheet(sheet, "@import url('bug1202095-2.css');" +
- "@import url('bug1202095.css');");
+ InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095-2.css');" +
+ "@import url('bug1202095.css');");
is(sheet.cssRules[0].styleSheet, suffixedSheet,
"reordering preserved suffixed style sheet");
is(sheet.cssRules[1].styleSheet, importedSheet,
"reordering preserved unsuffixed style sheet");
// Re-parse the style sheet, removing the imports.
- domUtils.parseStyleSheet(sheet, "");
+ InspectorUtils.parseStyleSheet(sheet, "");
is(sheet.cssRules.length, 0, "style sheet now has no rules");
// Re-parse the style sheet, adding one import back. This should
// not allow reuse.
- domUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');");
+ InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');");
is(sheet.cssRules[0].type, SpecialPowers.Ci.nsIDOMCSSRule.IMPORT_RULE,
"re-re-re-parsed sheet has @import rule");
isnot(sheet.cssRules[0].styleSheet, importedSheet,
"imported sheet has changed now");
// Re-parse the style sheet, importing the same URL twice.
// The style sheet should be reused once, but not two times.
importedSheet = sheet.cssRules[0].styleSheet;
- domUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" +
- "@import url('bug1202095.css');");
+ InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" +
+ "@import url('bug1202095.css');");
is(sheet.cssRules[0].styleSheet, importedSheet,
"first imported sheet is reused");
isnot(sheet.cssRules[1].styleSheet, importedSheet,
"second imported sheet is reused");
SimpleTest.finish();
}