| 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 this.hide(true); | 365 this.hide(true); |
| 366 } | 366 } |
| 367 | 367 |
| 368 this._anchorElement = element; | 368 this._anchorElement = element; |
| 369 | 369 |
| 370 this._spectrum.setColor(color); | 370 this._spectrum.setColor(color); |
| 371 this._spectrum._originalFormat = format !== WebInspector.Color.Format.Or
iginal ? format : color.format(); | 371 this._spectrum._originalFormat = format !== WebInspector.Color.Format.Or
iginal ? format : color.format(); |
| 372 this.reposition(element); | 372 this.reposition(element); |
| 373 | 373 |
| 374 document.addEventListener("mousedown", this._hideProxy, false); | 374 document.addEventListener("mousedown", this._hideProxy, false); |
| 375 window.addEventListener("blur", this._hideProxy, false); | 375 if (WebInspector.experimentsSettings.colorPicker.isEnabled()) { |
| 376 WebInspector.targetManager.addModelListener(WebInspector.ResourceTre
eModel, WebInspector.ResourceTreeModel.EventTypes.ColorPicked, this._colorPicked
, this); |
| 377 PageAgent.setColorPickerEnabled(true); |
| 378 } |
| 376 return true; | 379 return true; |
| 377 }, | 380 }, |
| 378 | 381 |
| 379 reposition: function(element) | 382 reposition: function(element) |
| 380 { | 383 { |
| 381 if (!this._previousFocusElement) | 384 if (!this._previousFocusElement) |
| 382 this._previousFocusElement = WebInspector.currentFocusElement(); | 385 this._previousFocusElement = WebInspector.currentFocusElement(); |
| 383 this._popover.showView(this._spectrum, element); | 386 this._popover.showView(this._spectrum, element); |
| 384 WebInspector.setCurrentFocusElement(this._spectrum.element); | 387 WebInspector.setCurrentFocusElement(this._spectrum.element); |
| 385 }, | 388 }, |
| 386 | 389 |
| 387 /** | 390 /** |
| 388 * @param {boolean=} commitEdit | 391 * @param {boolean=} commitEdit |
| 389 */ | 392 */ |
| 390 hide: function(commitEdit) | 393 hide: function(commitEdit) |
| 391 { | 394 { |
| 392 if (!this._popover.isShowing()) | 395 if (!this._popover.isShowing()) |
| 393 return; | 396 return; |
| 394 this._popover.hide(); | 397 this._popover.hide(); |
| 395 | 398 |
| 396 document.removeEventListener("mousedown", this._hideProxy, false); | 399 document.removeEventListener("mousedown", this._hideProxy, false); |
| 397 window.removeEventListener("blur", this._hideProxy, false); | 400 |
| 401 if (WebInspector.experimentsSettings.colorPicker.isEnabled()) { |
| 402 PageAgent.setColorPickerEnabled(false); |
| 403 WebInspector.targetManager.removeModelListener(WebInspector.Resource
TreeModel, WebInspector.ResourceTreeModel.EventTypes.ColorPicked, this._colorPic
ked, this); |
| 404 } |
| 398 | 405 |
| 399 this.dispatchEventToListeners(WebInspector.SpectrumPopupHelper.Events.Hi
dden, !!commitEdit); | 406 this.dispatchEventToListeners(WebInspector.SpectrumPopupHelper.Events.Hi
dden, !!commitEdit); |
| 400 | 407 |
| 401 WebInspector.setCurrentFocusElement(this._previousFocusElement); | 408 WebInspector.setCurrentFocusElement(this._previousFocusElement); |
| 402 delete this._previousFocusElement; | 409 delete this._previousFocusElement; |
| 403 | 410 |
| 404 delete this._anchorElement; | 411 delete this._anchorElement; |
| 405 }, | 412 }, |
| 406 | 413 |
| 407 _onKeyDown: function(event) | 414 _onKeyDown: function(event) |
| 408 { | 415 { |
| 409 if (event.keyIdentifier === "Enter") { | 416 if (event.keyIdentifier === "Enter") { |
| 410 this.hide(true); | 417 this.hide(true); |
| 411 event.consume(true); | 418 event.consume(true); |
| 412 return; | 419 return; |
| 413 } | 420 } |
| 414 if (event.keyIdentifier === "U+001B") { // Escape key | 421 if (event.keyIdentifier === "U+001B") { // Escape key |
| 415 this.hide(false); | 422 this.hide(false); |
| 416 event.consume(true); | 423 event.consume(true); |
| 417 } | 424 } |
| 418 }, | 425 }, |
| 419 | 426 |
| 427 /** |
| 428 * @param {!WebInspector.Event} event |
| 429 */ |
| 430 _colorPicked: function(event) |
| 431 { |
| 432 var color = /** @type {!DOMAgent.RGBA} */ (event.data); |
| 433 var rgba = [color.r, color.g, color.b, (color.a / 2.55 | 0) / 100]; |
| 434 this._spectrum.setColor(WebInspector.Color.fromRGBA(rgba)); |
| 435 this._spectrum._onchange(); |
| 436 InspectorFrontendHost.bringToFront(); |
| 437 }, |
| 438 |
| 420 __proto__: WebInspector.Object.prototype | 439 __proto__: WebInspector.Object.prototype |
| 421 } | 440 } |
| 422 | 441 |
| 423 /** | 442 /** |
| 424 * @constructor | 443 * @constructor |
| 425 * @param {boolean=} readOnly | 444 * @param {boolean=} readOnly |
| 426 */ | 445 */ |
| 427 WebInspector.ColorSwatch = function(readOnly) | 446 WebInspector.ColorSwatch = function(readOnly) |
| 428 { | 447 { |
| 429 this.element = document.createElementWithClass("span", "swatch"); | 448 this.element = document.createElementWithClass("span", "swatch"); |
| 430 this._swatchInnerElement = this.element.createChild("span", "swatch-inner"); | 449 this._swatchInnerElement = this.element.createChild("span", "swatch-inner"); |
| 431 var shiftClickMessage = WebInspector.UIString("Shift-click to change color f
ormat."); | 450 var shiftClickMessage = WebInspector.UIString("Shift-click to change color f
ormat."); |
| 432 this.element.title = readOnly ? shiftClickMessage : String.sprintf("%s\n%s",
WebInspector.UIString("Click to open a colorpicker."), shiftClickMessage); | 451 this.element.title = readOnly ? shiftClickMessage : String.sprintf("%s\n%s",
WebInspector.UIString("Click to open a colorpicker."), shiftClickMessage); |
| 433 this.element.addEventListener("mousedown", consumeEvent, false); | 452 this.element.addEventListener("mousedown", consumeEvent, false); |
| 434 this.element.addEventListener("dblclick", consumeEvent, false); | 453 this.element.addEventListener("dblclick", consumeEvent, false); |
| 435 } | 454 } |
| 436 | 455 |
| 437 WebInspector.ColorSwatch.prototype = { | 456 WebInspector.ColorSwatch.prototype = { |
| 438 /** | 457 /** |
| 439 * @param {string} colorString | 458 * @param {string} colorString |
| 440 */ | 459 */ |
| 441 setColorString: function(colorString) | 460 setColorString: function(colorString) |
| 442 { | 461 { |
| 443 this._swatchInnerElement.style.backgroundColor = colorString; | 462 this._swatchInnerElement.style.backgroundColor = colorString; |
| 444 } | 463 } |
| 445 } | 464 } |
| OLD | NEW |