| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Brian Grinstead All rights reserved. | 2 * Copyright (C) 2011 Brian Grinstead 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.Spectrum = class extends WebInspector.VBox { | 32 Components.Spectrum = class extends UI.VBox { |
| 33 constructor() { | 33 constructor() { |
| 34 /** | 34 /** |
| 35 * @param {!Element} parentElement | 35 * @param {!Element} parentElement |
| 36 */ | 36 */ |
| 37 function appendSwitcherIcon(parentElement) { | 37 function appendSwitcherIcon(parentElement) { |
| 38 var icon = parentElement.createSVGChild('svg'); | 38 var icon = parentElement.createSVGChild('svg'); |
| 39 icon.setAttribute('height', 16); | 39 icon.setAttribute('height', 16); |
| 40 icon.setAttribute('width', 16); | 40 icon.setAttribute('width', 16); |
| 41 var path = icon.createSVGChild('path'); | 41 var path = icon.createSVGChild('path'); |
| 42 path.setAttribute('d', 'M5,6 L11,6 L8,2 Z M5,10 L11,10 L8,14 Z'); | 42 path.setAttribute('d', 'M5,6 L11,6 L8,2 Z M5,10 L11,10 L8,14 Z'); |
| 43 return icon; | 43 return icon; |
| 44 } | 44 } |
| 45 | 45 |
| 46 super(true); | 46 super(true); |
| 47 this.registerRequiredCSS('components/spectrum.css'); | 47 this.registerRequiredCSS('components/spectrum.css'); |
| 48 this.contentElement.tabIndex = 0; | 48 this.contentElement.tabIndex = 0; |
| 49 this.setDefaultFocusedElement(this.contentElement); | 49 this.setDefaultFocusedElement(this.contentElement); |
| 50 | 50 |
| 51 this._colorElement = this.contentElement.createChild('div', 'spectrum-color'
); | 51 this._colorElement = this.contentElement.createChild('div', 'spectrum-color'
); |
| 52 this._colorDragElement = this._colorElement.createChild('div', 'spectrum-sat
fill') | 52 this._colorDragElement = this._colorElement.createChild('div', 'spectrum-sat
fill') |
| 53 .createChild('div', 'spectrum-val fill') | 53 .createChild('div', 'spectrum-val fill') |
| 54 .createChild('div', 'spectrum-dragger'); | 54 .createChild('div', 'spectrum-dragger'); |
| 55 var contrastRatioSVG = this._colorElement.createSVGChild('svg', 'spectrum-co
ntrast-container fill'); | 55 var contrastRatioSVG = this._colorElement.createSVGChild('svg', 'spectrum-co
ntrast-container fill'); |
| 56 this._contrastRatioLine = contrastRatioSVG.createSVGChild('path', 'spectrum-
contrast-line'); | 56 this._contrastRatioLine = contrastRatioSVG.createSVGChild('path', 'spectrum-
contrast-line'); |
| 57 | 57 |
| 58 var toolbar = new WebInspector.Toolbar('spectrum-eye-dropper', this.contentE
lement); | 58 var toolbar = new UI.Toolbar('spectrum-eye-dropper', this.contentElement); |
| 59 this._colorPickerButton = | 59 this._colorPickerButton = |
| 60 new WebInspector.ToolbarToggle(WebInspector.UIString('Toggle color picke
r'), 'largeicon-eyedropper'); | 60 new UI.ToolbarToggle(Common.UIString('Toggle color picker'), 'largeicon-
eyedropper'); |
| 61 this._colorPickerButton.setToggled(true); | 61 this._colorPickerButton.setToggled(true); |
| 62 this._colorPickerButton.addEventListener('click', this._toggleColorPicker.bi
nd(this, undefined)); | 62 this._colorPickerButton.addEventListener('click', this._toggleColorPicker.bi
nd(this, undefined)); |
| 63 toolbar.appendToolbarItem(this._colorPickerButton); | 63 toolbar.appendToolbarItem(this._colorPickerButton); |
| 64 | 64 |
| 65 var swatchElement = this.contentElement.createChild('span', 'swatch'); | 65 var swatchElement = this.contentElement.createChild('span', 'swatch'); |
| 66 this._swatchInnerElement = swatchElement.createChild('span', 'swatch-inner')
; | 66 this._swatchInnerElement = swatchElement.createChild('span', 'swatch-inner')
; |
| 67 | 67 |
| 68 this._hueElement = this.contentElement.createChild('div', 'spectrum-hue'); | 68 this._hueElement = this.contentElement.createChild('div', 'spectrum-hue'); |
| 69 this._hueSlider = this._hueElement.createChild('div', 'spectrum-slider'); | 69 this._hueSlider = this._hueElement.createChild('div', 'spectrum-slider'); |
| 70 this._alphaElement = this.contentElement.createChild('div', 'spectrum-alpha'
); | 70 this._alphaElement = this.contentElement.createChild('div', 'spectrum-alpha'
); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 this._hexContainer = this.contentElement.createChild('div', 'spectrum-text s
pectrum-text-hex source-code'); | 93 this._hexContainer = this.contentElement.createChild('div', 'spectrum-text s
pectrum-text-hex source-code'); |
| 94 this._hexValue = this._hexContainer.createChild('input', 'spectrum-text-valu
e'); | 94 this._hexValue = this._hexContainer.createChild('input', 'spectrum-text-valu
e'); |
| 95 this._hexValue.maxLength = 7; | 95 this._hexValue.maxLength = 7; |
| 96 this._hexValue.addEventListener('keydown', this._inputChanged.bind(this), fa
lse); | 96 this._hexValue.addEventListener('keydown', this._inputChanged.bind(this), fa
lse); |
| 97 this._hexValue.addEventListener('input', this._inputChanged.bind(this), fals
e); | 97 this._hexValue.addEventListener('input', this._inputChanged.bind(this), fals
e); |
| 98 this._hexValue.addEventListener('mousewheel', this._inputChanged.bind(this),
false); | 98 this._hexValue.addEventListener('mousewheel', this._inputChanged.bind(this),
false); |
| 99 | 99 |
| 100 var label = this._hexContainer.createChild('div', 'spectrum-text-label'); | 100 var label = this._hexContainer.createChild('div', 'spectrum-text-label'); |
| 101 label.textContent = 'HEX'; | 101 label.textContent = 'HEX'; |
| 102 | 102 |
| 103 WebInspector.installDragHandle( | 103 UI.installDragHandle( |
| 104 this._hueElement, dragStart.bind(this, positionHue.bind(this)), position
Hue.bind(this), null, 'default'); | 104 this._hueElement, dragStart.bind(this, positionHue.bind(this)), position
Hue.bind(this), null, 'default'); |
| 105 WebInspector.installDragHandle( | 105 UI.installDragHandle( |
| 106 this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), posi
tionAlpha.bind(this), null, 'default'); | 106 this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), posi
tionAlpha.bind(this), null, 'default'); |
| 107 WebInspector.installDragHandle( | 107 UI.installDragHandle( |
| 108 this._colorElement, dragStart.bind(this, positionColor.bind(this)), posi
tionColor.bind(this), null, 'default'); | 108 this._colorElement, dragStart.bind(this, positionColor.bind(this)), posi
tionColor.bind(this), null, 'default'); |
| 109 | 109 |
| 110 this.element.classList.add('palettes-enabled'); | 110 this.element.classList.add('palettes-enabled'); |
| 111 /** @type {!Map.<string, !WebInspector.Spectrum.Palette>} */ | 111 /** @type {!Map.<string, !Components.Spectrum.Palette>} */ |
| 112 this._palettes = new Map(); | 112 this._palettes = new Map(); |
| 113 this._palettePanel = this.contentElement.createChild('div', 'palette-panel')
; | 113 this._palettePanel = this.contentElement.createChild('div', 'palette-panel')
; |
| 114 this._palettePanelShowing = false; | 114 this._palettePanelShowing = false; |
| 115 this._paletteContainer = this.contentElement.createChild('div', 'spectrum-pa
lette'); | 115 this._paletteContainer = this.contentElement.createChild('div', 'spectrum-pa
lette'); |
| 116 this._paletteContainer.addEventListener('contextmenu', this._showPaletteColo
rContextMenu.bind(this, -1)); | 116 this._paletteContainer.addEventListener('contextmenu', this._showPaletteColo
rContextMenu.bind(this, -1)); |
| 117 this._shadesContainer = this.contentElement.createChild('div', 'palette-colo
r-shades hidden'); | 117 this._shadesContainer = this.contentElement.createChild('div', 'palette-colo
r-shades hidden'); |
| 118 WebInspector.installDragHandle( | 118 UI.installDragHandle( |
| 119 this._paletteContainer, this._paletteDragStart.bind(this), this._palette
Drag.bind(this), | 119 this._paletteContainer, this._paletteDragStart.bind(this), this._palette
Drag.bind(this), |
| 120 this._paletteDragEnd.bind(this), 'default'); | 120 this._paletteDragEnd.bind(this), 'default'); |
| 121 var paletteSwitcher = this.contentElement.createChild('div', 'spectrum-palet
te-switcher spectrum-switcher'); | 121 var paletteSwitcher = this.contentElement.createChild('div', 'spectrum-palet
te-switcher spectrum-switcher'); |
| 122 appendSwitcherIcon(paletteSwitcher); | 122 appendSwitcherIcon(paletteSwitcher); |
| 123 paletteSwitcher.addEventListener('click', this._togglePalettePanel.bind(this
, true)); | 123 paletteSwitcher.addEventListener('click', this._togglePalettePanel.bind(this
, true)); |
| 124 | 124 |
| 125 this._deleteIconToolbar = new WebInspector.Toolbar('delete-color-toolbar'); | 125 this._deleteIconToolbar = new UI.Toolbar('delete-color-toolbar'); |
| 126 this._deleteButton = new WebInspector.ToolbarButton('', 'largeicon-trash-bin
'); | 126 this._deleteButton = new UI.ToolbarButton('', 'largeicon-trash-bin'); |
| 127 this._deleteIconToolbar.appendToolbarItem(this._deleteButton); | 127 this._deleteIconToolbar.appendToolbarItem(this._deleteButton); |
| 128 | 128 |
| 129 var overlay = this.contentElement.createChild('div', 'spectrum-overlay fill'
); | 129 var overlay = this.contentElement.createChild('div', 'spectrum-overlay fill'
); |
| 130 overlay.addEventListener('click', this._togglePalettePanel.bind(this, false)
); | 130 overlay.addEventListener('click', this._togglePalettePanel.bind(this, false)
); |
| 131 | 131 |
| 132 this._addColorToolbar = new WebInspector.Toolbar('add-color-toolbar'); | 132 this._addColorToolbar = new UI.Toolbar('add-color-toolbar'); |
| 133 var addColorButton = new WebInspector.ToolbarButton(WebInspector.UIString('A
dd to palette'), 'largeicon-add'); | 133 var addColorButton = new UI.ToolbarButton(Common.UIString('Add to palette'),
'largeicon-add'); |
| 134 addColorButton.addEventListener('click', this._addColorToCustomPalette.bind(
this)); | 134 addColorButton.addEventListener('click', this._addColorToCustomPalette.bind(
this)); |
| 135 this._addColorToolbar.appendToolbarItem(addColorButton); | 135 this._addColorToolbar.appendToolbarItem(addColorButton); |
| 136 | 136 |
| 137 this._loadPalettes(); | 137 this._loadPalettes(); |
| 138 new WebInspector.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind
(this)); | 138 new Components.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(t
his)); |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * @param {function(!Event)} callback | 141 * @param {function(!Event)} callback |
| 142 * @param {!Event} event | 142 * @param {!Event} event |
| 143 * @return {boolean} | 143 * @return {boolean} |
| 144 * @this {WebInspector.Spectrum} | 144 * @this {Components.Spectrum} |
| 145 */ | 145 */ |
| 146 function dragStart(callback, event) { | 146 function dragStart(callback, event) { |
| 147 this._hueAlphaLeft = this._hueElement.totalOffsetLeft(); | 147 this._hueAlphaLeft = this._hueElement.totalOffsetLeft(); |
| 148 this._colorOffset = this._colorElement.totalOffset(); | 148 this._colorOffset = this._colorElement.totalOffset(); |
| 149 callback(event); | 149 callback(event); |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @param {!Event} event | 154 * @param {!Event} event |
| 155 * @this {WebInspector.Spectrum} | 155 * @this {Components.Spectrum} |
| 156 */ | 156 */ |
| 157 function positionHue(event) { | 157 function positionHue(event) { |
| 158 var hsva = this._hsv.slice(); | 158 var hsva = this._hsv.slice(); |
| 159 hsva[0] = Number.constrain(1 - (event.x - this._hueAlphaLeft) / this._hueA
lphaWidth, 0, 1); | 159 hsva[0] = Number.constrain(1 - (event.x - this._hueAlphaLeft) / this._hueA
lphaWidth, 0, 1); |
| 160 this._innerSetColor(hsva, '', undefined, WebInspector.Spectrum._ChangeSour
ce.Other); | 160 this._innerSetColor(hsva, '', undefined, Components.Spectrum._ChangeSource
.Other); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * @param {!Event} event | 164 * @param {!Event} event |
| 165 * @this {WebInspector.Spectrum} | 165 * @this {Components.Spectrum} |
| 166 */ | 166 */ |
| 167 function positionAlpha(event) { | 167 function positionAlpha(event) { |
| 168 var newAlpha = Math.round((event.x - this._hueAlphaLeft) / this._hueAlphaW
idth * 100) / 100; | 168 var newAlpha = Math.round((event.x - this._hueAlphaLeft) / this._hueAlphaW
idth * 100) / 100; |
| 169 var hsva = this._hsv.slice(); | 169 var hsva = this._hsv.slice(); |
| 170 hsva[3] = Number.constrain(newAlpha, 0, 1); | 170 hsva[3] = Number.constrain(newAlpha, 0, 1); |
| 171 var colorFormat = undefined; | 171 var colorFormat = undefined; |
| 172 if (hsva[3] !== 1 && (this._colorFormat === WebInspector.Color.Format.Shor
tHEX || | 172 if (hsva[3] !== 1 && (this._colorFormat === Common.Color.Format.ShortHEX |
| |
| 173 this._colorFormat === WebInspector.Color.Format.HEX
|| | 173 this._colorFormat === Common.Color.Format.HEX || |
| 174 this._colorFormat === WebInspector.Color.Format.Nick
name)) | 174 this._colorFormat === Common.Color.Format.Nickname)) |
| 175 colorFormat = WebInspector.Color.Format.RGB; | 175 colorFormat = Common.Color.Format.RGB; |
| 176 this._innerSetColor(hsva, '', colorFormat, WebInspector.Spectrum._ChangeSo
urce.Other); | 176 this._innerSetColor(hsva, '', colorFormat, Components.Spectrum._ChangeSour
ce.Other); |
| 177 } | 177 } |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * @param {!Event} event | 180 * @param {!Event} event |
| 181 * @this {WebInspector.Spectrum} | 181 * @this {Components.Spectrum} |
| 182 */ | 182 */ |
| 183 function positionColor(event) { | 183 function positionColor(event) { |
| 184 var hsva = this._hsv.slice(); | 184 var hsva = this._hsv.slice(); |
| 185 hsva[1] = Number.constrain((event.x - this._colorOffset.left) / this.dragW
idth, 0, 1); | 185 hsva[1] = Number.constrain((event.x - this._colorOffset.left) / this.dragW
idth, 0, 1); |
| 186 hsva[2] = Number.constrain(1 - (event.y - this._colorOffset.top) / this.dr
agHeight, 0, 1); | 186 hsva[2] = Number.constrain(1 - (event.y - this._colorOffset.top) / this.dr
agHeight, 0, 1); |
| 187 this._innerSetColor(hsva, '', undefined, WebInspector.Spectrum._ChangeSour
ce.Other); | 187 this._innerSetColor(hsva, '', undefined, Components.Spectrum._ChangeSource
.Other); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 _updatePalettePanel() { | 191 _updatePalettePanel() { |
| 192 this._palettePanel.removeChildren(); | 192 this._palettePanel.removeChildren(); |
| 193 var title = this._palettePanel.createChild('div', 'palette-title'); | 193 var title = this._palettePanel.createChild('div', 'palette-title'); |
| 194 title.textContent = WebInspector.UIString('Color Palettes'); | 194 title.textContent = Common.UIString('Color Palettes'); |
| 195 var toolbar = new WebInspector.Toolbar('', this._palettePanel); | 195 var toolbar = new UI.Toolbar('', this._palettePanel); |
| 196 var closeButton = new WebInspector.ToolbarButton('Return to color picker', '
largeicon-delete'); | 196 var closeButton = new UI.ToolbarButton('Return to color picker', 'largeicon-
delete'); |
| 197 closeButton.addEventListener('click', this._togglePalettePanel.bind(this, fa
lse)); | 197 closeButton.addEventListener('click', this._togglePalettePanel.bind(this, fa
lse)); |
| 198 toolbar.appendToolbarItem(closeButton); | 198 toolbar.appendToolbarItem(closeButton); |
| 199 for (var palette of this._palettes.values()) | 199 for (var palette of this._palettes.values()) |
| 200 this._palettePanel.appendChild(this._createPreviewPaletteElement(palette))
; | 200 this._palettePanel.appendChild(this._createPreviewPaletteElement(palette))
; |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * @param {boolean} show | 204 * @param {boolean} show |
| 205 */ | 205 */ |
| 206 _togglePalettePanel(show) { | 206 _togglePalettePanel(show) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 226 _createPaletteColor(colorText, animationDelay) { | 226 _createPaletteColor(colorText, animationDelay) { |
| 227 var element = createElementWithClass('div', 'spectrum-palette-color'); | 227 var element = createElementWithClass('div', 'spectrum-palette-color'); |
| 228 element.style.background = String.sprintf('linear-gradient(%s, %s), url(Imag
es/checker.png)', colorText, colorText); | 228 element.style.background = String.sprintf('linear-gradient(%s, %s), url(Imag
es/checker.png)', colorText, colorText); |
| 229 if (animationDelay) | 229 if (animationDelay) |
| 230 element.animate([{opacity: 0}, {opacity: 1}], {duration: 100, delay: anima
tionDelay, fill: 'backwards'}); | 230 element.animate([{opacity: 0}, {opacity: 1}], {duration: 100, delay: anima
tionDelay, fill: 'backwards'}); |
| 231 element.title = colorText; | 231 element.title = colorText; |
| 232 return element; | 232 return element; |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @param {!WebInspector.Spectrum.Palette} palette | 236 * @param {!Components.Spectrum.Palette} palette |
| 237 * @param {boolean} animate | 237 * @param {boolean} animate |
| 238 * @param {!Event=} event | 238 * @param {!Event=} event |
| 239 */ | 239 */ |
| 240 _showPalette(palette, animate, event) { | 240 _showPalette(palette, animate, event) { |
| 241 this._resizeForSelectedPalette(); | 241 this._resizeForSelectedPalette(); |
| 242 this._paletteContainer.removeChildren(); | 242 this._paletteContainer.removeChildren(); |
| 243 for (var i = 0; i < palette.colors.length; i++) { | 243 for (var i = 0; i < palette.colors.length; i++) { |
| 244 var animationDelay = animate ? i * 100 / palette.colors.length : 0; | 244 var animationDelay = animate ? i * 100 / palette.colors.length : 0; |
| 245 var colorElement = this._createPaletteColor(palette.colors[i], animationDe
lay); | 245 var colorElement = this._createPaletteColor(palette.colors[i], animationDe
lay); |
| 246 colorElement.addEventListener( | 246 colorElement.addEventListener( |
| 247 'mousedown', this._paletteColorSelected.bind(this, palette.colors[i],
palette.matchUserFormat)); | 247 'mousedown', this._paletteColorSelected.bind(this, palette.colors[i],
palette.matchUserFormat)); |
| 248 if (palette.mutable) { | 248 if (palette.mutable) { |
| 249 colorElement.__mutable = true; | 249 colorElement.__mutable = true; |
| 250 colorElement.__color = palette.colors[i]; | 250 colorElement.__color = palette.colors[i]; |
| 251 colorElement.addEventListener('contextmenu', this._showPaletteColorConte
xtMenu.bind(this, i)); | 251 colorElement.addEventListener('contextmenu', this._showPaletteColorConte
xtMenu.bind(this, i)); |
| 252 } else if (palette === WebInspector.Spectrum.MaterialPalette) { | 252 } else if (palette === Components.Spectrum.MaterialPalette) { |
| 253 colorElement.classList.add('has-material-shades'); | 253 colorElement.classList.add('has-material-shades'); |
| 254 var shadow = colorElement.createChild('div', 'spectrum-palette-color spe
ctrum-palette-color-shadow'); | 254 var shadow = colorElement.createChild('div', 'spectrum-palette-color spe
ctrum-palette-color-shadow'); |
| 255 shadow.style.background = palette.colors[i]; | 255 shadow.style.background = palette.colors[i]; |
| 256 shadow = colorElement.createChild('div', 'spectrum-palette-color spectru
m-palette-color-shadow'); | 256 shadow = colorElement.createChild('div', 'spectrum-palette-color spectru
m-palette-color-shadow'); |
| 257 shadow.style.background = palette.colors[i]; | 257 shadow.style.background = palette.colors[i]; |
| 258 colorElement.title = WebInspector.UIString(palette.colors[i] + '. Long-c
lick to show alternate shades.'); | 258 colorElement.title = Common.UIString(palette.colors[i] + '. Long-click t
o show alternate shades.'); |
| 259 new WebInspector.LongClickController( | 259 new UI.LongClickController( |
| 260 colorElement, this._showLightnessShades.bind(this, colorElement, pal
ette.colors[i])); | 260 colorElement, this._showLightnessShades.bind(this, colorElement, pal
ette.colors[i])); |
| 261 } | 261 } |
| 262 this._paletteContainer.appendChild(colorElement); | 262 this._paletteContainer.appendChild(colorElement); |
| 263 } | 263 } |
| 264 this._paletteContainerMutable = palette.mutable; | 264 this._paletteContainerMutable = palette.mutable; |
| 265 | 265 |
| 266 var numItems = palette.colors.length; | 266 var numItems = palette.colors.length; |
| 267 if (palette.mutable) | 267 if (palette.mutable) |
| 268 numItems++; | 268 numItems++; |
| 269 if (palette.mutable) { | 269 if (palette.mutable) { |
| 270 this._paletteContainer.appendChild(this._addColorToolbar.element); | 270 this._paletteContainer.appendChild(this._addColorToolbar.element); |
| 271 this._paletteContainer.appendChild(this._deleteIconToolbar.element); | 271 this._paletteContainer.appendChild(this._deleteIconToolbar.element); |
| 272 } else { | 272 } else { |
| 273 this._addColorToolbar.element.remove(); | 273 this._addColorToolbar.element.remove(); |
| 274 this._deleteIconToolbar.element.remove(); | 274 this._deleteIconToolbar.element.remove(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 this._togglePalettePanel(false); | 277 this._togglePalettePanel(false); |
| 278 this._focus(); | 278 this._focus(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * @param {!Element} colorElement | 282 * @param {!Element} colorElement |
| 283 * @param {string} colorText | 283 * @param {string} colorText |
| 284 * @param {!Event} event | 284 * @param {!Event} event |
| 285 */ | 285 */ |
| 286 _showLightnessShades(colorElement, colorText, event) { | 286 _showLightnessShades(colorElement, colorText, event) { |
| 287 /** | 287 /** |
| 288 * @param {!Element} element | 288 * @param {!Element} element |
| 289 * @this {!WebInspector.Spectrum} | 289 * @this {!Components.Spectrum} |
| 290 */ | 290 */ |
| 291 function closeLightnessShades(element) { | 291 function closeLightnessShades(element) { |
| 292 this._shadesContainer.classList.add('hidden'); | 292 this._shadesContainer.classList.add('hidden'); |
| 293 element.classList.remove('spectrum-shades-shown'); | 293 element.classList.remove('spectrum-shades-shown'); |
| 294 this._shadesContainer.ownerDocument.removeEventListener('mousedown', this.
_shadesCloseHandler, true); | 294 this._shadesContainer.ownerDocument.removeEventListener('mousedown', this.
_shadesCloseHandler, true); |
| 295 delete this._shadesCloseHandler; | 295 delete this._shadesCloseHandler; |
| 296 } | 296 } |
| 297 | 297 |
| 298 if (this._shadesCloseHandler) | 298 if (this._shadesCloseHandler) |
| 299 this._shadesCloseHandler(); | 299 this._shadesCloseHandler(); |
| 300 | 300 |
| 301 this._shadesContainer.classList.remove('hidden'); | 301 this._shadesContainer.classList.remove('hidden'); |
| 302 this._shadesContainer.removeChildren(); | 302 this._shadesContainer.removeChildren(); |
| 303 this._shadesContainer.animate( | 303 this._shadesContainer.animate( |
| 304 [{transform: 'scaleY(0)', opacity: '0'}, {transform: 'scaleY(1)', opacit
y: '1'}], | 304 [{transform: 'scaleY(0)', opacity: '0'}, {transform: 'scaleY(1)', opacit
y: '1'}], |
| 305 {duration: 200, easing: 'cubic-bezier(0.4, 0, 0.2, 1)'}); | 305 {duration: 200, easing: 'cubic-bezier(0.4, 0, 0.2, 1)'}); |
| 306 this._shadesContainer.style.top = colorElement.offsetTop + colorElement.pare
ntElement.offsetTop + 'px'; | 306 this._shadesContainer.style.top = colorElement.offsetTop + colorElement.pare
ntElement.offsetTop + 'px'; |
| 307 this._shadesContainer.style.left = colorElement.offsetLeft + 'px'; | 307 this._shadesContainer.style.left = colorElement.offsetLeft + 'px'; |
| 308 colorElement.classList.add('spectrum-shades-shown'); | 308 colorElement.classList.add('spectrum-shades-shown'); |
| 309 | 309 |
| 310 var shades = WebInspector.Spectrum.MaterialPaletteShades[colorText]; | 310 var shades = Components.Spectrum.MaterialPaletteShades[colorText]; |
| 311 for (var i = shades.length - 1; i >= 0; i--) { | 311 for (var i = shades.length - 1; i >= 0; i--) { |
| 312 var shadeElement = this._createPaletteColor(shades[i], i * 200 / shades.le
ngth + 100); | 312 var shadeElement = this._createPaletteColor(shades[i], i * 200 / shades.le
ngth + 100); |
| 313 shadeElement.addEventListener('mousedown', this._paletteColorSelected.bind
(this, shades[i], false)); | 313 shadeElement.addEventListener('mousedown', this._paletteColorSelected.bind
(this, shades[i], false)); |
| 314 this._shadesContainer.appendChild(shadeElement); | 314 this._shadesContainer.appendChild(shadeElement); |
| 315 } | 315 } |
| 316 | 316 |
| 317 this._shadesContainer.focus(); | 317 this._shadesContainer.focus(); |
| 318 this._shadesCloseHandler = closeLightnessShades.bind(this, colorElement); | 318 this._shadesCloseHandler = closeLightnessShades.bind(this, colorElement); |
| 319 this._shadesContainer.ownerDocument.addEventListener('mousedown', this._shad
esCloseHandler, true); | 319 this._shadesContainer.ownerDocument.addEventListener('mousedown', this._shad
esCloseHandler, true); |
| 320 } | 320 } |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * @param {!Event} e | 323 * @param {!Event} e |
| 324 * @return {number} | 324 * @return {number} |
| 325 */ | 325 */ |
| 326 _slotIndexForEvent(e) { | 326 _slotIndexForEvent(e) { |
| 327 var localX = e.pageX - this._paletteContainer.totalOffsetLeft(); | 327 var localX = e.pageX - this._paletteContainer.totalOffsetLeft(); |
| 328 var localY = e.pageY - this._paletteContainer.totalOffsetTop(); | 328 var localY = e.pageY - this._paletteContainer.totalOffsetTop(); |
| 329 var col = | 329 var col = |
| 330 Math.min(localX / WebInspector.Spectrum._colorChipSize | 0, WebInspector
.Spectrum._itemsPerPaletteRow - 1); | 330 Math.min(localX / Components.Spectrum._colorChipSize | 0, Components.Spe
ctrum._itemsPerPaletteRow - 1); |
| 331 var row = (localY / WebInspector.Spectrum._colorChipSize) | 0; | 331 var row = (localY / Components.Spectrum._colorChipSize) | 0; |
| 332 return Math.min( | 332 return Math.min( |
| 333 row * WebInspector.Spectrum._itemsPerPaletteRow + col, this._customPalet
teSetting.get().colors.length - 1); | 333 row * Components.Spectrum._itemsPerPaletteRow + col, this._customPalette
Setting.get().colors.length - 1); |
| 334 } | 334 } |
| 335 | 335 |
| 336 /** | 336 /** |
| 337 * @param {!Event} e | 337 * @param {!Event} e |
| 338 * @return {boolean} | 338 * @return {boolean} |
| 339 */ | 339 */ |
| 340 _isDraggingToBin(e) { | 340 _isDraggingToBin(e) { |
| 341 return e.pageX > this._deleteIconToolbar.element.totalOffsetLeft(); | 341 return e.pageX > this._deleteIconToolbar.element.totalOffsetLeft(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 /** | 344 /** |
| 345 * @param {!Event} e | 345 * @param {!Event} e |
| 346 * @return {boolean} | 346 * @return {boolean} |
| 347 */ | 347 */ |
| 348 _paletteDragStart(e) { | 348 _paletteDragStart(e) { |
| 349 var element = e.deepElementFromPoint(); | 349 var element = e.deepElementFromPoint(); |
| 350 if (!element || !element.__mutable) | 350 if (!element || !element.__mutable) |
| 351 return false; | 351 return false; |
| 352 | 352 |
| 353 var index = this._slotIndexForEvent(e); | 353 var index = this._slotIndexForEvent(e); |
| 354 this._dragElement = element; | 354 this._dragElement = element; |
| 355 this._dragHotSpotX = | 355 this._dragHotSpotX = |
| 356 e.pageX - (index % WebInspector.Spectrum._itemsPerPaletteRow) * WebInspe
ctor.Spectrum._colorChipSize; | 356 e.pageX - (index % Components.Spectrum._itemsPerPaletteRow) * Components
.Spectrum._colorChipSize; |
| 357 this._dragHotSpotY = | 357 this._dragHotSpotY = |
| 358 e.pageY - (index / WebInspector.Spectrum._itemsPerPaletteRow | 0) * WebI
nspector.Spectrum._colorChipSize; | 358 e.pageY - (index / Components.Spectrum._itemsPerPaletteRow | 0) * Compon
ents.Spectrum._colorChipSize; |
| 359 return true; | 359 return true; |
| 360 } | 360 } |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * @param {!Event} e | 363 * @param {!Event} e |
| 364 */ | 364 */ |
| 365 _paletteDrag(e) { | 365 _paletteDrag(e) { |
| 366 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this._pa
letteContainer.totalOffsetTop()) | 366 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this._pa
letteContainer.totalOffsetTop()) |
| 367 return; | 367 return; |
| 368 var newIndex = this._slotIndexForEvent(e); | 368 var newIndex = this._slotIndexForEvent(e); |
| 369 var offsetX = | 369 var offsetX = |
| 370 e.pageX - (newIndex % WebInspector.Spectrum._itemsPerPaletteRow) * WebIn
spector.Spectrum._colorChipSize; | 370 e.pageX - (newIndex % Components.Spectrum._itemsPerPaletteRow) * Compone
nts.Spectrum._colorChipSize; |
| 371 var offsetY = | 371 var offsetY = |
| 372 e.pageY - (newIndex / WebInspector.Spectrum._itemsPerPaletteRow | 0) * W
ebInspector.Spectrum._colorChipSize; | 372 e.pageY - (newIndex / Components.Spectrum._itemsPerPaletteRow | 0) * Com
ponents.Spectrum._colorChipSize; |
| 373 | 373 |
| 374 var isDeleting = this._isDraggingToBin(e); | 374 var isDeleting = this._isDraggingToBin(e); |
| 375 this._deleteIconToolbar.element.classList.add('dragging'); | 375 this._deleteIconToolbar.element.classList.add('dragging'); |
| 376 this._deleteIconToolbar.element.classList.toggle('delete-color-toolbar-activ
e', isDeleting); | 376 this._deleteIconToolbar.element.classList.toggle('delete-color-toolbar-activ
e', isDeleting); |
| 377 var dragElementTransform = | 377 var dragElementTransform = |
| 378 'translateX(' + (offsetX - this._dragHotSpotX) + 'px) translateY(' + (of
fsetY - this._dragHotSpotY) + 'px)'; | 378 'translateX(' + (offsetX - this._dragHotSpotX) + 'px) translateY(' + (of
fsetY - this._dragHotSpotY) + 'px)'; |
| 379 this._dragElement.style.transform = isDeleting ? dragElementTransform + ' sc
ale(0.8)' : dragElementTransform; | 379 this._dragElement.style.transform = isDeleting ? dragElementTransform + ' sc
ale(0.8)' : dragElementTransform; |
| 380 var children = Array.prototype.slice.call(this._paletteContainer.children); | 380 var children = Array.prototype.slice.call(this._paletteContainer.children); |
| 381 var index = children.indexOf(this._dragElement); | 381 var index = children.indexOf(this._dragElement); |
| 382 /** @type {!Map.<!Element, {left: number, top: number}>} */ | 382 /** @type {!Map.<!Element, {left: number, top: number}>} */ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 var palette = this._customPaletteSetting.get(); | 422 var palette = this._customPaletteSetting.get(); |
| 423 palette.colors = colors; | 423 palette.colors = colors; |
| 424 this._customPaletteSetting.set(palette); | 424 this._customPaletteSetting.set(palette); |
| 425 this._showPalette(this._customPaletteSetting.get(), false); | 425 this._showPalette(this._customPaletteSetting.get(), false); |
| 426 | 426 |
| 427 this._deleteIconToolbar.element.classList.remove('dragging'); | 427 this._deleteIconToolbar.element.classList.remove('dragging'); |
| 428 this._deleteIconToolbar.element.classList.remove('delete-color-toolbar-activ
e'); | 428 this._deleteIconToolbar.element.classList.remove('delete-color-toolbar-activ
e'); |
| 429 } | 429 } |
| 430 | 430 |
| 431 _loadPalettes() { | 431 _loadPalettes() { |
| 432 this._palettes.set(WebInspector.Spectrum.MaterialPalette.title, WebInspector
.Spectrum.MaterialPalette); | 432 this._palettes.set(Components.Spectrum.MaterialPalette.title, Components.Spe
ctrum.MaterialPalette); |
| 433 /** @type {!WebInspector.Spectrum.Palette} */ | 433 /** @type {!Components.Spectrum.Palette} */ |
| 434 var defaultCustomPalette = {title: 'Custom', colors: [], mutable: true}; | 434 var defaultCustomPalette = {title: 'Custom', colors: [], mutable: true}; |
| 435 this._customPaletteSetting = WebInspector.settings.createSetting('customColo
rPalette', defaultCustomPalette); | 435 this._customPaletteSetting = Common.settings.createSetting('customColorPalet
te', defaultCustomPalette); |
| 436 this._palettes.set(this._customPaletteSetting.get().title, this._customPalet
teSetting.get()); | 436 this._palettes.set(this._customPaletteSetting.get().title, this._customPalet
teSetting.get()); |
| 437 | 437 |
| 438 this._selectedColorPalette = | 438 this._selectedColorPalette = |
| 439 WebInspector.settings.createSetting('selectedColorPalette', WebInspector
.Spectrum.GeneratedPaletteTitle); | 439 Common.settings.createSetting('selectedColorPalette', Components.Spectru
m.GeneratedPaletteTitle); |
| 440 var palette = this._palettes.get(this._selectedColorPalette.get()); | 440 var palette = this._palettes.get(this._selectedColorPalette.get()); |
| 441 if (palette) | 441 if (palette) |
| 442 this._showPalette(palette, true); | 442 this._showPalette(palette, true); |
| 443 } | 443 } |
| 444 | 444 |
| 445 /** | 445 /** |
| 446 * @param {!WebInspector.Spectrum.Palette} generatedPalette | 446 * @param {!Components.Spectrum.Palette} generatedPalette |
| 447 */ | 447 */ |
| 448 _generatedPaletteLoaded(generatedPalette) { | 448 _generatedPaletteLoaded(generatedPalette) { |
| 449 if (generatedPalette.colors.length) | 449 if (generatedPalette.colors.length) |
| 450 this._palettes.set(generatedPalette.title, generatedPalette); | 450 this._palettes.set(generatedPalette.title, generatedPalette); |
| 451 if (this._selectedColorPalette.get() !== generatedPalette.title) { | 451 if (this._selectedColorPalette.get() !== generatedPalette.title) { |
| 452 return; | 452 return; |
| 453 } else if (!generatedPalette.colors.length) { | 453 } else if (!generatedPalette.colors.length) { |
| 454 this._paletteSelected(WebInspector.Spectrum.MaterialPalette); | 454 this._paletteSelected(Components.Spectrum.MaterialPalette); |
| 455 return; | 455 return; |
| 456 } | 456 } |
| 457 this._showPalette(generatedPalette, true); | 457 this._showPalette(generatedPalette, true); |
| 458 } | 458 } |
| 459 | 459 |
| 460 /** | 460 /** |
| 461 * @param {!WebInspector.Spectrum.Palette} palette | 461 * @param {!Components.Spectrum.Palette} palette |
| 462 * @return {!Element} | 462 * @return {!Element} |
| 463 */ | 463 */ |
| 464 _createPreviewPaletteElement(palette) { | 464 _createPreviewPaletteElement(palette) { |
| 465 var colorsPerPreviewRow = 5; | 465 var colorsPerPreviewRow = 5; |
| 466 var previewElement = createElementWithClass('div', 'palette-preview'); | 466 var previewElement = createElementWithClass('div', 'palette-preview'); |
| 467 var titleElement = previewElement.createChild('div', 'palette-preview-title'
); | 467 var titleElement = previewElement.createChild('div', 'palette-preview-title'
); |
| 468 titleElement.textContent = palette.title; | 468 titleElement.textContent = palette.title; |
| 469 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i++) | 469 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i++) |
| 470 previewElement.appendChild(this._createPaletteColor(palette.colors[i])); | 470 previewElement.appendChild(this._createPaletteColor(palette.colors[i])); |
| 471 for (; i < colorsPerPreviewRow; i++) | 471 for (; i < colorsPerPreviewRow; i++) |
| 472 previewElement.createChild('div', 'spectrum-palette-color empty-color'); | 472 previewElement.createChild('div', 'spectrum-palette-color empty-color'); |
| 473 previewElement.addEventListener('click', this._paletteSelected.bind(this, pa
lette)); | 473 previewElement.addEventListener('click', this._paletteSelected.bind(this, pa
lette)); |
| 474 return previewElement; | 474 return previewElement; |
| 475 } | 475 } |
| 476 | 476 |
| 477 /** | 477 /** |
| 478 * @param {!WebInspector.Spectrum.Palette} palette | 478 * @param {!Components.Spectrum.Palette} palette |
| 479 */ | 479 */ |
| 480 _paletteSelected(palette) { | 480 _paletteSelected(palette) { |
| 481 this._selectedColorPalette.set(palette.title); | 481 this._selectedColorPalette.set(palette.title); |
| 482 this._showPalette(palette, true); | 482 this._showPalette(palette, true); |
| 483 } | 483 } |
| 484 | 484 |
| 485 _resizeForSelectedPalette() { | 485 _resizeForSelectedPalette() { |
| 486 var palette = this._palettes.get(this._selectedColorPalette.get()); | 486 var palette = this._palettes.get(this._selectedColorPalette.get()); |
| 487 if (!palette) | 487 if (!palette) |
| 488 return; | 488 return; |
| 489 var numColors = palette.colors.length; | 489 var numColors = palette.colors.length; |
| 490 if (palette === this._customPaletteSetting.get()) | 490 if (palette === this._customPaletteSetting.get()) |
| 491 numColors++; | 491 numColors++; |
| 492 var rowsNeeded = Math.max(1, Math.ceil(numColors / WebInspector.Spectrum._it
emsPerPaletteRow)); | 492 var rowsNeeded = Math.max(1, Math.ceil(numColors / Components.Spectrum._item
sPerPaletteRow)); |
| 493 if (this._numPaletteRowsShown === rowsNeeded) | 493 if (this._numPaletteRowsShown === rowsNeeded) |
| 494 return; | 494 return; |
| 495 this._numPaletteRowsShown = rowsNeeded; | 495 this._numPaletteRowsShown = rowsNeeded; |
| 496 var paletteColorHeight = 12; | 496 var paletteColorHeight = 12; |
| 497 var paletteMargin = 12; | 497 var paletteMargin = 12; |
| 498 var paletteTop = 235; | 498 var paletteTop = 235; |
| 499 this.element.style.height = (paletteTop + paletteMargin + (paletteColorHeigh
t + paletteMargin) * rowsNeeded) + 'px'; | 499 this.element.style.height = (paletteTop + paletteMargin + (paletteColorHeigh
t + paletteMargin) * rowsNeeded) + 'px'; |
| 500 this.dispatchEventToListeners(WebInspector.Spectrum.Events.SizeChanged); | 500 this.dispatchEventToListeners(Components.Spectrum.Events.SizeChanged); |
| 501 } | 501 } |
| 502 | 502 |
| 503 /** | 503 /** |
| 504 * @param {string} colorText | 504 * @param {string} colorText |
| 505 * @param {boolean} matchUserFormat | 505 * @param {boolean} matchUserFormat |
| 506 */ | 506 */ |
| 507 _paletteColorSelected(colorText, matchUserFormat) { | 507 _paletteColorSelected(colorText, matchUserFormat) { |
| 508 var color = WebInspector.Color.parse(colorText); | 508 var color = Common.Color.parse(colorText); |
| 509 if (!color) | 509 if (!color) |
| 510 return; | 510 return; |
| 511 this._innerSetColor( | 511 this._innerSetColor( |
| 512 color.hsva(), colorText, matchUserFormat ? this._colorFormat : color.for
mat(), | 512 color.hsva(), colorText, matchUserFormat ? this._colorFormat : color.for
mat(), |
| 513 WebInspector.Spectrum._ChangeSource.Other); | 513 Components.Spectrum._ChangeSource.Other); |
| 514 } | 514 } |
| 515 | 515 |
| 516 _addColorToCustomPalette() { | 516 _addColorToCustomPalette() { |
| 517 var palette = this._customPaletteSetting.get(); | 517 var palette = this._customPaletteSetting.get(); |
| 518 palette.colors.push(this.colorString()); | 518 palette.colors.push(this.colorString()); |
| 519 this._customPaletteSetting.set(palette); | 519 this._customPaletteSetting.set(palette); |
| 520 this._showPalette(this._customPaletteSetting.get(), false); | 520 this._showPalette(this._customPaletteSetting.get(), false); |
| 521 } | 521 } |
| 522 | 522 |
| 523 /** | 523 /** |
| 524 * @param {number} colorIndex | 524 * @param {number} colorIndex |
| 525 * @param {!Event} event | 525 * @param {!Event} event |
| 526 */ | 526 */ |
| 527 _showPaletteColorContextMenu(colorIndex, event) { | 527 _showPaletteColorContextMenu(colorIndex, event) { |
| 528 if (!this._paletteContainerMutable) | 528 if (!this._paletteContainerMutable) |
| 529 return; | 529 return; |
| 530 var contextMenu = new WebInspector.ContextMenu(event); | 530 var contextMenu = new UI.ContextMenu(event); |
| 531 if (colorIndex !== -1) { | 531 if (colorIndex !== -1) { |
| 532 contextMenu.appendItem( | 532 contextMenu.appendItem( |
| 533 WebInspector.UIString('Remove color'), this._deletePaletteColors.bind(
this, colorIndex, false)); | 533 Common.UIString('Remove color'), this._deletePaletteColors.bind(this,
colorIndex, false)); |
| 534 contextMenu.appendItem( | 534 contextMenu.appendItem( |
| 535 WebInspector.UIString('Remove all to the right'), this._deletePaletteC
olors.bind(this, colorIndex, true)); | 535 Common.UIString('Remove all to the right'), this._deletePaletteColors.
bind(this, colorIndex, true)); |
| 536 } | 536 } |
| 537 contextMenu.appendItem(WebInspector.UIString('Clear palette'), this._deleteP
aletteColors.bind(this, -1, true)); | 537 contextMenu.appendItem(Common.UIString('Clear palette'), this._deletePalette
Colors.bind(this, -1, true)); |
| 538 contextMenu.show(); | 538 contextMenu.show(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 /** | 541 /** |
| 542 * @param {number} colorIndex | 542 * @param {number} colorIndex |
| 543 * @param {boolean} toRight | 543 * @param {boolean} toRight |
| 544 */ | 544 */ |
| 545 _deletePaletteColors(colorIndex, toRight) { | 545 _deletePaletteColors(colorIndex, toRight) { |
| 546 var palette = this._customPaletteSetting.get(); | 546 var palette = this._customPaletteSetting.get(); |
| 547 if (toRight) | 547 if (toRight) |
| 548 palette.colors.splice(colorIndex + 1, palette.colors.length - colorIndex -
1); | 548 palette.colors.splice(colorIndex + 1, palette.colors.length - colorIndex -
1); |
| 549 else | 549 else |
| 550 palette.colors.splice(colorIndex, 1); | 550 palette.colors.splice(colorIndex, 1); |
| 551 this._customPaletteSetting.set(palette); | 551 this._customPaletteSetting.set(palette); |
| 552 this._showPalette(this._customPaletteSetting.get(), false); | 552 this._showPalette(this._customPaletteSetting.get(), false); |
| 553 } | 553 } |
| 554 | 554 |
| 555 /** | 555 /** |
| 556 * @param {!WebInspector.Color} color | 556 * @param {!Common.Color} color |
| 557 * @param {string} colorFormat | 557 * @param {string} colorFormat |
| 558 */ | 558 */ |
| 559 setColor(color, colorFormat) { | 559 setColor(color, colorFormat) { |
| 560 this._originalFormat = colorFormat; | 560 this._originalFormat = colorFormat; |
| 561 this._innerSetColor(color.hsva(), '', colorFormat, WebInspector.Spectrum._Ch
angeSource.Model); | 561 this._innerSetColor(color.hsva(), '', colorFormat, Components.Spectrum._Chan
geSource.Model); |
| 562 } | 562 } |
| 563 | 563 |
| 564 /** | 564 /** |
| 565 * @param {!Array<number>|undefined} hsva | 565 * @param {!Array<number>|undefined} hsva |
| 566 * @param {string|undefined} colorString | 566 * @param {string|undefined} colorString |
| 567 * @param {string|undefined} colorFormat | 567 * @param {string|undefined} colorFormat |
| 568 * @param {string} changeSource | 568 * @param {string} changeSource |
| 569 */ | 569 */ |
| 570 _innerSetColor(hsva, colorString, colorFormat, changeSource) { | 570 _innerSetColor(hsva, colorString, colorFormat, changeSource) { |
| 571 if (hsva !== undefined) | 571 if (hsva !== undefined) |
| 572 this._hsv = hsva; | 572 this._hsv = hsva; |
| 573 if (colorString !== undefined) | 573 if (colorString !== undefined) |
| 574 this._colorString = colorString; | 574 this._colorString = colorString; |
| 575 if (colorFormat !== undefined) { | 575 if (colorFormat !== undefined) { |
| 576 console.assert(colorFormat !== WebInspector.Color.Format.Original, 'Spectr
um\'s color format cannot be Original'); | 576 console.assert(colorFormat !== Common.Color.Format.Original, 'Spectrum\'s
color format cannot be Original'); |
| 577 if (colorFormat === WebInspector.Color.Format.RGBA) | 577 if (colorFormat === Common.Color.Format.RGBA) |
| 578 colorFormat = WebInspector.Color.Format.RGB; | 578 colorFormat = Common.Color.Format.RGB; |
| 579 else if (colorFormat === WebInspector.Color.Format.HSLA) | 579 else if (colorFormat === Common.Color.Format.HSLA) |
| 580 colorFormat = WebInspector.Color.Format.HSL; | 580 colorFormat = Common.Color.Format.HSL; |
| 581 this._colorFormat = colorFormat; | 581 this._colorFormat = colorFormat; |
| 582 } | 582 } |
| 583 | 583 |
| 584 this._updateHelperLocations(); | 584 this._updateHelperLocations(); |
| 585 this._updateUI(); | 585 this._updateUI(); |
| 586 | 586 |
| 587 if (changeSource !== WebInspector.Spectrum._ChangeSource.Input) | 587 if (changeSource !== Components.Spectrum._ChangeSource.Input) |
| 588 this._updateInput(); | 588 this._updateInput(); |
| 589 if (changeSource !== WebInspector.Spectrum._ChangeSource.Model) | 589 if (changeSource !== Components.Spectrum._ChangeSource.Model) |
| 590 this.dispatchEventToListeners(WebInspector.Spectrum.Events.ColorChanged, t
his.colorString()); | 590 this.dispatchEventToListeners(Components.Spectrum.Events.ColorChanged, thi
s.colorString()); |
| 591 } | 591 } |
| 592 | 592 |
| 593 /** | 593 /** |
| 594 * @param {!WebInspector.Color} color | 594 * @param {!Common.Color} color |
| 595 */ | 595 */ |
| 596 setContrastColor(color) { | 596 setContrastColor(color) { |
| 597 this._contrastColor = color; | 597 this._contrastColor = color; |
| 598 this._updateUI(); | 598 this._updateUI(); |
| 599 } | 599 } |
| 600 | 600 |
| 601 /** | 601 /** |
| 602 * @return {!WebInspector.Color} | 602 * @return {!Common.Color} |
| 603 */ | 603 */ |
| 604 _color() { | 604 _color() { |
| 605 return WebInspector.Color.fromHSVA(this._hsv); | 605 return Common.Color.fromHSVA(this._hsv); |
| 606 } | 606 } |
| 607 | 607 |
| 608 /** | 608 /** |
| 609 * @return {string} | 609 * @return {string} |
| 610 */ | 610 */ |
| 611 colorString() { | 611 colorString() { |
| 612 if (this._colorString) | 612 if (this._colorString) |
| 613 return this._colorString; | 613 return this._colorString; |
| 614 var cf = WebInspector.Color.Format; | 614 var cf = Common.Color.Format; |
| 615 var color = this._color(); | 615 var color = this._color(); |
| 616 var colorString = color.asString(this._colorFormat); | 616 var colorString = color.asString(this._colorFormat); |
| 617 if (colorString) | 617 if (colorString) |
| 618 return colorString; | 618 return colorString; |
| 619 | 619 |
| 620 if (this._colorFormat === cf.Nickname || this._colorFormat === cf.ShortHEX)
{ | 620 if (this._colorFormat === cf.Nickname || this._colorFormat === cf.ShortHEX)
{ |
| 621 colorString = color.asString(cf.HEX); | 621 colorString = color.asString(cf.HEX); |
| 622 if (colorString) | 622 if (colorString) |
| 623 return colorString; | 623 return colorString; |
| 624 } | 624 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 648 this._colorDragElement.positionAt(dragX, dragY); | 648 this._colorDragElement.positionAt(dragX, dragY); |
| 649 | 649 |
| 650 // Where to show the bar that displays your current selected hue. | 650 // Where to show the bar that displays your current selected hue. |
| 651 var hueSlideX = (1 - h) * this._hueAlphaWidth - this.slideHelperWidth; | 651 var hueSlideX = (1 - h) * this._hueAlphaWidth - this.slideHelperWidth; |
| 652 this._hueSlider.style.left = hueSlideX + 'px'; | 652 this._hueSlider.style.left = hueSlideX + 'px'; |
| 653 var alphaSlideX = alpha * this._hueAlphaWidth - this.slideHelperWidth; | 653 var alphaSlideX = alpha * this._hueAlphaWidth - this.slideHelperWidth; |
| 654 this._alphaSlider.style.left = alphaSlideX + 'px'; | 654 this._alphaSlider.style.left = alphaSlideX + 'px'; |
| 655 } | 655 } |
| 656 | 656 |
| 657 _updateInput() { | 657 _updateInput() { |
| 658 var cf = WebInspector.Color.Format; | 658 var cf = Common.Color.Format; |
| 659 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX || thi
s._colorFormat === cf.Nickname) { | 659 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX || thi
s._colorFormat === cf.Nickname) { |
| 660 this._hexContainer.hidden = false; | 660 this._hexContainer.hidden = false; |
| 661 this._displayContainer.hidden = true; | 661 this._displayContainer.hidden = true; |
| 662 if (this._colorFormat === cf.ShortHEX && this._color().canBeShortHex()) | 662 if (this._colorFormat === cf.ShortHEX && this._color().canBeShortHex()) |
| 663 this._hexValue.value = this._color().asString(cf.ShortHEX); | 663 this._hexValue.value = this._color().asString(cf.ShortHEX); |
| 664 else | 664 else |
| 665 this._hexValue.value = this._color().asString(cf.HEX); | 665 this._hexValue.value = this._color().asString(cf.HEX); |
| 666 } else { | 666 } else { |
| 667 // RGBA, HSLA display. | 667 // RGBA, HSLA display. |
| 668 this._hexContainer.hidden = true; | 668 this._hexContainer.hidden = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 689 /** const */ var width = this.dragWidth; | 689 /** const */ var width = this.dragWidth; |
| 690 /** const */ var height = this.dragHeight; | 690 /** const */ var height = this.dragHeight; |
| 691 /** const */ var dS = 0.02; | 691 /** const */ var dS = 0.02; |
| 692 /** const */ var epsilon = 0.002; | 692 /** const */ var epsilon = 0.002; |
| 693 /** const */ var H = 0; | 693 /** const */ var H = 0; |
| 694 /** const */ var S = 1; | 694 /** const */ var S = 1; |
| 695 /** const */ var V = 2; | 695 /** const */ var V = 2; |
| 696 /** const */ var A = 3; | 696 /** const */ var A = 3; |
| 697 | 697 |
| 698 var fgRGBA = []; | 698 var fgRGBA = []; |
| 699 WebInspector.Color.hsva2rgba(this._hsv, fgRGBA); | 699 Common.Color.hsva2rgba(this._hsv, fgRGBA); |
| 700 var fgLuminance = WebInspector.Color.luminance(fgRGBA); | 700 var fgLuminance = Common.Color.luminance(fgRGBA); |
| 701 var bgRGBA = this._contrastColor.rgba(); | 701 var bgRGBA = this._contrastColor.rgba(); |
| 702 var bgLuminance = WebInspector.Color.luminance(bgRGBA); | 702 var bgLuminance = Common.Color.luminance(bgRGBA); |
| 703 var fgIsLighter = fgLuminance > bgLuminance; | 703 var fgIsLighter = fgLuminance > bgLuminance; |
| 704 var desiredLuminance = WebInspector.Color.desiredLuminance(bgLuminance, requ
iredContrast, fgIsLighter); | 704 var desiredLuminance = Common.Color.desiredLuminance(bgLuminance, requiredCo
ntrast, fgIsLighter); |
| 705 | 705 |
| 706 var lastV = this._hsv[V]; | 706 var lastV = this._hsv[V]; |
| 707 var currentSlope = 0; | 707 var currentSlope = 0; |
| 708 var candidateHSVA = [this._hsv[H], 0, 0, this._hsv[A]]; | 708 var candidateHSVA = [this._hsv[H], 0, 0, this._hsv[A]]; |
| 709 var pathBuilder = []; | 709 var pathBuilder = []; |
| 710 var candidateRGBA = []; | 710 var candidateRGBA = []; |
| 711 WebInspector.Color.hsva2rgba(candidateHSVA, candidateRGBA); | 711 Common.Color.hsva2rgba(candidateHSVA, candidateRGBA); |
| 712 var blendedRGBA = []; | 712 var blendedRGBA = []; |
| 713 WebInspector.Color.blendColors(candidateRGBA, bgRGBA, blendedRGBA); | 713 Common.Color.blendColors(candidateRGBA, bgRGBA, blendedRGBA); |
| 714 | 714 |
| 715 /** | 715 /** |
| 716 * Approach the desired contrast ratio by modifying the given component | 716 * Approach the desired contrast ratio by modifying the given component |
| 717 * from the given starting value. | 717 * from the given starting value. |
| 718 * @param {number} index | 718 * @param {number} index |
| 719 * @param {number} x | 719 * @param {number} x |
| 720 * @param {boolean} onAxis | 720 * @param {boolean} onAxis |
| 721 * @return {?number} | 721 * @return {?number} |
| 722 */ | 722 */ |
| 723 function approach(index, x, onAxis) { | 723 function approach(index, x, onAxis) { |
| 724 while (0 <= x && x <= 1) { | 724 while (0 <= x && x <= 1) { |
| 725 candidateHSVA[index] = x; | 725 candidateHSVA[index] = x; |
| 726 WebInspector.Color.hsva2rgba(candidateHSVA, candidateRGBA); | 726 Common.Color.hsva2rgba(candidateHSVA, candidateRGBA); |
| 727 WebInspector.Color.blendColors(candidateRGBA, bgRGBA, blendedRGBA); | 727 Common.Color.blendColors(candidateRGBA, bgRGBA, blendedRGBA); |
| 728 var fgLuminance = WebInspector.Color.luminance(blendedRGBA); | 728 var fgLuminance = Common.Color.luminance(blendedRGBA); |
| 729 var dLuminance = fgLuminance - desiredLuminance; | 729 var dLuminance = fgLuminance - desiredLuminance; |
| 730 | 730 |
| 731 if (Math.abs(dLuminance) < (onAxis ? epsilon / 10 : epsilon)) | 731 if (Math.abs(dLuminance) < (onAxis ? epsilon / 10 : epsilon)) |
| 732 return x; | 732 return x; |
| 733 else | 733 else |
| 734 x += (index === V ? -dLuminance : dLuminance); | 734 x += (index === V ? -dLuminance : dLuminance); |
| 735 } | 735 } |
| 736 return null; | 736 return null; |
| 737 } | 737 } |
| 738 | 738 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 759 candidateHSVA[V] = 1; | 759 candidateHSVA[V] = 1; |
| 760 s = approach(S, s, true); | 760 s = approach(S, s, true); |
| 761 if (s !== null) | 761 if (s !== null) |
| 762 pathBuilder = pathBuilder.concat(['L', s * width, -1]); | 762 pathBuilder = pathBuilder.concat(['L', s * width, -1]); |
| 763 } | 763 } |
| 764 | 764 |
| 765 this._contrastRatioLine.setAttribute('d', pathBuilder.join(' ')); | 765 this._contrastRatioLine.setAttribute('d', pathBuilder.join(' ')); |
| 766 } | 766 } |
| 767 | 767 |
| 768 _updateUI() { | 768 _updateUI() { |
| 769 var h = WebInspector.Color.fromHSVA([this._hsv[0], 1, 1, 1]); | 769 var h = Common.Color.fromHSVA([this._hsv[0], 1, 1, 1]); |
| 770 this._colorElement.style.backgroundColor = /** @type {string} */ (h.asString
(WebInspector.Color.Format.RGB)); | 770 this._colorElement.style.backgroundColor = /** @type {string} */ (h.asString
(Common.Color.Format.RGB)); |
| 771 if (Runtime.experiments.isEnabled('colorContrastRatio')) { | 771 if (Runtime.experiments.isEnabled('colorContrastRatio')) { |
| 772 // TODO(samli): Determine size of text and switch between AA/AAA ratings. | 772 // TODO(samli): Determine size of text and switch between AA/AAA ratings. |
| 773 this._drawContrastRatioLine(4.5); | 773 this._drawContrastRatioLine(4.5); |
| 774 } | 774 } |
| 775 this._swatchInnerElement.style.backgroundColor = | 775 this._swatchInnerElement.style.backgroundColor = |
| 776 /** @type {string} */ (this._color().asString(WebInspector.Color.Format.
RGBA)); | 776 /** @type {string} */ (this._color().asString(Common.Color.Format.RGBA))
; |
| 777 // Show border if the swatch is white. | 777 // Show border if the swatch is white. |
| 778 this._swatchInnerElement.classList.toggle('swatch-inner-white', this._color(
).hsla()[2] > 0.9); | 778 this._swatchInnerElement.classList.toggle('swatch-inner-white', this._color(
).hsla()[2] > 0.9); |
| 779 this._colorDragElement.style.backgroundColor = | 779 this._colorDragElement.style.backgroundColor = |
| 780 /** @type {string} */ (this._color().asString(WebInspector.Color.Format.
RGBA)); | 780 /** @type {string} */ (this._color().asString(Common.Color.Format.RGBA))
; |
| 781 var noAlpha = WebInspector.Color.fromHSVA(this._hsv.slice(0, 3).concat(1)); | 781 var noAlpha = Common.Color.fromHSVA(this._hsv.slice(0, 3).concat(1)); |
| 782 this._alphaElementBackground.style.backgroundImage = | 782 this._alphaElementBackground.style.backgroundImage = |
| 783 String.sprintf('linear-gradient(to right, rgba(0,0,0,0), %s)', noAlpha.a
sString(WebInspector.Color.Format.RGB)); | 783 String.sprintf('linear-gradient(to right, rgba(0,0,0,0), %s)', noAlpha.a
sString(Common.Color.Format.RGB)); |
| 784 } | 784 } |
| 785 | 785 |
| 786 _formatViewSwitch() { | 786 _formatViewSwitch() { |
| 787 var cf = WebInspector.Color.Format; | 787 var cf = Common.Color.Format; |
| 788 var format = cf.RGB; | 788 var format = cf.RGB; |
| 789 if (this._colorFormat === cf.RGB) | 789 if (this._colorFormat === cf.RGB) |
| 790 format = cf.HSL; | 790 format = cf.HSL; |
| 791 else if (this._colorFormat === cf.HSL && !this._color().hasAlpha()) | 791 else if (this._colorFormat === cf.HSL && !this._color().hasAlpha()) |
| 792 format = this._originalFormat === cf.ShortHEX ? cf.ShortHEX : cf.HEX; | 792 format = this._originalFormat === cf.ShortHEX ? cf.ShortHEX : cf.HEX; |
| 793 this._innerSetColor(undefined, '', format, WebInspector.Spectrum._ChangeSour
ce.Other); | 793 this._innerSetColor(undefined, '', format, Components.Spectrum._ChangeSource
.Other); |
| 794 } | 794 } |
| 795 | 795 |
| 796 /** | 796 /** |
| 797 * @param {!Event} event | 797 * @param {!Event} event |
| 798 */ | 798 */ |
| 799 _inputChanged(event) { | 799 _inputChanged(event) { |
| 800 /** | 800 /** |
| 801 * @param {!Element} element | 801 * @param {!Element} element |
| 802 * @return {string} | 802 * @return {string} |
| 803 */ | 803 */ |
| 804 function elementValue(element) { | 804 function elementValue(element) { |
| 805 return element.value; | 805 return element.value; |
| 806 } | 806 } |
| 807 | 807 |
| 808 var inputElement = /** @type {!Element} */ (event.currentTarget); | 808 var inputElement = /** @type {!Element} */ (event.currentTarget); |
| 809 var newValue = WebInspector.createReplacementString(inputElement.value, even
t); | 809 var newValue = UI.createReplacementString(inputElement.value, event); |
| 810 if (newValue) { | 810 if (newValue) { |
| 811 inputElement.value = newValue; | 811 inputElement.value = newValue; |
| 812 inputElement.selectionStart = 0; | 812 inputElement.selectionStart = 0; |
| 813 inputElement.selectionEnd = newValue.length; | 813 inputElement.selectionEnd = newValue.length; |
| 814 event.consume(true); | 814 event.consume(true); |
| 815 } | 815 } |
| 816 | 816 |
| 817 const cf = WebInspector.Color.Format; | 817 const cf = Common.Color.Format; |
| 818 var colorString; | 818 var colorString; |
| 819 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) { | 819 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) { |
| 820 colorString = this._hexValue.value; | 820 colorString = this._hexValue.value; |
| 821 } else { | 821 } else { |
| 822 var format = this._colorFormat === cf.RGB ? 'rgba' : 'hsla'; | 822 var format = this._colorFormat === cf.RGB ? 'rgba' : 'hsla'; |
| 823 var values = this._textValues.map(elementValue).join(', '); | 823 var values = this._textValues.map(elementValue).join(', '); |
| 824 colorString = String.sprintf('%s(%s)', format, values); | 824 colorString = String.sprintf('%s(%s)', format, values); |
| 825 } | 825 } |
| 826 | 826 |
| 827 var color = WebInspector.Color.parse(colorString); | 827 var color = Common.Color.parse(colorString); |
| 828 if (!color) | 828 if (!color) |
| 829 return; | 829 return; |
| 830 var hsv = color.hsva(); | 830 var hsv = color.hsva(); |
| 831 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) | 831 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) |
| 832 this._colorFormat = color.canBeShortHex() ? cf.ShortHEX : cf.HEX; | 832 this._colorFormat = color.canBeShortHex() ? cf.ShortHEX : cf.HEX; |
| 833 this._innerSetColor(hsv, colorString, undefined, WebInspector.Spectrum._Chan
geSource.Input); | 833 this._innerSetColor(hsv, colorString, undefined, Components.Spectrum._Change
Source.Input); |
| 834 } | 834 } |
| 835 | 835 |
| 836 /** | 836 /** |
| 837 * @override | 837 * @override |
| 838 */ | 838 */ |
| 839 wasShown() { | 839 wasShown() { |
| 840 this._hueAlphaWidth = this._hueElement.offsetWidth; | 840 this._hueAlphaWidth = this._hueElement.offsetWidth; |
| 841 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; | 841 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; |
| 842 this.dragWidth = this._colorElement.offsetWidth; | 842 this.dragWidth = this._colorElement.offsetWidth; |
| 843 this.dragHeight = this._colorElement.offsetHeight; | 843 this.dragHeight = this._colorElement.offsetHeight; |
| 844 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; | 844 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; |
| 845 this._innerSetColor(undefined, undefined, undefined, WebInspector.Spectrum._
ChangeSource.Model); | 845 this._innerSetColor(undefined, undefined, undefined, Components.Spectrum._Ch
angeSource.Model); |
| 846 this._toggleColorPicker(true); | 846 this._toggleColorPicker(true); |
| 847 WebInspector.targetManager.addModelListener( | 847 SDK.targetManager.addModelListener( |
| 848 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Co
lorPicked, this._colorPicked, this); | 848 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); |
| 849 } | 849 } |
| 850 | 850 |
| 851 /** | 851 /** |
| 852 * @override | 852 * @override |
| 853 */ | 853 */ |
| 854 willHide() { | 854 willHide() { |
| 855 this._toggleColorPicker(false); | 855 this._toggleColorPicker(false); |
| 856 WebInspector.targetManager.removeModelListener( | 856 SDK.targetManager.removeModelListener( |
| 857 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Co
lorPicked, this._colorPicked, this); | 857 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); |
| 858 } | 858 } |
| 859 | 859 |
| 860 /** | 860 /** |
| 861 * @param {boolean=} enabled | 861 * @param {boolean=} enabled |
| 862 * @param {!WebInspector.Event=} event | 862 * @param {!Common.Event=} event |
| 863 */ | 863 */ |
| 864 _toggleColorPicker(enabled, event) { | 864 _toggleColorPicker(enabled, event) { |
| 865 if (enabled === undefined) | 865 if (enabled === undefined) |
| 866 enabled = !this._colorPickerButton.toggled(); | 866 enabled = !this._colorPickerButton.toggled(); |
| 867 this._colorPickerButton.setToggled(enabled); | 867 this._colorPickerButton.setToggled(enabled); |
| 868 for (var target of WebInspector.targetManager.targets()) | 868 for (var target of SDK.targetManager.targets()) |
| 869 target.pageAgent().setColorPickerEnabled(enabled); | 869 target.pageAgent().setColorPickerEnabled(enabled); |
| 870 } | 870 } |
| 871 | 871 |
| 872 /** | 872 /** |
| 873 * @param {!WebInspector.Event} event | 873 * @param {!Common.Event} event |
| 874 */ | 874 */ |
| 875 _colorPicked(event) { | 875 _colorPicked(event) { |
| 876 var rgbColor = /** @type {!Protocol.DOM.RGBA} */ (event.data); | 876 var rgbColor = /** @type {!Protocol.DOM.RGBA} */ (event.data); |
| 877 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; | 877 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; |
| 878 var color = WebInspector.Color.fromRGBA(rgba); | 878 var color = Common.Color.fromRGBA(rgba); |
| 879 this._innerSetColor(color.hsva(), '', undefined, WebInspector.Spectrum._Chan
geSource.Other); | 879 this._innerSetColor(color.hsva(), '', undefined, Components.Spectrum._Change
Source.Other); |
| 880 InspectorFrontendHost.bringToFront(); | 880 InspectorFrontendHost.bringToFront(); |
| 881 } | 881 } |
| 882 }; | 882 }; |
| 883 | 883 |
| 884 WebInspector.Spectrum._ChangeSource = { | 884 Components.Spectrum._ChangeSource = { |
| 885 Input: 'Input', | 885 Input: 'Input', |
| 886 Model: 'Model', | 886 Model: 'Model', |
| 887 Other: 'Other' | 887 Other: 'Other' |
| 888 }; | 888 }; |
| 889 | 889 |
| 890 /** @enum {symbol} */ | 890 /** @enum {symbol} */ |
| 891 WebInspector.Spectrum.Events = { | 891 Components.Spectrum.Events = { |
| 892 ColorChanged: Symbol('ColorChanged'), | 892 ColorChanged: Symbol('ColorChanged'), |
| 893 SizeChanged: Symbol('SizeChanged') | 893 SizeChanged: Symbol('SizeChanged') |
| 894 }; | 894 }; |
| 895 | 895 |
| 896 WebInspector.Spectrum._colorChipSize = 24; | 896 Components.Spectrum._colorChipSize = 24; |
| 897 WebInspector.Spectrum._itemsPerPaletteRow = 8; | 897 Components.Spectrum._itemsPerPaletteRow = 8; |
| 898 | 898 |
| 899 /** @typedef {{ title: string, colors: !Array.<string>, mutable: boolean }} */ | 899 /** @typedef {{ title: string, colors: !Array.<string>, mutable: boolean }} */ |
| 900 WebInspector.Spectrum.Palette; | 900 Components.Spectrum.Palette; |
| 901 WebInspector.Spectrum.GeneratedPaletteTitle = 'Page colors'; | 901 Components.Spectrum.GeneratedPaletteTitle = 'Page colors'; |
| 902 | 902 |
| 903 /** | 903 /** |
| 904 * @unrestricted | 904 * @unrestricted |
| 905 */ | 905 */ |
| 906 WebInspector.Spectrum.PaletteGenerator = class { | 906 Components.Spectrum.PaletteGenerator = class { |
| 907 /** | 907 /** |
| 908 * @param {function(!WebInspector.Spectrum.Palette)} callback | 908 * @param {function(!Components.Spectrum.Palette)} callback |
| 909 */ | 909 */ |
| 910 constructor(callback) { | 910 constructor(callback) { |
| 911 this._callback = callback; | 911 this._callback = callback; |
| 912 /** @type {!Map.<string, number>} */ | 912 /** @type {!Map.<string, number>} */ |
| 913 this._frequencyMap = new Map(); | 913 this._frequencyMap = new Map(); |
| 914 var stylesheetPromises = []; | 914 var stylesheetPromises = []; |
| 915 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.DOM)) { | 915 for (var target of SDK.targetManager.targets(SDK.Target.Capability.DOM)) { |
| 916 var cssModel = WebInspector.CSSModel.fromTarget(target); | 916 var cssModel = SDK.CSSModel.fromTarget(target); |
| 917 for (var stylesheet of cssModel.allStyleSheets()) | 917 for (var stylesheet of cssModel.allStyleSheets()) |
| 918 stylesheetPromises.push(new Promise(this._processStylesheet.bind(this, s
tylesheet))); | 918 stylesheetPromises.push(new Promise(this._processStylesheet.bind(this, s
tylesheet))); |
| 919 } | 919 } |
| 920 Promise.all(stylesheetPromises).catchException(null).then(this._finish.bind(
this)); | 920 Promise.all(stylesheetPromises).catchException(null).then(this._finish.bind(
this)); |
| 921 } | 921 } |
| 922 | 922 |
| 923 /** | 923 /** |
| 924 * @param {string} a | 924 * @param {string} a |
| 925 * @param {string} b | 925 * @param {string} b |
| 926 * @return {number} | 926 * @return {number} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 949 | 949 |
| 950 // Equal hue -> sort by sat | 950 // Equal hue -> sort by sat |
| 951 if (hsvb[0] === hsva[0]) | 951 if (hsvb[0] === hsva[0]) |
| 952 return hsvb[1] * hsvb[3] - hsva[1] * hsva[3]; | 952 return hsvb[1] * hsvb[3] - hsva[1] * hsva[3]; |
| 953 | 953 |
| 954 return (hsvb[0] + 0.94) % 1 - (hsva[0] + 0.94) % 1; | 954 return (hsvb[0] + 0.94) % 1 - (hsva[0] + 0.94) % 1; |
| 955 } | 955 } |
| 956 | 956 |
| 957 var colors = this._frequencyMap.keysArray(); | 957 var colors = this._frequencyMap.keysArray(); |
| 958 colors = colors.sort(this._frequencyComparator.bind(this)); | 958 colors = colors.sort(this._frequencyComparator.bind(this)); |
| 959 /** @type {!Map.<string, !WebInspector.Color>} */ | 959 /** @type {!Map.<string, !Common.Color>} */ |
| 960 var paletteColors = new Map(); | 960 var paletteColors = new Map(); |
| 961 var colorsPerRow = 24; | 961 var colorsPerRow = 24; |
| 962 while (paletteColors.size < colorsPerRow && colors.length) { | 962 while (paletteColors.size < colorsPerRow && colors.length) { |
| 963 var colorText = colors.shift(); | 963 var colorText = colors.shift(); |
| 964 var color = WebInspector.Color.parse(colorText); | 964 var color = Common.Color.parse(colorText); |
| 965 if (!color || color.nickname() === 'white' || color.nickname() === 'black'
) | 965 if (!color || color.nickname() === 'white' || color.nickname() === 'black'
) |
| 966 continue; | 966 continue; |
| 967 paletteColors.set(colorText, color); | 967 paletteColors.set(colorText, color); |
| 968 } | 968 } |
| 969 | 969 |
| 970 this._callback({ | 970 this._callback({ |
| 971 title: WebInspector.Spectrum.GeneratedPaletteTitle, | 971 title: Components.Spectrum.GeneratedPaletteTitle, |
| 972 colors: paletteColors.keysArray().sort(hueComparator), | 972 colors: paletteColors.keysArray().sort(hueComparator), |
| 973 mutable: false | 973 mutable: false |
| 974 }); | 974 }); |
| 975 } | 975 } |
| 976 | 976 |
| 977 /** | 977 /** |
| 978 * @param {!WebInspector.CSSStyleSheetHeader} stylesheet | 978 * @param {!SDK.CSSStyleSheetHeader} stylesheet |
| 979 * @param {function(?)} resolve | 979 * @param {function(?)} resolve |
| 980 * @this {WebInspector.Spectrum.PaletteGenerator} | 980 * @this {Components.Spectrum.PaletteGenerator} |
| 981 */ | 981 */ |
| 982 _processStylesheet(stylesheet, resolve) { | 982 _processStylesheet(stylesheet, resolve) { |
| 983 /** | 983 /** |
| 984 * @param {?string} text | 984 * @param {?string} text |
| 985 * @this {WebInspector.Spectrum.PaletteGenerator} | 985 * @this {Components.Spectrum.PaletteGenerator} |
| 986 */ | 986 */ |
| 987 function parseContent(text) { | 987 function parseContent(text) { |
| 988 text = text.toLowerCase(); | 988 text = text.toLowerCase(); |
| 989 var regexResult = text.match(/((?:rgb|hsl)a?\([^)]+\)|#[0-9a-f]{6}|#[0-9a-
f]{3})/g) || []; | 989 var regexResult = text.match(/((?:rgb|hsl)a?\([^)]+\)|#[0-9a-f]{6}|#[0-9a-
f]{3})/g) || []; |
| 990 for (var c of regexResult) { | 990 for (var c of regexResult) { |
| 991 var frequency = this._frequencyMap.get(c) || 0; | 991 var frequency = this._frequencyMap.get(c) || 0; |
| 992 this._frequencyMap.set(c, ++frequency); | 992 this._frequencyMap.set(c, ++frequency); |
| 993 } | 993 } |
| 994 resolve(null); | 994 resolve(null); |
| 995 } | 995 } |
| 996 | 996 |
| 997 stylesheet.requestContent().then(parseContent.bind(this)); | 997 stylesheet.requestContent().then(parseContent.bind(this)); |
| 998 } | 998 } |
| 999 }; | 999 }; |
| 1000 | 1000 |
| 1001 WebInspector.Spectrum.MaterialPaletteShades = { | 1001 Components.Spectrum.MaterialPaletteShades = { |
| 1002 '#F44336': | 1002 '#F44336': |
| 1003 ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E5393
5', '#D32F2F', '#C62828', '#B71C1C'], | 1003 ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E5393
5', '#D32F2F', '#C62828', '#B71C1C'], |
| 1004 '#E91E63': | 1004 '#E91E63': |
| 1005 ['#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B6
0', '#C2185B', '#AD1457', '#880E4F'], | 1005 ['#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B6
0', '#C2185B', '#AD1457', '#880E4F'], |
| 1006 '#9C27B0': | 1006 '#9C27B0': |
| 1007 ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24A
A', '#7B1FA2', '#6A1B9A', '#4A148C'], | 1007 ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24A
A', '#7B1FA2', '#6A1B9A', '#4A148C'], |
| 1008 '#673AB7': | 1008 '#673AB7': |
| 1009 ['#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B
1', '#512DA8', '#4527A0', '#311B92'], | 1009 ['#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B
1', '#512DA8', '#4527A0', '#311B92'], |
| 1010 '#3F51B5': | 1010 '#3F51B5': |
| 1011 ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949A
B', '#303F9F', '#283593', '#1A237E'], | 1011 ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949A
B', '#303F9F', '#283593', '#1A237E'], |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1032 '#FF5722': | 1032 '#FF5722': |
| 1033 ['#FBE9E7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511
E', '#E64A19', '#D84315', '#BF360C'], | 1033 ['#FBE9E7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511
E', '#E64A19', '#D84315', '#BF360C'], |
| 1034 '#795548': | 1034 '#795548': |
| 1035 ['#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C4
1', '#5D4037', '#4E342E', '#3E2723'], | 1035 ['#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C4
1', '#5D4037', '#4E342E', '#3E2723'], |
| 1036 '#9E9E9E': | 1036 '#9E9E9E': |
| 1037 ['#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#75757
5', '#616161', '#424242', '#212121'], | 1037 ['#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#75757
5', '#616161', '#424242', '#212121'], |
| 1038 '#607D8B': | 1038 '#607D8B': |
| 1039 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] | 1039 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] |
| 1040 }; | 1040 }; |
| 1041 | 1041 |
| 1042 WebInspector.Spectrum.MaterialPalette = { | 1042 Components.Spectrum.MaterialPalette = { |
| 1043 title: 'Material', | 1043 title: 'Material', |
| 1044 mutable: false, | 1044 mutable: false, |
| 1045 matchUserFormat: true, | 1045 matchUserFormat: true, |
| 1046 colors: Object.keys(WebInspector.Spectrum.MaterialPaletteShades) | 1046 colors: Object.keys(Components.Spectrum.MaterialPaletteShades) |
| 1047 }; | 1047 }; |
| OLD | NEW |