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 58bdf45e533b57dca5820d254a73a6d9d2db28a3..39aea6fd930fc93ee94b5c72b1b3b10defecf640 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
+++ b/third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js |
@@ -39,6 +39,8 @@ WebInspector.CSSSourceFrame = function(uiSourceCode) |
this.textEditor.setAutocompleteDelegate(new WebInspector.CSSSourceFrame.AutocompleteDelegate()); |
this._registerShortcuts(); |
this._colorBookmarks = []; |
+ this._swatchPopoverHelper = new WebInspector.SwatchPopoverHelper(); |
+ this._muteColorProcessing = false; |
} |
/** @type {number} */ |
@@ -152,12 +154,8 @@ WebInspector.CSSSourceFrame.prototype = { |
for (var i = 0; i < colorPositions.length; i++) { |
var colorPosition = colorPositions[i]; |
- |
- var swatch = WebInspector.ColorSwatch.create(); |
- swatch.setColorText(colorPosition.color.asString(WebInspector.Color.Format.Original)); |
- swatch.hideText(true); |
- |
- var bookmark = this.textEditor.addBookmark(colorPosition.textRange.startLine, colorPosition.textRange.startColumn, swatch); |
+ var swatch = new WebInspector.CSSSourceFrame.ColorSwatch(this, colorPosition); |
+ var bookmark = this.textEditor.addBookmark(colorPosition.textRange.startLine, colorPosition.textRange.startColumn, swatch.element()); |
this._colorBookmarks.push(bookmark); |
} |
}, |
@@ -170,12 +168,67 @@ WebInspector.CSSSourceFrame.prototype = { |
}, |
/** |
+ * @param {!WebInspector.CSSSourceFrame.ColorSwatch} swatch |
+ */ |
+ _showSpectrum: function(swatch) |
+ { |
+ if (this._swatchPopoverHelper.isShowing()) { |
+ this._swatchPopoverHelper.hide(); |
+ return; |
+ } |
+ this._currentSwatch = swatch; |
+ this._spectrum = new WebInspector.Spectrum(); |
+ this._spectrum.setColor(swatch.element().color(), swatch.element().format()); |
+ this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged, this._spectrumResized, this); |
+ this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChanged, this._spectrumChanged, this); |
+ this._swatchPopoverHelper.show(this._spectrum, swatch.element().iconElement(), this._spectrumHidden.bind(this)); |
+ }, |
+ |
+ /** |
+ * @param {!WebInspector.Event} event |
+ */ |
+ _spectrumResized: function(event) |
+ { |
+ this._swatchPopoverHelper.reposition(); |
+ }, |
+ |
+ /** |
+ * @param {!WebInspector.Event} event |
+ */ |
+ _spectrumChanged: function(event) |
+ { |
+ this._muteColorProcessing = true; |
+ var colorString = /** @type {string} */ (event.data); |
+ this._currentSwatch.setColorText(colorString); |
+ this._replaceColorText(this._currentSwatch.colorPosition(), colorString); |
+ }, |
+ |
+ _spectrumHidden: function() |
+ { |
+ this._muteColorProcessing = false; |
+ this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChanged, this._spectrumResized, this); |
+ this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorChanged, this._spectrumChanged, this); |
+ delete this._spectrum; |
+ }, |
+ |
+ /** |
+ * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition |
+ * @param {string} colorString |
+ */ |
+ _replaceColorText: function(colorPosition, colorString) |
lushnikov
2016/07/20 00:49:23
you can inline this now
flandy
2016/07/20 01:56:18
Done.
|
+ { |
+ this._textEditor.editRange(colorPosition.textRange, colorString); |
+ colorPosition.color = WebInspector.Color.parse(colorString); |
+ colorPosition.textRange.endColumn = colorPosition.textRange.startColumn + colorString.length; |
+ }, |
+ |
+ /** |
* @override |
*/ |
onTextEditorContentSet: function() |
{ |
WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(this); |
- if (Runtime.experiments.isEnabled("sourceColorPicker")) |
+ if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceColorPicker")) |
this._updateColorSwatches(); |
}, |
@@ -187,13 +240,24 @@ WebInspector.CSSSourceFrame.prototype = { |
onTextChanged: function(oldRange, newRange) |
{ |
WebInspector.UISourceCodeFrame.prototype.onTextChanged.call(this, oldRange, newRange); |
- if (Runtime.experiments.isEnabled("sourceColorPicker")) { |
+ if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceColorPicker")) { |
if (this._updateTimeout) |
clearTimeout(this._updateTimeout); |
this._updateTimeout = setTimeout(this._updateColorSwatches.bind(this), WebInspector.CSSSourceFrame.UpdateTimeout); |
} |
}, |
+ /** |
+ * @override |
+ * @param {number} lineNumber |
+ */ |
+ scrollChanged: function(lineNumber) |
+ { |
+ WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNumber); |
+ if (this._swatchPopoverHelper.isShowing()) |
+ this._swatchPopoverHelper.hide(); |
+ }, |
+ |
__proto__: WebInspector.UISourceCodeFrame.prototype |
} |
@@ -212,6 +276,58 @@ WebInspector.CSSSourceFrame.ColorPosition = function(color, lineNumber, startCol |
/** |
* @constructor |
+ * @param {!WebInspector.CSSSourceFrame} cssSourceFrame |
+ * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition |
+ */ |
+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.
|
+{ |
+ this._cssSourceFrame = cssSourceFrame; |
+ this._colorPosition = colorPosition; |
+ |
+ this._swatch = WebInspector.ColorSwatch.create(); |
+ this._swatch.setColorText(colorPosition.color.asString(WebInspector.Color.Format.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
|
+ this._swatch.iconElement().title = WebInspector.UIString("Open color picker."); |
+ this._swatch.iconElement().addEventListener("click", this._handleClick.bind(this), true); |
+ this._swatch.hideText(true); |
+} |
+ |
+WebInspector.CSSSourceFrame.ColorSwatch.prototype = { |
+ /** |
+ * @param {!Event} event |
+ */ |
+ _handleClick: function(event) |
+ { |
+ this._cssSourceFrame._showSpectrum(this); |
+ event.consume(true); |
+ }, |
+ |
+ /** |
+ * @return {!WebInspector.ColorSwatch} |
+ */ |
+ element: function() |
+ { |
+ return this._swatch; |
+ }, |
+ |
+ /** |
+ * @return {!WebInspector.CSSSourceFrame.ColorPosition} |
+ */ |
+ colorPosition: function() |
+ { |
+ return this._colorPosition; |
+ }, |
+ |
+ /** |
+ * @param {string} colorString |
+ */ |
+ setColorText: function(colorString) |
+ { |
+ this._swatch.setColorText(colorString); |
+ } |
+} |
+ |
+/** |
+ * @constructor |
* @implements {WebInspector.TextEditorAutocompleteDelegate} |
*/ |
WebInspector.CSSSourceFrame.AutocompleteDelegate = function() |