Chromium Code Reviews| 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..2ce9adb7bb5e0cf62458541bbbc1d075256bd6af 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 |
|
lushnikov
2016/08/05 07:16:33
The ambiguity here was coming from the WI.CSSMetad
|
| + * @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; |
| @@ -131,9 +127,7 @@ WebInspector.CSSMetadata.canonicalPropertyName = function(name) |
| if (!name || name.length < 9 || name.charAt(0) !== "-") |
| return name.toLowerCase(); |
| var match = name.match(/(?:-webkit-)(.+)/); |
|
dgozman
2016/08/05 16:38:21
toLowerCase
lushnikov
2016/08/05 17:12:01
Done.
|
| - var propertiesSet = WebInspector.CSSMetadata.cssPropertiesMetainfo.keySet(); |
| - var hasSupportedProperties = WebInspector.CSSMetadata.cssPropertiesMetainfo._values.length > 0; |
|
lushnikov
2016/08/05 07:16:33
cssPropertiesMetainfo could be empty iff the Suppo
|
| - if (!match || (hasSupportedProperties && !propertiesSet.hasOwnProperty(match[1].toLowerCase()))) |
| + if (!match || !WebInspector.CSSMetadata.cssPropertiesMetainfo.hasProperty(match[1].toLowerCase())) |
| return name.toLowerCase(); |
| return match[1].toLowerCase(); |
| } |
| @@ -144,10 +138,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 +637,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 +918,44 @@ WebInspector.CSSMetadata.Weight = { |
| "zoom": 200 |
| }; |
| - |
| -WebInspector.CSSMetadata.prototype = { |
| - /** |
| - * @param {string} prefix |
| - * @return {!Array.<string>} |
| - */ |
| - startsWith: function(prefix) |
| - { |
| - var firstIndex = this._firstIndexOfPrefix(prefix); |
|
lushnikov
2016/08/05 07:16:33
this implementation of startsWith pretends to be f
|
| - 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) |
|
lushnikov
2016/08/05 07:16:33
renamed into WI.CSSMetadata.mostUserProperty
|
| - { |
| - 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) |
|
lushnikov
2016/08/05 07:16:33
next, previoius, _closest: dead code
|
| - { |
| - 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 +977,4 @@ WebInspector.CSSMetadata.prototype = { |
| } |
| } |
| -WebInspector.CSSMetadata.initializeWithSupportedProperties([]); |
| +WebInspector.CSSMetadata.initializeWithSupportedProperties([]); |