Bug 1427419 - Part 14: Move inIDOMUtils.getSubpropertiesForCSSProperty to InspectorUtils. r=bz
MozReview-Commit-ID: 8Nyt0V2NUmq
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -60,17 +60,17 @@ function generateCssProperties() {
// Don't send colors over RDP, these will be re-attached by the front.
let values = InspectorUtils.getCSSValuesForProperty(name);
if (values.includes("aliceblue")) {
values = values.filter(x => !colors.includes(x));
values.unshift("COLOR");
}
- let subproperties = DOMUtils.getSubpropertiesForCSSProperty(name);
+ let subproperties = InspectorUtils.getSubpropertiesForCSSProperty(name);
properties[name] = {
isInherited: InspectorUtils.isInheritedProperty(name),
values,
supports,
subproperties,
};
});
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -30,16 +30,17 @@ namespace InspectorUtils {
unsigned long selectorIndex,
[TreatNullAs=EmptyString] optional DOMString pseudo = "");
boolean isInheritedProperty(DOMString property);
sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
[Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
[Throws] DOMString rgbToColorName(octet r, octet g, octet b);
InspectorRGBATuple? colorToRGBA(DOMString colorString);
boolean isValidCSSColor(DOMString colorString);
+ [Throws] sequence<DOMString> getSubpropertiesForCSSProperty(DOMString property);
};
dictionary PropertyNamesOptions {
boolean includeAliases = false;
};
dictionary InspectorRGBATuple {
/*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -129,16 +129,26 @@ public:
static void ColorToRGBA(GlobalObject& aGlobal,
const nsAString& aColorString,
Nullable<InspectorRGBATuple>& aResult);
// Check whether a given color is a valid CSS color.
static bool IsValidCSSColor(GlobalObject& aGlobal,
const nsAString& aColorString);
+ // Utilities for obtaining information about a CSS property.
+
+ // Get a list of the longhands corresponding to the given CSS property. If
+ // the property is a longhand already, just returns the property itself.
+ // Throws on unsupported property names.
+ static void GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
+ const nsAString& aProperty,
+ nsTArray<nsString>& aResult,
+ 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
@@ -547,59 +547,53 @@ static void GetOtherValuesForProperty(co
InsertNoDuplicates(aArray, NS_LITERAL_STRING("repeating-radial-gradient"));
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-linear-gradient"));
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-radial-gradient"));
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-repeating-linear-gradient"));
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-repeating-radial-gradient"));
}
}
-NS_IMETHODIMP
-inDOMUtils::GetSubpropertiesForCSSProperty(const nsAString& aProperty,
- uint32_t* aLength,
- char16_t*** aValues)
+namespace mozilla {
+namespace dom {
+
+/* static */ void
+InspectorUtils::GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
+ const nsAString& aProperty,
+ nsTArray<nsString>& aResult,
+ ErrorResult& aRv)
{
nsCSSPropertyID propertyID =
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) {
- return NS_ERROR_FAILURE;
+ aRv.Throw(NS_ERROR_FAILURE);
+ return;
}
if (propertyID == eCSSPropertyExtra_variable) {
- *aValues = static_cast<char16_t**>(moz_xmalloc(sizeof(char16_t*)));
- (*aValues)[0] = ToNewUnicode(aProperty);
- *aLength = 1;
- return NS_OK;
+ aResult.AppendElement(aProperty);
+ return;
}
if (!nsCSSProps::IsShorthand(propertyID)) {
- *aValues = static_cast<char16_t**>(moz_xmalloc(sizeof(char16_t*)));
- (*aValues)[0] = ToNewUnicode(nsCSSProps::GetStringValue(propertyID));
- *aLength = 1;
- return NS_OK;
+ nsString* name = aResult.AppendElement();
+ CopyASCIItoUTF16(nsCSSProps::GetStringValue(propertyID), *name);
+ return;
}
- // Count up how many subproperties we have.
- size_t subpropCount = 0;
- for (const nsCSSPropertyID *props = nsCSSProps::SubpropertyEntryFor(propertyID);
+ for (const nsCSSPropertyID* props = nsCSSProps::SubpropertyEntryFor(propertyID);
*props != eCSSProperty_UNKNOWN; ++props) {
- ++subpropCount;
+ nsString* name = aResult.AppendElement();
+ CopyASCIItoUTF16(nsCSSProps::GetStringValue(*props), *name);
}
+}
- *aValues =
- static_cast<char16_t**>(moz_xmalloc(subpropCount * sizeof(char16_t*)));
- *aLength = subpropCount;
- for (const nsCSSPropertyID *props = nsCSSProps::SubpropertyEntryFor(propertyID),
- *props_start = props;
- *props != eCSSProperty_UNKNOWN; ++props) {
- (*aValues)[props-props_start] = ToNewUnicode(nsCSSProps::GetStringValue(*props));
- }
- return NS_OK;
-}
+} // namespace dom
+} // namespace mozilla
NS_IMETHODIMP
inDOMUtils::CssPropertyIsShorthand(const nsAString& aProperty, bool *_retval)
{
nsCSSPropertyID propertyID =
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE;
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,24 +15,16 @@ interface nsIDOMNode;
interface nsIDOMNodeList;
interface nsIDOMFontFaceList;
interface nsIDOMRange;
interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
- // Utilities for obtaining information about a CSS property.
-
- // Get a list of the longhands corresponding to the given CSS property. If
- // the property is a longhand already, just returns the property itself.
- // Throws on unsupported property names.
- void getSubpropertiesForCSSProperty(in AString aProperty,
- [optional] out unsigned long aLength,
- [array, size_is(aLength), retval] out wstring aValues);
// Check whether a given CSS property is a shorthand. Throws on unsupported
// property names.
bool cssPropertyIsShorthand(in AString aProperty);
// Check whether values of the given type are valid values for the property.
// For shorthands, checks whether there's a corresponding longhand property
// that accepts values of this type. Throws on unsupported properties or
// unknown types.
--- a/layout/inspector/tests/test_bug1006595.html
+++ b/layout/inspector/tests/test_bug1006595.html
@@ -6,38 +6,41 @@ https://bugzilla.mozilla.org/show_bug.cg
<head>
<meta charset="utf-8">
<title>Test for Bug 1006595</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">
/** Test for Bug 1006595 **/
+
+ const InspectorUtils = SpecialPowers.InspectorUtils;
+
function arraysEqual(arr1, arr2, message) {
is(arr1.length, arr2.length, message + " length");
for (var i = 0; i < arr1.length; ++i) {
is(arr1[i], arr2[i], message + " element at index " + i);
}
}
var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils);
- var paddingSubProps = utils.getSubpropertiesForCSSProperty("padding");
+ var paddingSubProps = InspectorUtils.getSubpropertiesForCSSProperty("padding");
arraysEqual(paddingSubProps,
[ "padding-top",
"padding-right",
"padding-bottom",
"padding-left" ],
"'padding' subproperties");
- var displaySubProps = utils.getSubpropertiesForCSSProperty("color");
+ var displaySubProps = InspectorUtils.getSubpropertiesForCSSProperty("color");
arraysEqual(displaySubProps, [ "color" ],
"'color' subproperties");
- var varProps = utils.getSubpropertiesForCSSProperty("--foo");
+ var varProps = InspectorUtils.getSubpropertiesForCSSProperty("--foo");
arraysEqual(varProps, ["--foo"], "'--foo' subproperties");
ok(utils.cssPropertyIsShorthand("padding"), "'padding' is a shorthand")
ok(!utils.cssPropertyIsShorthand("color"), "'color' is not a shorthand")
ok(utils.cssPropertySupportsType("padding", utils.TYPE_LENGTH),
"'padding' can be a length");
ok(!utils.cssPropertySupportsType("padding", utils.TYPE_COLOR),