Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js b/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js |
| index b0bada022b10ab39a9c8379afb97d078f1c7817a..73b37e67258dde81d5ff83b70af2582283bc430a 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js |
| @@ -11,12 +11,17 @@ WebInspector.ClassesPaneWidget = function() |
| WebInspector.Widget.call(this); |
| this.element.className = "styles-element-classes-pane"; |
| var container = this.element.createChild("div", "title-container"); |
| - this._input = container.createChild("input", "new-class-input monospace"); |
| - this._input.placeholder = WebInspector.UIString("Add new class"); |
| - this._input.addEventListener("keydown", this._onKeyDown.bind(this), false); |
| + this._input = container.createChild("div", "new-class-input monospace"); |
| + this._input.setAttribute("placeholder", WebInspector.UIString("Add new class")); |
| this.setDefaultFocusedElement(this._input); |
| this._classesContainer = this.element.createChild("div", "source-code"); |
| this._classesContainer.classList.add("styles-element-classes-container"); |
| + this._prompt = new WebInspector.ClassesPaneWidget.ClassNamePrompt(); |
| + this._prompt.setAutocompletionTimeout(0); |
| + this._prompt.renderAsBlock(); |
| + |
| + var proxyElement = this._prompt.attach(this._input); |
| + proxyElement.addEventListener("keydown", this._onKeyDown.bind(this), false); |
| WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.DOMMutated, this._onDOMMutated, this); |
| /** @type {!Set<!WebInspector.DOMNode>} */ |
| @@ -32,9 +37,9 @@ WebInspector.ClassesPaneWidget.prototype = { |
| */ |
| _onKeyDown: function(event) |
| { |
| - var text = event.target.value; |
| + var text = event.target.textContent; |
| if (isEscKey(event)) { |
| - event.target.value = ""; |
| + event.target.textContent = ""; |
| if (!text.isWhitespace()) |
| event.consume(true); |
| return; |
| @@ -46,7 +51,8 @@ WebInspector.ClassesPaneWidget.prototype = { |
| if (!node) |
| return; |
| - event.target.value = ""; |
| + this._prompt.clearAutocomplete(); |
| + event.target.textContent = ""; |
| var classNames = text.split(/[.,\s]/); |
| for (var className of classNames) { |
| var className = className.trim(); |
| @@ -211,3 +217,74 @@ WebInspector.ClassesPaneWidget.ButtonProvider.prototype = { |
| return this._button; |
| } |
| } |
| + |
| +/** |
| + * @constructor |
| + * @extends {WebInspector.TextPrompt} |
| + */ |
| +WebInspector.ClassesPaneWidget.ClassNamePrompt = function() |
| +{ |
| + WebInspector.TextPrompt.call(this, this._buildClassNameCompletions.bind(this), " "); |
| + this.setSuggestBoxEnabled(true); |
| + this.disableDefaultSuggestionForEmptyInput(); |
| + this._selectedFrameId = ""; |
| + this._classNamesPromise = null; |
| +} |
| + |
| +WebInspector.ClassesPaneWidget.ClassNamePrompt.prototype = { |
| + _getClassNames: function() |
|
lushnikov
2016/09/29 21:01:50
let's add jsdoc and pass in selectedNode. This wil
ahmetemirercin
2016/09/30 17:38:40
Done.
|
| + { |
| + var promises = []; |
| + var completions = new Set(); |
| + var selectedNode = WebInspector.context.flavor(WebInspector.DOMNode); |
| + this._selectedFrameId = selectedNode.frameId() || WebInspector.ResourceTreeModel.fromTarget(selectedNode.target()).mainFrame.id; |
|
lushnikov
2016/09/29 21:01:50
you can drop "|| WebInspector.ResourceTreeModel.."
ahmetemirercin
2016/09/30 17:38:40
Done.
|
| + |
| + var cssModel = WebInspector.CSSModel.fromTarget(selectedNode.target()); |
| + var allStyleSheets = cssModel.allStyleSheets(); |
| + for (var stylesheet of allStyleSheets) { |
| + if (stylesheet.frameId !== this._selectedFrameId) |
| + continue; |
| + var cssPromise = cssModel.classNamesPromise(stylesheet.id).then(classes => completions.addAll(classes)); |
| + promises.push(cssPromise); |
| + } |
| + |
| + var domPromise = selectedNode.domModel().classNamesPromise(selectedNode.ownerDocument.id).then(classes => completions.addAll(classes)); |
| + promises.push(domPromise); |
| + return Promise.all(promises).then(() => completions.valuesArray()); |
| + }, |
| + |
| + /** |
| + * @param {!Element} proxyElement |
| + * @param {!Range} wordRange |
| + * @param {boolean} force |
| + * @param {function(!Array.<string>, number=)} completionsReadyCallback |
| + */ |
| + _buildClassNameCompletions: function(proxyElement, wordRange, force, completionsReadyCallback) |
| + { |
| + var prefix = wordRange.toString(); |
| + if (!prefix || force) |
|
lushnikov
2016/09/29 21:01:50
let's embed this in the "if" on line 269
ahmetemirercin
2016/09/30 17:38:40
We can't embed this with that if while expecting f
lushnikov
2016/09/30 18:05:54
ah, indeed!
|
| + this._classNamesPromise = null; |
| + |
| + var selectedNode = WebInspector.context.flavor(WebInspector.DOMNode); |
| + if (!selectedNode || (!prefix && !force && !proxyElement.textContent.length)) { |
| + completionsReadyCallback([]); |
| + return; |
| + } |
| + |
| + if (!this._classNamesPromise || this._selectedFrameId !== selectedNode.frameId()) |
| + this._classNamesPromise = this._getClassNames(); |
| + |
| + this._classNamesPromise.then(completions => { |
| + var results = []; |
| + completions.forEach(value => { |
| + if (prefix.substring(0, 1) === ".") |
|
lushnikov
2016/09/29 21:01:50
let's filter/map
if (prefix[0] === ".")
compl
ahmetemirercin
2016/09/30 17:38:40
Done.
|
| + value = "." + value; |
| + if (value.startsWith(prefix)) |
| + results.push(value); |
| + }); |
| + completionsReadyCallback(results, 0); |
| + }); |
| + }, |
| + |
| + __proto__: WebInspector.TextPrompt.prototype |
| +} |