Commit 12112116 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: allow editing custom color palette, move it out of experimental.

NOTRY=true

Review URL: https://codereview.chromium.org/1308563002

git-svn-id: svn://svn.chromium.org/blink/trunk@201008 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 76569929
...@@ -102,13 +102,14 @@ WebInspector.Spectrum = function() ...@@ -102,13 +102,14 @@ WebInspector.Spectrum = function()
WebInspector.installDragHandle(this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), positionAlpha.bind(this), null, "default"); WebInspector.installDragHandle(this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), positionAlpha.bind(this), null, "default");
WebInspector.installDragHandle(this._colorElement, dragStart.bind(this, positionColor.bind(this)), positionColor.bind(this), null, "default"); WebInspector.installDragHandle(this._colorElement, dragStart.bind(this, positionColor.bind(this)), positionColor.bind(this), null, "default");
if (Runtime.experiments.isEnabled("colorPalettes")) {
this.element.classList.add("palettes-enabled"); this.element.classList.add("palettes-enabled");
/** @type {!Map.<string, !WebInspector.Spectrum.Palette>} */ /** @type {!Map.<string, !WebInspector.Spectrum.Palette>} */
this._palettes = new Map(); this._palettes = new Map();
this._palettePanel = this.contentElement.createChild("div", "palette-panel"); this._palettePanel = this.contentElement.createChild("div", "palette-panel");
this._palettePanelShowing = false; this._palettePanelShowing = false;
this._paletteContainer = this.contentElement.createChild("div", "spectrum-palette"); this._paletteContainer = this.contentElement.createChild("div", "spectrum-palette");
this._paletteContainer.addEventListener("contextmenu", this._showPaletteColorContextMenu.bind(this, -1));
WebInspector.installDragHandle(this._paletteContainer, this._paletteDragStart.bind(this), this._paletteDrag.bind(this), this._paletteDragEnd.bind(this), "default");
var paletteSwitcher = this.contentElement.createChild("div", "spectrum-palette-switcher spectrum-switcher"); var paletteSwitcher = this.contentElement.createChild("div", "spectrum-palette-switcher spectrum-switcher");
appendSwitcherIcon(paletteSwitcher); appendSwitcherIcon(paletteSwitcher);
paletteSwitcher.addEventListener("click", this._togglePalettePanel.bind(this, true)); paletteSwitcher.addEventListener("click", this._togglePalettePanel.bind(this, true));
...@@ -116,12 +117,12 @@ WebInspector.Spectrum = function() ...@@ -116,12 +117,12 @@ WebInspector.Spectrum = function()
overlay.addEventListener("click", this._togglePalettePanel.bind(this, false)); overlay.addEventListener("click", this._togglePalettePanel.bind(this, false));
this._addColorToolbar = new WebInspector.Toolbar(); this._addColorToolbar = new WebInspector.Toolbar();
this._addColorToolbar.element.classList.add("add-color-toolbar");
var addColorButton = new WebInspector.ToolbarButton(WebInspector.UIString("Add to palette"), "add-toolbar-item"); var addColorButton = new WebInspector.ToolbarButton(WebInspector.UIString("Add to palette"), "add-toolbar-item");
addColorButton.addEventListener("click", this._addColorToCustomPalette.bind(this)); addColorButton.addEventListener("click", this._addColorToCustomPalette.bind(this));
this._addColorToolbar.appendToolbarItem(addColorButton); this._addColorToolbar.appendToolbarItem(addColorButton);
new WebInspector.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(this)); new WebInspector.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(this));
}
/** /**
* @param {function(!Event)} callback * @param {function(!Event)} callback
...@@ -187,6 +188,9 @@ WebInspector.Spectrum.Events = { ...@@ -187,6 +188,9 @@ WebInspector.Spectrum.Events = {
SizeChanged: "SizeChanged" SizeChanged: "SizeChanged"
}; };
WebInspector.Spectrum._colorChipSize = 24;
WebInspector.Spectrum._itemsPerPaletteRow = 8;
WebInspector.Spectrum.prototype = { WebInspector.Spectrum.prototype = {
_updatePalettePanel: function() _updatePalettePanel: function()
{ {
...@@ -240,20 +244,26 @@ WebInspector.Spectrum.prototype = { ...@@ -240,20 +244,26 @@ WebInspector.Spectrum.prototype = {
for (var i = 0; i < palette.colors.length; i++) { for (var i = 0; i < palette.colors.length; i++) {
var animationDelay = animate ? i * 100 / palette.colors.length : 0; var animationDelay = animate ? i * 100 / palette.colors.length : 0;
var colorElement = this._createPaletteColor(palette.colors[i], animationDelay); var colorElement = this._createPaletteColor(palette.colors[i], animationDelay);
colorElement.addEventListener("click", this._paletteColorSelected.bind(this, palette.colors[i])); colorElement.addEventListener("mousedown", this._paletteColorSelected.bind(this, palette.colors[i]));
if (palette.mutable) if (palette.mutable) {
colorElement.__mutable = true;
colorElement.__color = palette.colors[i];
colorElement.addEventListener("contextmenu", this._showPaletteColorContextMenu.bind(this, i)); colorElement.addEventListener("contextmenu", this._showPaletteColorContextMenu.bind(this, i));
}
this._paletteContainer.appendChild(colorElement); this._paletteContainer.appendChild(colorElement);
} }
this._paletteContainerMutable = palette.mutable;
var numItems = palette.colors.length; var numItems = palette.colors.length;
if (palette.mutable) if (palette.mutable)
numItems++; numItems++;
var rowsNeeded = Math.max(1, Math.ceil(numItems / 8)); var rowsNeeded = Math.max(1, Math.ceil(numItems / WebInspector.Spectrum._itemsPerPaletteRow));
for (var i = 0; palette.mutable && i < rowsNeeded * 8 - numItems; i++) for (var i = 0; palette.mutable && i < rowsNeeded * WebInspector.Spectrum._itemsPerPaletteRow - numItems; i++)
this._paletteContainer.createChild("div", "spectrum-palette-color empty-color"); this._paletteContainer.createChild("div", "spectrum-palette-color empty-color");
if (palette.mutable) if (palette.mutable)
this._paletteContainer.appendChild(this._addColorToolbar.element); this.contentElement.appendChild(this._addColorToolbar.element);
else
this._addColorToolbar.element.remove();
this._togglePalettePanel(false); this._togglePalettePanel(false);
var paletteColorHeight = 12; var paletteColorHeight = 12;
...@@ -262,6 +272,76 @@ WebInspector.Spectrum.prototype = { ...@@ -262,6 +272,76 @@ WebInspector.Spectrum.prototype = {
this.dispatchEventToListeners(WebInspector.Spectrum.Events.SizeChanged); this.dispatchEventToListeners(WebInspector.Spectrum.Events.SizeChanged);
}, },
/**
* @param {!Event} e
* @return {number}
*/
_slotIndexForEvent: function(e)
{
var localX = e.pageX - this._paletteContainer.totalOffsetLeft();
var localY = e.pageY - this._paletteContainer.totalOffsetTop();
var col = Math.min(localX / WebInspector.Spectrum._colorChipSize | 0, WebInspector.Spectrum._itemsPerPaletteRow - 1);
var row = (localY / WebInspector.Spectrum._colorChipSize) | 0;
return Math.min(row * WebInspector.Spectrum._itemsPerPaletteRow + col, this._paletteContainer.children.length - 1);
},
/**
* @param {!Event} e
* @return {boolean}
*/
_paletteDragStart: function(e)
{
var element = e.deepElementFromPoint();
if (!element.__mutable)
return false;
var index = this._slotIndexForEvent(e);
this._dragElement = element;
this._dragHotSpotX = e.pageX - (index % WebInspector.Spectrum._itemsPerPaletteRow) * WebInspector.Spectrum._colorChipSize;
this._dragHotSpotY = e.pageY - (index / WebInspector.Spectrum._itemsPerPaletteRow | 0) * WebInspector.Spectrum._colorChipSize;
return true;
},
/**
* @param {!Event} e
*/
_paletteDrag: function(e)
{
if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this._paletteContainer.totalOffsetTop())
return;
var newIndex = this._slotIndexForEvent(e);
var offsetX = e.pageX - (newIndex % WebInspector.Spectrum._itemsPerPaletteRow) * WebInspector.Spectrum._colorChipSize;
var offsetY = e.pageY - (newIndex / WebInspector.Spectrum._itemsPerPaletteRow | 0) * WebInspector.Spectrum._colorChipSize;
this._dragElement.style.position = "relative";
this._dragElement.style.left = (offsetX - this._dragHotSpotX) + "px";
this._dragElement.style.top = (offsetY - this._dragHotSpotY) + "px";
var children = Array.prototype.slice.call(this._paletteContainer.children);
var index = children.indexOf(this._dragElement);
if (index !== newIndex)
this._paletteContainer.insertBefore(this._dragElement, children[newIndex > index ? newIndex + 1 : newIndex]);
},
/**
* @param {!Event} e
*/
_paletteDragEnd: function(e)
{
this._dragElement.style.removeProperty("position");
this._dragElement.style.removeProperty("left");
this._dragElement.style.removeProperty("top");
var children = this._paletteContainer.children;
var colors = [];
for (var i = 0; i < children.length; ++i) {
if (children[i].__color)
colors.push(children[i].__color);
}
var palette = this._customPaletteSetting.get();
palette.colors = colors;
this._customPaletteSetting.set(palette);
this._showPalette(this._customPaletteSetting.get(), false);
},
/** /**
* @param {!WebInspector.Spectrum.Palette} generatedPalette * @param {!WebInspector.Spectrum.Palette} generatedPalette
*/ */
...@@ -334,22 +414,28 @@ WebInspector.Spectrum.prototype = { ...@@ -334,22 +414,28 @@ WebInspector.Spectrum.prototype = {
*/ */
_showPaletteColorContextMenu: function(colorIndex, event) _showPaletteColorContextMenu: function(colorIndex, event)
{ {
if (!this._paletteContainerMutable)
return;
var contextMenu = new WebInspector.ContextMenu(event); var contextMenu = new WebInspector.ContextMenu(event);
contextMenu.appendItem(WebInspector.UIString("Remove color"), this._deletePaletteColor.bind(this, colorIndex)); if (colorIndex !== -1) {
contextMenu.appendItem(WebInspector.UIString("Clear palette"), this._deletePaletteColor.bind(this, undefined)); contextMenu.appendItem(WebInspector.UIString("Remove color"), this._deletePaletteColors.bind(this, colorIndex, false));
contextMenu.appendItem(WebInspector.UIString("Remove all to the right"), this._deletePaletteColors.bind(this, colorIndex, true));
}
contextMenu.appendItem(WebInspector.UIString("Clear palette"), this._deletePaletteColors.bind(this, -1, true));
contextMenu.show(); contextMenu.show();
}, },
/** /**
* @param {number=} colorIndex * @param {number} colorIndex
* @param {boolean} toRight
*/ */
_deletePaletteColor: function(colorIndex) _deletePaletteColors: function(colorIndex, toRight)
{ {
var palette = this._customPaletteSetting.get(); var palette = this._customPaletteSetting.get();
if (colorIndex !== undefined) if (toRight)
palette.colors.splice(colorIndex, 1); palette.colors.splice(colorIndex + 1, palette.colors.length - colorIndex - 1);
else else
palette.colors = []; palette.colors.splice(colorIndex, 1);
this._customPaletteSetting.set(palette); this._customPaletteSetting.set(palette);
this._showPalette(this._customPaletteSetting.get(), false); this._showPalette(this._customPaletteSetting.get(), false);
}, },
......
...@@ -88,12 +88,12 @@ ...@@ -88,12 +88,12 @@
} }
.swatch { .swatch {
width: 16px; width: 24px;
height: 16px; height: 24px;
margin: 0; margin: 0;
position: absolute; position: absolute;
top: 148px; top: 144px;
left: 48px; left: 47px;
background-image: url(Images/checker.png); background-image: url(Images/checker.png);
border-radius: 16px; border-radius: 16px;
} }
...@@ -190,36 +190,38 @@ ...@@ -190,36 +190,38 @@
position: absolute; position: absolute;
top: 235px; top: 235px;
width: 100%; width: 100%;
padding-right: 24px; padding: 6px 24px 6px 6px;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
} }
.spectrum-palette-color { .spectrum-palette-color {
width: 12px;
height: 12px; height: 12px;
flex: 0 0 12px; flex: 0 0 12px;
display: inline-block; display: inline-block;
border-radius: 2px; border-radius: 2px;
margin-left: 12px; margin: 6px;
margin-top: 12px;
cursor: pointer; cursor: pointer;
} }
.spectrum-palette-color.empty-color {
border: 1px solid #dadada;
}
.spectrum-palette > .spectrum-palette-color { .spectrum-palette > .spectrum-palette-color {
transition: transform 100ms cubic-bezier(0, 0, 0.2, 1); transition: transform 100ms cubic-bezier(0, 0, 0.2, 1);
border: 1px solid rgba(0, 0, 0, 0.1);
}
.spectrum-palette > .spectrum-palette-color.empty-color {
border-color: transparent;
} }
.spectrum-palette > .spectrum-palette-color:not(.empty-color):hover { .spectrum-palette > .spectrum-palette-color:not(.empty-color):hover {
transform: scale(1.15); transform: scale(1.15);
} }
.spectrum-palette > .toolbar { .add-color-toolbar {
margin-left: 5px; position: absolute;
margin-top: 5px; right: 29px;
bottom: 5px;
} }
.spectrum-palette-switcher { .spectrum-palette-switcher {
......
...@@ -126,7 +126,6 @@ WebInspector.Main.prototype = { ...@@ -126,7 +126,6 @@ WebInspector.Main.prototype = {
Runtime.experiments.register("applyCustomStylesheet", "Allow custom UI themes"); Runtime.experiments.register("applyCustomStylesheet", "Allow custom UI themes");
Runtime.experiments.register("blackboxJSFramesOnTimeline", "Blackbox JavaScript frames on Timeline", true); Runtime.experiments.register("blackboxJSFramesOnTimeline", "Blackbox JavaScript frames on Timeline", true);
Runtime.experiments.register("colorContrastRatio", "Contrast ratio line in color picker", true); Runtime.experiments.register("colorContrastRatio", "Contrast ratio line in color picker", true);
Runtime.experiments.register("colorPalettes", "Color palettes");
Runtime.experiments.register("customObjectFormatters", "Custom object formatters", true); Runtime.experiments.register("customObjectFormatters", "Custom object formatters", true);
Runtime.experiments.register("emptySourceMapAutoStepping", "Empty sourcemap auto-stepping"); Runtime.experiments.register("emptySourceMapAutoStepping", "Empty sourcemap auto-stepping");
Runtime.experiments.register("fileSystemInspection", "FileSystem inspection"); Runtime.experiments.register("fileSystemInspection", "FileSystem inspection");
......
...@@ -13,8 +13,8 @@ WebInspector.Tooltip = function(doc) ...@@ -13,8 +13,8 @@ WebInspector.Tooltip = function(doc)
this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tooltip.css")); this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tooltip.css"));
this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); this._tooltipElement = this._shadowRoot.createChild("div", "tooltip");
doc.addEventListener("mousemove", this._mouseMove.bind(this), false); doc.addEventListener("mousemove", this._mouseMove.bind(this), true);
doc.addEventListener("mousedown", this._hide.bind(this), false); doc.addEventListener("mousedown", this._hide.bind(this), true);
} }
WebInspector.Tooltip.Timing = { WebInspector.Tooltip.Timing = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment