Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js b/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
| index 1a9085987f308174302c2fff97730dee4c170a3d..9da65d14650c07bacf420ed4c7f7e0f6ed58d9eb 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
| @@ -38,6 +38,11 @@ WebInspector.CSSSourceFrame = function(uiSourceCode) |
| WebInspector.UISourceCodeFrame.call(this, uiSourceCode); |
| this.textEditor.setAutocompleteDelegate(new WebInspector.CSSSourceFrame.AutocompleteDelegate()); |
| this._registerShortcuts(); |
| + |
| + if (Runtime.experiments.isEnabled("sourceColorPicker")) { |
| + this._colorBookmarks = []; |
| + this.uiSourceCode().addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this); |
| + } |
| } |
| WebInspector.CSSSourceFrame.prototype = { |
| @@ -97,7 +102,113 @@ WebInspector.CSSSourceFrame.prototype = { |
| return true; |
| }, |
| - __proto__: WebInspector.UISourceCodeFrame.prototype |
| + __proto__: WebInspector.UISourceCodeFrame.prototype, |
|
lushnikov
2016/07/12 03:48:02
nit: __proto__ should be the last thing in the obj
flandy
2016/07/12 21:17:15
Done.
|
| + |
| + _workingCopyChanged: function(event) |
|
lushnikov
2016/07/12 03:48:02
let's add jsdoc here
flandy
2016/07/12 21:17:15
Done.
|
| + { |
| + this._addColorSwatches(); |
| + }, |
| + |
| + _addColorSwatches: function() |
| + { |
| + var colorPositions = this._extractColorPositions(this._uiSourceCode.workingCopy()); |
| + this._putColorSwatchesInline(colorPositions); |
| + }, |
| + |
| + /** |
| + * @param {string} content |
| + * @return {?Array<!WebInspector.CSSSourceFrame.ColorPosition>} |
| + */ |
| + _extractColorPositions: function(content) |
| + { |
| + if (!content) |
| + return null; |
| + |
| + var colorPositions = []; |
| + |
| + var lines = content.split(/\r?\n/); |
| + for (var lineNum = 0; lineNum < lines.length; lineNum++) { |
| + var line = lines[lineNum] + "\n"; |
| + |
| + var colorRegex = /[\s:;,(){}]((?:rgb|hsl)a?\([^)]+\)|#[0-9a-f]{8}|#[0-9a-f]{6}|#[0-9a-f]{3,4}|[a-z]+)(?=[\s;,(){}])/gi; |
| + var arrResult; |
| + |
| + while ((arrResult = colorRegex.exec(line)) !== null) { |
| + if (arrResult.length >= 1) { |
| + var colorText = arrResult[1]; |
| + var color = WebInspector.Color.parse(colorText); |
| + if (color) { |
| + var startIndex = arrResult[0].search(/[a-z]|#/i); |
| + var startColumn = arrResult.index + startIndex; |
| + |
| + colorPositions.push(new WebInspector.CSSSourceFrame.ColorPosition(color, lineNum, startColumn, colorText.length)); |
| + } |
| + } |
| + } |
| + } |
| + |
| + return colorPositions; |
| + }, |
| + |
| + |
| + /** |
| + * @param {?Array<!WebInspector.CSSSourceFrame.ColorPosition>} colorPositions |
| + */ |
| + _putColorSwatchesInline: function(colorPositions) |
|
lushnikov
2016/07/12 03:48:02
this whole function should be a codemirror operati
flandy
2016/07/12 21:17:15
Awesome! Done.
|
| + { |
| + if (colorPositions) { |
| + this._clearColorBookmarks(); |
|
lushnikov
2016/07/12 03:48:02
i guess you want clear color bookmarks outside of
flandy
2016/07/12 21:17:15
Done.
|
| + |
| + for (var i = 0; i < colorPositions.length; i++) { |
| + var colorPos = colorPositions[i]; |
| + |
| + var swatch = WebInspector.ColorSwatch.create(); |
| + swatch.setColorText(colorPos.color.asString(WebInspector.Color.Format.Original)); |
| + swatch.setFormat(WebInspector.Color.detectColorFormat(colorPos.color)); |
| + swatch.iconElement().title = WebInspector.UIString("Open color picker"); |
| + |
| + var bookmark = this.textEditor.addBookmark(colorPos.textRange.startLine, colorPos.textRange.startColumn, swatch); |
| + this._colorBookmarks.push(bookmark); |
| + } |
| + } |
| + }, |
| + |
| + _clearColorBookmarks: function() { |
| + for (var i = 0; i < this._colorBookmarks.length; i++) { |
| + this._colorBookmarks[i].clear(); |
| + } |
| + this._colorBookmarks = []; |
| + }, |
| + |
| + /** |
| + * @override |
| + */ |
| + onTextEditorContentLoaded: function() |
| + { |
| + WebInspector.UISourceCodeFrame.prototype.onTextEditorContentLoaded.call(this); |
| + if (Runtime.experiments.isEnabled("sourceColorPicker")) { |
| + this._addColorSwatches(); |
| + } |
| + }, |
| + |
| + dispose: function() |
| + { |
| + this.uiSourceCode().removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this); |
| + WebInspector.UISourceCodeFrame.prototype.dispose.call(this); |
| + } |
| +} |
| + |
| +/** |
| + * @constructor |
| + * @param {!WebInspector.Color} color |
| + * @param {number} lineNumber |
| + * @param {number} startColumn |
| + * @param {number} textLength |
| + */ |
| +WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startColumn, textLength) |
| +{ |
| + this.color = color; |
| + this.textRange = new WebInspector.TextRange(lineNumber, startColumn, lineNumber, startColumn + textLength); |
| } |
| /** |