Bug 1465628 part 2 - Add InspectorUtils API for getting property preferences. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 31 May 2018 14:11:01 +1000
changeset 803956 8b16a81b7d10dda5c84971bd61ad48d04ad9400c
parent 803955 a965254b2b3b54391934111fe8cb41a96c5cbc22
child 803957 31c0364198569aa71d19a00fd55fe69ff4814726
push id112243
push userxquan@mozilla.com
push dateTue, 05 Jun 2018 04:32:37 +0000
reviewersemilio
bugs1465628
milestone62.0a1
Bug 1465628 part 2 - Add InspectorUtils API for getting property preferences. r?emilio MozReview-Commit-ID: G3ZjnC4cTKD
dom/chrome-webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.cpp
layout/inspector/InspectorUtils.h
--- a/dom/chrome-webidl/InspectorUtils.webidl
+++ b/dom/chrome-webidl/InspectorUtils.webidl
@@ -28,16 +28,17 @@ namespace InspectorUtils {
                                              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);
+  sequence<PropertyPref> getCSSPropertyPrefs();
   [Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
   [Throws] DOMString rgbToColorName(octet r, octet g, octet b);
   InspectorRGBATuple? colorToRGBA(DOMString colorString);
   boolean isValidCSSColor(DOMString colorString);
   [Throws] sequence<DOMString> getSubpropertiesForCSSProperty(DOMString property);
   [Throws] boolean cssPropertyIsShorthand(DOMString property);
 
   // TODO: Change this to use an enum.
@@ -80,16 +81,21 @@ namespace InspectorUtils {
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
   boolean includeShorthands = true;
   boolean includeExperimentals = false;
 };
 
+dictionary PropertyPref {
+  required DOMString name;
+  required DOMString pref;
+};
+
 dictionary InspectorRGBATuple {
   /*
    * NOTE: This tuple is in the normal 0-255-sized RGB space but can be
    * fractional and may extend outside the 0-255 range.
    *
    * a is in the range 0 - 1.
    */
   double r = 0;
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -394,16 +394,29 @@ InspectorUtils::GetCSSPropertyNames(Glob
   if (aOptions.mIncludeAliases) {
     for (prop = eCSSProperty_COUNT; prop < eCSSProperty_COUNT_with_aliases; ++prop) {
       appendProperty(prop);
     }
   }
 }
 
 /* static */ void
+InspectorUtils::GetCSSPropertyPrefs(GlobalObject& aGlobalObject,
+                                    nsTArray<PropertyPref>& aResult)
+{
+  for (const auto* src = nsCSSProps::kPropertyPrefTable;
+       src->mPropID != eCSSProperty_UNKNOWN; src++) {
+    PropertyPref& dest = *aResult.AppendElement();
+    const nsCString& name = nsCSSProps::GetStringValue(src->mPropID);
+    dest.mName.Assign(NS_ConvertASCIItoUTF16(name));
+    dest.mPref.AssignASCII(src->mPref);
+  }
+}
+
+/* static */ void
 InspectorUtils::GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
                                                const nsAString& aProperty,
                                                nsTArray<nsString>& aResult,
                                                ErrorResult& aRv)
 {
   nsCSSPropertyID propertyID =
     nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
 
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 #ifndef mozilla_dom_InspectorUtils_h
 #define mozilla_dom_InspectorUtils_h
 
-#include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/InspectorUtilsBinding.h"
 
 class nsAtom;
 class nsIDocument;
 class ComputedStyle;
 
 namespace mozilla {
 class StyleSheet;
 namespace css {
@@ -109,16 +109,21 @@ public:
                                   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);
 
+  // Get a list of all properties controlled by preference, as well as
+  // their corresponding preference names.
+  static void GetCSSPropertyPrefs(GlobalObject& aGlobal,
+                                  nsTArray<PropertyPref>& aResult);
+
   // Get a list of all valid keywords and colors for aProperty.
   static void GetCSSValuesForProperty(GlobalObject& aGlobal,
                                       const nsAString& aPropertyName,
                                       nsTArray<nsString>& aResult,
                                       ErrorResult& aRv);
 
   // Utilities for working with CSS colors
   static void RgbToColorName(GlobalObject& aGlobal,