зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1427419 - Part 14: Move inIDOMUtils.getSubpropertiesForCSSProperty to InspectorUtils. r=bz
MozReview-Commit-ID: 8Nyt0V2NUmq
This commit is contained in:
Родитель
0ef012043a
Коммит
2212f2845a
|
@ -65,7 +65,7 @@ function generateCssProperties() {
|
|||
values.unshift("COLOR");
|
||||
}
|
||||
|
||||
let subproperties = DOMUtils.getSubpropertiesForCSSProperty(name);
|
||||
let subproperties = InspectorUtils.getSubpropertiesForCSSProperty(name);
|
||||
|
||||
properties[name] = {
|
||||
isInherited: InspectorUtils.isInheritedProperty(name),
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace InspectorUtils {
|
|||
[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 {
|
||||
|
|
|
@ -134,6 +134,16 @@ public:
|
|||
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);
|
||||
|
|
|
@ -552,50 +552,44 @@ static void GetOtherValuesForProperty(const uint32_t aParserVariant,
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -20,14 +20,6 @@ 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);
|
||||
|
|
|
@ -11,6 +11,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1006595
|
|||
<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) {
|
||||
|
@ -20,7 +23,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1006595
|
|||
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",
|
||||
|
@ -28,11 +31,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1006595
|
|||
"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")
|
||||
|
|
Загрузка…
Ссылка в новой задаче