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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 /** 56 /**
57 * @param {!WebInspector.CSSProperty} property 57 * @param {!WebInspector.CSSProperty} property
58 * @return {!Element} 58 * @return {!Element}
59 */ 59 */
60 WebInspector.StylesSidebarPane.createExclamationMark = function(property) 60 WebInspector.StylesSidebarPane.createExclamationMark = function(property)
61 { 61 {
62 var exclamationElement = createElement("label", "dt-icon-label"); 62 var exclamationElement = createElement("label", "dt-icon-label");
63 exclamationElement.className = "exclamation-mark"; 63 exclamationElement.className = "exclamation-mark";
64 if (!WebInspector.StylesSidebarPane.ignoreErrorsForProperty(property)) 64 if (!WebInspector.StylesSidebarPane.ignoreErrorsForProperty(property))
65 exclamationElement.type = "warning-icon"; 65 exclamationElement.type = "warning-icon";
66 exclamationElement.title = WebInspector.CSSMetadata.cssPropertiesMetainfo.ke ySet()[property.name.toLowerCase()] ? WebInspector.UIString("Invalid property va lue") : WebInspector.UIString("Unknown property name"); 66 exclamationElement.title = WebInspector.CSSMetadata.isCSSPropertyName(proper ty.name) ? WebInspector.UIString("Invalid property value") : WebInspector.UIStri ng("Unknown property name");
67 return exclamationElement; 67 return exclamationElement;
68 } 68 }
69 69
70 /** 70 /**
71 * @param {!WebInspector.CSSProperty} property 71 * @param {!WebInspector.CSSProperty} property
72 * @return {boolean} 72 * @return {boolean}
73 */ 73 */
74 WebInspector.StylesSidebarPane.ignoreErrorsForProperty = function(property) { 74 WebInspector.StylesSidebarPane.ignoreErrorsForProperty = function(property) {
75 /** 75 /**
76 * @param {string} string 76 * @param {string} string
(...skipping 2303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 this.editingCommitted(text, context, moveDirection); 2380 this.editingCommitted(text, context, moveDirection);
2381 } 2381 }
2382 2382
2383 this._originalPropertyText = this.property.propertyText; 2383 this._originalPropertyText = this.property.propertyText;
2384 2384
2385 this._parentPane.setEditingStyle(true); 2385 this._parentPane.setEditingStyle(true);
2386 if (selectElement.parentElement) 2386 if (selectElement.parentElement)
2387 selectElement.parentElement.scrollIntoViewIfNeeded(false); 2387 selectElement.parentElement.scrollIntoViewIfNeeded(false);
2388 2388
2389 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdi t.bind(this) : undefined; 2389 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdi t.bind(this) : undefined;
2390 this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(isEd itingName ? WebInspector.CSSMetadata.cssPropertiesMetainfo : WebInspector.CSSMet adata.keywordsForProperty(this.nameElement.textContent), this, isEditingName); 2390 var cssCompletions = isEditingName ? WebInspector.CSSMetadata.cssPropert iesMetainfo.allProperties() : WebInspector.CSSMetadata.propertyValues(this.nameE lement.textContent);
2391 this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(cssC ompletions, this, isEditingName);
2391 this._prompt.setAutocompletionTimeout(0); 2392 this._prompt.setAutocompletionTimeout(0);
2392 if (applyItemCallback) { 2393 if (applyItemCallback) {
2393 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApp lied, applyItemCallback, this); 2394 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApp lied, applyItemCallback, this);
2394 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAcc epted, applyItemCallback, this); 2395 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAcc epted, applyItemCallback, this);
2395 } 2396 }
2396 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blu rListener.bind(this, context)); 2397 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blu rListener.bind(this, context));
2397 this._navigateToSource(selectElement, true); 2398 this._navigateToSource(selectElement, true);
2398 2399
2399 proxyElement.addEventListener("keydown", this._editingNameValueKeyDown.b ind(this, context), false); 2400 proxyElement.addEventListener("keydown", this._editingNameValueKeyDown.b ind(this, context), false);
2400 proxyElement.addEventListener("keypress", this._editingNameValueKeyPress .bind(this, context), false); 2401 proxyElement.addEventListener("keypress", this._editingNameValueKeyPress .bind(this, context), false);
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 { 2792 {
2792 return event.target === this._expandElement; 2793 return event.target === this._expandElement;
2793 }, 2794 },
2794 2795
2795 __proto__: TreeElement.prototype 2796 __proto__: TreeElement.prototype
2796 } 2797 }
2797 2798
2798 /** 2799 /**
2799 * @constructor 2800 * @constructor
2800 * @extends {WebInspector.TextPrompt} 2801 * @extends {WebInspector.TextPrompt}
2801 * @param {!WebInspector.CSSMetadata} cssCompletions 2802 * @param {!Array<string>} cssCompletions
2802 * @param {!WebInspector.StylePropertyTreeElement} treeElement 2803 * @param {!WebInspector.StylePropertyTreeElement} treeElement
2803 * @param {boolean} isEditingName 2804 * @param {boolean} isEditingName
2804 */ 2805 */
2805 WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, tree Element, isEditingName) 2806 WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, tree Element, isEditingName)
2806 { 2807 {
2807 // Use the same callback both for applyItemCallback and acceptItemCallback. 2808 // Use the same callback both for applyItemCallback and acceptItemCallback.
2808 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) , WebInspector.StyleValueDelimiters); 2809 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) , WebInspector.StyleValueDelimiters);
2809 this.setSuggestBoxEnabled(true); 2810 this.setSuggestBoxEnabled(true);
2810 this._cssCompletions = cssCompletions; 2811 this._cssCompletions = cssCompletions;
2811 this._treeElement = treeElement; 2812 this._treeElement = treeElement;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2937 * @param {function(!Array.<string>, number=)} completionsReadyCallback 2938 * @param {function(!Array.<string>, number=)} completionsReadyCallback
2938 */ 2939 */
2939 _buildPropertyCompletions: function(proxyElement, wordRange, force, completi onsReadyCallback) 2940 _buildPropertyCompletions: function(proxyElement, wordRange, force, completi onsReadyCallback)
2940 { 2941 {
2941 var prefix = wordRange.toString().toLowerCase(); 2942 var prefix = wordRange.toString().toLowerCase();
2942 if (!prefix && !force && (this._isEditingName || proxyElement.textConten t.length)) { 2943 if (!prefix && !force && (this._isEditingName || proxyElement.textConten t.length)) {
2943 completionsReadyCallback([]); 2944 completionsReadyCallback([]);
2944 return; 2945 return;
2945 } 2946 }
2946 2947
2947 var results = this._cssCompletions.startsWith(prefix); 2948 var results = this._cssCompletions.filter(completion => completion.start sWith(prefix));
2948 if (!this._isEditingName && !results.length && prefix.length > 1 && "!im portant".startsWith(prefix)) 2949 if (!this._isEditingName && !results.length && prefix.length > 1 && "!im portant".startsWith(prefix))
2949 results.push("!important"); 2950 results.push("!important");
2950 var userEnteredText = wordRange.toString().replace("-", ""); 2951 var userEnteredText = wordRange.toString().replace("-", "");
2951 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase( ))) { 2952 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase( ))) {
2952 for (var i = 0; i < results.length; ++i) 2953 for (var i = 0; i < results.length; ++i)
2953 results[i] = results[i].toUpperCase(); 2954 results[i] = results[i].toUpperCase();
2954 } 2955 }
2955 var selectedIndex = this._cssCompletions.mostUsedOf(results); 2956 var selectedIndex = this._isEditingName ? WebInspector.CSSMetadata.mostU sedProperty(results) : 0;
2956 completionsReadyCallback(results, selectedIndex); 2957 completionsReadyCallback(results, selectedIndex);
2957 }, 2958 },
2958 2959
2959 __proto__: WebInspector.TextPrompt.prototype 2960 __proto__: WebInspector.TextPrompt.prototype
2960 } 2961 }
2961 2962
2962 /** 2963 /**
2963 * @constructor 2964 * @constructor
2964 * @param {?WebInspector.CSSRule} rule 2965 * @param {?WebInspector.CSSRule} rule
2965 * @param {?WebInspector.DOMNode} node 2966 * @param {?WebInspector.DOMNode} node
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3109 3110
3110 /** 3111 /**
3111 * @override 3112 * @override
3112 * @return {!WebInspector.ToolbarItem} 3113 * @return {!WebInspector.ToolbarItem}
3113 */ 3114 */
3114 item: function() 3115 item: function()
3115 { 3116 {
3116 return this._button; 3117 return this._button;
3117 } 3118 }
3118 } 3119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698