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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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._colorPickedBound = this._colorPicked.bind(this); |
| 144 |
143 this._loadPalettes(); | 145 this._loadPalettes(); |
144 new ColorPicker.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(
this)); | 146 new ColorPicker.Spectrum.PaletteGenerator(this._generatedPaletteLoaded.bind(
this)); |
145 | 147 |
146 /** | 148 /** |
147 * @param {function(!Event)} callback | 149 * @param {function(!Event)} callback |
148 * @param {!Event} event | 150 * @param {!Event} event |
149 * @return {boolean} | 151 * @return {boolean} |
150 * @this {ColorPicker.Spectrum} | 152 * @this {ColorPicker.Spectrum} |
151 */ | 153 */ |
152 function dragStart(callback, event) { | 154 function dragStart(callback, event) { |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 * @override | 850 * @override |
849 */ | 851 */ |
850 wasShown() { | 852 wasShown() { |
851 this._hueAlphaWidth = this._hueElement.offsetWidth; | 853 this._hueAlphaWidth = this._hueElement.offsetWidth; |
852 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; | 854 this.slideHelperWidth = this._hueSlider.offsetWidth / 2; |
853 this.dragWidth = this._colorElement.offsetWidth; | 855 this.dragWidth = this._colorElement.offsetWidth; |
854 this.dragHeight = this._colorElement.offsetHeight; | 856 this.dragHeight = this._colorElement.offsetHeight; |
855 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; | 857 this._colorDragElementHeight = this._colorDragElement.offsetHeight / 2; |
856 this._innerSetColor(undefined, undefined, undefined, ColorPicker.Spectrum._C
hangeSource.Model); | 858 this._innerSetColor(undefined, undefined, undefined, ColorPicker.Spectrum._C
hangeSource.Model); |
857 this._toggleColorPicker(true); | 859 this._toggleColorPicker(true); |
858 SDK.targetManager.addModelListener( | |
859 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); | |
860 } | 860 } |
861 | 861 |
862 /** | 862 /** |
863 * @override | 863 * @override |
864 */ | 864 */ |
865 willHide() { | 865 willHide() { |
866 this._toggleColorPicker(false); | 866 this._toggleColorPicker(false); |
867 SDK.targetManager.removeModelListener( | |
868 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.ColorPicked, this._c
olorPicked, this); | |
869 } | 867 } |
870 | 868 |
871 /** | 869 /** |
872 * @param {boolean=} enabled | 870 * @param {boolean=} enabled |
873 * @param {!Common.Event=} event | 871 * @param {!Common.Event=} event |
874 */ | 872 */ |
875 _toggleColorPicker(enabled, event) { | 873 _toggleColorPicker(enabled, event) { |
876 if (enabled === undefined) | 874 if (enabled === undefined) |
877 enabled = !this._colorPickerButton.toggled(); | 875 enabled = !this._colorPickerButton.toggled(); |
878 this._colorPickerButton.setToggled(enabled); | 876 this._colorPickerButton.setToggled(enabled); |
879 for (var target of SDK.targetManager.targets()) | 877 InspectorFrontendHost.setEyeDropperActive(enabled); |
880 target.pageAgent().setColorPickerEnabled(enabled); | 878 if (enabled) { |
| 879 InspectorFrontendHost.events.addEventListener( |
| 880 InspectorFrontendHostAPI.Events.EyeDropperPickedColor, this._colorPick
edBound); |
| 881 } else { |
| 882 InspectorFrontendHost.events.removeEventListener( |
| 883 InspectorFrontendHostAPI.Events.EyeDropperPickedColor, this._colorPick
edBound); |
| 884 } |
881 } | 885 } |
882 | 886 |
883 /** | 887 /** |
884 * @param {!Common.Event} event | 888 * @param {!Common.Event} event |
885 */ | 889 */ |
886 _colorPicked(event) { | 890 _colorPicked(event) { |
887 var rgbColor = /** @type {!Protocol.DOM.RGBA} */ (event.data); | 891 var rgbColor = /** @type {!{r: number, g: number, b: number, a: number}} */
(event.data); |
888 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; | 892 var rgba = [rgbColor.r, rgbColor.g, rgbColor.b, (rgbColor.a / 2.55 | 0) / 10
0]; |
889 var color = Common.Color.fromRGBA(rgba); | 893 var color = Common.Color.fromRGBA(rgba); |
890 this._innerSetColor(color.hsva(), '', undefined, ColorPicker.Spectrum._Chang
eSource.Other); | 894 this._innerSetColor(color.hsva(), '', undefined, ColorPicker.Spectrum._Chang
eSource.Other); |
891 InspectorFrontendHost.bringToFront(); | 895 InspectorFrontendHost.bringToFront(); |
892 } | 896 } |
893 }; | 897 }; |
894 | 898 |
895 ColorPicker.Spectrum._ChangeSource = { | 899 ColorPicker.Spectrum._ChangeSource = { |
896 Input: 'Input', | 900 Input: 'Input', |
897 Model: 'Model', | 901 Model: 'Model', |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 '#607D8B': | 1052 '#607D8B': |
1049 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] | 1053 ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7
A', '#455A64', '#37474F', '#263238'] |
1050 }; | 1054 }; |
1051 | 1055 |
1052 ColorPicker.Spectrum.MaterialPalette = { | 1056 ColorPicker.Spectrum.MaterialPalette = { |
1053 title: 'Material', | 1057 title: 'Material', |
1054 mutable: false, | 1058 mutable: false, |
1055 matchUserFormat: true, | 1059 matchUserFormat: true, |
1056 colors: Object.keys(ColorPicker.Spectrum.MaterialPaletteShades) | 1060 colors: Object.keys(ColorPicker.Spectrum.MaterialPaletteShades) |
1057 }; | 1061 }; |
OLD | NEW |