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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 * @param {!Event} event |
| 180 */ |
| 181 _showSpectrum: function(swatch, colorPosition, event) |
| 182 { |
| 183 event.consume(true); |
| 184 if (this._swatchPopoverHelper.isShowing()) { |
| 185 this._swatchPopoverHelper.hide(); |
| 186 return; |
| 187 } |
| 188 this._currentSwatch = swatch; |
| 189 this._currentColorPosition = colorPosition; |
| 190 this._spectrum = new WebInspector.Spectrum(); |
| 191 this._spectrum.setColor(swatch.color(), swatch.format()); |
| 192 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged
, this._spectrumResized, this); |
| 193 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange
d, this._spectrumChanged, this); |
| 194 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), thi
s._spectrumHidden.bind(this)); |
| 195 }, |
| 196 |
| 197 /** |
| 198 * @param {!WebInspector.Event} event |
| 199 */ |
| 200 _spectrumResized: function(event) |
| 201 { |
| 202 this._swatchPopoverHelper.reposition(); |
| 203 }, |
| 204 |
| 205 /** |
| 206 * @param {!WebInspector.Event} event |
| 207 */ |
| 208 _spectrumChanged: function(event) |
| 209 { |
| 210 this._muteColorProcessing = true; |
| 211 var colorString = /** @type {string} */ (event.data); |
| 212 this._currentSwatch.setColorText(colorString); |
| 213 this._textEditor.editRange(this._currentColorPosition.textRange, colorSt
ring); |
| 214 this._currentColorPosition.color = WebInspector.Color.parse(colorString)
; |
| 215 this._currentColorPosition.textRange.endColumn = this._currentColorPosit
ion.textRange.startColumn + colorString.length; |
| 216 }, |
| 217 |
| 218 _spectrumHidden: function() |
| 219 { |
| 220 this._muteColorProcessing = false; |
| 221 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan
ged, this._spectrumResized, this); |
| 222 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha
nged, this._spectrumChanged, this); |
| 223 delete this._spectrum; |
| 224 this._updateColorSwatches(); |
| 225 }, |
| 226 |
| 227 /** |
173 * @override | 228 * @override |
174 */ | 229 */ |
175 onTextEditorContentSet: function() | 230 onTextEditorContentSet: function() |
176 { | 231 { |
177 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi
s); | 232 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi
s); |
178 if (Runtime.experiments.isEnabled("sourceColorPicker")) | 233 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC
olorPicker")) |
179 this._updateColorSwatches(); | 234 this._updateColorSwatches(); |
180 }, | 235 }, |
181 | 236 |
182 /** | 237 /** |
183 * @override | 238 * @override |
184 * @param {!WebInspector.TextRange} oldRange | 239 * @param {!WebInspector.TextRange} oldRange |
185 * @param {!WebInspector.TextRange} newRange | 240 * @param {!WebInspector.TextRange} newRange |
186 */ | 241 */ |
187 onTextChanged: function(oldRange, newRange) | 242 onTextChanged: function(oldRange, newRange) |
188 { | 243 { |
189 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan
ge, newRange); | 244 WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRan
ge, newRange); |
190 if (Runtime.experiments.isEnabled("sourceColorPicker")) { | 245 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC
olorPicker")) { |
191 if (this._updateTimeout) | 246 if (this._updateTimeout) |
192 clearTimeout(this._updateTimeout); | 247 clearTimeout(this._updateTimeout); |
193 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this
), WebInspector.CSSSourceFrame.UpdateTimeout); | 248 this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this
), WebInspector.CSSSourceFrame.UpdateTimeout); |
194 } | 249 } |
195 }, | 250 }, |
196 | 251 |
| 252 /** |
| 253 * @override |
| 254 * @param {number} lineNumber |
| 255 */ |
| 256 scrollChanged: function(lineNumber) |
| 257 { |
| 258 WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNu
mber); |
| 259 if (this._swatchPopoverHelper.isShowing()) |
| 260 this._swatchPopoverHelper.hide(); |
| 261 }, |
| 262 |
197 __proto__: WebInspector.UISourceCodeFrame.prototype | 263 __proto__: WebInspector.UISourceCodeFrame.prototype |
198 } | 264 } |
199 | 265 |
200 /** | 266 /** |
201 * @constructor | 267 * @constructor |
202 * @param {!WebInspector.Color} color | 268 * @param {!WebInspector.Color} color |
203 * @param {number} lineNumber | 269 * @param {number} lineNumber |
204 * @param {number} startColumn | 270 * @param {number} startColumn |
205 * @param {number} textLength | 271 * @param {number} textLength |
206 */ | 272 */ |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta
rtLine, prefixRange.startColumn - 1); | 364 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta
rtLine, prefixRange.startColumn - 1); |
299 if (!propertyToken) | 365 if (!propertyToken) |
300 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub
stituteRange); | 366 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub
stituteRange); |
301 | 367 |
302 var line = editor.line(prefixRange.startLine); | 368 var line = editor.line(prefixRange.startLine); |
303 var tokenContent = line.substring(propertyToken.startColumn, propertyTok
en.endColumn); | 369 var tokenContent = line.substring(propertyToken.startColumn, propertyTok
en.endColumn); |
304 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent
); | 370 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent
); |
305 return keywords.startsWith(prefix); | 371 return keywords.startsWith(prefix); |
306 }, | 372 }, |
307 } | 373 } |
OLD | NEW |