OLD | NEW |
---|---|
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 Loading... | |
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._analyzeTextColors = true; | |
lushnikov
2016/07/19 21:12:16
We usually call this kind of flags like muteXXX, e
flandy
2016/07/19 22:58:15
Done.
| |
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 * @param {?Array<!WebInspector.CSSSourceFrame.ColorPosition>} colorPosition s | 147 * @param {?Array<!WebInspector.CSSSourceFrame.ColorPosition>} colorPosition s |
146 */ | 148 */ |
147 _putColorSwatchesInline: function(colorPositions) | 149 _putColorSwatchesInline: function(colorPositions) |
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 var swatch = new WebInspector.CSSSourceFrame.ColorSwatch(this, color Position); |
156 var swatch = WebInspector.ColorSwatch.create(); | 158 var bookmark = this.textEditor.addBookmark(colorPosition.textRange.s tartLine, colorPosition.textRange.startColumn, swatch.getElement()); |
157 swatch.setColorText(colorPosition.color.asString(WebInspector.Color. Format.Original)); | |
158 swatch.hideText(true); | |
159 | |
160 var bookmark = this.textEditor.addBookmark(colorPosition.textRange.s tartLine, colorPosition.textRange.startColumn, swatch); | |
161 this._colorBookmarks.push(bookmark); | 159 this._colorBookmarks.push(bookmark); |
162 } | 160 } |
163 }, | 161 }, |
164 | 162 |
165 _clearColorBookmarks: function() | 163 _clearColorBookmarks: function() |
166 { | 164 { |
167 for (var i = 0; i < this._colorBookmarks.length; i++) | 165 for (var i = 0; i < this._colorBookmarks.length; i++) |
168 this._colorBookmarks[i].clear(); | 166 this._colorBookmarks[i].clear(); |
169 this._colorBookmarks = []; | 167 this._colorBookmarks = []; |
170 }, | 168 }, |
171 | 169 |
172 /** | 170 /** |
171 * @param {!WebInspector.ColorSwatch} swatch | |
172 */ | |
173 _showSpectrum: function(swatch) | |
174 { | |
175 if (this._swatchPopoverHelper.isShowing()) { | |
176 this._swatchPopoverHelper.hide(); | |
177 return; | |
178 } | |
179 var color = swatch.color(); | |
180 var format = swatch.format(); | |
181 if (format === WebInspector.Color.Format.Original) | |
182 format = color.format(); | |
183 | |
184 this._spectrum = new WebInspector.Spectrum(); | |
185 this._spectrum.setColor(color, format); | |
186 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged , this._spectrumResized, this); | |
lushnikov
2016/07/19 21:12:16
When does this event fire?
flandy
2016/07/19 22:58:15
This event fires when changing the color palette o
| |
187 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange d, this._spectrumChanged, this); | |
188 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), thi s._spectrumHidden.bind(this)); | |
189 }, | |
190 | |
191 /** | |
192 * @param {!WebInspector.Event} event | |
193 */ | |
194 _spectrumResized: function(event) | |
195 { | |
196 this._swatchPopoverHelper.reposition(); | |
197 }, | |
198 | |
199 /** | |
200 * @param {!WebInspector.Event} event | |
201 */ | |
202 _spectrumChanged: function(event) | |
203 { | |
204 this._analyzeTextColors = false; | |
205 var colorString = /** @type {string} */ (event.data); | |
206 this._currentSwatch.setColorText(colorString); | |
207 this._replaceColorText(this._currentSwatch.getColorPosition(), colorStri ng); | |
208 }, | |
209 | |
210 _spectrumHidden: function() | |
211 { | |
212 this._analyzeTextColors = true; | |
213 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan ged, this._spectrumResized, this); | |
214 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha nged, this._spectrumChanged, this); | |
215 delete this._spectrum; | |
lushnikov
2016/07/19 21:12:16
you should schedule updateColorSwatches here
flandy
2016/07/19 22:58:15
Why? We already change the color and position of t
lushnikov
2016/07/20 00:49:23
Imagine you have multiple color swatches in the li
flandy
2016/07/20 01:56:18
Yes, good point! Done.
| |
216 }, | |
217 | |
218 /** | |
219 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition | |
220 * @param {string} colorString | |
221 */ | |
222 _replaceColorText: function(colorPosition, colorString) | |
223 { | |
224 this._textEditor.editRange(colorPosition.textRange, colorString); | |
225 colorPosition.color = WebInspector.Color.parse(colorString); | |
226 colorPosition.textRange.endColumn = colorPosition.textRange.startColumn + colorString.length; | |
227 }, | |
228 | |
229 /** | |
173 * @override | 230 * @override |
174 */ | 231 */ |
175 onTextEditorContentSet: function() | 232 onTextEditorContentSet: function() |
176 { | 233 { |
177 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s); | 234 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s); |
178 if (Runtime.experiments.isEnabled("sourceColorPicker")) | 235 if (Runtime.experiments.isEnabled("sourceColorPicker") && this._analyzeT extColors) |
lushnikov
2016/07/19 21:12:16
nit: I'd check for the flag first
flandy
2016/07/19 22:58:15
Done.
| |
179 this._updateColorSwatches(); | 236 this._updateColorSwatches(); |
180 }, | 237 }, |
181 | 238 |
182 /** | 239 /** |
183 * @override | 240 * @override |
184 * @param {!WebInspector.TextRange} oldRange | 241 * @param {!WebInspector.TextRange} oldRange |
185 * @param {!WebInspector.TextRange} newRange | 242 * @param {!WebInspector.TextRange} newRange |
186 */ | 243 */ |
187 onTextChanged: function(oldRange, newRange) | 244 onTextChanged: function(oldRange, newRange) |
188 { | 245 { |
189 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan ge, newRange); | 246 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan ge, newRange); |
190 if (Runtime.experiments.isEnabled("sourceColorPicker")) { | 247 if (Runtime.experiments.isEnabled("sourceColorPicker") && this._analyzeT extColors) { |
191 if (this._updateTimeout) | 248 if (this._updateTimeout) |
192 clearTimeout(this._updateTimeout); | 249 clearTimeout(this._updateTimeout); |
193 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this ), WebInspector.CSSSourceFrame.UpdateTimeout); | 250 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this ), WebInspector.CSSSourceFrame.UpdateTimeout); |
194 } | 251 } |
195 }, | 252 }, |
196 | 253 |
254 /** | |
255 * @override | |
256 * @param {number} lineNumber | |
257 */ | |
258 scrollChanged: function(lineNumber) | |
259 { | |
260 WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNu mber); | |
261 if (this._swatchPopoverHelper.isShowing()) | |
262 this._swatchPopoverHelper.hide(); | |
263 }, | |
264 | |
197 __proto__: WebInspector.UISourceCodeFrame.prototype | 265 __proto__: WebInspector.UISourceCodeFrame.prototype |
198 } | 266 } |
199 | 267 |
200 /** | 268 /** |
201 * @constructor | 269 * @constructor |
202 * @param {!WebInspector.Color} color | 270 * @param {!WebInspector.Color} color |
203 * @param {number} lineNumber | 271 * @param {number} lineNumber |
204 * @param {number} startColumn | 272 * @param {number} startColumn |
205 * @param {number} textLength | 273 * @param {number} textLength |
206 */ | 274 */ |
207 WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startCol umn, textLength) | 275 WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startCol umn, textLength) |
208 { | 276 { |
209 this.color = color; | 277 this.color = color; |
210 this.textRange = new WebInspector.TextRange(lineNumber, startColumn, lineNum ber, startColumn + textLength); | 278 this.textRange = new WebInspector.TextRange(lineNumber, startColumn, lineNum ber, startColumn + textLength); |
211 } | 279 } |
212 | 280 |
213 /** | 281 /** |
214 * @constructor | 282 * @constructor |
283 * @param {!WebInspector.CSSSourceFrame} cssSourceFrame | |
284 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition | |
285 */ | |
286 WebInspector.CSSSourceFrame.ColorSwatch = function(cssSourceFrame, colorPosition ) | |
287 { | |
288 this._cssSourceFrame = cssSourceFrame; | |
289 this._colorPosition = colorPosition; | |
290 | |
291 this._swatch = WebInspector.ColorSwatch.create(); | |
292 this._swatch.setColorText(colorPosition.color.asString(WebInspector.Color.Fo rmat.Original) || "white"); | |
293 var shiftClickMessage = WebInspector.UIString("Shift + Click to change color format."); | |
294 this._swatch.iconElement().title = WebInspector.UIString("Open color picker. %s", shiftClickMessage); | |
295 this._swatch.setClickHandler(this._handleClick.bind(this)); | |
296 this._swatch.hideText(true); | |
297 } | |
298 | |
299 WebInspector.CSSSourceFrame.ColorSwatch.prototype = { | |
300 /** | |
301 * @param {!Event} event | |
302 */ | |
303 _handleClick: function(event) | |
304 { | |
305 if (event.shiftKey) { | |
lushnikov
2016/07/19 21:12:16
I'm not convinced we need the shift-click in the s
flandy
2016/07/19 22:58:15
I think it would be nice to have, in order to mirr
| |
306 this._swatch.toggleNextFormat(); | |
307 this._cssSourceFrame._analyzeTextColors = false; | |
308 this._cssSourceFrame._replaceColorText(this._colorPosition, this._sw atch.color().asString(this._swatch.format()) || "white"); | |
lushnikov
2016/07/19 21:12:16
where does "white" come from?
flandy
2016/07/19 22:58:15
color.asString() may return null|string according
| |
309 this._cssSourceFrame._analyzeTextColors = true; | |
310 } else { | |
311 this._cssSourceFrame._currentSwatch = this; | |
lushnikov
2016/07/19 21:12:16
let's not reach to internal fields of cssSourceFra
flandy
2016/07/19 22:58:15
Done.
| |
312 this._cssSourceFrame._showSpectrum(this._swatch); | |
lushnikov
2016/07/19 21:12:16
I think it would be easier if you just pass the WI
flandy
2016/07/19 22:58:15
Done.
| |
313 } | |
314 event.consume(true); | |
315 }, | |
316 | |
317 /** | |
318 * @return {!WebInspector.ColorSwatch} | |
319 */ | |
320 getElement: function() | |
lushnikov
2016/07/19 21:12:16
element: ...
(we use nouns for getters and verbs
flandy
2016/07/19 22:58:15
Done.
| |
321 { | |
322 return this._swatch; | |
323 }, | |
324 | |
325 /** | |
326 * @return {!WebInspector.CSSSourceFrame.ColorPosition} | |
327 */ | |
328 getColorPosition: function() | |
lushnikov
2016/07/19 21:12:16
colorPosition: ..
flandy
2016/07/19 22:58:15
Done.
| |
329 { | |
330 return this._colorPosition; | |
331 }, | |
332 | |
333 /** | |
334 * @param {string} colorString | |
335 */ | |
336 setColorText: function(colorString) | |
337 { | |
338 this._swatch.setColorText(colorString); | |
339 } | |
340 } | |
341 | |
342 /** | |
343 * @constructor | |
215 * @implements {WebInspector.TextEditorAutocompleteDelegate} | 344 * @implements {WebInspector.TextEditorAutocompleteDelegate} |
216 */ | 345 */ |
217 WebInspector.CSSSourceFrame.AutocompleteDelegate = function() | 346 WebInspector.CSSSourceFrame.AutocompleteDelegate = function() |
218 { | 347 { |
219 this._simpleDelegate = new WebInspector.SimpleAutocompleteDelegate(".-$"); | 348 this._simpleDelegate = new WebInspector.SimpleAutocompleteDelegate(".-$"); |
220 } | 349 } |
221 | 350 |
222 WebInspector.CSSSourceFrame._backtrackDepth = 10; | 351 WebInspector.CSSSourceFrame._backtrackDepth = 10; |
223 | 352 |
224 WebInspector.CSSSourceFrame.AutocompleteDelegate.prototype = { | 353 WebInspector.CSSSourceFrame.AutocompleteDelegate.prototype = { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); | 427 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); |
299 if (!propertyToken) | 428 if (!propertyToken) |
300 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); | 429 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); |
301 | 430 |
302 var line = editor.line(prefixRange.startLine); | 431 var line = editor.line(prefixRange.startLine); |
303 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); | 432 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); |
304 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); | 433 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); |
305 return keywords.startsWith(prefix); | 434 return keywords.startsWith(prefix); |
306 }, | 435 }, |
307 } | 436 } |
OLD | NEW |