| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 this._currentFormat = WebInspector.Color.Format.HEX; | 71 this._currentFormat = WebInspector.Color.Format.HEX; |
| 72 var displaySwitcher = this.contentElement.createChild("div", "spectrum-displ
ay-switcher"); | 72 var displaySwitcher = this.contentElement.createChild("div", "spectrum-displ
ay-switcher"); |
| 73 appendSwitcherIcon(displaySwitcher); | 73 appendSwitcherIcon(displaySwitcher); |
| 74 displaySwitcher.addEventListener("click", this._formatViewSwitch.bind(this))
; | 74 displaySwitcher.addEventListener("click", this._formatViewSwitch.bind(this))
; |
| 75 | 75 |
| 76 // RGBA/HSLA display. | 76 // RGBA/HSLA display. |
| 77 this._displayContainer = this.contentElement.createChild("div", "spectrum-te
xt source-code"); | 77 this._displayContainer = this.contentElement.createChild("div", "spectrum-te
xt source-code"); |
| 78 this._textValues = []; | 78 this._textValues = []; |
| 79 for (var i = 0; i < 4; ++i) { | 79 for (var i = 0; i < 4; ++i) { |
| 80 var inputValue = this._displayContainer.createChild("span", "spectrum-te
xt-value"); | 80 var inputValue = this._displayContainer.createChild("input", "spectrum-t
ext-value"); |
| 81 inputValue.maxLength = 4; | 81 inputValue.maxLength = 4; |
| 82 this._textValues.push(inputValue); | 82 this._textValues.push(inputValue); |
| 83 inputValue.addEventListener("keydown", this._checkForTabEvent.bind(this)
); | |
| 84 inputValue.addEventListener("keyup", this._inputChanged.bind(this)); | 83 inputValue.addEventListener("keyup", this._inputChanged.bind(this)); |
| 85 inputValue.addEventListener("mousewheel", this._inputChanged.bind(this))
; | 84 inputValue.addEventListener("mousewheel", this._inputChanged.bind(this))
; |
| 86 } | 85 } |
| 87 | 86 |
| 88 this._textLabels = this._displayContainer.createChild("div", "spectrum-text-
label"); | 87 this._textLabels = this._displayContainer.createChild("div", "spectrum-text-
label"); |
| 89 | 88 |
| 90 // HEX display. | 89 // HEX display. |
| 91 this._hexContainer = this.contentElement.createChild("div", "spectrum-text s
pectrum-text-hex source-code"); | 90 this._hexContainer = this.contentElement.createChild("div", "spectrum-text s
pectrum-text-hex source-code"); |
| 92 this._hexValue = this._hexContainer.createChild("span", "spectrum-text-value
"); | 91 this._hexValue = this._hexContainer.createChild("input", "spectrum-text-valu
e"); |
| 93 this._hexValue.maxLength = 7; | 92 this._hexValue.maxLength = 7; |
| 94 this._hexValue.addEventListener("keyup", this._inputChanged.bind(this)); | 93 this._hexValue.addEventListener("keyup", this._inputChanged.bind(this)); |
| 95 this._hexValue.addEventListener("mousewheel", this._inputChanged.bind(this))
; | 94 this._hexValue.addEventListener("mousewheel", this._inputChanged.bind(this))
; |
| 96 | 95 |
| 97 var label = this._hexContainer.createChild("div", "spectrum-text-label"); | 96 var label = this._hexContainer.createChild("div", "spectrum-text-label"); |
| 98 label.textContent = "HEX"; | 97 label.textContent = "HEX"; |
| 99 | 98 |
| 100 WebInspector.installDragHandle(this._hueElement, dragStart.bind(this, positi
onHue.bind(this)), positionHue.bind(this), null, "default"); | 99 WebInspector.installDragHandle(this._hueElement, dragStart.bind(this, positi
onHue.bind(this)), positionHue.bind(this), null, "default"); |
| 101 WebInspector.installDragHandle(this._alphaElement, dragStart.bind(this, posi
tionAlpha.bind(this)), positionAlpha.bind(this), null, "default"); | 100 WebInspector.installDragHandle(this._alphaElement, dragStart.bind(this, posi
tionAlpha.bind(this)), positionAlpha.bind(this), null, "default"); |
| 102 WebInspector.installDragHandle(this._colorElement, dragStart.bind(this, posi
tionColor.bind(this)), positionColor.bind(this), null, "default"); | 101 WebInspector.installDragHandle(this._colorElement, dragStart.bind(this, posi
tionColor.bind(this)), positionColor.bind(this), null, "default"); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 this._alphaSlider.style.left = alphaSlideX + "px"; | 249 this._alphaSlider.style.left = alphaSlideX + "px"; |
| 251 }, | 250 }, |
| 252 | 251 |
| 253 _updateInput: function() | 252 _updateInput: function() |
| 254 { | 253 { |
| 255 var cf = WebInspector.Color.Format; | 254 var cf = WebInspector.Color.Format; |
| 256 if (this._currentFormat === cf.HEX || this._currentFormat === cf.ShortHE
X || this._currentFormat === cf.Nickname) { | 255 if (this._currentFormat === cf.HEX || this._currentFormat === cf.ShortHE
X || this._currentFormat === cf.Nickname) { |
| 257 this._hexContainer.hidden = false; | 256 this._hexContainer.hidden = false; |
| 258 this._displayContainer.hidden = true; | 257 this._displayContainer.hidden = true; |
| 259 if (this._currentFormat === cf.ShortHEX && this._color().canBeShortH
ex()) | 258 if (this._currentFormat === cf.ShortHEX && this._color().canBeShortH
ex()) |
| 260 this._hexValue.textContent = this._color().asString(cf.ShortHEX)
; | 259 this._hexValue.value = this._color().asString(cf.ShortHEX); |
| 261 else | 260 else |
| 262 this._hexValue.textContent = this._color().asString(cf.HEX); | 261 this._hexValue.value = this._color().asString(cf.HEX); |
| 263 } else { | 262 } else { |
| 264 // RGBA, HSLA display. | 263 // RGBA, HSLA display. |
| 265 this._hexContainer.hidden = true; | 264 this._hexContainer.hidden = true; |
| 266 this._displayContainer.hidden = false; | 265 this._displayContainer.hidden = false; |
| 267 var isRgb = this._currentFormat === cf.RGB; | 266 var isRgb = this._currentFormat === cf.RGB; |
| 268 this._textLabels.textContent = isRgb ? "RGBA" : "HSLA"; | 267 this._textLabels.textContent = isRgb ? "RGBA" : "HSLA"; |
| 269 var colorValues = isRgb ? this._color().canonicalRGBA() : this._colo
r().canonicalHSLA(); | 268 var colorValues = isRgb ? this._color().canonicalRGBA() : this._colo
r().canonicalHSLA(); |
| 270 for (var i = 0; i < 3; ++i) { | 269 for (var i = 0; i < 3; ++i) { |
| 271 this._textValues[i].textContent = colorValues[i]; | 270 this._textValues[i].value = colorValues[i]; |
| 272 if (!isRgb && (i === 1 || i === 2)) | 271 if (!isRgb && (i === 1 || i === 2)) |
| 273 this._textValues[i].textContent += "%"; | 272 this._textValues[i].value += "%"; |
| 274 } | 273 } |
| 275 this._textValues[3].textContent = Math.round(colorValues[3] * 100) /
100; | 274 this._textValues[3].value= Math.round(colorValues[3] * 100) / 100; |
| 276 } | 275 } |
| 277 }, | 276 }, |
| 278 | 277 |
| 279 _updateUI: function() | 278 _updateUI: function() |
| 280 { | 279 { |
| 281 var h = WebInspector.Color.fromHSVA([this._hsv[0], 1, 1, 1]); | 280 var h = WebInspector.Color.fromHSVA([this._hsv[0], 1, 1, 1]); |
| 282 this._colorElement.style.backgroundColor = /** @type {string} */ (h.asSt
ring(WebInspector.Color.Format.RGB)); | 281 this._colorElement.style.backgroundColor = /** @type {string} */ (h.asSt
ring(WebInspector.Color.Format.RGB)); |
| 283 this._swatchInnerElement.style.backgroundColor = /** @type {string} */ (
this._color().asString(WebInspector.Color.Format.RGBA)); | 282 this._swatchInnerElement.style.backgroundColor = /** @type {string} */ (
this._color().asString(WebInspector.Color.Format.RGBA)); |
| 284 // Show border if the swatch is white. | 283 // Show border if the swatch is white. |
| 285 this._swatchInnerElement.classList.toggle("swatch-inner-white", this._co
lor().hsla()[2] > 0.9); | 284 this._swatchInnerElement.classList.toggle("swatch-inner-white", this._co
lor().hsla()[2] > 0.9); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 296 else if (this._currentFormat === cf.HSL && !this._color().hasAlpha()) | 295 else if (this._currentFormat === cf.HSL && !this._color().hasAlpha()) |
| 297 this._currentFormat = this._originalFormat === cf.ShortHEX ? cf.Shor
tHEX : cf.HEX; | 296 this._currentFormat = this._originalFormat === cf.ShortHEX ? cf.Shor
tHEX : cf.HEX; |
| 298 else | 297 else |
| 299 this._currentFormat = cf.RGB; | 298 this._currentFormat = cf.RGB; |
| 300 this._onchange(); | 299 this._onchange(); |
| 301 }, | 300 }, |
| 302 | 301 |
| 303 /** | 302 /** |
| 304 * @param {!Event} event | 303 * @param {!Event} event |
| 305 */ | 304 */ |
| 306 _checkForTabEvent: function(event) | |
| 307 { | |
| 308 var sibling = event.shiftKey ? event.target.previousSibling : event.targ
et.nextSibling; | |
| 309 if (event.code !== "Tab" || !sibling || !sibling.classList.contains("spe
ctrum-text-value")) | |
| 310 return; | |
| 311 sibling.getComponentSelection().setBaseAndExtent(sibling, 0, sibling, 1)
; | |
| 312 event.consume(true); | |
| 313 }, | |
| 314 | |
| 315 /** | |
| 316 * @param {!Event} event | |
| 317 */ | |
| 318 _inputChanged: function(event) | 305 _inputChanged: function(event) |
| 319 { | 306 { |
| 320 /** | 307 /** |
| 321 * @param {!Element} element | 308 * @param {!Element} element |
| 322 * @return {string} | 309 * @return {string} |
| 323 */ | 310 */ |
| 324 function elementValue(element) | 311 function elementValue(element) |
| 325 { | 312 { |
| 326 return element.textContent; | 313 return element.value; |
| 327 } | 314 } |
| 328 | 315 |
| 329 var element = /** @type {!Element} */(event.currentTarget); | 316 var element = /** @type {!Element} */(event.currentTarget); |
| 330 WebInspector.handleElementValueModifications(event, element); | 317 WebInspector.handleElementValueModifications(event, element); |
| 331 | 318 |
| 332 const cf = WebInspector.Color.Format; | 319 const cf = WebInspector.Color.Format; |
| 333 var colorString; | 320 var colorString; |
| 334 if (this._currentFormat === cf.HEX || this._currentFormat === cf.ShortHE
X) { | 321 if (this._currentFormat === cf.HEX || this._currentFormat === cf.ShortHE
X) { |
| 335 colorString = this._hexValue.textContent; | 322 colorString = this._hexValue.value; |
| 336 } else { | 323 } else { |
| 337 var format = this._currentFormat === cf.RGB ? "rgba" : "hsla"; | 324 var format = this._currentFormat === cf.RGB ? "rgba" : "hsla"; |
| 338 var values = this._textValues.map(elementValue).join(","); | 325 var values = this._textValues.map(elementValue).join(","); |
| 339 colorString = String.sprintf("%s(%s)", format, values); | 326 colorString = String.sprintf("%s(%s)", format, values); |
| 340 } | 327 } |
| 341 | 328 |
| 342 var color = WebInspector.Color.parse(colorString); | 329 var color = WebInspector.Color.parse(colorString); |
| 343 if (!color) | 330 if (!color) |
| 344 return; | 331 return; |
| 345 this._hsv = color.hsva(); | 332 this._hsv = color.hsva(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0)
/ 100]; | 378 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0)
/ 100]; |
| 392 var color = WebInspector.Color.fromRGBA(rgba); | 379 var color = WebInspector.Color.fromRGBA(rgba); |
| 393 this.setColor(color); | 380 this.setColor(color); |
| 394 this._dispatchChangeEvent(); | 381 this._dispatchChangeEvent(); |
| 395 InspectorFrontendHost.bringToFront(); | 382 InspectorFrontendHost.bringToFront(); |
| 396 }, | 383 }, |
| 397 | 384 |
| 398 | 385 |
| 399 __proto__: WebInspector.VBox.prototype | 386 __proto__: WebInspector.VBox.prototype |
| 400 } | 387 } |
| OLD | NEW |