| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 colorElement.addEventListener("contextmenu", this._showPaletteCo
lorContextMenu.bind(this, i)); | 251 colorElement.addEventListener("contextmenu", this._showPaletteCo
lorContextMenu.bind(this, i)); |
| 252 } | 252 } |
| 253 this._paletteContainer.appendChild(colorElement); | 253 this._paletteContainer.appendChild(colorElement); |
| 254 } | 254 } |
| 255 this._paletteContainerMutable = palette.mutable; | 255 this._paletteContainerMutable = palette.mutable; |
| 256 | 256 |
| 257 var numItems = palette.colors.length; | 257 var numItems = palette.colors.length; |
| 258 if (palette.mutable) | 258 if (palette.mutable) |
| 259 numItems++; | 259 numItems++; |
| 260 var rowsNeeded = Math.max(1, Math.ceil(numItems / WebInspector.Spectrum.
_itemsPerPaletteRow)); | 260 var rowsNeeded = Math.max(1, Math.ceil(numItems / WebInspector.Spectrum.
_itemsPerPaletteRow)); |
| 261 for (var i = 0; palette.mutable && i < rowsNeeded * WebInspector.Spectru
m._itemsPerPaletteRow - numItems; i++) | |
| 262 this._paletteContainer.createChild("div", "spectrum-palette-color em
pty-color"); | |
| 263 if (palette.mutable) | 261 if (palette.mutable) |
| 264 this.contentElement.appendChild(this._addColorToolbar.element); | 262 this.contentElement.appendChild(this._addColorToolbar.element); |
| 265 else | 263 else |
| 266 this._addColorToolbar.element.remove(); | 264 this._addColorToolbar.element.remove(); |
| 267 | 265 |
| 268 this._togglePalettePanel(false); | 266 this._togglePalettePanel(false); |
| 269 var paletteColorHeight = 12; | 267 var paletteColorHeight = 12; |
| 270 var paletteMargin = 12; | 268 var paletteMargin = 12; |
| 271 this.element.style.height = (this._paletteContainer.offsetTop + paletteM
argin + (paletteColorHeight + paletteMargin) * rowsNeeded) + "px"; | 269 this.element.style.height = (this._paletteContainer.offsetTop + paletteM
argin + (paletteColorHeight + paletteMargin) * rowsNeeded) + "px"; |
| 272 this.dispatchEventToListeners(WebInspector.Spectrum.Events.SizeChanged); | 270 this.dispatchEventToListeners(WebInspector.Spectrum.Events.SizeChanged); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 * @param {!Event} e | 304 * @param {!Event} e |
| 307 */ | 305 */ |
| 308 _paletteDrag: function(e) | 306 _paletteDrag: function(e) |
| 309 { | 307 { |
| 310 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this
._paletteContainer.totalOffsetTop()) | 308 if (e.pageX < this._paletteContainer.totalOffsetLeft() || e.pageY < this
._paletteContainer.totalOffsetTop()) |
| 311 return; | 309 return; |
| 312 var newIndex = this._slotIndexForEvent(e); | 310 var newIndex = this._slotIndexForEvent(e); |
| 313 var offsetX = e.pageX - (newIndex % WebInspector.Spectrum._itemsPerPalet
teRow) * WebInspector.Spectrum._colorChipSize; | 311 var offsetX = e.pageX - (newIndex % WebInspector.Spectrum._itemsPerPalet
teRow) * WebInspector.Spectrum._colorChipSize; |
| 314 var offsetY = e.pageY - (newIndex / WebInspector.Spectrum._itemsPerPalet
teRow | 0) * WebInspector.Spectrum._colorChipSize; | 312 var offsetY = e.pageY - (newIndex / WebInspector.Spectrum._itemsPerPalet
teRow | 0) * WebInspector.Spectrum._colorChipSize; |
| 315 | 313 |
| 316 this._dragElement.style.position = "relative"; | 314 this._dragElement.style.transform = "translateX(" + (offsetX - this._dra
gHotSpotX) + "px) translateY(" + (offsetY - this._dragHotSpotY) + "px)"; |
| 317 this._dragElement.style.left = (offsetX - this._dragHotSpotX) + "px"; | |
| 318 this._dragElement.style.top = (offsetY - this._dragHotSpotY) + "px"; | |
| 319 var children = Array.prototype.slice.call(this._paletteContainer.childre
n); | 315 var children = Array.prototype.slice.call(this._paletteContainer.childre
n); |
| 320 var index = children.indexOf(this._dragElement); | 316 var index = children.indexOf(this._dragElement); |
| 317 /** @type {!Map.<!Element, {left: number, top: number}>} */ |
| 318 var swatchOffsets = new Map(); |
| 319 for (var swatch of children) |
| 320 swatchOffsets.set(swatch, swatch.totalOffset()); |
| 321 |
| 321 if (index !== newIndex) | 322 if (index !== newIndex) |
| 322 this._paletteContainer.insertBefore(this._dragElement, children[newI
ndex > index ? newIndex + 1 : newIndex]); | 323 this._paletteContainer.insertBefore(this._dragElement, children[newI
ndex > index ? newIndex + 1 : newIndex]); |
| 324 |
| 325 for (var swatch of children) { |
| 326 if (swatch === this._dragElement) |
| 327 continue; |
| 328 var before = swatchOffsets.get(swatch); |
| 329 var after = swatch.totalOffset(); |
| 330 if (before.left !== after.left || before.top !== after.top) { |
| 331 swatch.animate([ |
| 332 { transform: "translateX(" + (before.left - after.left) + "p
x) translateY(" + (before.top - after.top) + "px)" }, |
| 333 { transform: "none" }], { duration: 100, easing: "cubic-bezi
er(0, 0, 0.2, 1)" }); |
| 334 } |
| 335 } |
| 323 }, | 336 }, |
| 324 | 337 |
| 325 /** | 338 /** |
| 326 * @param {!Event} e | 339 * @param {!Event} e |
| 327 */ | 340 */ |
| 328 _paletteDragEnd: function(e) | 341 _paletteDragEnd: function(e) |
| 329 { | 342 { |
| 330 this._dragElement.style.removeProperty("position"); | 343 this._dragElement.style.removeProperty("transform"); |
| 331 this._dragElement.style.removeProperty("left"); | |
| 332 this._dragElement.style.removeProperty("top"); | |
| 333 var children = this._paletteContainer.children; | 344 var children = this._paletteContainer.children; |
| 334 var colors = []; | 345 var colors = []; |
| 335 for (var i = 0; i < children.length; ++i) { | 346 for (var i = 0; i < children.length; ++i) { |
| 336 if (children[i].__color) | 347 if (children[i].__color) |
| 337 colors.push(children[i].__color); | 348 colors.push(children[i].__color); |
| 338 } | 349 } |
| 339 var palette = this._customPaletteSetting.get(); | 350 var palette = this._customPaletteSetting.get(); |
| 340 palette.colors = colors; | 351 palette.colors = colors; |
| 341 this._customPaletteSetting.set(palette); | 352 this._customPaletteSetting.set(palette); |
| 342 this._showPalette(this._customPaletteSetting.get(), false); | 353 this._showPalette(this._customPaletteSetting.get(), false); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 "#8BC34A", | 905 "#8BC34A", |
| 895 "#CDDC39", | 906 "#CDDC39", |
| 896 "#FFEB3B", | 907 "#FFEB3B", |
| 897 "#FFC107", | 908 "#FFC107", |
| 898 "#FF9800", | 909 "#FF9800", |
| 899 "#FF5722", | 910 "#FF5722", |
| 900 "#795548", | 911 "#795548", |
| 901 "#9E9E9E", | 912 "#9E9E9E", |
| 902 "#607D8B" | 913 "#607D8B" |
| 903 ]}; | 914 ]}; |
| OLD | NEW |