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 Components.Spectrum = class extends UI.VBox { | 32 Spectrum.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('spectrum/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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 label.textContent = 'HEX'; | 107 label.textContent = 'HEX'; |
108 | 108 |
109 UI.installDragHandle( | 109 UI.installDragHandle( |
110 this._hueElement, dragStart.bind(this, positionHue.bind(this)), position
Hue.bind(this), null, 'default'); | 110 this._hueElement, dragStart.bind(this, positionHue.bind(this)), position
Hue.bind(this), null, 'default'); |
111 UI.installDragHandle( | 111 UI.installDragHandle( |
112 this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), posi
tionAlpha.bind(this), null, 'default'); | 112 this._alphaElement, dragStart.bind(this, positionAlpha.bind(this)), posi
tionAlpha.bind(this), null, 'default'); |
113 UI.installDragHandle( | 113 UI.installDragHandle( |
114 this._colorElement, dragStart.bind(this, positionColor.bind(this)), posi
tionColor.bind(this), null, 'default'); | 114 this._colorElement, dragStart.bind(this, positionColor.bind(this)), posi
tionColor.bind(this), null, 'default'); |
115 | 115 |
116 this.element.classList.add('palettes-enabled'); | 116 this.element.classList.add('palettes-enabled'); |
117 /** @type {!Map.<string, !Components.Spectrum.Palette>} */ | 117 /** @type {!Map.<string, !Spectrum.Spectrum.Palette>} */ |
118 this._palettes = new Map(); | 118 this._palettes = new Map(); |
119 this._palettePanel = this.contentElement.createChild('div', 'palette-panel')
; | 119 this._palettePanel = this.contentElement.createChild('div', 'palette-panel')
; |
120 this._palettePanelShowing = false; | 120 this._palettePanelShowing = false; |
121 this._paletteContainer = this.contentElement.createChild('div', 'spectrum-pa
lette'); | 121 this._paletteContainer = this.contentElement.createChild('div', 'spectrum-pa
lette'); |
122 this._paletteContainer.addEventListener('contextmenu', this._showPaletteColo
rContextMenu.bind(this, -1)); | 122 this._paletteContainer.addEventListener('contextmenu', this._showPaletteColo
rContextMenu.bind(this, -1)); |
123 this._shadesContainer = this.contentElement.createChild('div', 'palette-colo
r-shades hidden'); | 123 this._shadesContainer = this.contentElement.createChild('div', 'palette-colo
r-shades hidden'); |
124 UI.installDragHandle( | 124 UI.installDragHandle( |
125 this._paletteContainer, this._paletteDragStart.bind(this), this._palette
Drag.bind(this), | 125 this._paletteContainer, this._paletteDragStart.bind(this), this._palette
Drag.bind(this), |
126 this._paletteDragEnd.bind(this), 'default'); | 126 this._paletteDragEnd.bind(this), 'default'); |
127 var paletteSwitcher = this.contentElement.createChild('div', 'spectrum-palet
te-switcher spectrum-switcher'); | 127 var paletteSwitcher = this.contentElement.createChild('div', 'spectrum-palet
te-switcher spectrum-switcher'); |
128 appendSwitcherIcon(paletteSwitcher); | 128 appendSwitcherIcon(paletteSwitcher); |
129 paletteSwitcher.addEventListener('click', this._togglePalettePanel.bind(this
, true)); | 129 paletteSwitcher.addEventListener('click', this._togglePalettePanel.bind(this
, true)); |
130 | 130 |
131 this._deleteIconToolbar = new UI.Toolbar('delete-color-toolbar'); | 131 this._deleteIconToolbar = new UI.Toolbar('delete-color-toolbar'); |
132 this._deleteButton = new UI.ToolbarButton('', 'largeicon-trash-bin'); | 132 this._deleteButton = new UI.ToolbarButton('', 'largeicon-trash-bin'); |
133 this._deleteIconToolbar.appendToolbarItem(this._deleteButton); | 133 this._deleteIconToolbar.appendToolbarItem(this._deleteButton); |
134 | 134 |
135 var overlay = this.contentElement.createChild('div', 'spectrum-overlay fill'
); | 135 var overlay = this.contentElement.createChild('div', 'spectrum-overlay fill'
); |
136 overlay.addEventListener('click', this._togglePalettePanel.bind(this, false)
); | 136 overlay.addEventListener('click', this._togglePalettePanel.bind(this, false)
); |
137 | 137 |
138 this._addColorToolbar = new UI.Toolbar('add-color-toolbar'); | 138 this._addColorToolbar = new UI.Toolbar('add-color-toolbar'); |
139 var addColorButton = new UI.ToolbarButton(Common.UIString('Add to palette'),
'largeicon-add'); | 139 var addColorButton = new UI.ToolbarButton(Common.UIString('Add to palette'),
'largeicon-add'); |
140 addColorButton.addEventListener(UI.ToolbarButton.Events.Click, this._addColo
rToCustomPalette, this); | 140 addColorButton.addEventListener(UI.ToolbarButton.Events.Click, this._addColo
rToCustomPalette, this); |
141 this._addColorToolbar.appendToolbarItem(addColorButton); | 141 this._addColorToolbar.appendToolbarItem(addColorButton); |
142 | 142 |
143 this._loadPalettes(); | 143 this._loadPalettes(); |
144 new Components.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(t
his)); | 144 new Spectrum.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(thi
s)); |
145 | 145 |
146 /** | 146 /** |
147 * @param {function(!Event)} callback | 147 * @param {function(!Event)} callback |
148 * @param {!Event} event | 148 * @param {!Event} event |
149 * @return {boolean} | 149 * @return {boolean} |
150 * @this {Components.Spectrum} | 150 * @this {Spectrum.Spectrum} |
151 */ | 151 */ |
152 function dragStart(callback, event) { | 152 function dragStart(callback, event) { |
153 this._hueAlphaLeft = this._hueElement.totalOffsetLeft(); | 153 this._hueAlphaLeft = this._hueElement.totalOffsetLeft(); |
154 this._colorOffset = this._colorElement.totalOffset(); | 154 this._colorOffset = this._colorElement.totalOffset(); |
155 callback(event); | 155 callback(event); |
156 return true; | 156 return true; |
157 } | 157 } |
158 | 158 |
159 /** | 159 /** |
160 * @param {!Event} event | 160 * @param {!Event} event |
161 * @this {Components.Spectrum} | 161 * @this {Spectrum.Spectrum} |
162 */ | 162 */ |
163 function positionHue(event) { | 163 function positionHue(event) { |
164 var hsva = this._hsv.slice(); | 164 var hsva = this._hsv.slice(); |
165 hsva[0] = Number.constrain(1 - (event.x - this._hueAlphaLeft) / this._hueA
lphaWidth, 0, 1); | 165 hsva[0] = Number.constrain(1 - (event.x - this._hueAlphaLeft) / this._hueA
lphaWidth, 0, 1); |
166 this._innerSetColor(hsva, '', undefined, Components.Spectrum._ChangeSource
.Other); | 166 this._innerSetColor(hsva, '', undefined, Spectrum.Spectrum._ChangeSource.O
ther); |
167 } | 167 } |
168 | 168 |
169 /** | 169 /** |
170 * @param {!Event} event | 170 * @param {!Event} event |
171 * @this {Components.Spectrum} | 171 * @this {Spectrum.Spectrum} |
172 */ | 172 */ |
173 function positionAlpha(event) { | 173 function positionAlpha(event) { |
174 var newAlpha = Math.round((event.x - this._hueAlphaLeft) / this._hueAlphaW
idth * 100) / 100; | 174 var newAlpha = Math.round((event.x - this._hueAlphaLeft) / this._hueAlphaW
idth * 100) / 100; |
175 var hsva = this._hsv.slice(); | 175 var hsva = this._hsv.slice(); |
176 hsva[3] = Number.constrain(newAlpha, 0, 1); | 176 hsva[3] = Number.constrain(newAlpha, 0, 1); |
177 var colorFormat = undefined; | 177 var colorFormat = undefined; |
178 if (hsva[3] !== 1 && | 178 if (hsva[3] !== 1 && |
179 (this._colorFormat === Common.Color.Format.ShortHEX || this._colorForm
at === Common.Color.Format.HEX || | 179 (this._colorFormat === Common.Color.Format.ShortHEX || this._colorForm
at === Common.Color.Format.HEX || |
180 this._colorFormat === Common.Color.Format.Nickname)) | 180 this._colorFormat === Common.Color.Format.Nickname)) |
181 colorFormat = Common.Color.Format.RGB; | 181 colorFormat = Common.Color.Format.RGB; |
182 this._innerSetColor(hsva, '', colorFormat, Components.Spectrum._ChangeSour
ce.Other); | 182 this._innerSetColor(hsva, '', colorFormat, Spectrum.Spectrum._ChangeSource
.Other); |
183 } | 183 } |
184 | 184 |
185 /** | 185 /** |
186 * @param {!Event} event | 186 * @param {!Event} event |
187 * @this {Components.Spectrum} | 187 * @this {Spectrum.Spectrum} |
188 */ | 188 */ |
189 function positionColor(event) { | 189 function positionColor(event) { |
190 var hsva = this._hsv.slice(); | 190 var hsva = this._hsv.slice(); |
191 hsva[1] = Number.constrain((event.x - this._colorOffset.left) / this.dragW
idth, 0, 1); | 191 hsva[1] = Number.constrain((event.x - this._colorOffset.left) / this.dragW
idth, 0, 1); |
192 hsva[2] = Number.constrain(1 - (event.y - this._colorOffset.top) / this.dr
agHeight, 0, 1); | 192 hsva[2] = Number.constrain(1 - (event.y - this._colorOffset.top) / this.dr
agHeight, 0, 1); |
193 this._innerSetColor(hsva, '', undefined, Components.Spectrum._ChangeSource
.Other); | 193 this._innerSetColor(hsva, '', undefined, Spectrum.Spectrum._ChangeSource.O
ther); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 _onCopyIconClick() { | 197 _onCopyIconClick() { |
198 this._swatchCopyIcon.setIconType('largeicon-checkmark'); | 198 this._swatchCopyIcon.setIconType('largeicon-checkmark'); |
199 InspectorFrontendHost.copyText(this.colorString()); | 199 InspectorFrontendHost.copyText(this.colorString()); |
200 } | 200 } |
201 | 201 |
202 _onCopyIconMouseout() { | 202 _onCopyIconMouseout() { |
203 this._swatchCopyIcon.setIconType('largeicon-copy'); | 203 this._swatchCopyIcon.setIconType('largeicon-copy'); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 _createPaletteColor(colorText, animationDelay) { | 241 _createPaletteColor(colorText, animationDelay) { |
242 var element = createElementWithClass('div', 'spectrum-palette-color'); | 242 var element = createElementWithClass('div', 'spectrum-palette-color'); |
243 element.style.background = String.sprintf('linear-gradient(%s, %s), url(Imag
es/checker.png)', colorText, colorText); | 243 element.style.background = String.sprintf('linear-gradient(%s, %s), url(Imag
es/checker.png)', colorText, colorText); |
244 if (animationDelay) | 244 if (animationDelay) |
245 element.animate([{opacity: 0}, {opacity: 1}], {duration: 100, delay: anima
tionDelay, fill: 'backwards'}); | 245 element.animate([{opacity: 0}, {opacity: 1}], {duration: 100, delay: anima
tionDelay, fill: 'backwards'}); |
246 element.title = colorText; | 246 element.title = colorText; |
247 return element; | 247 return element; |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * @param {!Components.Spectrum.Palette} palette | 251 * @param {!Spectrum.Spectrum.Palette} palette |
252 * @param {boolean} animate | 252 * @param {boolean} animate |
253 * @param {!Event=} event | 253 * @param {!Event=} event |
254 */ | 254 */ |
255 _showPalette(palette, animate, event) { | 255 _showPalette(palette, animate, event) { |
256 this._resizeForSelectedPalette(); | 256 this._resizeForSelectedPalette(); |
257 this._paletteContainer.removeChildren(); | 257 this._paletteContainer.removeChildren(); |
258 for (var i = 0; i < palette.colors.length; i++) { | 258 for (var i = 0; i < palette.colors.length; i++) { |
259 var animationDelay = animate ? i * 100 / palette.colors.length : 0; | 259 var animationDelay = animate ? i * 100 / palette.colors.length : 0; |
260 var colorElement = this._createPaletteColor(palette.colors[i], animationDe
lay); | 260 var colorElement = this._createPaletteColor(palette.colors[i], animationDe
lay); |
261 colorElement.addEventListener( | 261 colorElement.addEventListener( |
262 'mousedown', this._paletteColorSelected.bind(this, palette.colors[i],
palette.matchUserFormat)); | 262 'mousedown', this._paletteColorSelected.bind(this, palette.colors[i],
palette.matchUserFormat)); |
263 if (palette.mutable) { | 263 if (palette.mutable) { |
264 colorElement.__mutable = true; | 264 colorElement.__mutable = true; |
265 colorElement.__color = palette.colors[i]; | 265 colorElement.__color = palette.colors[i]; |
266 colorElement.addEventListener('contextmenu', this._showPaletteColorConte
xtMenu.bind(this, i)); | 266 colorElement.addEventListener('contextmenu', this._showPaletteColorConte
xtMenu.bind(this, i)); |
267 } else if (palette === Components.Spectrum.MaterialPalette) { | 267 } else if (palette === Spectrum.Spectrum.MaterialPalette) { |
268 colorElement.classList.add('has-material-shades'); | 268 colorElement.classList.add('has-material-shades'); |
269 var shadow = colorElement.createChild('div', 'spectrum-palette-color spe
ctrum-palette-color-shadow'); | 269 var shadow = colorElement.createChild('div', 'spectrum-palette-color spe
ctrum-palette-color-shadow'); |
270 shadow.style.background = palette.colors[i]; | 270 shadow.style.background = palette.colors[i]; |
271 shadow = colorElement.createChild('div', 'spectrum-palette-color spectru
m-palette-color-shadow'); | 271 shadow = colorElement.createChild('div', 'spectrum-palette-color spectru
m-palette-color-shadow'); |
272 shadow.style.background = palette.colors[i]; | 272 shadow.style.background = palette.colors[i]; |
273 colorElement.title = Common.UIString(palette.colors[i] + '. Long-click t
o show alternate shades.'); | 273 colorElement.title = Common.UIString(palette.colors[i] + '. Long-click t
o show alternate shades.'); |
274 new UI.LongClickController(colorElement, this._showLightnessShades.bind(
this, colorElement, palette.colors[i])); | 274 new UI.LongClickController(colorElement, this._showLightnessShades.bind(
this, colorElement, palette.colors[i])); |
275 } | 275 } |
276 this._paletteContainer.appendChild(colorElement); | 276 this._paletteContainer.appendChild(colorElement); |
277 } | 277 } |
(...skipping 12 matching lines...) Expand all Loading... |
290 } | 290 } |
291 | 291 |
292 /** | 292 /** |
293 * @param {!Element} colorElement | 293 * @param {!Element} colorElement |
294 * @param {string} colorText | 294 * @param {string} colorText |
295 * @param {!Event} event | 295 * @param {!Event} event |
296 */ | 296 */ |
297 _showLightnessShades(colorElement, colorText, event) { | 297 _showLightnessShades(colorElement, colorText, event) { |
298 /** | 298 /** |
299 * @param {!Element} element | 299 * @param {!Element} element |
300 * @this {!Components.Spectrum} | 300 * @this {!Spectrum.Spectrum} |
301 */ | 301 */ |
302 function closeLightnessShades(element) { | 302 function closeLightnessShades(element) { |
303 this._shadesContainer.classList.add('hidden'); | 303 this._shadesContainer.classList.add('hidden'); |
304 element.classList.remove('spectrum-shades-shown'); | 304 element.classList.remove('spectrum-shades-shown'); |
305 this._shadesContainer.ownerDocument.removeEventListener('mousedown', this.
_shadesCloseHandler, true); | 305 this._shadesContainer.ownerDocument.removeEventListener('mousedown', this.
_shadesCloseHandler, true); |
306 delete this._shadesCloseHandler; | 306 delete this._shadesCloseHandler; |
307 } | 307 } |
308 | 308 |
309 if (this._shadesCloseHandler) | 309 if (this._shadesCloseHandler) |
310 this._shadesCloseHandler(); | 310 this._shadesCloseHandler(); |
311 | 311 |
312 this._shadesContainer.classList.remove('hidden'); | 312 this._shadesContainer.classList.remove('hidden'); |
313 this._shadesContainer.removeChildren(); | 313 this._shadesContainer.removeChildren(); |
314 this._shadesContainer.animate( | 314 this._shadesContainer.animate( |
315 [{transform: 'scaleY(0)', opacity: '0'}, {transform: 'scaleY(1)', opacit
y: '1'}], | 315 [{transform: 'scaleY(0)', opacity: '0'}, {transform: 'scaleY(1)', opacit
y: '1'}], |
316 {duration: 200, easing: 'cubic-bezier(0.4, 0, 0.2, 1)'}); | 316 {duration: 200, easing: 'cubic-bezier(0.4, 0, 0.2, 1)'}); |
317 this._shadesContainer.style.top = colorElement.offsetTop + colorElement.pare
ntElement.offsetTop + 'px'; | 317 this._shadesContainer.style.top = colorElement.offsetTop + colorElement.pare
ntElement.offsetTop + 'px'; |
318 this._shadesContainer.style.left = colorElement.offsetLeft + 'px'; | 318 this._shadesContainer.style.left = colorElement.offsetLeft + 'px'; |
319 colorElement.classList.add('spectrum-shades-shown'); | 319 colorElement.classList.add('spectrum-shades-shown'); |
320 | 320 |
321 var shades = Components.Spectrum.MaterialPaletteShades[colorText]; | 321 var shades = Spectrum.Spectrum.MaterialPaletteShades[colorText]; |
322 for (var i = shades.length - 1; i >= 0; i--) { | 322 for (var i = shades.length - 1; i >= 0; i--) { |
323 var shadeElement = this._createPaletteColor(shades[i], i * 200 / shades.le
ngth + 100); | 323 var shadeElement = this._createPaletteColor(shades[i], i * 200 / shades.le
ngth + 100); |
324 shadeElement.addEventListener('mousedown', this._paletteColorSelected.bind
(this, shades[i], false)); | 324 shadeElement.addEventListener('mousedown', this._paletteColorSelected.bind
(this, shades[i], false)); |
325 this._shadesContainer.appendChild(shadeElement); | 325 this._shadesContainer.appendChild(shadeElement); |
326 } | 326 } |
327 | 327 |
328 this._shadesContainer.focus(); | 328 this._shadesContainer.focus(); |
329 this._shadesCloseHandler = closeLightnessShades.bind(this, colorElement); | 329 this._shadesCloseHandler = closeLightnessShades.bind(this, colorElement); |
330 this._shadesContainer.ownerDocument.addEventListener('mousedown', this._shad
esCloseHandler, true); | 330 this._shadesContainer.ownerDocument.addEventListener('mousedown', this._shad
esCloseHandler, true); |
331 } | 331 } |
332 | 332 |
333 /** | 333 /** |
334 * @param {!Event} e | 334 * @param {!Event} e |
335 * @return {number} | 335 * @return {number} |
336 */ | 336 */ |
337 _slotIndexForEvent(e) { | 337 _slotIndexForEvent(e) { |
338 var localX = e.pageX - this._paletteContainer.totalOffsetLeft(); | 338 var localX = e.pageX - this._paletteContainer.totalOffsetLeft(); |
339 var localY = e.pageY - this._paletteContainer.totalOffsetTop(); | 339 var localY = e.pageY - this._paletteContainer.totalOffsetTop(); |
340 var col = Math.min(localX / Components.Spectrum._colorChipSize | 0, Componen
ts.Spectrum._itemsPerPaletteRow - 1); | 340 var col = Math.min(localX / Spectrum.Spectrum._colorChipSize | 0, Spectrum.S
pectrum._itemsPerPaletteRow - 1); |
341 var row = (localY / Components.Spectrum._colorChipSize) | 0; | 341 var row = (localY / Spectrum.Spectrum._colorChipSize) | 0; |
342 return Math.min( | 342 return Math.min( |
343 row * Components.Spectrum._itemsPerPaletteRow + col, this._customPalette
Setting.get().colors.length - 1); | 343 row * Spectrum.Spectrum._itemsPerPaletteRow + col, this._customPaletteSe
tting.get().colors.length - 1); |
344 } | 344 } |
345 | 345 |
346 /** | 346 /** |
347 * @param {!Event} e | 347 * @param {!Event} e |
348 * @return {boolean} | 348 * @return {boolean} |
349 */ | 349 */ |
350 _isDraggingToBin(e) { | 350 _isDraggingToBin(e) { |
351 return e.pageX > this._deleteIconToolbar.element.totalOffsetLeft(); | 351 return e.pageX > this._deleteIconToolbar.element.totalOffsetLeft(); |
352 } | 352 } |
353 | 353 |
354 /** | 354 /** |
355 * @param {!Event} e | 355 * @param {!Event} e |
356 * @return {boolean} | 356 * @return {boolean} |
357 */ | 357 */ |
358 _paletteDragStart(e) { | 358 _paletteDragStart(e) { |
359 var element = e.deepElementFromPoint(); | 359 var element = e.deepElementFromPoint(); |
360 if (!element || !element.__mutable) | 360 if (!element || !element.__mutable) |
361 return false; | 361 return false; |
362 | 362 |
363 var index = this._slotIndexForEvent(e); | 363 var index = this._slotIndexForEvent(e); |
364 this._dragElement = element; | 364 this._dragElement = element; |
365 this._dragHotSpotX = | 365 this._dragHotSpotX = e.pageX - (index % Spectrum.Spectrum._itemsPerPaletteRo
w) * Spectrum.Spectrum._colorChipSize; |
366 e.pageX - (index % Components.Spectrum._itemsPerPaletteRow) * Components
.Spectrum._colorChipSize; | |
367 this._dragHotSpotY = | 366 this._dragHotSpotY = |
368 e.pageY - (index / Components.Spectrum._itemsPerPaletteRow | 0) * Compon
ents.Spectrum._colorChipSize; | 367 e.pageY - (index / Spectrum.Spectrum._itemsPerPaletteRow | 0) * Spectrum
.Spectrum._colorChipSize; |
369 return true; | 368 return true; |
370 } | 369 } |
371 | 370 |
372 /** | 371 /** |
373 * @param {!Event} e | 372 * @param {!Event} e |
374 */ | 373 */ |
375 _paletteDrag(e) { | 374 _paletteDrag(e) { |
376 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this._pa
letteContainer.totalOffsetTop()) | 375 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this._pa
letteContainer.totalOffsetTop()) |
377 return; | 376 return; |
378 var newIndex = this._slotIndexForEvent(e); | 377 var newIndex = this._slotIndexForEvent(e); |
379 var offsetX = e.pageX - (newIndex % Components.Spectrum._itemsPerPaletteRow)
* Components.Spectrum._colorChipSize; | 378 var offsetX = e.pageX - (newIndex % Spectrum.Spectrum._itemsPerPaletteRow) *
Spectrum.Spectrum._colorChipSize; |
380 var offsetY = | 379 var offsetY = e.pageY - (newIndex / Spectrum.Spectrum._itemsPerPaletteRow |
0) * Spectrum.Spectrum._colorChipSize; |
381 e.pageY - (newIndex / Components.Spectrum._itemsPerPaletteRow | 0) * Com
ponents.Spectrum._colorChipSize; | |
382 | 380 |
383 var isDeleting = this._isDraggingToBin(e); | 381 var isDeleting = this._isDraggingToBin(e); |
384 this._deleteIconToolbar.element.classList.add('dragging'); | 382 this._deleteIconToolbar.element.classList.add('dragging'); |
385 this._deleteIconToolbar.element.classList.toggle('delete-color-toolbar-activ
e', isDeleting); | 383 this._deleteIconToolbar.element.classList.toggle('delete-color-toolbar-activ
e', isDeleting); |
386 var dragElementTransform = | 384 var dragElementTransform = |
387 'translateX(' + (offsetX - this._dragHotSpotX) + 'px) translateY(' + (of
fsetY - this._dragHotSpotY) + 'px)'; | 385 'translateX(' + (offsetX - this._dragHotSpotX) + 'px) translateY(' + (of
fsetY - this._dragHotSpotY) + 'px)'; |
388 this._dragElement.style.transform = isDeleting ? dragElementTransform + ' sc
ale(0.8)' : dragElementTransform; | 386 this._dragElement.style.transform = isDeleting ? dragElementTransform + ' sc
ale(0.8)' : dragElementTransform; |
389 var children = Array.prototype.slice.call(this._paletteContainer.children); | 387 var children = Array.prototype.slice.call(this._paletteContainer.children); |
390 var index = children.indexOf(this._dragElement); | 388 var index = children.indexOf(this._dragElement); |
391 /** @type {!Map.<!Element, {left: number, top: number}>} */ | 389 /** @type {!Map.<!Element, {left: number, top: number}>} */ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 var palette = this._customPaletteSetting.get(); | 429 var palette = this._customPaletteSetting.get(); |
432 palette.colors = colors; | 430 palette.colors = colors; |
433 this._customPaletteSetting.set(palette); | 431 this._customPaletteSetting.set(palette); |
434 this._showPalette(this._customPaletteSetting.get(), false); | 432 this._showPalette(this._customPaletteSetting.get(), false); |
435 | 433 |
436 this._deleteIconToolbar.element.classList.remove('dragging'); | 434 this._deleteIconToolbar.element.classList.remove('dragging'); |
437 this._deleteIconToolbar.element.classList.remove('delete-color-toolbar-activ
e'); | 435 this._deleteIconToolbar.element.classList.remove('delete-color-toolbar-activ
e'); |
438 } | 436 } |
439 | 437 |
440 _loadPalettes() { | 438 _loadPalettes() { |
441 this._palettes.set(Components.Spectrum.MaterialPalette.title, Components.Spe
ctrum.MaterialPalette); | 439 this._palettes.set(Spectrum.Spectrum.MaterialPalette.title, Spectrum.Spectru
m.MaterialPalette); |
442 /** @type {!Components.Spectrum.Palette} */ | 440 /** @type {!Spectrum.Spectrum.Palette} */ |
443 var defaultCustomPalette = {title: 'Custom', colors: [], mutable: true}; | 441 var defaultCustomPalette = {title: 'Custom', colors: [], mutable: true}; |
444 this._customPaletteSetting = Common.settings.createSetting('customColorPalet
te', defaultCustomPalette); | 442 this._customPaletteSetting = Common.settings.createSetting('customColorPalet
te', defaultCustomPalette); |
445 this._palettes.set(this._customPaletteSetting.get().title, this._customPalet
teSetting.get()); | 443 this._palettes.set(this._customPaletteSetting.get().title, this._customPalet
teSetting.get()); |
446 | 444 |
447 this._selectedColorPalette = | 445 this._selectedColorPalette = |
448 Common.settings.createSetting('selectedColorPalette', Components.Spectru
m.GeneratedPaletteTitle); | 446 Common.settings.createSetting('selectedColorPalette', Spectrum.Spectrum.
GeneratedPaletteTitle); |
449 var palette = this._palettes.get(this._selectedColorPalette.get()); | 447 var palette = this._palettes.get(this._selectedColorPalette.get()); |
450 if (palette) | 448 if (palette) |
451 this._showPalette(palette, true); | 449 this._showPalette(palette, true); |
452 } | 450 } |
453 | 451 |
454 /** | 452 /** |
455 * @param {!Components.Spectrum.Palette} generatedPalette | 453 * @param {!Spectrum.Spectrum.Palette} generatedPalette |
456 */ | 454 */ |
457 _generatedPaletteLoaded(generatedPalette) { | 455 _generatedPaletteLoaded(generatedPalette) { |
458 if (generatedPalette.colors.length) | 456 if (generatedPalette.colors.length) |
459 this._palettes.set(generatedPalette.title, generatedPalette); | 457 this._palettes.set(generatedPalette.title, generatedPalette); |
460 if (this._selectedColorPalette.get() !== generatedPalette.title) { | 458 if (this._selectedColorPalette.get() !== generatedPalette.title) { |
461 return; | 459 return; |
462 } else if (!generatedPalette.colors.length) { | 460 } else if (!generatedPalette.colors.length) { |
463 this._paletteSelected(Components.Spectrum.MaterialPalette); | 461 this._paletteSelected(Spectrum.Spectrum.MaterialPalette); |
464 return; | 462 return; |
465 } | 463 } |
466 this._showPalette(generatedPalette, true); | 464 this._showPalette(generatedPalette, true); |
467 } | 465 } |
468 | 466 |
469 /** | 467 /** |
470 * @param {!Components.Spectrum.Palette} palette | 468 * @param {!Spectrum.Spectrum.Palette} palette |
471 * @return {!Element} | 469 * @return {!Element} |
472 */ | 470 */ |
473 _createPreviewPaletteElement(palette) { | 471 _createPreviewPaletteElement(palette) { |
474 var colorsPerPreviewRow = 5; | 472 var colorsPerPreviewRow = 5; |
475 var previewElement = createElementWithClass('div', 'palette-preview'); | 473 var previewElement = createElementWithClass('div', 'palette-preview'); |
476 var titleElement = previewElement.createChild('div', 'palette-preview-title'
); | 474 var titleElement = previewElement.createChild('div', 'palette-preview-title'
); |
477 titleElement.textContent = palette.title; | 475 titleElement.textContent = palette.title; |
478 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i++) | 476 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i++) |
479 previewElement.appendChild(this._createPaletteColor(palette.colors[i])); | 477 previewElement.appendChild(this._createPaletteColor(palette.colors[i])); |
480 for (; i < colorsPerPreviewRow; i++) | 478 for (; i < colorsPerPreviewRow; i++) |
481 previewElement.createChild('div', 'spectrum-palette-color empty-color'); | 479 previewElement.createChild('div', 'spectrum-palette-color empty-color'); |
482 previewElement.addEventListener('click', this._paletteSelected.bind(this, pa
lette)); | 480 previewElement.addEventListener('click', this._paletteSelected.bind(this, pa
lette)); |
483 return previewElement; | 481 return previewElement; |
484 } | 482 } |
485 | 483 |
486 /** | 484 /** |
487 * @param {!Components.Spectrum.Palette} palette | 485 * @param {!Spectrum.Spectrum.Palette} palette |
488 */ | 486 */ |
489 _paletteSelected(palette) { | 487 _paletteSelected(palette) { |
490 this._selectedColorPalette.set(palette.title); | 488 this._selectedColorPalette.set(palette.title); |
491 this._showPalette(palette, true); | 489 this._showPalette(palette, true); |
492 } | 490 } |
493 | 491 |
494 _resizeForSelectedPalette() { | 492 _resizeForSelectedPalette() { |
495 var palette = this._palettes.get(this._selectedColorPalette.get()); | 493 var palette = this._palettes.get(this._selectedColorPalette.get()); |
496 if (!palette) | 494 if (!palette) |
497 return; | 495 return; |
498 var numColors = palette.colors.length; | 496 var numColors = palette.colors.length; |
499 if (palette === this._customPaletteSetting.get()) | 497 if (palette === this._customPaletteSetting.get()) |
500 numColors++; | 498 numColors++; |
501 var rowsNeeded = Math.max(1, Math.ceil(numColors / Components.Spectrum._item
sPerPaletteRow)); | 499 var rowsNeeded = Math.max(1, Math.ceil(numColors / Spectrum.Spectrum._itemsP
erPaletteRow)); |
502 if (this._numPaletteRowsShown === rowsNeeded) | 500 if (this._numPaletteRowsShown === rowsNeeded) |
503 return; | 501 return; |
504 this._numPaletteRowsShown = rowsNeeded; | 502 this._numPaletteRowsShown = rowsNeeded; |
505 var paletteColorHeight = 12; | 503 var paletteColorHeight = 12; |
506 var paletteMargin = 12; | 504 var paletteMargin = 12; |
507 var paletteTop = 235; | 505 var paletteTop = 235; |
508 this.element.style.height = (paletteTop + paletteMargin + (paletteColorHeigh
t + paletteMargin) * rowsNeeded) + 'px'; | 506 this.element.style.height = (paletteTop + paletteMargin + (paletteColorHeigh
t + paletteMargin) * rowsNeeded) + 'px'; |
509 this.dispatchEventToListeners(Components.Spectrum.Events.SizeChanged); | 507 this.dispatchEventToListeners(Spectrum.Spectrum.Events.SizeChanged); |
510 } | 508 } |
511 | 509 |
512 /** | 510 /** |
513 * @param {string} colorText | 511 * @param {string} colorText |
514 * @param {boolean} matchUserFormat | 512 * @param {boolean} matchUserFormat |
515 */ | 513 */ |
516 _paletteColorSelected(colorText, matchUserFormat) { | 514 _paletteColorSelected(colorText, matchUserFormat) { |
517 var color = Common.Color.parse(colorText); | 515 var color = Common.Color.parse(colorText); |
518 if (!color) | 516 if (!color) |
519 return; | 517 return; |
520 this._innerSetColor( | 518 this._innerSetColor( |
521 color.hsva(), colorText, matchUserFormat ? this._colorFormat : color.for
mat(), | 519 color.hsva(), colorText, matchUserFormat ? this._colorFormat : color.for
mat(), |
522 Components.Spectrum._ChangeSource.Other); | 520 Spectrum.Spectrum._ChangeSource.Other); |
523 } | 521 } |
524 | 522 |
525 /** | 523 /** |
526 * @param {!Common.Event} event | 524 * @param {!Common.Event} event |
527 */ | 525 */ |
528 _addColorToCustomPalette(event) { | 526 _addColorToCustomPalette(event) { |
529 var palette = this._customPaletteSetting.get(); | 527 var palette = this._customPaletteSetting.get(); |
530 palette.colors.push(this.colorString()); | 528 palette.colors.push(this.colorString()); |
531 this._customPaletteSetting.set(palette); | 529 this._customPaletteSetting.set(palette); |
532 this._showPalette(this._customPaletteSetting.get(), false); | 530 this._showPalette(this._customPaletteSetting.get(), false); |
(...skipping 29 matching lines...) Expand all Loading... |
562 this._customPaletteSetting.set(palette); | 560 this._customPaletteSetting.set(palette); |
563 this._showPalette(this._customPaletteSetting.get(), false); | 561 this._showPalette(this._customPaletteSetting.get(), false); |
564 } | 562 } |
565 | 563 |
566 /** | 564 /** |
567 * @param {!Common.Color} color | 565 * @param {!Common.Color} color |
568 * @param {string} colorFormat | 566 * @param {string} colorFormat |
569 */ | 567 */ |
570 setColor(color, colorFormat) { | 568 setColor(color, colorFormat) { |
571 this._originalFormat = colorFormat; | 569 this._originalFormat = colorFormat; |
572 this._innerSetColor(color.hsva(), '', colorFormat, Components.Spectrum._Chan
geSource.Model); | 570 this._innerSetColor(color.hsva(), '', colorFormat, Spectrum.Spectrum._Change
Source.Model); |
573 } | 571 } |
574 | 572 |
575 /** | 573 /** |
576 * @param {!Array<number>|undefined} hsva | 574 * @param {!Array<number>|undefined} hsva |
577 * @param {string|undefined} colorString | 575 * @param {string|undefined} colorString |
578 * @param {string|undefined} colorFormat | 576 * @param {string|undefined} colorFormat |
579 * @param {string} changeSource | 577 * @param {string} changeSource |
580 */ | 578 */ |
581 _innerSetColor(hsva, colorString, colorFormat, changeSource) { | 579 _innerSetColor(hsva, colorString, colorFormat, changeSource) { |
582 if (hsva !== undefined) | 580 if (hsva !== undefined) |
583 this._hsv = hsva; | 581 this._hsv = hsva; |
584 if (colorString !== undefined) | 582 if (colorString !== undefined) |
585 this._colorString = colorString; | 583 this._colorString = colorString; |
586 if (colorFormat !== undefined) { | 584 if (colorFormat !== undefined) { |
587 console.assert(colorFormat !== Common.Color.Format.Original, 'Spectrum\'s
color format cannot be Original'); | 585 console.assert(colorFormat !== Common.Color.Format.Original, 'Spectrum\'s
color format cannot be Original'); |
588 if (colorFormat === Common.Color.Format.RGBA) | 586 if (colorFormat === Common.Color.Format.RGBA) |
589 colorFormat = Common.Color.Format.RGB; | 587 colorFormat = Common.Color.Format.RGB; |
590 else if (colorFormat === Common.Color.Format.HSLA) | 588 else if (colorFormat === Common.Color.Format.HSLA) |
591 colorFormat = Common.Color.Format.HSL; | 589 colorFormat = Common.Color.Format.HSL; |
592 this._colorFormat = colorFormat; | 590 this._colorFormat = colorFormat; |
593 } | 591 } |
594 | 592 |
595 this._updateHelperLocations(); | 593 this._updateHelperLocations(); |
596 this._updateUI(); | 594 this._updateUI(); |
597 | 595 |
598 if (changeSource !== Components.Spectrum._ChangeSource.Input) | 596 if (changeSource !== Spectrum.Spectrum._ChangeSource.Input) |
599 this._updateInput(); | 597 this._updateInput(); |
600 if (changeSource !== Components.Spectrum._ChangeSource.Model) | 598 if (changeSource !== Spectrum.Spectrum._ChangeSource.Model) |
601 this.dispatchEventToListeners(Components.Spectrum.Events.ColorChanged, thi
s.colorString()); | 599 this.dispatchEventToListeners(Spectrum.Spectrum.Events.ColorChanged, this.
colorString()); |
602 } | 600 } |
603 | 601 |
604 /** | 602 /** |
605 * @param {!Common.Color} color | 603 * @param {!Common.Color} color |
606 */ | 604 */ |
607 setContrastColor(color) { | 605 setContrastColor(color) { |
608 this._contrastColor = color; | 606 this._contrastColor = color; |
609 this._updateUI(); | 607 this._updateUI(); |
610 } | 608 } |
611 | 609 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 String.sprintf('linear-gradient(to right, rgba(0,0,0,0), %s)', noAlpha.a
sString(Common.Color.Format.RGB)); | 792 String.sprintf('linear-gradient(to right, rgba(0,0,0,0), %s)', noAlpha.a
sString(Common.Color.Format.RGB)); |
795 } | 793 } |
796 | 794 |
797 _formatViewSwitch() { | 795 _formatViewSwitch() { |
798 var cf = Common.Color.Format; | 796 var cf = Common.Color.Format; |
799 var format = cf.RGB; | 797 var format = cf.RGB; |
800 if (this._colorFormat === cf.RGB) | 798 if (this._colorFormat === cf.RGB) |
801 format = cf.HSL; | 799 format = cf.HSL; |
802 else if (this._colorFormat === cf.HSL && !this._color().hasAlpha()) | 800 else if (this._colorFormat === cf.HSL && !this._color().hasAlpha()) |
803 format = this._originalFormat === cf.ShortHEX ? cf.ShortHEX : cf.HEX; | 801 format = this._originalFormat === cf.ShortHEX ? cf.ShortHEX : cf.HEX; |
804 this._innerSetColor(undefined, '', format, Components.Spectrum._ChangeSource
.Other); | 802 this._innerSetColor(undefined, '', format, Spectrum.Spectrum._ChangeSource.O
ther); |
805 } | 803 } |
806 | 804 |
807 /** | 805 /** |
808 * @param {!Event} event | 806 * @param {!Event} event |
809 */ | 807 */ |
810 _inputChanged(event) { | 808 _inputChanged(event) { |
811 /** | 809 /** |
812 * @param {!Element} element | 810 * @param {!Element} element |
813 * @return {string} | 811 * @return {string} |
814 */ | 812 */ |
(...skipping 19 matching lines...) Expand all Loading... |
834 var values = this._textValues.map(elementValue).join(', '); | 832 var values = this._textValues.map(elementValue).join(', '); |
835 colorString = String.sprintf('%s(%s)', format, values); | 833 colorString = String.sprintf('%s(%s)', format, values); |
836 } | 834 } |
837 | 835 |
838 var color = Common.Color.parse(colorString); | 836 var color = Common.Color.parse(colorString); |
839 if (!color) | 837 if (!color) |
840 return; | 838 return; |
841 var hsv = color.hsva(); | 839 var hsv = color.hsva(); |
842 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) | 840 if (this._colorFormat === cf.HEX || this._colorFormat === cf.ShortHEX) |
843 this._colorFormat = color.canBeShortHex() ? cf.ShortHEX : cf.HEX; | 841 this._colorFormat = color.canBeShortHex() ? cf.ShortHEX : cf.HEX; |
844 this._innerSetColor(hsv, colorString, undefined, Components.Spectrum._Change
Source.Input); | 842 this._innerSetColor(hsv, colorString, undefined, Spectrum.Spectrum._ChangeSo
urce.Input); |
845 } | 843 } |
846 | 844 |
847 /** | 845 /** |
848 * @override | 846 * @override |
849 */ | 847 */ |
850 wasShown() { | 848 wasShown() { |
851 this._hueAlphaWidth = this._hueElement.offsetWidth; | 849 this._hueAlphaWidth = this._hueElement.offsetWidth; |
852 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; | 850 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; |
853 this.dragWidth = this._colorElement.offsetWidth; | 851 this.dragWidth = this._colorElement.offsetWidth; |
854 this.dragHeight = this._colorElement.offsetHeight; | 852 this.dragHeight = this._colorElement.offsetHeight; |
855 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; | 853 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; |
856 this._innerSetColor(undefined, undefined, undefined, Components.Spectrum._Ch
angeSource.Model); | 854 this._innerSetColor(undefined, undefined, undefined, Spectrum.Spectrum._Chan
geSource.Model); |
857 this._toggleColorPicker(true); | 855 this._toggleColorPicker(true); |
858 SDK.targetManager.addModelListener( | 856 SDK.targetManager.addModelListener( |
859 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); | 857 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); |
860 } | 858 } |
861 | 859 |
862 /** | 860 /** |
863 * @override | 861 * @override |
864 */ | 862 */ |
865 willHide() { | 863 willHide() { |
866 this._toggleColorPicker(false); | 864 this._toggleColorPicker(false); |
(...skipping 13 matching lines...) Expand all Loading... |
880 target.pageAgent().setColorPickerEnabled(enabled); | 878 target.pageAgent().setColorPickerEnabled(enabled); |
881 } | 879 } |
882 | 880 |
883 /** | 881 /** |
884 * @param {!Common.Event} event | 882 * @param {!Common.Event} event |
885 */ | 883 */ |
886 _colorPicked(event) { | 884 _colorPicked(event) { |
887 var rgbColor = /** @type {!Protocol.DOM.RGBA} */ (event.data); | 885 var rgbColor = /** @type {!Protocol.DOM.RGBA} */ (event.data); |
888 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; | 886 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; |
889 var color = Common.Color.fromRGBA(rgba); | 887 var color = Common.Color.fromRGBA(rgba); |
890 this._innerSetColor(color.hsva(), '', undefined, Components.Spectrum._Change
Source.Other); | 888 this._innerSetColor(color.hsva(), '', undefined, Spectrum.Spectrum._ChangeSo
urce.Other); |
891 InspectorFrontendHost.bringToFront(); | 889 InspectorFrontendHost.bringToFront(); |
892 } | 890 } |
893 }; | 891 }; |
894 | 892 |
895 Components.Spectrum._ChangeSource = { | 893 Spectrum.Spectrum._ChangeSource = { |
896 Input: 'Input', | 894 Input: 'Input', |
897 Model: 'Model', | 895 Model: 'Model', |
898 Other: 'Other' | 896 Other: 'Other' |
899 }; | 897 }; |
900 | 898 |
901 /** @enum {symbol} */ | 899 /** @enum {symbol} */ |
902 Components.Spectrum.Events = { | 900 Spectrum.Spectrum.Events = { |
903 ColorChanged: Symbol('ColorChanged'), | 901 ColorChanged: Symbol('ColorChanged'), |
904 SizeChanged: Symbol('SizeChanged') | 902 SizeChanged: Symbol('SizeChanged') |
905 }; | 903 }; |
906 | 904 |
907 Components.Spectrum._colorChipSize = 24; | 905 Spectrum.Spectrum._colorChipSize = 24; |
908 Components.Spectrum._itemsPerPaletteRow = 8; | 906 Spectrum.Spectrum._itemsPerPaletteRow = 8; |
909 | 907 |
910 /** @typedef {{ title: string, colors: !Array.<string>, mutable: boolean }} */ | 908 /** @typedef {{ title: string, colors: !Array.<string>, mutable: boolean }} */ |
911 Components.Spectrum.Palette; | 909 Spectrum.Spectrum.Palette; |
912 Components.Spectrum.GeneratedPaletteTitle = 'Page colors'; | 910 Spectrum.Spectrum.GeneratedPaletteTitle = 'Page colors'; |
913 | 911 |
914 /** | 912 /** |
915 * @unrestricted | 913 * @unrestricted |
916 */ | 914 */ |
917 Components.Spectrum.PaletteGenerator = class { | 915 Spectrum.Spectrum.PaletteGenerator = class { |
918 /** | 916 /** |
919 * @param {function(!Components.Spectrum.Palette)} callback | 917 * @param {function(!Spectrum.Spectrum.Palette)} callback |
920 */ | 918 */ |
921 constructor(callback) { | 919 constructor(callback) { |
922 this._callback = callback; | 920 this._callback = callback; |
923 /** @type {!Map.<string, number>} */ | 921 /** @type {!Map.<string, number>} */ |
924 this._frequencyMap = new Map(); | 922 this._frequencyMap = new Map(); |
925 var stylesheetPromises = []; | 923 var stylesheetPromises = []; |
926 for (var target of SDK.targetManager.targets(SDK.Target.Capability.DOM)) { | 924 for (var target of SDK.targetManager.targets(SDK.Target.Capability.DOM)) { |
927 var cssModel = SDK.CSSModel.fromTarget(target); | 925 var cssModel = SDK.CSSModel.fromTarget(target); |
928 for (var stylesheet of cssModel.allStyleSheets()) | 926 for (var stylesheet of cssModel.allStyleSheets()) |
929 stylesheetPromises.push(new Promise(this._processStylesheet.bind(this, s
tylesheet))); | 927 stylesheetPromises.push(new Promise(this._processStylesheet.bind(this, s
tylesheet))); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 var colorsPerRow = 24; | 970 var colorsPerRow = 24; |
973 while (paletteColors.size < colorsPerRow && colors.length) { | 971 while (paletteColors.size < colorsPerRow && colors.length) { |
974 var colorText = colors.shift(); | 972 var colorText = colors.shift(); |
975 var color = Common.Color.parse(colorText); | 973 var color = Common.Color.parse(colorText); |
976 if (!color || color.nickname() === 'white' || color.nickname() === 'black'
) | 974 if (!color || color.nickname() === 'white' || color.nickname() === 'black'
) |
977 continue; | 975 continue; |
978 paletteColors.set(colorText, color); | 976 paletteColors.set(colorText, color); |
979 } | 977 } |
980 | 978 |
981 this._callback({ | 979 this._callback({ |
982 title: Components.Spectrum.GeneratedPaletteTitle, | 980 title: Spectrum.Spectrum.GeneratedPaletteTitle, |
983 colors: paletteColors.keysArray().sort(hueComparator), | 981 colors: paletteColors.keysArray().sort(hueComparator), |
984 mutable: false | 982 mutable: false |
985 }); | 983 }); |
986 } | 984 } |
987 | 985 |
988 /** | 986 /** |
989 * @param {!SDK.CSSStyleSheetHeader} stylesheet | 987 * @param {!SDK.CSSStyleSheetHeader} stylesheet |
990 * @param {function(?)} resolve | 988 * @param {function(?)} resolve |
991 * @this {Components.Spectrum.PaletteGenerator} | 989 * @this {Spectrum.Spectrum.PaletteGenerator} |
992 */ | 990 */ |
993 _processStylesheet(stylesheet, resolve) { | 991 _processStylesheet(stylesheet, resolve) { |
994 /** | 992 /** |
995 * @param {?string} text | 993 * @param {?string} text |
996 * @this {Components.Spectrum.PaletteGenerator} | 994 * @this {Spectrum.Spectrum.PaletteGenerator} |
997 */ | 995 */ |
998 function parseContent(text) { | 996 function parseContent(text) { |
999 text = text.toLowerCase(); | 997 text = text.toLowerCase(); |
1000 var regexResult = text.match(/((?:rgb|hsl)a?\([^)]+\)|#[0-9a-f]{6}|#[0-9a-
f]{3})/g) || []; | 998 var regexResult = text.match(/((?:rgb|hsl)a?\([^)]+\)|#[0-9a-f]{6}|#[0-9a-
f]{3})/g) || []; |
1001 for (var c of regexResult) { | 999 for (var c of regexResult) { |
1002 var frequency = this._frequencyMap.get(c) || 0; | 1000 var frequency = this._frequencyMap.get(c) || 0; |
1003 this._frequencyMap.set(c, ++frequency); | 1001 this._frequencyMap.set(c, ++frequency); |
1004 } | 1002 } |
1005 resolve(null); | 1003 resolve(null); |
1006 } | 1004 } |
1007 | 1005 |
1008 stylesheet.requestContent().then(parseContent.bind(this)); | 1006 stylesheet.requestContent().then(parseContent.bind(this)); |
1009 } | 1007 } |
1010 }; | 1008 }; |
1011 | 1009 |
1012 Components.Spectrum.MaterialPaletteShades = { | 1010 Spectrum.Spectrum.MaterialPaletteShades = { |
1013 '#F44336': | 1011 '#F44336': |
1014 ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E5393
5', '#D32F2F', '#C62828', '#B71C1C'], | 1012 ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E5393
5', '#D32F2F', '#C62828', '#B71C1C'], |
1015 '#E91E63': | 1013 '#E91E63': |
1016 ['#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B6
0', '#C2185B', '#AD1457', '#880E4F'], | 1014 ['#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B6
0', '#C2185B', '#AD1457', '#880E4F'], |
1017 '#9C27B0': | 1015 '#9C27B0': |
1018 ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24A
A', '#7B1FA2', '#6A1B9A', '#4A148C'], | 1016 ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24A
A', '#7B1FA2', '#6A1B9A', '#4A148C'], |
1019 '#673AB7': | 1017 '#673AB7': |
1020 ['#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B
1', '#512DA8', '#4527A0', '#311B92'], | 1018 ['#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B
1', '#512DA8', '#4527A0', '#311B92'], |
1021 '#3F51B5': | 1019 '#3F51B5': |
1022 ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949A
B', '#303F9F', '#283593', '#1A237E'], | 1020 ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949A
B', '#303F9F', '#283593', '#1A237E'], |
(...skipping 20 matching lines...) Expand all Loading... |
1043 '#FF5722': | 1041 '#FF5722': |
1044 ['#FBE9E7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511
E', '#E64A19', '#D84315', '#BF360C'], | 1042 ['#FBE9E7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511
E', '#E64A19', '#D84315', '#BF360C'], |
1045 '#795548': | 1043 '#795548': |
1046 ['#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C4
1', '#5D4037', '#4E342E', '#3E2723'], | 1044 ['#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C4
1', '#5D4037', '#4E342E', '#3E2723'], |
1047 '#9E9E9E': | 1045 '#9E9E9E': |
1048 ['#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#75757
5', '#616161', '#424242', '#212121'], | 1046 ['#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#75757
5', '#616161', '#424242', '#212121'], |
1049 '#607D8B': | 1047 '#607D8B': |
1050 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] | 1048 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] |
1051 }; | 1049 }; |
1052 | 1050 |
1053 Components.Spectrum.MaterialPalette = { | 1051 Spectrum.Spectrum.MaterialPalette = { |
1054 title: 'Material', | 1052 title: 'Material', |
1055 mutable: false, | 1053 mutable: false, |
1056 matchUserFormat: true, | 1054 matchUserFormat: true, |
1057 colors: Object.keys(Components.Spectrum.MaterialPaletteShades) | 1055 colors: Object.keys(Spectrum.Spectrum.MaterialPaletteShades) |
1058 }; | 1056 }; |
OLD | NEW |