Bug 1427419 - Part 8: Move inIDOMUtils.getCSSPropertyNames to InspectorUtils. r=bz draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 06 Jan 2018 15:08:14 +0800
changeset 716753 6b30d752eddbd61ec5a53e01a72e66e4b596cff6
parent 716752 da596c2c8eabe9bb358041c35b06ca8b0bb3d243
child 716754 4337aeb9f092e05d33b3ae9c3a4f10598439775b
push id94496
push userbmo:cam@mcc.id.au
push dateSat, 06 Jan 2018 07:08:40 +0000
reviewersbz
bugs1427419
milestone59.0a1
Bug 1427419 - Part 8: Move inIDOMUtils.getCSSPropertyNames to InspectorUtils. r=bz While we're at it, move to a more friendly API. EXCLUDE_SHORTHANDS is currently unused so we drop that. MozReview-Commit-ID: H64ou63We4a
devtools/server/actors/css-properties.js
dom/webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -41,17 +41,17 @@ exports.CssPropertiesActor = ActorClassW
 /**
  * Generate the CSS properties object. Every key is the property name, while
  * the values are objects that contain information about that property.
  *
  * @return {Object}
  */
 function generateCssProperties() {
   const properties = {};
-  const propertyNames = DOMUtils.getCSSPropertyNames(DOMUtils.INCLUDE_ALIASES);
+  const propertyNames = InspectorUtils.getCSSPropertyNames({ includeAliases: true });
   const colors = Object.keys(cssColors);
 
   propertyNames.forEach(name => {
     // Get the list of CSS types this property supports.
     let supports = [];
     for (let type in CSS_TYPES) {
       if (safeCssPropertySupportsType(name, DOMUtils["TYPE_" + type])) {
         supports.push(CSS_TYPES[type]);
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -25,16 +25,21 @@ namespace InspectorUtils {
   [Throws] unsigned long long getSpecificity(CSSStyleRule rule,
                                              unsigned long selectorIndex);
   [Throws] boolean selectorMatchesElement(
       Element element,
       CSSStyleRule rule,
       unsigned long selectorIndex,
       [TreatNullAs=EmptyString] optional DOMString pseudo = "");
   boolean isInheritedProperty(DOMString property);
+  sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
+};
+
+dictionary PropertyNamesOptions {
+  boolean includeAliases = false;
 };
 
 dictionary InspectorRGBTriple {
   /*
    * NOTE: Using octet for RGB components is not generally OK, because
    * they can be outside the 0-255 range, but for backwards-compatible
    * named colors (which is what we use this dictionary for) the 0-255
    * assumption is fine.
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -98,16 +98,22 @@ public:
                                      ErrorResult& aRv);
 
   // Utilities for working with CSS properties
   //
   // Returns true if the string names a property that is inherited by default.
   static bool IsInheritedProperty(GlobalObject& aGlobal,
                                   const nsAString& aPropertyName);
 
+  // Get a list of all our supported property names.  Optionally
+  // property aliases included.
+  static void GetCSSPropertyNames(GlobalObject& aGlobal,
+                                  const PropertyNamesOptions& aOptions,
+                                  nsTArray<nsString>& aResult);
+
 private:
   static already_AddRefed<nsStyleContext>
     GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -55,16 +55,18 @@
 #include "mozilla/ServoStyleRuleMap.h"
 #include "mozilla/ServoCSSParser.h"
 #include "mozilla/dom/InspectorUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
 using namespace mozilla::dom;
 
+extern const char* const kCSSRawProperties[];
+
 ///////////////////////////////////////////////////////////////////////////////
 
 inDOMUtils::inDOMUtils()
 {
 }
 
 inDOMUtils::~inDOMUtils()
 {
@@ -401,85 +403,58 @@ InspectorUtils::IsInheritedProperty(Glob
   if (nsCSSProps::IsShorthand(prop)) {
     prop = nsCSSProps::SubpropertyEntryFor(prop)[0];
   }
 
   nsStyleStructID sid = nsCSSProps::kSIDTable[prop];
   return !nsStyleContext::IsReset(sid);
 }
 
-} // namespace dom
-} // namespace mozilla
-
-extern const char* const kCSSRawProperties[];
-
-NS_IMETHODIMP
-inDOMUtils::GetCSSPropertyNames(uint32_t aFlags, uint32_t* aCount,
-                                char16_t*** aProps)
+/* static */ void
+InspectorUtils::GetCSSPropertyNames(GlobalObject& aGlobalObject,
+                                    const PropertyNamesOptions& aOptions,
+                                    nsTArray<nsString>& aResult)
 {
-  // maxCount is the largest number of properties we could have; our actual
-  // number might be smaller because properties might be disabled.
-  uint32_t maxCount;
-  if (aFlags & EXCLUDE_SHORTHANDS) {
-    maxCount = eCSSProperty_COUNT_no_shorthands;
-  } else {
-    maxCount = eCSSProperty_COUNT;
-  }
-
-  if (aFlags & INCLUDE_ALIASES) {
-    maxCount += (eCSSProperty_COUNT_with_aliases - eCSSProperty_COUNT);
-  }
-
-  char16_t** props =
-    static_cast<char16_t**>(moz_xmalloc(maxCount * sizeof(char16_t*)));
-
 #define DO_PROP(_prop)                                                      \
   PR_BEGIN_MACRO                                                            \
-    nsCSSPropertyID cssProp = nsCSSPropertyID(_prop);                           \
+    nsCSSPropertyID cssProp = nsCSSPropertyID(_prop);                       \
     if (nsCSSProps::IsEnabled(cssProp, CSSEnabledState::eForAllContent)) {  \
-      props[propCount] =                                                    \
-        ToNewUnicode(nsDependentCString(kCSSRawProperties[_prop]));         \
-      ++propCount;                                                          \
+      nsDependentCString name(kCSSRawProperties[_prop]);                    \
+      aResult.AppendElement(NS_ConvertASCIItoUTF16(name));                  \
     }                                                                       \
   PR_END_MACRO
 
-  // prop is the property id we're considering; propCount is how many properties
-  // we've put into props so far.
-  uint32_t prop = 0, propCount = 0;
+  uint32_t prop = 0;
   for ( ; prop < eCSSProperty_COUNT_no_shorthands; ++prop) {
     if (nsCSSProps::PropertyParseType(nsCSSPropertyID(prop)) !=
         CSS_PROPERTY_PARSE_INACCESSIBLE) {
       DO_PROP(prop);
     }
   }
 
-  if (!(aFlags & EXCLUDE_SHORTHANDS)) {
-    for ( ; prop < eCSSProperty_COUNT; ++prop) {
-      // Some shorthands are also aliases
-      if ((aFlags & INCLUDE_ALIASES) ||
-          !nsCSSProps::PropHasFlags(nsCSSPropertyID(prop),
-                                    CSS_PROPERTY_IS_ALIAS)) {
-        DO_PROP(prop);
-      }
+  for ( ; prop < eCSSProperty_COUNT; ++prop) {
+    // Some shorthands are also aliases
+    if (aOptions.mIncludeAliases ||
+        !nsCSSProps::PropHasFlags(nsCSSPropertyID(prop),
+                                  CSS_PROPERTY_IS_ALIAS)) {
+      DO_PROP(prop);
     }
   }
 
-  if (aFlags & INCLUDE_ALIASES) {
+  if (aOptions.mIncludeAliases) {
     for (prop = eCSSProperty_COUNT; prop < eCSSProperty_COUNT_with_aliases; ++prop) {
       DO_PROP(prop);
     }
   }
 
 #undef DO_PROP
+}
 
-  *aCount = propCount;
-  *aProps = props;
-
-  return NS_OK;
-}
+} // namespace dom
+} // namespace mozilla
 
 static void InsertNoDuplicates(nsTArray<nsString>& aArray,
                                const nsAString& aString)
 {
   size_t i = aArray.IndexOfFirstElementGt(aString);
   if (i > 0 && aArray[i-1].Equals(aString)) {
     return;
   }
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,24 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  // Get a list of all our supported property names.  Optionally
-  // shorthands can be excluded or property aliases included.
-  const unsigned long EXCLUDE_SHORTHANDS = (1<<0);
-  const unsigned long INCLUDE_ALIASES = (1<<1);
-  void getCSSPropertyNames([optional] in unsigned long aFlags,
-			   [optional] out unsigned long aCount,
-			   [retval, array, size_is(aCount)] out wstring aProps);
-
   // Get a list of all valid keywords and colors for aProperty.
   void getCSSValuesForProperty(in AString aProperty,
                                [optional] out unsigned long aLength,
                                [array, size_is(aLength), retval] out wstring aValues);
 
   // Utilities for working with CSS colors
   [implicit_jscontext]
   jsval colorNameToRGB(in DOMString aColorName);