Bug 1310681 - put css-color-4 color function supporting information into css property db. r?tromey draft
authorJerryShih <hshih@mozilla.com>
Fri, 21 Oct 2016 15:15:16 -0400
changeset 453220 6ffecc937a89
parent 453219 24d9449ca96f
child 453221 15741fa813f7
push id39601
push userbmo:hshih@mozilla.com
push dateFri, 23 Dec 2016 01:20:43 +0000
reviewerstromey
bugs1310681
milestone53.0a1
Bug 1310681 - put css-color-4 color function supporting information into css property db. r?tromey MozReview-Commit-ID: 8xRKGJ5wJkq
devtools/server/actors/css-properties.js
devtools/shared/fronts/css-properties.js
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -25,18 +25,22 @@ exports.CssPropertiesActor = ActorClassW
 
   destroy() {
     Actor.prototype.destroy.call(this);
   },
 
   getCSSDatabase() {
     const properties = generateCssProperties();
     const pseudoElements = DOMUtils.getCSSPseudoElementNames();
+    const supportedFeature = {
+      // checking for css-color-4 color function support.
+      "css-color-4-color-function": DOMUtils.isValidCSSColor("rgb(1 1 1 / 100%"),
+    };
 
-    return { properties, pseudoElements };
+    return { properties, pseudoElements, supportedFeature };
   }
 });
 
 /**
  * Generate the CSS properties object. Every key is the property name, while
  * the values are objects that contain information about that property.
  *
  * @return {Object}
--- a/devtools/shared/fronts/css-properties.js
+++ b/devtools/shared/fronts/css-properties.js
@@ -42,35 +42,55 @@ var cachedCssProperties = new WeakMap();
 const CssPropertiesFront = FrontClassWithSpec(cssPropertiesSpec, {
   initialize: function (client, { cssPropertiesActor }) {
     Front.prototype.initialize.call(this, client, {actor: cssPropertiesActor});
     this.manage(this);
   }
 });
 
 /**
+ * Query the feature supporting status in the featureSet.
+ *
+ * @param {Hashmap} featureSet the feature set hashmap
+ * @param {String} feature the feature name string
+ * @return {Boolean} has the feature or not
+ */
+function hasFeature(featureSet, feature) {
+  if (feature in featureSet) {
+    return featureSet[feature];
+  }
+  return false;
+}
+
+/**
  * Ask questions to a CSS database. This class does not care how the database
  * gets loaded in, only the questions that you can ask to it.
  * Prototype functions are bound to 'this' so they can be passed around as helper
  * functions.
  *
  * @param {Object} db
  *                 A database of CSS properties
  * @param {Object} inheritedList
  *                 The key is the property name, the value is whether or not
  *                 that property is inherited.
  */
 function CssProperties(db) {
   this.properties = db.properties;
   this.pseudoElements = db.pseudoElements;
 
+  // supported feature
+  this.cssColor4ColorFunction = hasFeature(db.supportedFeature,
+                                           "css-color-4-color-function");
+
   this.isKnown = this.isKnown.bind(this);
   this.isInherited = this.isInherited.bind(this);
   this.supportsType = this.supportsType.bind(this);
   this.isValidOnClient = this.isValidOnClient.bind(this);
+  this.supportsCssColor4ColorFunction =
+    this.supportsCssColor4ColorFunction.bind(this);
 
   // A weakly held dummy HTMLDivElement to test CSS properties on the client.
   this._dummyElements = new WeakMap();
 }
 
 CssProperties.prototype = {
   /**
    * Checks to see if the property is known by the browser. This function has
@@ -176,16 +196,25 @@ CssProperties.prototype = {
     if (this.isKnown(name)) {
       if (this.properties[name] && this.properties[name].subproperties) {
         return this.properties[name].subproperties;
       }
       return [name];
     }
     return [];
   },
+
+  /**
+   * Checking for the css-color-4 color function support.
+   *
+   * @return {Boolean} Return true if the server supports css-color-4 color function.
+   */
+  supportsCssColor4ColorFunction() {
+    return this.cssColor4ColorFunction;
+  },
 };
 
 /**
  * Create a CssProperties object with a fully loaded CSS database. The
  * CssProperties interface can be queried synchronously, but the initialization
  * is potentially async and should be handled up-front when the tool is created.
  *
  * The front is returned only with this function so that it can be destroyed
@@ -291,16 +320,21 @@ function normalizeCssData(db) {
         db.properties[name].subproperties =
           CSS_PROPERTIES_DB.properties[name].subproperties;
       }
     }
   }
 
   reattachCssColorValues(db);
 
+  // If there is no supportedFeature in db, create an empty one.
+  if (!db.supportedFeature) {
+    db.supportedFeature = {};
+  }
+
   return db;
 }
 
 /**
  * Color values are omitted to save on space. Add them back here.
  * @param {Object} The CSS database.
  */
 function reattachCssColorValues(db) {