Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
authorMina Almasry <almasry.mina@gmail.com>
Fri, 19 Jul 2013 10:32:52 -0400
changeset 151526 5fae2f62da6697700b08972148e6ec8fa512875f
parent 151525 319da88f992ec3cb00b09be257f0d926dd2ecede
child 151527 5e4e054f3c0088f444a33a1bc9e6747c403b3b03
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs895076
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
layout/inspector/src/inDOMUtils.cpp
layout/inspector/tests/test_bug877690.html
--- a/layout/inspector/src/inDOMUtils.cpp
+++ b/layout/inspector/src/inDOMUtils.cpp
@@ -414,77 +414,133 @@ inDOMUtils::GetCSSPropertyNames(uint32_t
 #undef DO_PROP
 
   *aCount = propCount;
   *aProps = props;
 
   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)
 {
   if (nsCSSProps::IsShorthand(aProperty)) {
     // Shorthand props have no keywords.
     return;
   }
   const int32_t *keywordTable = nsCSSProps::kKeywordTableTable[aProperty];
   if (keywordTable) {
     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;
     }
   }
 }
 
-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++) {
       CopyASCIItoUTF16(allColorNames[i], *aArray.AppendElement());
     }
   }
   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,
                                     PRUnichar*** aValues)
 {
   nsCSSProperty propertyID = nsCSSProps::LookupProperty(aProperty,
                                                         nsCSSProps::eEnabled);
   if (propertyID == eCSSProperty_UNKNOWN) {
     return NS_ERROR_FAILURE;
   }
 
   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 =
     static_cast<PRUnichar**>(NS_Alloc(*aLength * sizeof(PRUnichar*)));
   for (uint32_t i = 0; i < *aLength; ++i) {
     ret[i] = ToNewUnicode(array[i]);
   }
   *aValues = ret;
--- a/layout/inspector/tests/test_bug877690.html
+++ b/layout/inspector/tests/test_bug877690.html
@@ -58,17 +58,17 @@ function do_test() {
       "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine",
       "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen",
       "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite",
       "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen",
       "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
       "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
   var prop = "background";
   var values = utils.getCSSValuesForProperty(prop);
   var expected = [ "-moz-initial", "inherit", "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
       "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue",
       "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue",
@@ -86,17 +86,17 @@ function do_test() {
       "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod",
       "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum",
       "powderblue", "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", "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
   var prop = "border-top";
   var values = utils.getCSSValuesForProperty(prop);
   var expected = [ "-moz-initial", "inherit", "thin", "medium", "thick", "none", "hidden", "dotted",
       "dashed", "solid", "double", "groove", "ridge", "inset", "outset", "-moz-use-text-color",
       "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black",
@@ -113,23 +113,23 @@ function do_test() {
       "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine",
       "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen",
       "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite",
       "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen",
       "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
       "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
   var prop = "display";
   var values = utils.getCSSValuesForProperty(prop);
   var expected = [ "-moz-initial", "inherit", "none", "inline", "block", "inline-block", "list-item",
       "table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row",
       "table-column-group", "table-column", "table-cell", "table-caption", "-moz-box", "-moz-inline-box",
@@ -138,16 +138,36 @@ function do_test() {
   ok(testValues(values, expected), "property display's values.");
 
   // test property
   var prop = "float";
   var values = utils.getCSSValuesForProperty(prop);
   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 {
     utils.getCSSValuesForProperty(prop);
     ok(false, "invalid property should throw an exception");
   }
   catch(e) {
     // test passed