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._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 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.element()); |
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.CSSSourceFrame.ColorSwatch} swatch | |
172 */ | |
173 _showSpectrum: function(swatch) | |
174 { | |
175 if (this._swatchPopoverHelper.isShowing()) { | |
176 this._swatchPopoverHelper.hide(); | |
177 return; | |
178 } | |
179 this._currentSwatch = swatch; | |
180 this._spectrum = new WebInspector.Spectrum(); | |
181 this._spectrum.setColor(swatch.element().color(), swatch.element().forma t()); | |
182 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged , this._spectrumResized, this); | |
183 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange d, this._spectrumChanged, this); | |
184 this._swatchPopoverHelper.show(this._spectrum, swatch.element().iconElem ent(), this._spectrumHidden.bind(this)); | |
185 }, | |
186 | |
187 /** | |
188 * @param {!WebInspector.Event} event | |
189 */ | |
190 _spectrumResized: function(event) | |
191 { | |
192 this._swatchPopoverHelper.reposition(); | |
193 }, | |
194 | |
195 /** | |
196 * @param {!WebInspector.Event} event | |
197 */ | |
198 _spectrumChanged: function(event) | |
199 { | |
200 this._muteColorProcessing = true; | |
201 var colorString = /** @type {string} */ (event.data); | |
202 this._currentSwatch.setColorText(colorString); | |
203 this._replaceColorText(this._currentSwatch.colorPosition(), colorString) ; | |
204 }, | |
205 | |
206 _spectrumHidden: function() | |
207 { | |
208 this._muteColorProcessing = false; | |
209 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan ged, this._spectrumResized, this); | |
210 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha nged, this._spectrumChanged, this); | |
211 delete this._spectrum; | |
212 }, | |
213 | |
214 /** | |
215 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition | |
216 * @param {string} colorString | |
217 */ | |
218 _replaceColorText: function(colorPosition, colorString) | |
lushnikov
2016/07/20 00:49:23
you can inline this now
flandy
2016/07/20 01:56:18
Done.
| |
219 { | |
220 this._textEditor.editRange(colorPosition.textRange, colorString); | |
221 colorPosition.color = WebInspector.Color.parse(colorString); | |
222 colorPosition.textRange.endColumn = colorPosition.textRange.startColumn + colorString.length; | |
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 */ |
207 WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startCol umn, textLength) | 271 WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startCol umn, textLength) |
208 { | 272 { |
209 this.color = color; | 273 this.color = color; |
210 this.textRange = new WebInspector.TextRange(lineNumber, startColumn, lineNum ber, startColumn + textLength); | 274 this.textRange = new WebInspector.TextRange(lineNumber, startColumn, lineNum ber, startColumn + textLength); |
211 } | 275 } |
212 | 276 |
213 /** | 277 /** |
214 * @constructor | 278 * @constructor |
279 * @param {!WebInspector.CSSSourceFrame} cssSourceFrame | |
280 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition | |
281 */ | |
282 WebInspector.CSSSourceFrame.ColorSwatch = function(cssSourceFrame, colorPosition ) | |
lushnikov
2016/07/20 00:49:23
And it's clear that this class by itself doesn't h
flandy
2016/07/20 01:56:18
Done.
| |
283 { | |
284 this._cssSourceFrame = cssSourceFrame; | |
285 this._colorPosition = colorPosition; | |
286 | |
287 this._swatch = WebInspector.ColorSwatch.create(); | |
288 this._swatch.setColorText(colorPosition.color.asString(WebInspector.Color.Fo rmat.Original) || "white"); | |
lushnikov
2016/07/20 00:49:23
As you create color objects only with WebInspector
flandy
2016/07/20 01:56:18
The compiler no longer complains about this after
| |
289 this._swatch.iconElement().title = WebInspector.UIString("Open color picker. "); | |
290 this._swatch.iconElement().addEventListener("click", this._handleClick.bind( this), true); | |
291 this._swatch.hideText(true); | |
292 } | |
293 | |
294 WebInspector.CSSSourceFrame.ColorSwatch.prototype = { | |
295 /** | |
296 * @param {!Event} event | |
297 */ | |
298 _handleClick: function(event) | |
299 { | |
300 this._cssSourceFrame._showSpectrum(this); | |
301 event.consume(true); | |
302 }, | |
303 | |
304 /** | |
305 * @return {!WebInspector.ColorSwatch} | |
306 */ | |
307 element: function() | |
308 { | |
309 return this._swatch; | |
310 }, | |
311 | |
312 /** | |
313 * @return {!WebInspector.CSSSourceFrame.ColorPosition} | |
314 */ | |
315 colorPosition: function() | |
316 { | |
317 return this._colorPosition; | |
318 }, | |
319 | |
320 /** | |
321 * @param {string} colorString | |
322 */ | |
323 setColorText: function(colorString) | |
324 { | |
325 this._swatch.setColorText(colorString); | |
326 } | |
327 } | |
328 | |
329 /** | |
330 * @constructor | |
215 * @implements {WebInspector.TextEditorAutocompleteDelegate} | 331 * @implements {WebInspector.TextEditorAutocompleteDelegate} |
216 */ | 332 */ |
217 WebInspector.CSSSourceFrame.AutocompleteDelegate = function() | 333 WebInspector.CSSSourceFrame.AutocompleteDelegate = function() |
218 { | 334 { |
219 this._simpleDelegate = new WebInspector.SimpleAutocompleteDelegate(".-$"); | 335 this._simpleDelegate = new WebInspector.SimpleAutocompleteDelegate(".-$"); |
220 } | 336 } |
221 | 337 |
222 WebInspector.CSSSourceFrame._backtrackDepth = 10; | 338 WebInspector.CSSSourceFrame._backtrackDepth = 10; |
223 | 339 |
224 WebInspector.CSSSourceFrame.AutocompleteDelegate.prototype = { | 340 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); | 414 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); |
299 if (!propertyToken) | 415 if (!propertyToken) |
300 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); | 416 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); |
301 | 417 |
302 var line = editor.line(prefixRange.startLine); | 418 var line = editor.line(prefixRange.startLine); |
303 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); | 419 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); |
304 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); | 420 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); |
305 return keywords.startsWith(prefix); | 421 return keywords.startsWith(prefix); |
306 }, | 422 }, |
307 } | 423 } |
OLD | NEW |