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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js

Issue 2157533003: DevTools: Source color picker experiment. Make color swatches clickable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed further comments Created 4 years, 5 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 21 matching lines...) Expand all
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.UISourceCodeFrame} 33 * @extends {WebInspector.UISourceCodeFrame}
34 * @param {!WebInspector.UISourceCode} uiSourceCode 34 * @param {!WebInspector.UISourceCode} uiSourceCode
35 */ 35 */
36 WebInspector.CSSSourceFrame = function(uiSourceCode) 36 WebInspector.CSSSourceFrame = function(uiSourceCode)
37 { 37 {
38 WebInspector.UISourceCodeFrame.call(this, uiSourceCode); 38 WebInspector.UISourceCodeFrame.call(this, uiSourceCode);
39 this.textEditor.setAutocompleteDelegate(new WebInspector.CSSSourceFrame.Auto completeDelegate()); 39 this.textEditor.setAutocompleteDelegate(new WebInspector.CSSSourceFrame.Auto completeDelegate());
40 this._registerShortcuts(); 40 this._registerShortcuts();
41 this._colorBookmarks = []; 41 this._colorBookmarks = [];
42 this._swatchPopoverHelper = new WebInspector.SwatchPopoverHelper();
43 this._muteColorProcessing = false;
42 } 44 }
43 45
44 /** @type {number} */ 46 /** @type {number} */
45 WebInspector.CSSSourceFrame.UpdateTimeout = 200; 47 WebInspector.CSSSourceFrame.UpdateTimeout = 200;
46 48
47 WebInspector.CSSSourceFrame.prototype = { 49 WebInspector.CSSSourceFrame.prototype = {
48 _registerShortcuts: function() 50 _registerShortcuts: function()
49 { 51 {
50 var shortcutKeys = WebInspector.ShortcutsScreen.SourcesPanelShortcuts; 52 var shortcutKeys = WebInspector.ShortcutsScreen.SourcesPanelShortcuts;
51 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i) 53 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 { 150 {
149 this._clearColorBookmarks(); 151 this._clearColorBookmarks();
150 if (!colorPositions) 152 if (!colorPositions)
151 return; 153 return;
152 154
153 for (var i = 0; i < colorPositions.length; i++) { 155 for (var i = 0; i < colorPositions.length; i++) {
154 var colorPosition = colorPositions[i]; 156 var colorPosition = colorPositions[i];
155 157
156 var swatch = WebInspector.ColorSwatch.create(); 158 var swatch = WebInspector.ColorSwatch.create();
157 swatch.setColorText(colorPosition.color.asString(WebInspector.Color. Format.Original)); 159 swatch.setColorText(colorPosition.color.asString(WebInspector.Color. Format.Original));
160 swatch.iconElement().title = WebInspector.UIString("Open color picke r.");
161 swatch.iconElement().addEventListener("click", this._showSpectrum.bi nd(this, swatch, colorPosition), true);
158 swatch.hideText(true); 162 swatch.hideText(true);
159 163
160 var bookmark = this.textEditor.addBookmark(colorPosition.textRange.s tartLine, colorPosition.textRange.startColumn, swatch); 164 var bookmark = this.textEditor.addBookmark(colorPosition.textRange.s tartLine, colorPosition.textRange.startColumn, swatch);
161 this._colorBookmarks.push(bookmark); 165 this._colorBookmarks.push(bookmark);
162 } 166 }
163 }, 167 },
164 168
165 _clearColorBookmarks: function() 169 _clearColorBookmarks: function()
166 { 170 {
167 for (var i = 0; i < this._colorBookmarks.length; i++) 171 for (var i = 0; i < this._colorBookmarks.length; i++)
168 this._colorBookmarks[i].clear(); 172 this._colorBookmarks[i].clear();
169 this._colorBookmarks = []; 173 this._colorBookmarks = [];
170 }, 174 },
171 175
172 /** 176 /**
177 * @param {!WebInspector.ColorSwatch} swatch
178 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition
179 */
180 _showSpectrum: function(swatch, colorPosition)
lushnikov 2016/07/20 02:45:45 don't you want to consume event here?
flandy 2016/07/20 16:59:03 Done.
181 {
182 if (this._swatchPopoverHelper.isShowing()) {
183 this._swatchPopoverHelper.hide();
184 return;
185 }
186 this._currentSwatch = swatch;
187 this._currentColorPosition = colorPosition;
188 this._spectrum = new WebInspector.Spectrum();
189 this._spectrum.setColor(swatch.color(), swatch.format());
190 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged , this._spectrumResized, this);
191 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange d, this._spectrumChanged, this);
192 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), thi s._spectrumHidden.bind(this));
193 },
194
195 /**
196 * @param {!WebInspector.Event} event
197 */
198 _spectrumResized: function(event)
199 {
200 this._swatchPopoverHelper.reposition();
201 },
202
203 /**
204 * @param {!WebInspector.Event} event
205 */
206 _spectrumChanged: function(event)
207 {
208 this._muteColorProcessing = true;
209 var colorString = /** @type {string} */ (event.data);
210 this._currentSwatch.setColorText(colorString);
211 this._textEditor.editRange(this._currentColorPosition.textRange, colorSt ring);
212 this._currentColorPosition.color = WebInspector.Color.parse(colorString) ;
213 this._currentColorPosition.textRange.endColumn = this._currentColorPosit ion.textRange.startColumn + colorString.length;
214 },
215
216 _spectrumHidden: function()
217 {
218 this._muteColorProcessing = false;
219 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan ged, this._spectrumResized, this);
220 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha nged, this._spectrumChanged, this);
221 delete this._spectrum;
222 this._updateColorSwatches();
223 },
224
225 /**
173 * @override 226 * @override
174 */ 227 */
175 onTextEditorContentSet: function() 228 onTextEditorContentSet: function()
176 { 229 {
177 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s); 230 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s);
178 if (Runtime.experiments.isEnabled("sourceColorPicker")) 231 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC olorPicker"))
179 this._updateColorSwatches(); 232 this._updateColorSwatches();
180 }, 233 },
181 234
182 /** 235 /**
183 * @override 236 * @override
184 * @param {!WebInspector.TextRange} oldRange 237 * @param {!WebInspector.TextRange} oldRange
185 * @param {!WebInspector.TextRange} newRange 238 * @param {!WebInspector.TextRange} newRange
186 */ 239 */
187 onTextChanged: function(oldRange, newRange) 240 onTextChanged: function(oldRange, newRange)
188 { 241 {
189 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan ge, newRange); 242 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan ge, newRange);
190 if (Runtime.experiments.isEnabled("sourceColorPicker")) { 243 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC olorPicker")) {
191 if (this._updateTimeout) 244 if (this._updateTimeout)
192 clearTimeout(this._updateTimeout); 245 clearTimeout(this._updateTimeout);
193 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this ), WebInspector.CSSSourceFrame.UpdateTimeout); 246 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this ), WebInspector.CSSSourceFrame.UpdateTimeout);
194 } 247 }
195 }, 248 },
196 249
250 /**
251 * @override
252 * @param {number} lineNumber
253 */
254 scrollChanged: function(lineNumber)
255 {
256 WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNu mber);
257 if (this._swatchPopoverHelper.isShowing())
258 this._swatchPopoverHelper.hide();
259 },
260
197 __proto__: WebInspector.UISourceCodeFrame.prototype 261 __proto__: WebInspector.UISourceCodeFrame.prototype
198 } 262 }
199 263
200 /** 264 /**
201 * @constructor 265 * @constructor
202 * @param {!WebInspector.Color} color 266 * @param {!WebInspector.Color} color
203 * @param {number} lineNumber 267 * @param {number} lineNumber
204 * @param {number} startColumn 268 * @param {number} startColumn
205 * @param {number} textLength 269 * @param {number} textLength
206 */ 270 */
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); 362 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1);
299 if (!propertyToken) 363 if (!propertyToken)
300 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); 364 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange);
301 365
302 var line = editor.line(prefixRange.startLine); 366 var line = editor.line(prefixRange.startLine);
303 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); 367 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn);
304 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); 368 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent );
305 return keywords.startsWith(prefix); 369 return keywords.startsWith(prefix);
306 }, 370 },
307 } 371 }
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