Bug 1427419 - Part 23: Move inIDOMUtils.getCSSPseudoElementNames to InspectorUtils. r=bz
MozReview-Commit-ID: A6FhXc2mJm1
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -1,16 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-loader.lazyServiceGetter(this, "DOMUtils",
- "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
loader.lazyRequireGetter(this, "CSS_TYPES",
"devtools/shared/css/properties-db", true);
const protocol = require("devtools/shared/protocol");
const { ActorClassWithSpec, Actor } = protocol;
const { cssPropertiesSpec } = require("devtools/shared/specs/css-properties");
const { cssColors } = require("devtools/shared/css/color-db");
const InspectorUtils = require("InspectorUtils");
@@ -23,17 +21,17 @@ exports.CssPropertiesActor = ActorClassW
},
destroy() {
Actor.prototype.destroy.call(this);
},
getCSSDatabase() {
const properties = generateCssProperties();
- const pseudoElements = DOMUtils.getCSSPseudoElementNames();
+ const pseudoElements = InspectorUtils.getCSSPseudoElementNames();
const supportedFeature = {
// checking for css-color-4 color function support.
"css-color-4-color-function": InspectorUtils.isValidCSSColor("rgb(1 1 1 / 100%)"),
};
return { properties, pseudoElements, supportedFeature };
}
});
--- a/devtools/server/actors/styles.js
+++ b/devtools/server/actors/styles.js
@@ -23,20 +23,18 @@ loader.lazyRequireGetter(this, "isCssPro
"devtools/server/actors/css-properties", true);
loader.lazyRequireGetter(this, "parseNamedDeclarations",
"devtools/shared/css/parsing-utils", true);
loader.lazyRequireGetter(this, "UPDATE_PRESERVING_RULES",
"devtools/server/actors/stylesheets", true);
loader.lazyRequireGetter(this, "UPDATE_GENERAL",
"devtools/server/actors/stylesheets", true);
-loader.lazyServiceGetter(this, "DOMUtils", "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
-
loader.lazyGetter(this, "PSEUDO_ELEMENTS", () => {
- return DOMUtils.getCSSPseudoElementNames();
+ return InspectorUtils.getCSSPseudoElementNames();
});
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const FONT_PREVIEW_TEXT = "Abc";
const FONT_PREVIEW_FONT_SIZE = 40;
const FONT_PREVIEW_FILLSTYLE = "black";
const NORMAL_FONT_WEIGHT = 400;
const BOLD_FONT_WEIGHT = 700;
--- a/devtools/shared/css/generated/generate-properties-db.js
+++ b/devtools/shared/css/generated/generate-properties-db.js
@@ -1,21 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
"use strict";
+/* globals InspectorUtils */
+
/*
* This is an xpcshell script that runs to generate a static list of CSS properties
* as known by the platform. It is run from ./mach_commands.py by running
* `mach devtools-css-db`.
*/
var {require} = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
var {generateCssProperties} = require("devtools/server/actors/css-properties");
+Components.utils.importGlobalProperties(["InspectorUtils"]);
+
// xpcshell can output extra information, so place some delimiter text between
// the output of the css properties database.
dump("DEVTOOLS_CSS_DB_DELIMITER");
// Output JSON
dump(JSON.stringify({
cssProperties: cssProperties(),
pseudoElements: pseudoElements()
@@ -43,13 +48,10 @@ function cssProperties() {
}
return properties;
}
/**
* The list of all CSS Pseudo Elements.
*/
function pseudoElements() {
- const {classes: Cc, interfaces: Ci} = Components;
- const domUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(Ci.inIDOMUtils);
- return domUtils.getCSSPseudoElementNames();
+ return InspectorUtils.getCSSPseudoElementNames();
}
--- a/devtools/shared/tests/unit/test_css-properties-db.js
+++ b/devtools/shared/tests/unit/test_css-properties-db.js
@@ -14,33 +14,33 @@
* Because of these difficulties, the database only needs to be up to date with Nightly.
* It is a fallback that is only used if the remote debugging protocol doesn't support
* providing a CSS database, so it's ok if the provided properties don't exactly match
* the inspected target in this particular case.
*/
"use strict";
-const DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
- .getService(Components.interfaces.inIDOMUtils);
-
const {PSEUDO_ELEMENTS, CSS_PROPERTIES, PREFERENCES} = require("devtools/shared/css/generated/properties-db");
const {generateCssProperties} = require("devtools/server/actors/css-properties");
const {Preferences} = require("resource://gre/modules/Preferences.jsm");
+Components.utils.importGlobalProperties(["InspectorUtils"]);
+
function run_test() {
const propertiesErrorMessage = "If this assertion fails, then the client side CSS " +
"properties list in devtools is out of sync with the " +
"CSS properties on the platform. To fix this " +
"assertion run `mach devtools-css-db` to re-generate " +
"the client side properties.";
// Check that the platform and client match for pseudo elements.
- deepEqual(PSEUDO_ELEMENTS, DOMUtils.getCSSPseudoElementNames(), `The pseudo elements ` +
- `match on the client and platform. ${propertiesErrorMessage}`);
+ deepEqual(PSEUDO_ELEMENTS, InspectorUtils.getCSSPseudoElementNames(),
+ "The pseudo elements match on the client and platform. " +
+ propertiesErrorMessage);
/**
* Check that the platform and client match for the details on their CSS properties.
* Enumerate each property to aid in debugging. Sometimes these properties don't
* completely agree due to differences in preferences. Check the currently set
* preference for that property to see if it's enabled.
*/
const platformProperties = generateCssProperties();
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -59,16 +59,17 @@ namespace InspectorUtils {
sequence<DOMString> getBindingURLs(Element element);
[Throws] void setContentState(Element element, unsigned long long state);
[Throws] void removeContentState(
Element element,
unsigned long long state,
optional boolean clearActiveDocument = false);
unsigned long long getContentState(Element element);
[NewObject, Throws] sequence<InspectorFontFace> getUsedFontFaces(Range range);
+ sequence<DOMString> getCSSPseudoElementNames();
};
dictionary PropertyNamesOptions {
boolean includeAliases = false;
};
dictionary InspectorRGBATuple {
/*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -218,16 +218,24 @@ public:
ErrorResult& aRv);
static uint64_t GetContentState(GlobalObject& aGlobal, Element& aElement);
static void GetUsedFontFaces(GlobalObject& aGlobal,
nsRange& aRange,
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
ErrorResult& aRv);
+ /**
+ * Get the names of all the supported pseudo-elements.
+ * Pseudo-elements which are only accepted in UA style sheets are
+ * not included.
+ */
+ static void GetCSSPseudoElementNames(GlobalObject& aGlobal,
+ nsTArray<nsString>& aResult);
+
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
};
} // namespace dom
} // namespace mozilla
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -1022,40 +1022,36 @@ GetStatesForPseudoClass(const nsAString&
type == CSSPseudoClassType::mozAnyLink) {
return EventStates();
}
// Our array above is long enough that indexing into it with
// NotPseudo is ok.
return sPseudoClassStates[static_cast<CSSPseudoClassTypeBase>(type)];
}
-NS_IMETHODIMP
-inDOMUtils::GetCSSPseudoElementNames(uint32_t* aLength, char16_t*** aNames)
+namespace mozilla {
+namespace dom {
+
+/* static */ void
+InspectorUtils::GetCSSPseudoElementNames(GlobalObject& aGlobalObject,
+ nsTArray<nsString>& aResult)
{
- nsTArray<nsAtom*> array;
-
const CSSPseudoElementTypeBase pseudoCount =
static_cast<CSSPseudoElementTypeBase>(CSSPseudoElementType::Count);
for (CSSPseudoElementTypeBase i = 0; i < pseudoCount; ++i) {
CSSPseudoElementType type = static_cast<CSSPseudoElementType>(i);
if (nsCSSPseudoElements::IsEnabled(type, CSSEnabledState::eForAllContent)) {
nsAtom* atom = nsCSSPseudoElements::GetPseudoAtom(type);
- array.AppendElement(atom);
+ aResult.AppendElement(nsDependentAtomString(atom));
}
}
+}
- *aLength = array.Length();
- char16_t** ret =
- static_cast<char16_t**>(moz_xmalloc(*aLength * sizeof(char16_t*)));
- for (uint32_t i = 0; i < *aLength; ++i) {
- ret[i] = ToNewUnicode(nsDependentAtomString(array[i]));
- }
- *aNames = ret;
- return NS_OK;
-}
+} // namespace dom
+} // namespace mozilla
NS_IMETHODIMP
inDOMUtils::AddPseudoClassLock(nsIDOMElement *aElement,
const nsAString &aPseudoClass,
bool aEnabled,
uint8_t aArgc)
{
EventStates state = GetStatesForPseudoClass(aPseudoClass);
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,27 +15,16 @@ interface nsIDOMNode;
interface nsIDOMNodeList;
interface nsIDOMFontFaceList;
interface nsIDOMRange;
interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
- /**
- * Get the names of all the supported pseudo-elements.
- * Pseudo-elements which are only accepted in UA style sheets are
- * not included.
- *
- * @param {unsigned long} aCount the number of items returned
- * @param {wstring[]} aNames the names
- */
- void getCSSPseudoElementNames([optional] out unsigned long aCount,
- [retval, array, size_is(aCount)] out wstring aNames);
-
// pseudo-class style locking methods. aPseudoClass must be a valid pseudo-class
// selector string, e.g. ":hover". ":any-link" and non-event-state
// pseudo-classes are ignored. aEnabled sets whether the psuedo-class
// should be locked to on or off.
[optional_argc] void addPseudoClassLock(in nsIDOMElement aElement,
in DOMString aPseudoClass,
[optional] in boolean aEnabled);
void removePseudoClassLock(in nsIDOMElement aElement, in DOMString aPseudoClass);
--- a/layout/inspector/tests/test_getCSSPseudoElementNames.html
+++ b/layout/inspector/tests/test_getCSSPseudoElementNames.html
@@ -1,18 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
- <title>Test inDOMUtils::getCSSPseudoElementNames</title>
+ <title>Test InspectorUtils::getCSSPseudoElementNames</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
- let utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
- .getService(SpecialPowers.Ci.inIDOMUtils);
+ const InspectorUtils = SpecialPowers.InspectorUtils;
let expected = new Set([
":after",
":before",
":backdrop",
":cue",
":first-letter",
":first-line",
@@ -27,34 +26,34 @@
":-moz-placeholder",
":-moz-progress-bar",
":-moz-range-progress",
":-moz-range-thumb",
":-moz-range-track",
":-moz-selection",
]);
- let names = utils.getCSSPseudoElementNames();
+ let names = InspectorUtils.getCSSPseudoElementNames();
for (let name of names) {
ok(expected.has(name), name + " is included");
expected.delete(name);
}
if (expected.size > 0) {
todo_is(expected.size, 0,
"ideally all pseudo-element names would be listed in this test");
for (let extra of expected) {
info("extra element: " + extra);
}
}
</script>
</head>
<body>
-<h1>Test inDOMUtils::getCSSPseudoElementNames</h1>
+<h1>Test InspectorUtils::getCSSPseudoElementNames</h1>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>