Bug 898455 - remove domUtils.getCSSValuesForProperty duplicate entries; r= bz

Removes duplicate entries from the values that are returned by getCSSValuesForProperty,
and returns url for the proper properties.
This commit is contained in:
Mina Almasry 2013-07-29 14:42:51 +02:00
Родитель dfe29b8d9f
Коммит 21462c589f
2 изменённых файлов: 40 добавлений и 3 удалений

Просмотреть файл

@ -498,6 +498,9 @@ static void GetColorsForProperty(const uint32_t aParserVariant,
nsTArray<nsString>& aArray) nsTArray<nsString>& aArray)
{ {
if (aParserVariant & VARIANT_COLOR) { if (aParserVariant & VARIANT_COLOR) {
// GetKeywordsForProperty and GetOtherValuesForProperty assume aArray is sorted,
// and if aArray is not empty here, then it's not going to be sorted coming out.
MOZ_ASSERT(aArray.Length() == 0);
size_t size; size_t size;
const char * const *allColorNames = NS_AllColorNames(&size); const char * const *allColorNames = NS_AllColorNames(&size);
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
@ -544,6 +547,9 @@ static void GetOtherValuesForProperty(const uint32_t aParserVariant,
InsertNoDuplicates(aArray, NS_LITERAL_STRING("calc")); InsertNoDuplicates(aArray, NS_LITERAL_STRING("calc"));
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-calc")); InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-calc"));
} }
if (aParserVariant & VARIANT_URL) {
InsertNoDuplicates(aArray, NS_LITERAL_STRING("url"));
}
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -569,10 +575,16 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
GetOtherValuesForProperty(propertyParserVariant, array); GetOtherValuesForProperty(propertyParserVariant, array);
} else { } else {
// Property is shorthand. // Property is shorthand.
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
// Get colors (once) first.
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
if (propertyParserVariant & VARIANT_COLOR) {
GetColorsForProperty(propertyParserVariant, array);
break;
}
}
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) { CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty); uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
// Get colors first.
GetColorsForProperty(propertyParserVariant, array);
GetKeywordsForProperty(*subproperty, array); GetKeywordsForProperty(*subproperty, array);
GetOtherValuesForProperty(propertyParserVariant, array); GetOtherValuesForProperty(propertyParserVariant, array);
} }

Просмотреть файл

@ -91,7 +91,32 @@ function do_test() {
"violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen", "no-repeat", "repeat", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen", "no-repeat", "repeat",
"repeat-x", "repeat-y", "fixed", "scroll", "local", "center", "top", "bottom", "left", "right", "repeat-x", "repeat-y", "fixed", "scroll", "local", "center", "top", "bottom", "left", "right",
"border-box", "padding-box", "content-box", "border-box", "padding-box", "content-box", "contain", "border-box", "padding-box", "content-box", "border-box", "padding-box", "content-box", "contain",
"cover", "rgb", "hsl", "-moz-rgba", "-moz-hsla", "rgba", "hsla", "none", "-moz-element", "-moz-image-rect" ]; "cover", "rgb", "hsl", "-moz-rgba", "-moz-hsla", "rgba", "hsla", "none", "-moz-element", "-moz-image-rect", "url" ];
ok(testValues(values, expected), "Shorthand property values.");
var prop = "border";
var values = utils.getCSSValuesForProperty(prop);
var expected = [ "-moz-calc", "-moz-hsla", "-moz-initial", "-moz-rgba", "-moz-use-text-color", "aliceblue",
"antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet",
"brown", "burlywood", "cadetblue", "calc", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk",
"crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki",
"darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
"darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", "darkviolet", "dashed", "deeppink",
"deepskyblue", "dimgray", "dimgrey", "dodgerblue", "dotted", "double", "fill", "firebrick", "floralwhite",
"forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", "greenyellow",
"groove", "hidden", "honeydew", "hotpink", "hsl", "hsla", "indianred", "indigo", "inherit", "inset", "ivory",
"khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan",
"lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey", "lightpink", "lightsalmon", "lightseagreen",
"lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", "lightyellow", "lime", "limegreen",
"linen", "logical", "magenta", "maroon", "medium", "mediumaquamarine", "mediumblue", "mediumorchid",
"mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "none",
"oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "outset", "palegoldenrod", "palegreen",
"paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "physical", "pink", "plum", "powderblue",
"purple", "red", "repeat", "rgb", "rgba", "ridge", "rosybrown", "round", "royalblue", "saddlebrown", "salmon",
"sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey",
"snow", "solid", "springgreen", "steelblue", "stretch", "tan", "teal", "thick", "thin", "thistle", "tomato",
"transparent", "turquoise", "url", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen" ]
ok(testValues(values, expected), "Shorthand property values."); ok(testValues(values, expected), "Shorthand property values.");
// test keywords only // test keywords only