Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sources/CSSSourceFrame.js

Issue 2157533003: DevTools: Source color picker experiment. Make color swatches clickable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Consume event Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..eed8305089dc0111298b341d1f0336bf5e72e543 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} */
@@ -155,6 +157,8 @@ WebInspector.CSSSourceFrame.prototype = {
var swatch = WebInspector.ColorSwatch.create();
swatch.setColorText(colorPosition.color.asString(WebInspector.Color.Format.Original));
+ swatch.iconElement().title = WebInspector.UIString("Open color picker.");
+ swatch.iconElement().addEventListener("click", this._showSpectrum.bind(this, swatch, colorPosition), true);
swatch.hideText(true);
var bookmark = this.textEditor.addBookmark(colorPosition.textRange.startLine, colorPosition.textRange.startColumn, swatch);
@@ -170,12 +174,63 @@ WebInspector.CSSSourceFrame.prototype = {
},
/**
+ * @param {!WebInspector.ColorSwatch} swatch
+ * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition
+ * @param {!Event} event
+ */
+ _showSpectrum: function(swatch, colorPosition, event)
+ {
+ event.consume(true);
+ if (this._swatchPopoverHelper.isShowing()) {
+ this._swatchPopoverHelper.hide();
+ return;
+ }
+ this._currentSwatch = swatch;
+ this._currentColorPosition = colorPosition;
+ this._spectrum = new WebInspector.Spectrum();
+ this._spectrum.setColor(swatch.color(), swatch.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.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._textEditor.editRange(this._currentColorPosition.textRange, colorString);
+ this._currentColorPosition.color = WebInspector.Color.parse(colorString);
+ this._currentColorPosition.textRange.endColumn = this._currentColorPosition.textRange.startColumn + colorString.length;
+ },
+
+ _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;
+ this._updateColorSwatches();
+ },
+
+ /**
* @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 +242,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
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698