Title: [286844] trunk/Source/WebInspectorUI
Revision
286844
Author
[email protected]
Date
2021-12-10 04:23:49 -0800 (Fri, 10 Dec 2021)

Log Message

Web Inspector: Extract a specialized CSSNameCompletions from CSSCompletions
https://bugs.webkit.org/show_bug.cgi?id=233369
<rdar://83206520>

Reviewed by Devin Rousso.

`WI.CSSPropertyNameCompletions` is a long-lived object that holds the list of all CSS properties
supported by the target. It is instantiated only once on Web Inspector startup.

By contrast, `WI.CSSCompletions` is an object instantiated as often as needed with
lists of property values, CSS function values, etc. It holds the generic logic for
matching values against a given query.

The specialized logic for CSS property names was mixed-in with the generic logic in `WI.CSSCompletions`.
The main difference is in the format of the payload provided:
- an array of objects with key/value pairs for `WI.CSSPropertyNameCompletions`.
- an array of strings for general purpose `WI.CSSCompletions`.

This patch reduces the complexity in `WI.Completions`:
- moves the one-time initialization method to `WI.cssManager.initializeCSSCompletions`.
- simplifies `WI.Completions` constructor to expect just an array of strings.
- introduces `WI.CSSPropertyNameCompletions` as a sub-class of `WI.CSSCompletions` where its constructor
  is specialized to handle the payload received from the backend.
- moves the `WI.CSSPropertyNameCompletions` instance to `WI.cssManager.cssPropertyNameCompletions`.
- removes unused accessors for navigating the list of matched completions.

* UserInterface/Base/Main.js:
(WI.performOneTimeFrontendInitializationsUsingTarget):
* UserInterface/Controllers/CSSManager.js:
(WI.CSSManager):
(WI.CSSManager.prototype.initializeCSSPropertyNameCompletions.):
(WI.CSSManager.prototype.initializeCSSPropertyNameCompletions):
Moved the initializiation method for objects used to get CSS completions
from `WI.CSSCompletions` with data from the backed to a more appropriate place.

(WI.CSSManager.prototype.get propertyNameCompletions):
* UserInterface/Controllers/CodeMirrorCompletionController.js:
(WI.CodeMirrorCompletionController.prototype._generateCSSCompletions):
* UserInterface/Main.html:
* UserInterface/Models/CSSCompletions.js:
(WI.CSSCompletions.prototype._firstIndexOfPrefix):
(WI.CSSCompletions):
(WI.CSSCompletions.initializeCSSCompletions.): Deleted.
(WI.CSSCompletions.initializeCSSCompletions.collectPropertyNameForCodeMirror): Deleted.
(WI.CSSCompletions.initializeCSSCompletions.propertiesCallback): Deleted.
(WI.CSSCompletions.initializeCSSCompletions.fontFamilyNamesCallback): Deleted.
(WI.CSSCompletions.initializeCSSCompletions): Deleted.
Moved to `WI.CSSManager`.

(WI.CSSCompletions.prototype.next): Deleted.
(WI.CSSCompletions.prototype.previous): Deleted.
(WI.CSSCompletions.prototype._closest): Deleted.
Removed unused methods for navigating the completions list.
This behavior is encapsulated in `WI.CompletionSuggestionsView`.

(WI.CSSCompletions.prototype.isValidPropertyName): Deleted.
Moved to `WI.CSSPropertyNameCompletions`.

* UserInterface/Models/CSSKeywordCompletions.js:
(WI.CSSKeywordCompletions.forPartialPropertyName):
* UserInterface/Models/CSSPropertyNameCompletions.js: Added.
(WI.CSSPropertyNameCompletions.prototype.isValidPropertyName):
(WI.CSSPropertyNameCompletions):
* UserInterface/Test.html:
* UserInterface/Test/Test.js:
(WI.performOneTimeFrontendInitializationsUsingTarget):
* UserInterface/Views/SpreadsheetStyleProperty.js:
(WI.SpreadsheetStyleProperty.prototype.updateStatus):
(WI.SpreadsheetStyleProperty.prototype._addCSSDocumentationButton):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (286843 => 286844)


--- trunk/Source/WebInspectorUI/ChangeLog	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/ChangeLog	2021-12-10 12:23:49 UTC (rev 286844)
@@ -1,3 +1,75 @@
+2021-12-10  Razvan Caliman  <[email protected]>
+
+        Web Inspector: Extract a specialized CSSNameCompletions from CSSCompletions
+        https://bugs.webkit.org/show_bug.cgi?id=233369
+        <rdar://83206520>
+
+        Reviewed by Devin Rousso.
+
+        `WI.CSSPropertyNameCompletions` is a long-lived object that holds the list of all CSS properties
+        supported by the target. It is instantiated only once on Web Inspector startup.
+
+        By contrast, `WI.CSSCompletions` is an object instantiated as often as needed with
+        lists of property values, CSS function values, etc. It holds the generic logic for
+        matching values against a given query.
+
+        The specialized logic for CSS property names was mixed-in with the generic logic in `WI.CSSCompletions`.
+        The main difference is in the format of the payload provided:
+        - an array of objects with key/value pairs for `WI.CSSPropertyNameCompletions`.
+        - an array of strings for general purpose `WI.CSSCompletions`.
+
+        This patch reduces the complexity in `WI.Completions`:
+        - moves the one-time initialization method to `WI.cssManager.initializeCSSCompletions`.
+        - simplifies `WI.Completions` constructor to expect just an array of strings.
+        - introduces `WI.CSSPropertyNameCompletions` as a sub-class of `WI.CSSCompletions` where its constructor
+          is specialized to handle the payload received from the backend.
+        - moves the `WI.CSSPropertyNameCompletions` instance to `WI.cssManager.cssPropertyNameCompletions`.
+        - removes unused accessors for navigating the list of matched completions.
+
+        * UserInterface/Base/Main.js:
+        (WI.performOneTimeFrontendInitializationsUsingTarget):
+        * UserInterface/Controllers/CSSManager.js:
+        (WI.CSSManager):
+        (WI.CSSManager.prototype.initializeCSSPropertyNameCompletions.):
+        (WI.CSSManager.prototype.initializeCSSPropertyNameCompletions):
+        Moved the initializiation method for objects used to get CSS completions
+        from `WI.CSSCompletions` with data from the backed to a more appropriate place.
+
+        (WI.CSSManager.prototype.get propertyNameCompletions):
+        * UserInterface/Controllers/CodeMirrorCompletionController.js:
+        (WI.CodeMirrorCompletionController.prototype._generateCSSCompletions):
+        * UserInterface/Main.html:
+        * UserInterface/Models/CSSCompletions.js:
+        (WI.CSSCompletions.prototype._firstIndexOfPrefix):
+        (WI.CSSCompletions):
+        (WI.CSSCompletions.initializeCSSCompletions.): Deleted.
+        (WI.CSSCompletions.initializeCSSCompletions.collectPropertyNameForCodeMirror): Deleted.
+        (WI.CSSCompletions.initializeCSSCompletions.propertiesCallback): Deleted.
+        (WI.CSSCompletions.initializeCSSCompletions.fontFamilyNamesCallback): Deleted.
+        (WI.CSSCompletions.initializeCSSCompletions): Deleted.
+        Moved to `WI.CSSManager`.
+
+        (WI.CSSCompletions.prototype.next): Deleted.
+        (WI.CSSCompletions.prototype.previous): Deleted.
+        (WI.CSSCompletions.prototype._closest): Deleted.
+        Removed unused methods for navigating the completions list.
+        This behavior is encapsulated in `WI.CompletionSuggestionsView`.
+
+        (WI.CSSCompletions.prototype.isValidPropertyName): Deleted.
+        Moved to `WI.CSSPropertyNameCompletions`.
+
+        * UserInterface/Models/CSSKeywordCompletions.js:
+        (WI.CSSKeywordCompletions.forPartialPropertyName):
+        * UserInterface/Models/CSSPropertyNameCompletions.js: Added.
+        (WI.CSSPropertyNameCompletions.prototype.isValidPropertyName):
+        (WI.CSSPropertyNameCompletions):
+        * UserInterface/Test.html:
+        * UserInterface/Test/Test.js:
+        (WI.performOneTimeFrontendInitializationsUsingTarget):
+        * UserInterface/Views/SpreadsheetStyleProperty.js:
+        (WI.SpreadsheetStyleProperty.prototype.updateStatus):
+        (WI.SpreadsheetStyleProperty.prototype._addCSSDocumentationButton):
+
 2021-12-09  Brent Fulgham  <[email protected]>
 
         Unprefix CSS value text-align: -webkit-match-parent

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -623,7 +623,7 @@
 
     if (!WI.__didPerformCSSInitialization && target.hasDomain("CSS")) {
         WI.__didPerformCSSInitialization = true;
-        WI.CSSCompletions.initializeCSSCompletions(target);
+        WI.cssManager.initializeCSSPropertyNameCompletions(target);
     }
 };
 
@@ -810,7 +810,7 @@
             WI.pageTarget = WI.mainTarget;
 
         if (WI.mainTarget.hasDomain("CSS"))
-            WI.CSSCompletions.initializeCSSCompletions(WI.assumingMainTarget());
+            WI.cssManager.initializeCSSPropertyNameCompletions(WI.assumingMainTarget());
 
         if (WI.mainTarget.hasDomain("DOM"))
             WI.domManager.ensureDocument();

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSManager.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSManager.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSManager.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -48,6 +48,8 @@
         this._modifiedStyles = new Map;
         this._defaultAppearance = null;
         this._forcedAppearance = null;
+
+        this._propertyNameCompletions = null;
     }
 
     // Target
@@ -58,6 +60,86 @@
             target.CSSAgent.enable();
     }
 
+    initializeCSSPropertyNameCompletions(target)
+    {
+        console.assert(target.hasDomain("CSS"));
+
+        if (this._propertyNameCompletions)
+            return;
+
+        target.CSSAgent.getSupportedCSSProperties((error, cssProperties) => {
+            if (error)
+                return;
+
+            this._propertyNameCompletions = new WI.CSSPropertyNameCompletions(cssProperties);
+
+            WI.CSSKeywordCompletions.addCustomCompletions(cssProperties);
+
+            // CodeMirror is not included by tests so we shouldn't assume it always exists.
+            // If it isn't available we skip MIME type associations.
+            if (!window.CodeMirror)
+                return;
+
+            let propertyNamesForCodeMirror = {};
+            let valueKeywordsForCodeMirror = {"inherit": true, "initial": true, "unset": true, "revert": true, "var": true, "env": true};
+            let colorKeywordsForCodeMirror = {};
+
+            function nameForCodeMirror(name) {
+                // CodeMirror parses the vendor prefix separate from the property or keyword name,
+                // so we need to strip vendor prefixes from our names. Also strip function parenthesis.
+                return name.replace(/^-[^-]+-/, "").replace(/\(\)$/, "").toLowerCase();
+            }
+
+            for (let property of cssProperties) {
+                // Properties can also be value keywords, like when used in a transition.
+                // So we add them to both lists.
+                let codeMirrorPropertyName = nameForCodeMirror(property.name);
+                propertyNamesForCodeMirror[codeMirrorPropertyName] = true;
+                valueKeywordsForCodeMirror[codeMirrorPropertyName] = true;
+            }
+
+            for (let propertyName in WI.CSSKeywordCompletions._propertyKeywordMap) {
+                let keywords = WI.CSSKeywordCompletions._propertyKeywordMap[propertyName];
+                for (let keyword of keywords) {
+                    // Skip numbers, like the ones defined for font-weight.
+                    if (keyword === WI.CSSKeywordCompletions.AllPropertyNamesPlaceholder || !isNaN(Number(keyword)))
+                        continue;
+                    valueKeywordsForCodeMirror[nameForCodeMirror(keyword)] = true;
+                }
+            }
+
+            for (let color of WI.CSSKeywordCompletions._colors)
+                colorKeywordsForCodeMirror[nameForCodeMirror(color)] = true;
+
+            function updateCodeMirrorCSSMode(mimeType) {
+                let modeSpec = CodeMirror.resolveMode(mimeType);
+
+                console.assert(modeSpec.propertyKeywords);
+                console.assert(modeSpec.valueKeywords);
+                console.assert(modeSpec.colorKeywords);
+
+                modeSpec.propertyKeywords = propertyNamesForCodeMirror;
+                modeSpec.valueKeywords = valueKeywordsForCodeMirror;
+                modeSpec.colorKeywords = colorKeywordsForCodeMirror;
+
+                CodeMirror.defineMIME(mimeType, modeSpec);
+            }
+
+            updateCodeMirrorCSSMode("text/css");
+            updateCodeMirrorCSSMode("text/x-scss");
+        });
+
+        if (target.hasCommand("CSS.getSupportedSystemFontFamilyNames")) {
+            target.CSSAgent.getSupportedSystemFontFamilyNames((error, fontFamilyNames) =>{
+                if (error)
+                    return;
+
+                WI.CSSKeywordCompletions.addPropertyCompletionValues("font-family", fontFamilyNames);
+                WI.CSSKeywordCompletions.addPropertyCompletionValues("font", fontFamilyNames);
+            });
+        }
+    }
+
     // Static
 
     static supportsInspectorStyleSheet()
@@ -180,6 +262,8 @@
 
     // Public
 
+    get propertyNameCompletions() { return this._propertyNameCompletions; }
+
     get preferredColorFormat()
     {
         return this._colorFormatSetting.value;

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -627,7 +627,7 @@
         this._implicitSuffix = suffix !== ":" ? ": " : "";
 
         // Complete property names.
-        return WI.CSSCompletions.cssNameCompletions.startsWith(this._prefix);
+        return WI.cssManager.propertyNameCompletions.startsWith(this._prefix);
     }
 
     _generateJavaScriptCompletions(mainToken, base, suffix)

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2021-12-10 12:23:49 UTC (rev 286844)
@@ -396,6 +396,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -33,127 +33,19 @@
 
 WI.CSSCompletions = class CSSCompletions
 {
-    constructor(properties, acceptEmptyPrefix)
+    constructor(values, {acceptEmptyPrefix} = {})
     {
-        this._values = [];
+        console.assert(Array.isArray(values), values);
+        console.assert(typeof values[0] === "string", "Expect an array of string values", values);
 
-        // The `properties` parameter can be either a list of objects with 'name' / 'longhand'
-        // properties when initialized from the protocol for CSSCompletions.cssNameCompletions.
-        // Or it may just a list of strings when quickly initialized for other completion purposes.
-        if (properties.length && typeof properties[0] === "string")
-            this._values.pushAll(properties);
-        else {
-            for (var property of properties) {
-                var propertyName = property.name;
-                console.assert(propertyName);
-
-                this._values.push(propertyName);
-
-                let aliases = property.aliases;
-                if (aliases)
-                    this._values.pushAll(aliases);
-            }
-        }
-
+        this._values = values.slice();
         this._values.sort();
-
-        this._acceptEmptyPrefix = acceptEmptyPrefix;
+        this._acceptEmptyPrefix = !!acceptEmptyPrefix;
         this._queryController = null;
     }
 
     // Static
 
-    static initializeCSSCompletions(target)
-    {
-        console.assert(target.hasDomain("CSS"));
-
-        if (WI.CSSCompletions.cssNameCompletions)
-            return;
-
-        function propertiesCallback(error, cssProperties)
-        {
-            if (error)
-                return;
-
-            WI.CSSCompletions.cssNameCompletions = new WI.CSSCompletions(cssProperties, false);
-
-            WI.CSSKeywordCompletions.addCustomCompletions(cssProperties);
-
-            // CodeMirror is not included by tests so we shouldn't assume it always exists.
-            // If it isn't available we skip MIME type associations.
-            if (!window.CodeMirror)
-                return;
-
-            var propertyNamesForCodeMirror = {};
-            var valueKeywordsForCodeMirror = {"inherit": true, "initial": true, "unset": true, "revert": true, "var": true, "env": true};
-            var colorKeywordsForCodeMirror = {};
-
-            function nameForCodeMirror(name)
-            {
-                // CodeMirror parses the vendor prefix separate from the property or keyword name,
-                // so we need to strip vendor prefixes from our names. Also strip function parenthesis.
-                return name.replace(/^-[^-]+-/, "").replace(/\(\)$/, "").toLowerCase();
-            }
-
-            function collectPropertyNameForCodeMirror(propertyName)
-            {
-                // Properties can also be value keywords, like when used in a transition.
-                // So we add them to both lists.
-                var codeMirrorPropertyName = nameForCodeMirror(propertyName);
-                propertyNamesForCodeMirror[codeMirrorPropertyName] = true;
-                valueKeywordsForCodeMirror[codeMirrorPropertyName] = true;
-            }
-
-            for (var property of cssProperties)
-                collectPropertyNameForCodeMirror(property.name);
-
-            for (var propertyName in WI.CSSKeywordCompletions._propertyKeywordMap) {
-                var keywords = WI.CSSKeywordCompletions._propertyKeywordMap[propertyName];
-                for (var i = 0; i < keywords.length; ++i) {
-                    // Skip numbers, like the ones defined for font-weight.
-                    if (keywords[i] === WI.CSSKeywordCompletions.AllPropertyNamesPlaceholder || !isNaN(Number(keywords[i])))
-                        continue;
-                    valueKeywordsForCodeMirror[nameForCodeMirror(keywords[i])] = true;
-                }
-            }
-
-            WI.CSSKeywordCompletions._colors.forEach(function(colorName) {
-                colorKeywordsForCodeMirror[nameForCodeMirror(colorName)] = true;
-            });
-
-            function updateCodeMirrorCSSMode(mimeType)
-            {
-                var modeSpec = CodeMirror.resolveMode(mimeType);
-
-                console.assert(modeSpec.propertyKeywords);
-                console.assert(modeSpec.valueKeywords);
-                console.assert(modeSpec.colorKeywords);
-
-                modeSpec.propertyKeywords = propertyNamesForCodeMirror;
-                modeSpec.valueKeywords = valueKeywordsForCodeMirror;
-                modeSpec.colorKeywords = colorKeywordsForCodeMirror;
-
-                CodeMirror.defineMIME(mimeType, modeSpec);
-            }
-
-            updateCodeMirrorCSSMode("text/css");
-            updateCodeMirrorCSSMode("text/x-scss");
-        }
-
-        function fontFamilyNamesCallback(error, fontFamilyNames)
-        {
-            if (error)
-                return;
-
-            WI.CSSKeywordCompletions.addPropertyCompletionValues("font-family", fontFamilyNames);
-            WI.CSSKeywordCompletions.addPropertyCompletionValues("font", fontFamilyNames);
-        }
-
-        target.CSSAgent.getSupportedCSSProperties(propertiesCallback);
-        if (target.hasCommand("CSS.getSupportedSystemFontFamilyNames"))
-            target.CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback);
-    }
-
     static completeUnbalancedValue(value)
     {
         const State = {
@@ -311,45 +203,8 @@
 
         return foundIndex;
     }
-
-    next(str, prefix)
-    {
-        return this._closest(str, prefix, 1);
-    }
-
-    previous(str, prefix)
-    {
-        return this._closest(str, prefix, -1);
-    }
-
-    _closest(str, prefix, shift)
-    {
-        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];
-    }
-
-    isValidPropertyName(name)
-    {
-        return this._values.includes(name);
-    }
 };
 
-WI.CSSCompletions.cssNameCompletions = null;
-
 WI.CSSCompletions.lengthUnits = new Set([
     "ch",
     "cm",

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -41,13 +41,13 @@
         return {prefix: text, completions: []};
 
     if (!text.length && allowEmptyPrefix)
-        return {prefix: text, completions: WI.CSSCompletions.cssNameCompletions.values};
+        return {prefix: text, completions: WI.cssManager.propertyNameCompletions.values};
 
     let completions;
     if (useFuzzyMatching)
-        completions = WI.CSSCompletions.cssNameCompletions.executeQuery(text);
+        completions = WI.cssManager.propertyNameCompletions.executeQuery(text);
     else
-        completions = WI.CSSCompletions.cssNameCompletions.startsWith(text);
+        completions = WI.cssManager.propertyNameCompletions.startsWith(text);
 
     return {prefix: text, completions};
 };
@@ -170,12 +170,12 @@
             addKeywordsForName(longhandName);
     }
 
-    if (acceptedKeywords.includes(WI.CSSKeywordCompletions.AllPropertyNamesPlaceholder) && WI.CSSCompletions.cssNameCompletions) {
+    if (acceptedKeywords.includes(WI.CSSKeywordCompletions.AllPropertyNamesPlaceholder) && WI.cssManager.propertyNameCompletions) {
         acceptedKeywords.remove(WI.CSSKeywordCompletions.AllPropertyNamesPlaceholder);
-        acceptedKeywords.pushAll(WI.CSSCompletions.cssNameCompletions.values);
+        acceptedKeywords.pushAll(WI.cssManager.propertyNameCompletions.values);
     }
 
-    return new WI.CSSCompletions(Array.from(new Set(acceptedKeywords)), true);
+    return new WI.CSSCompletions(Array.from(new Set(acceptedKeywords)), {acceptEmptyPrefix: true});
 };
 
 WI.CSSKeywordCompletions.isColorAwareProperty = function(name)
@@ -226,7 +226,7 @@
         suggestions.pushAll(WI.CSSKeywordCompletions._colors);
     }
 
-    return new WI.CSSCompletions(suggestions, true);
+    return new WI.CSSCompletions(suggestions, {acceptEmptyPrefix: true});
 };
 
 WI.CSSKeywordCompletions.addCustomCompletions = function(properties)

Added: trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js (0 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSPropertyNameCompletions.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WI.CSSPropertyNameCompletions = class CSSPropertyNameCompletions extends WI.CSSCompletions
+{
+    constructor(properties, options = {})
+    {
+        console.assert(Array.isArray(properties), properties);
+        console.assert(properties[0].name, "Expected an array of objects with `name` key", properties);
+
+        let values = [];
+        for (let property of properties) {
+            console.assert(property.name);
+
+            values.push(property.name);
+            if (Array.isArray(property.aliases))
+                values.pushAll(property.aliases);
+        }
+
+        super(values, options);
+    }
+
+    // Public
+
+    isValidPropertyName(name)
+    {
+        return this.values.includes(name);
+    }
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/Test.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -125,7 +125,7 @@
     // FIXME: This slows down test debug logging considerably.
     if (!WI.__didPerformCSSInitialization && target.hasDomain("CSS")) {
         WI.__didPerformCSSInitialization = true;
-        WI.CSSCompletions.initializeCSSCompletions(target);
+        WI.cssManager.initializeCSSPropertyNameCompletions(target);
     }
 };
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Test.html (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Test.html	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Test.html	2021-12-10 12:23:49 UTC (rev 286844)
@@ -132,6 +132,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js (286843 => 286844)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2021-12-10 12:19:40 UTC (rev 286843)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2021-12-10 12:23:49 UTC (rev 286844)
@@ -300,13 +300,9 @@
         if (!this._property.valid && this._property.hasOtherVendorNameOrKeyword())
             classNames.push("other-vendor");
         else if (this._hasInvalidVariableValue || (!this._property.valid && this._property.value !== "")) {
-            let propertyNameIsValid = false;
-            if (WI.CSSCompletions.cssNameCompletions)
-                propertyNameIsValid = WI.CSSCompletions.cssNameCompletions.isValidPropertyName(this._property.name);
-
             classNames.push("has-warning");
 
-            if (!propertyNameIsValid) {
+            if (!WI.cssManager.propertyNameCompletions?.isValidPropertyName(this._property.name)) {
                 classNames.push("invalid-name");
                 elementTitle = WI.UIString("Unsupported property name");
             } else {
@@ -539,7 +535,7 @@
         if (this.property.isVariable)
             return;
 
-        if (!WI.CSSCompletions.cssNameCompletions.isValidPropertyName(this._property.name))
+        if (!WI.cssManager.propertyNameCompletions?.isValidPropertyName(this._property.name))
             return;
 
         if (!CSSDocumentation.hasOwnProperty(this._property.name) && !CSSDocumentation.hasOwnProperty(this._property.canonicalName))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to