Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js

Issue 2215253002: DevTools: do not use CSSMetadata instances for autocompletion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@css-meta-data
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js b/third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js
index f8141db7c8b001e16be71451b9de4fe32479a452..e3db94d369be00a9c0384c94cc8805f0b2cd8fcc 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/CSSMetadata.js
@@ -32,7 +32,7 @@
/**
* @constructor
- * @param {!Array.<!{name: string, longhands: !Array.<string>}|string>} properties
+ * @param {!Array.<!{name: string, longhands: !Array.<string>}>} properties
*/
WebInspector.CSSMetadata = function(properties)
{
@@ -41,10 +41,6 @@ WebInspector.CSSMetadata = function(properties)
this._shorthands = {};
for (var i = 0; i < properties.length; ++i) {
var property = properties[i];
- if (typeof property === "string") {
- this._values.push(property);
- continue;
- }
var propertyName = property.name;
if (!CSS.supports(propertyName, "initial"))
continue;
@@ -82,6 +78,7 @@ WebInspector.CSSMetadata.isColorAwareProperty = function(propertyName)
*/
WebInspector.CSSMetadata.isLengthProperty = function(propertyName)
{
+ propertyName = propertyName.toLowerCase();
if (propertyName === "line-height")
return false;
if (!WebInspector.CSSMetadata._distancePropertiesKeySet)
@@ -128,14 +125,13 @@ WebInspector.CSSMetadata.NonStandardInheritedProperties = [
*/
WebInspector.CSSMetadata.canonicalPropertyName = function(name)
{
+ name = name.toLowerCase();
if (!name || name.length < 9 || name.charAt(0) !== "-")
- return name.toLowerCase();
+ return name;
var match = name.match(/(?:-webkit-)(.+)/);
- var propertiesSet = WebInspector.CSSMetadata.cssPropertiesMetainfo.keySet();
- var hasSupportedProperties = WebInspector.CSSMetadata.cssPropertiesMetainfo._values.length > 0;
- if (!match || (hasSupportedProperties && !propertiesSet.hasOwnProperty(match[1].toLowerCase())))
- return name.toLowerCase();
- return match[1].toLowerCase();
+ if (!match || !WebInspector.CSSMetadata.cssPropertiesMetainfo.hasProperty(match[1]))
+ return name;
+ return match[1];
}
/**
@@ -144,10 +140,10 @@ WebInspector.CSSMetadata.canonicalPropertyName = function(name)
*/
WebInspector.CSSMetadata.isCSSPropertyName = function(propertyName)
{
+ propertyName = propertyName.toLowerCase();
if (propertyName.startsWith("-moz-") || propertyName.startsWith("-o-") || propertyName.startsWith("-webkit-") || propertyName.startsWith("-ms-"))
return true;
- var hasSupportedProperties = WebInspector.CSSMetadata.cssPropertiesMetainfo._values.length > 0;
- return !hasSupportedProperties || WebInspector.CSSMetadata.cssPropertiesMetainfo.keySet().hasOwnProperty(propertyName);
+ return WebInspector.CSSMetadata.cssPropertiesMetainfo.hasProperty(propertyName);
}
/**
@@ -643,36 +639,22 @@ WebInspector.CSSMetadata._propertyDataMap = {
/**
* @param {string} propertyName
- * @return {!WebInspector.CSSMetadata}
+ * @return {!Array<string>}
*/
-WebInspector.CSSMetadata.keywordsForProperty = function(propertyName)
+WebInspector.CSSMetadata.propertyValues = function(propertyName)
{
var acceptedKeywords = ["inherit", "initial"];
- var descriptor = WebInspector.CSSMetadata.descriptor(propertyName);
- if (descriptor && descriptor.values)
- acceptedKeywords.push.apply(acceptedKeywords, descriptor.values);
+ propertyName = propertyName.toLowerCase();
+ var unprefixedName = propertyName.replace(/^-webkit-/, "");
+ var entry = WebInspector.CSSMetadata._propertyDataMap[propertyName] || WebInspector.CSSMetadata._propertyDataMap[unprefixedName];
+ if (entry && entry.values)
+ acceptedKeywords.pushAll(entry.values);
if (WebInspector.CSSMetadata.isColorAwareProperty(propertyName)) {
acceptedKeywords.push("currentColor");
for (var color in WebInspector.Color.Nicknames)
acceptedKeywords.push(color);
}
- return new WebInspector.CSSMetadata(acceptedKeywords);
-}
-
-/**
- * @param {string} propertyName
- * @return {?Object}
- */
-WebInspector.CSSMetadata.descriptor = function(propertyName)
-{
- if (!propertyName)
- return null;
- var unprefixedName = propertyName.replace(/^-webkit-/, "");
- propertyName = propertyName.toLowerCase();
- var entry = WebInspector.CSSMetadata._propertyDataMap[propertyName];
- if (!entry && unprefixedName !== propertyName)
- entry = WebInspector.CSSMetadata._propertyDataMap[unprefixedName];
- return entry || null;
+ return acceptedKeywords.sort();
}
WebInspector.CSSMetadata.initializeWithSupportedProperties = function(properties)
@@ -938,130 +920,44 @@ WebInspector.CSSMetadata.Weight = {
"zoom": 200
};
-
-WebInspector.CSSMetadata.prototype = {
- /**
- * @param {string} prefix
- * @return {!Array.<string>}
- */
- startsWith: function(prefix)
- {
- var firstIndex = this._firstIndexOfPrefix(prefix);
- if (firstIndex === -1)
- return [];
-
- var results = [];
- while (firstIndex < this._values.length && this._values[firstIndex].startsWith(prefix))
- results.push(this._values[firstIndex++]);
- return results;
- },
-
- /**
- * @param {!Array.<string>} properties
- * @return {number}
- */
- mostUsedOf: function(properties)
- {
- var maxWeight = 0;
- var index = 0;
- for (var i = 0; i < properties.length; i++) {
- var weight = WebInspector.CSSMetadata.Weight[properties[i]];
- if (!weight)
- weight = WebInspector.CSSMetadata.Weight[WebInspector.CSSMetadata.canonicalPropertyName(properties[i])];
- if (weight > maxWeight) {
- maxWeight = weight;
- index = i;
- }
+/**
+ * @param {!Array.<string>} properties
+ * @return {number}
+ */
+WebInspector.CSSMetadata.mostUsedProperty = function(properties)
+{
+ var maxWeight = 0;
+ var index = 0;
+ for (var i = 0; i < properties.length; i++) {
+ var weight = WebInspector.CSSMetadata.Weight[properties[i]];
+ if (!weight)
+ weight = WebInspector.CSSMetadata.Weight[WebInspector.CSSMetadata.canonicalPropertyName(properties[i])];
+ if (weight > maxWeight) {
+ maxWeight = weight;
+ index = i;
}
- return index;
- },
-
- _firstIndexOfPrefix: function(prefix)
- {
- if (!this._values.length)
- return -1;
- if (!prefix)
- return 0;
-
- var maxIndex = this._values.length - 1;
- var minIndex = 0;
- var foundIndex;
-
- do {
- var middleIndex = (maxIndex + minIndex) >> 1;
- if (this._values[middleIndex].startsWith(prefix)) {
- foundIndex = middleIndex;
- break;
- }
- if (this._values[middleIndex] < prefix)
- minIndex = middleIndex + 1;
- else
- maxIndex = middleIndex - 1;
- } while (minIndex <= maxIndex);
-
- if (foundIndex === undefined)
- return -1;
-
- while (foundIndex && this._values[foundIndex - 1].startsWith(prefix))
- foundIndex--;
-
- return foundIndex;
- },
-
- /**
- * @return {!Object.<string, boolean>}
- */
- keySet: function()
- {
- if (!this._keySet)
- this._keySet = this._values.keySet();
- return this._keySet;
- },
-
- /**
- * @param {string} str
- * @param {string} prefix
- * @return {string}
- */
- next: function(str, prefix)
- {
- return this._closest(str, prefix, 1);
- },
+ }
+ return index;
+}
+WebInspector.CSSMetadata.prototype = {
/**
- * @param {string} str
- * @param {string} prefix
- * @return {string}
+ * @return {!Array<string>}
*/
- previous: function(str, prefix)
+ allProperties: function()
{
- return this._closest(str, prefix, -1);
+ return this._values;
},
/**
- * @param {string} str
- * @param {string} prefix
- * @param {number} shift
- * @return {string}
+ * @param {string} propertyName
+ * @return {boolean}
*/
- _closest: function(str, prefix, shift)
+ hasProperty: function(propertyName)
{
- if (!str)
- return "";
-
- var index = this._values.indexOf(str);
- if (index === -1)
- return "";
-
- if (!prefix) {
- index = (index + this._values.length + shift) % this._values.length;
- return this._values[index];
- }
-
- var propertiesWithPrefix = this.startsWith(prefix);
- var j = propertiesWithPrefix.indexOf(str);
- j = (j + propertiesWithPrefix.length + shift) % propertiesWithPrefix.length;
- return propertiesWithPrefix[j];
+ if (!this._valuesSet)
+ this._valuesSet = new Set(this._values);
+ return this._valuesSet.has(propertyName);
},
/**
@@ -1083,4 +979,4 @@ WebInspector.CSSMetadata.prototype = {
}
}
-WebInspector.CSSMetadata.initializeWithSupportedProperties([]);
+WebInspector.CSSMetadata.initializeWithSupportedProperties([]);

Powered by Google App Engine
This is Rietveld 408576698