Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: Source/devtools/front_end/elements/Spectrum.js

Issue 1319823002: Devtools Color: Animate drag rearrangement of custom color palette (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.position = "relative";
317 this._dragElement.style.left = (offsetX - this._dragHotSpotX) + "px"; 315 this._dragElement.style.left = (offsetX - this._dragHotSpotX) + "px";
318 this._dragElement.style.top = (offsetY - this._dragHotSpotY) + "px"; 316 this._dragElement.style.top = (offsetY - this._dragHotSpotY) + "px";
319 var children = Array.prototype.slice.call(this._paletteContainer.childre n); 317 var children = Array.prototype.slice.call(this._paletteContainer.childre n);
320 var index = children.indexOf(this._dragElement); 318 var index = children.indexOf(this._dragElement);
319 /** @type {!Map.<!Element, {left: number, top: number}>} */
320 var swatchOffsets = new Map();
321 for (var swatch of children)
322 swatchOffsets.set(swatch, swatch.totalOffset());
323
321 if (index !== newIndex) 324 if (index !== newIndex)
322 this._paletteContainer.insertBefore(this._dragElement, children[newI ndex > index ? newIndex + 1 : newIndex]); 325 this._paletteContainer.insertBefore(this._dragElement, children[newI ndex > index ? newIndex + 1 : newIndex]);
326
327 for (var swatch of children) {
328 if (swatch === this._dragElement)
329 continue;
330 var before = swatchOffsets.get(swatch);
331 var after = swatch.totalOffset();
332 if (before.left !== after.left || before.top !== after.top) {
333 swatch.animate([
334 { transform: "translateX(" + (before.left - after.left) + "p x) translateY(" + (before.top - after.top) + "px)" },
335 { transform: "none" }], { duration: 100, easing: "cubic-bezi er(0, 0, 0.2, 1)" });
336 }
337 }
323 }, 338 },
324 339
325 /** 340 /**
326 * @param {!Event} e 341 * @param {!Event} e
327 */ 342 */
328 _paletteDragEnd: function(e) 343 _paletteDragEnd: function(e)
329 { 344 {
330 this._dragElement.style.removeProperty("position"); 345 this._dragElement.style.removeProperty("position");
331 this._dragElement.style.removeProperty("left"); 346 this._dragElement.style.removeProperty("left");
332 this._dragElement.style.removeProperty("top"); 347 this._dragElement.style.removeProperty("top");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 _createPreviewPaletteElement: function(palette) 384 _createPreviewPaletteElement: function(palette)
370 { 385 {
371 var colorsPerPreviewRow = 5; 386 var colorsPerPreviewRow = 5;
372 var previewElement = createElementWithClass("div", "palette-preview"); 387 var previewElement = createElementWithClass("div", "palette-preview");
373 var titleElement = previewElement.createChild("div", "palette-preview-ti tle"); 388 var titleElement = previewElement.createChild("div", "palette-preview-ti tle");
374 titleElement.textContent = palette.title; 389 titleElement.textContent = palette.title;
375 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i+ +) 390 for (var i = 0; i < colorsPerPreviewRow && i < palette.colors.length; i+ +)
376 previewElement.appendChild(this._createPaletteColor(palette.colors[i ])); 391 previewElement.appendChild(this._createPaletteColor(palette.colors[i ]));
377 for (; i < colorsPerPreviewRow; i++) 392 for (; i < colorsPerPreviewRow; i++)
378 previewElement.createChild("div", "spectrum-palette-color empty-colo r"); 393 previewElement.createChild("div", "spectrum-palette-color empty-colo r");
394
379 previewElement.addEventListener("click", this._paletteSelected.bind(this , palette)); 395 previewElement.addEventListener("click", this._paletteSelected.bind(this , palette));
380 return previewElement; 396 return previewElement;
381 }, 397 },
382 398
383 /** 399 /**
384 * @param {!WebInspector.Spectrum.Palette} palette 400 * @param {!WebInspector.Spectrum.Palette} palette
385 */ 401 */
386 _paletteSelected: function(palette) 402 _paletteSelected: function(palette)
387 { 403 {
388 this._selectedColorPalette.set(palette.title); 404 this._selectedColorPalette.set(palette.title);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 "#8BC34A", 910 "#8BC34A",
895 "#CDDC39", 911 "#CDDC39",
896 "#FFEB3B", 912 "#FFEB3B",
897 "#FFC107", 913 "#FFC107",
898 "#FF9800", 914 "#FF9800",
899 "#FF5722", 915 "#FF5722",
900 "#795548", 916 "#795548",
901 "#9E9E9E", 917 "#9E9E9E",
902 "#607D8B" 918 "#607D8B"
903 ]}; 919 ]};
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/elements/spectrum.css » ('j') | Source/devtools/front_end/elements/spectrum.css » ('J')

Powered by Google App Engine
This is Rietveld 408576698