Bug 1427419 - Part 15: Move inIDOMUtils.cssPropertyIsShorthand to InspectorUtils. r=bz
MozReview-Commit-ID: LphGIXzOlDB
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -85,17 +85,17 @@ exports.generateCssProperties = generate
* @param {string} name
* @return {Boolean}
*/
function isCssPropertyKnown(name) {
try {
// If the property name is unknown, the cssPropertyIsShorthand
// will throw an exception. But if it is known, no exception will
// be thrown; so we just ignore the return value.
- DOMUtils.cssPropertyIsShorthand(name);
+ InspectorUtils.cssPropertyIsShorthand(name);
return true;
} catch (e) {
return false;
}
}
exports.isCssPropertyKnown = isCssPropertyKnown;
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -31,16 +31,17 @@ namespace InspectorUtils {
[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);
+ [Throws] boolean cssPropertyIsShorthand(DOMString property);
};
dictionary PropertyNamesOptions {
boolean includeAliases = false;
};
dictionary InspectorRGBATuple {
/*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -139,16 +139,22 @@ public:
// 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);
+ // Check whether a given CSS property is a shorthand. Throws on unsupported
+ // property names.
+ static bool CssPropertyIsShorthand(GlobalObject& aGlobal,
+ const nsAString& aProperty,
+ 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
@@ -582,36 +582,38 @@ InspectorUtils::GetSubpropertiesForCSSPr
for (const nsCSSPropertyID* props = nsCSSProps::SubpropertyEntryFor(propertyID);
*props != eCSSProperty_UNKNOWN; ++props) {
nsString* name = aResult.AppendElement();
CopyASCIItoUTF16(nsCSSProps::GetStringValue(*props), *name);
}
}
-} // namespace dom
-} // namespace mozilla
-
-NS_IMETHODIMP
-inDOMUtils::CssPropertyIsShorthand(const nsAString& aProperty, bool *_retval)
+/* static */ bool
+InspectorUtils::CssPropertyIsShorthand(GlobalObject& aGlobalObject,
+ const nsAString& aProperty,
+ ErrorResult& aRv)
{
nsCSSPropertyID propertyID =
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) {
- return NS_ERROR_FAILURE;
+ aRv.Throw(NS_ERROR_FAILURE);
+ return false;
}
if (propertyID == eCSSPropertyExtra_variable) {
- *_retval = false;
- } else {
- *_retval = nsCSSProps::IsShorthand(propertyID);
+ return false;
}
- return NS_OK;
+
+ return nsCSSProps::IsShorthand(propertyID);
}
+} // namespace dom
+} // namespace mozilla
+
// A helper function that determines whether the given property
// supports the given type.
static bool
PropertySupportsVariant(nsCSSPropertyID aPropertyID, uint32_t aVariant)
{
if (nsCSSProps::IsShorthand(aPropertyID)) {
// We need a special case for border here, because while it resets
// border-image, it can't actually parse an image.
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,20 +15,16 @@ interface nsIDOMNode;
interface nsIDOMNodeList;
interface nsIDOMFontFaceList;
interface nsIDOMRange;
interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
- // 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.
const unsigned long TYPE_LENGTH = 0;
const unsigned long TYPE_PERCENTAGE = 1;
const unsigned long TYPE_COLOR = 2;
const unsigned long TYPE_URL = 3;
--- a/layout/inspector/tests/test_bug1006595.html
+++ b/layout/inspector/tests/test_bug1006595.html
@@ -33,18 +33,18 @@ https://bugzilla.mozilla.org/show_bug.cg
var displaySubProps = InspectorUtils.getSubpropertiesForCSSProperty("color");
arraysEqual(displaySubProps, [ "color" ],
"'color' subproperties");
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(InspectorUtils.cssPropertyIsShorthand("padding"), "'padding' is a shorthand")
+ ok(!InspectorUtils.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),
"'padding' can't be a color");
ok(utils.cssPropertySupportsType("padding", utils.TYPE_PERCENTAGE),
"'padding' can be a percentage");
--- a/layout/inspector/tests/test_css_property_is_shorthand.html
+++ b/layout/inspector/tests/test_css_property_is_shorthand.html
@@ -1,18 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
- <title>Test inDOMUtils::CssPropertyIsShorthand</title>
+ <title>Test InspectorUtils::CssPropertyIsShorthand</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 tests = [
{
property: "color",
expected: false
},
{
property: "background",
@@ -20,32 +19,32 @@
},
{
property: "--anything",
expected: false
}
];
for (let {property, expected} of tests) {
- let result = utils.cssPropertyIsShorthand(property);
+ let result = InspectorUtils.cssPropertyIsShorthand(property);
is(result, expected, "checking whether " + property + " is shorthand");
}
let sawException = false;
try {
- let result = utils.cssPropertyIsShorthand("nosuchproperty");
+ let result = InspectorUtils.cssPropertyIsShorthand("nosuchproperty");
} catch (e) {
sawException = true;
}
ok(sawException, "checking whether nosuchproperty throws");
</script>
</head>
<body>
-<h1>Test inDOMUtils::CssPropertyIsShorthand</h1>
+<h1>Test InspectorUtils::CssPropertyIsShorthand</h1>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>