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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js

Issue 2682743003: DevTools: live ClassPane (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 Elements.ClassesPaneWidget = class extends UI.Widget { 7 Elements.ClassesPaneWidget = class extends UI.Widget {
8 constructor() { 8 constructor() {
9 super(); 9 super();
10 this.element.className = 'styles-element-classes-pane'; 10 this.element.className = 'styles-element-classes-pane';
11 var container = this.element.createChild('div', 'title-container'); 11 var container = this.element.createChild('div', 'title-container');
12 this._input = container.createChild('div', 'new-class-input monospace'); 12 this._input = container.createChild('div', 'new-class-input monospace');
13 this.setDefaultFocusedElement(this._input); 13 this.setDefaultFocusedElement(this._input);
14 this._classesContainer = this.element.createChild('div', 'source-code'); 14 this._classesContainer = this.element.createChild('div', 'source-code');
15 this._classesContainer.classList.add('styles-element-classes-container'); 15 this._classesContainer.classList.add('styles-element-classes-container');
16 this._prompt = new Elements.ClassesPaneWidget.ClassNamePrompt(); 16 this._prompt = new Elements.ClassesPaneWidget.ClassNamePrompt();
17 this._prompt.setAutocompletionTimeout(0); 17 this._prompt.setAutocompletionTimeout(0);
18 this._prompt.renderAsBlock(); 18 this._prompt.renderAsBlock();
19 19
20 var proxyElement = this._prompt.attach(this._input); 20 var proxyElement = this._prompt.attach(this._input);
21 this._prompt.setPlaceholder(Common.UIString('Add new class')); 21 this._prompt.setPlaceholder(Common.UIString('Add new class'));
22 this._prompt.addEventListener(UI.TextPrompt.Events.ItemApplied, this._onItem Applied, this);
22 proxyElement.addEventListener('keydown', this._onKeyDown.bind(this), false); 23 proxyElement.addEventListener('keydown', this._onKeyDown.bind(this), false);
23 24
24 SDK.targetManager.addModelListener(SDK.DOMModel, SDK.DOMModel.Events.DOMMuta ted, this._onDOMMutated, this); 25 SDK.targetManager.addModelListener(SDK.DOMModel, SDK.DOMModel.Events.DOMMuta ted, this._onDOMMutated, this);
25 /** @type {!Set<!SDK.DOMNode>} */ 26 /** @type {!Set<!SDK.DOMNode>} */
26 this._mutatingNodes = new Set(); 27 this._mutatingNodes = new Set();
27 UI.context.addFlavorChangeListener(SDK.DOMNode, this._update, this); 28 UI.context.addFlavorChangeListener(SDK.DOMNode, this._update, this);
28 } 29 }
29 30
30 /** 31 /**
31 * @param {!Event} event 32 * @param {!Event} event
(...skipping 20 matching lines...) Expand all
52 var className = className.trim(); 53 var className = className.trim();
53 if (!className.length) 54 if (!className.length)
54 continue; 55 continue;
55 this._toggleClass(node, className, true); 56 this._toggleClass(node, className, true);
56 } 57 }
57 this._installNodeClasses(node); 58 this._installNodeClasses(node);
58 this._update(); 59 this._update();
59 event.consume(true); 60 event.consume(true);
60 } 61 }
61 62
63 _onItemApplied() {
64 var node = UI.context.flavor(SDK.DOMNode);
65 if (!node)
66 return;
67
68 this._installNodeClasses(node, this._prompt._currentSuggestion);
69 this._update();
70 }
71
62 /** 72 /**
63 * @param {!Common.Event} event 73 * @param {!Common.Event} event
64 */ 74 */
65 _onDOMMutated(event) { 75 _onDOMMutated(event) {
66 var node = /** @type {!SDK.DOMNode} */ (event.data); 76 var node = /** @type {!SDK.DOMNode} */ (event.data);
67 if (this._mutatingNodes.has(node)) 77 if (this._mutatingNodes.has(node))
68 return; 78 return;
69 delete node[Elements.ClassesPaneWidget._classesSymbol]; 79 delete node[Elements.ClassesPaneWidget._classesSymbol];
70 this._update(); 80 this._update();
71 } 81 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 * @param {boolean} enabled 154 * @param {boolean} enabled
145 */ 155 */
146 _toggleClass(node, className, enabled) { 156 _toggleClass(node, className, enabled) {
147 var classes = this._nodeClasses(node); 157 var classes = this._nodeClasses(node);
148 classes.set(className, enabled); 158 classes.set(className, enabled);
149 } 159 }
150 160
151 /** 161 /**
152 * @param {!SDK.DOMNode} node 162 * @param {!SDK.DOMNode} node
153 */ 163 */
154 _installNodeClasses(node) { 164 _installNodeClasses(node, additionalClass) {
155 var classes = this._nodeClasses(node); 165 var classes = this._nodeClasses(node);
156 var activeClasses = new Set(); 166 var activeClasses = new Set();
157 for (var className of classes.keys()) { 167 for (var className of classes.keys()) {
158 if (classes.get(className)) 168 if (classes.get(className))
159 activeClasses.add(className); 169 activeClasses.add(className);
160 } 170 }
161 171
172 if (additionalClass)
173 activeClasses.add(additionalClass);
162 var newClasses = activeClasses.valuesArray(); 174 var newClasses = activeClasses.valuesArray();
163 newClasses.sort(); 175 newClasses.sort();
164 this._mutatingNodes.add(node); 176 this._mutatingNodes.add(node);
165 node.setAttributeValue('class', newClasses.join(' '), onClassNameUpdated.bin d(this)); 177 node.setAttributeValue('class', newClasses.join(' '), onClassNameUpdated.bin d(this));
166 178
167 /** 179 /**
168 * @this {Elements.ClassesPaneWidget} 180 * @this {Elements.ClassesPaneWidget}
169 */ 181 */
170 function onClassNameUpdated() { 182 function onClassNameUpdated() {
171 this._mutatingNodes.delete(node); 183 this._mutatingNodes.delete(node);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (!this._classNamesPromise || this._selectedFrameId !== selectedNode.frame Id()) 267 if (!this._classNamesPromise || this._selectedFrameId !== selectedNode.frame Id())
256 this._classNamesPromise = this._getClassNames(selectedNode); 268 this._classNamesPromise = this._getClassNames(selectedNode);
257 269
258 return this._classNamesPromise.then(completions => { 270 return this._classNamesPromise.then(completions => {
259 if (prefix[0] === '.') 271 if (prefix[0] === '.')
260 completions = completions.map(value => '.' + value); 272 completions = completions.map(value => '.' + value);
261 return completions.filter(value => value.startsWith(prefix)).map(completio n => ({text: completion})); 273 return completions.filter(value => value.startsWith(prefix)).map(completio n => ({text: completion}));
262 }); 274 });
263 } 275 }
264 }; 276 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698