mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto, normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
This commit is contained in:
parent
99080c7766
commit
d0e202df25
@ -419,6 +419,16 @@ inDOMUtils::GetCSSPropertyNames(uint32_t aFlags, uint32_t* aCount,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void InsertNoDuplicates(nsTArray<nsString>& aArray,
|
||||
const nsAString& aString)
|
||||
{
|
||||
size_t i = aArray.IndexOfFirstElementGt(aString);
|
||||
if (i > 0 && aArray[i-1].Equals(aString)) {
|
||||
return;
|
||||
}
|
||||
aArray.InsertElementAt(i, aString);
|
||||
}
|
||||
|
||||
static void GetKeywordsForProperty(const nsCSSProperty aProperty,
|
||||
nsTArray<nsString>& aArray)
|
||||
{
|
||||
@ -431,8 +441,8 @@ static void GetKeywordsForProperty(const nsCSSProperty aProperty,
|
||||
size_t i = 0;
|
||||
while (nsCSSKeyword(keywordTable[i]) != eCSSKeyword_UNKNOWN) {
|
||||
nsCSSKeyword word = nsCSSKeyword(keywordTable[i]);
|
||||
CopyASCIItoUTF16(nsCSSKeywords::GetStringValue(word),
|
||||
*aArray.AppendElement());
|
||||
InsertNoDuplicates(aArray,
|
||||
NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(word)));
|
||||
// Increment counter by 2, because in this table every second
|
||||
// element is a nsCSSKeyword.
|
||||
i += 2;
|
||||
@ -440,11 +450,10 @@ static void GetKeywordsForProperty(const nsCSSProperty aProperty,
|
||||
}
|
||||
}
|
||||
|
||||
static void GetColorsForProperty(const nsCSSProperty propertyID,
|
||||
static void GetColorsForProperty(const uint32_t aParserVariant,
|
||||
nsTArray<nsString>& aArray)
|
||||
{
|
||||
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
|
||||
if (propertyParserVariant & VARIANT_COLOR) {
|
||||
if (aParserVariant & VARIANT_COLOR) {
|
||||
size_t size;
|
||||
const char * const *allColorNames = NS_AllColorNames(&size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
@ -454,6 +463,45 @@ static void GetColorsForProperty(const nsCSSProperty propertyID,
|
||||
return;
|
||||
}
|
||||
|
||||
static void GetOtherValuesForProperty(const uint32_t aParserVariant,
|
||||
nsTArray<nsString>& aArray)
|
||||
{
|
||||
if (aParserVariant & VARIANT_AUTO) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("auto"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_NORMAL) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("normal"));
|
||||
}
|
||||
if(aParserVariant & VARIANT_ALL) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("all"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_NONE) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("none"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_ELEMENT) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-element"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_IMAGE_RECT) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-image-rect"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_COLOR) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("rgb"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("hsl"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-rgba"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-hsla"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("rgba"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("hsla"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_TIMING_FUNCTION) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("cubic-bezier"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("steps"));
|
||||
}
|
||||
if (aParserVariant & VARIANT_CALC) {
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("calc"));
|
||||
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-calc"));
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
|
||||
uint32_t* aLength,
|
||||
@ -466,20 +514,28 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
|
||||
}
|
||||
|
||||
nsTArray<nsString> array;
|
||||
// All CSS properties take initial and inherit.
|
||||
array.AppendElement(NS_LITERAL_STRING("-moz-initial"));
|
||||
array.AppendElement(NS_LITERAL_STRING("inherit"));
|
||||
// We start collecting the values, BUT colors need to go in first, because array
|
||||
// needs to stay sorted, and the colors are sorted, so we just append them.
|
||||
if (!nsCSSProps::IsShorthand(propertyID)) {
|
||||
// Property is longhand.
|
||||
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
|
||||
// Get colors first.
|
||||
GetColorsForProperty(propertyParserVariant, array);
|
||||
GetKeywordsForProperty(propertyID, array);
|
||||
GetColorsForProperty(propertyID, array);
|
||||
GetOtherValuesForProperty(propertyParserVariant, array);
|
||||
} else {
|
||||
// Property is shorthand.
|
||||
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
|
||||
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
|
||||
// Get colors first.
|
||||
GetColorsForProperty(propertyParserVariant, array);
|
||||
GetKeywordsForProperty(*subproperty, array);
|
||||
GetColorsForProperty(*subproperty, array);
|
||||
GetOtherValuesForProperty(propertyParserVariant, array);
|
||||
}
|
||||
}
|
||||
// All CSS properties take initial and inherit.
|
||||
InsertNoDuplicates(array, NS_LITERAL_STRING("-moz-initial"));
|
||||
InsertNoDuplicates(array, NS_LITERAL_STRING("inherit"));
|
||||
|
||||
*aLength = array.Length();
|
||||
PRUnichar** ret =
|
||||
|
@ -63,7 +63,7 @@ function do_test() {
|
||||
"purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen",
|
||||
"seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen",
|
||||
"steelblue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat",
|
||||
"white", "whitesmoke", "yellow", "yellowgreen" ];
|
||||
"white", "whitesmoke", "yellow", "yellowgreen", "rgb", "hsl", "-moz-rgba", "-moz-hsla", "rgba", "hsla" ];
|
||||
ok(testValues(values, expected), "property color's values.");
|
||||
|
||||
// test a shorthand property
|
||||
@ -91,7 +91,7 @@ function do_test() {
|
||||
"violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen", "no-repeat", "repeat",
|
||||
"repeat-x", "repeat-y", "fixed", "scroll", "center", "top", "bottom", "left", "right",
|
||||
"border-box", "padding-box", "content-box", "border-box", "padding-box", "content-box", "contain",
|
||||
"cover" ];
|
||||
"cover", "rgb", "hsl", "-moz-rgba", "-moz-hsla", "rgba", "hsla", "none", "-moz-element", "-moz-image-rect" ];
|
||||
ok(testValues(values, expected), "Shorthand property values.");
|
||||
|
||||
// test keywords only
|
||||
@ -118,13 +118,13 @@ function do_test() {
|
||||
"purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell",
|
||||
"sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen", "steelblue",
|
||||
"tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat", "white", "whitesmoke",
|
||||
"yellow", "yellowgreen" ];
|
||||
"yellow", "yellowgreen", "calc", "-moz-calc", "rgb", "hsl", "-moz-rgba", "-moz-hsla", "rgba", "hsla" ];
|
||||
ok(testValues(values, expected), "property border-top's values.");
|
||||
|
||||
// tests no keywords or colors
|
||||
var prop = "padding-bottom";
|
||||
var values = utils.getCSSValuesForProperty(prop);
|
||||
var expected = [ "-moz-initial", "inherit" ];
|
||||
var expected = [ "-moz-initial", "inherit", "calc", "-moz-calc" ];
|
||||
ok(testValues(values, expected), "property padding-bottom's values.");
|
||||
|
||||
// test proprety
|
||||
@ -143,6 +143,26 @@ function do_test() {
|
||||
var expected = [ "-moz-initial", "inherit", "none", "left", "right" ];
|
||||
ok(testValues(values, expected), "proprety float values");
|
||||
|
||||
// Test property with "auto"
|
||||
var prop = "margin";
|
||||
var values = utils.getCSSValuesForProperty(prop);
|
||||
var expected = [ "-moz-calc", "-moz-initial", "auto", "calc", "inherit", "logical", "physical" ];
|
||||
ok(testValues(values, expected), "property margin's values.");
|
||||
|
||||
// Test property with "normal"
|
||||
var prop = "font-style";
|
||||
var values = utils.getCSSValuesForProperty(prop);
|
||||
var expected = [ "-moz-initial", "inherit", "italic", "normal", "oblique" ];
|
||||
ok(testValues(values, expected), "property font-style's values.");
|
||||
|
||||
// Test property with "cubic-bezier" and "step".
|
||||
var prop = "-moz-transition";
|
||||
var values = utils.getCSSValuesForProperty(prop);
|
||||
var expected = [ "-moz-initial", "all", "cubic-bezier", "ease", "ease-in", "ease-in-out",
|
||||
"ease-out", "inherit", "linear", "none", "step-end", "step-start",
|
||||
"steps" ];
|
||||
ok(testValues(values, expected), "property -moz-transition's values.");
|
||||
|
||||
// test invalid property
|
||||
var prop = "invalidProperty";
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user