| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @constructor |
| 7 * @param {!WebInspector.StylePropertyTreeElement} treeElement |
| 8 * @param {!WebInspector.EditorPopoverHelper} editorPopoverHelper |
| 9 * @param {string} text |
| 10 */ |
| 11 WebInspector.BezierPopoverIcon = function(treeElement, editorPopoverHelper, text
) |
| 12 { |
| 13 this._treeElement = treeElement; |
| 14 this._editorPopoverHelper = editorPopoverHelper; |
| 15 this._createDOM(text); |
| 16 |
| 17 this._boundBezierChanged = this._bezierChanged.bind(this); |
| 18 } |
| 19 |
| 20 /** |
| 21 * @param {!Element} parentElement |
| 22 * @return {!Element} |
| 23 */ |
| 24 WebInspector.BezierPopoverIcon.createIcon = function(parentElement) |
| 25 { |
| 26 var element = parentElement.createSVGChild("svg", "popover-icon bezier-icon"
); |
| 27 element.setAttribute("height", 10); |
| 28 element.setAttribute("width", 10); |
| 29 var path = element.createSVGChild("path"); |
| 30 path.setAttribute("d", "M2,8 C2,3 8,7 8,2"); |
| 31 return element; |
| 32 } |
| 33 |
| 34 WebInspector.BezierPopoverIcon.prototype = { |
| 35 /** |
| 36 * @return {!Element} |
| 37 */ |
| 38 element: function() |
| 39 { |
| 40 return this._element; |
| 41 }, |
| 42 |
| 43 /** |
| 44 * @param {string} text |
| 45 */ |
| 46 _createDOM: function(text) |
| 47 { |
| 48 this._element = createElement("nobr"); |
| 49 this._iconElement = WebInspector.BezierPopoverIcon.createIcon(this._elem
ent); |
| 50 this._iconElement.addEventListener("click", this._iconClick.bind(this),
false); |
| 51 this._bezierValueElement = this._element.createChild("span"); |
| 52 this._bezierValueElement.textContent = text; |
| 53 }, |
| 54 |
| 55 /** |
| 56 * @param {!Event} event |
| 57 */ |
| 58 _iconClick: function(event) |
| 59 { |
| 60 event.consume(true); |
| 61 if (this._editorPopoverHelper.isShowing()) { |
| 62 this._editorPopoverHelper.hide(true); |
| 63 return; |
| 64 } |
| 65 |
| 66 this._bezierEditor = new WebInspector.BezierEditor(); |
| 67 var geometry = WebInspector.Geometry.CubicBezier.parse(this._bezierValue
Element.textContent); |
| 68 this._bezierEditor.setBezier(geometry); |
| 69 this._bezierEditor.addEventListener(WebInspector.BezierEditor.Events.Bez
ierChanged, this._boundBezierChanged); |
| 70 var scrollerElement = this._iconElement.enclosingNodeOrSelfWithClass("st
yle-panes-wrapper"); |
| 71 this._editorPopoverHelper.show(this._bezierEditor, this._iconElement, sc
rollerElement, this._onPopoverHidden.bind(this)); |
| 72 |
| 73 this._originalPropertyText = this._treeElement.property.propertyText; |
| 74 this._treeElement.parentPane().setEditingStyle(true); |
| 75 }, |
| 76 |
| 77 /** |
| 78 * @param {!WebInspector.Event} event |
| 79 */ |
| 80 _bezierChanged: function(event) |
| 81 { |
| 82 this._bezierValueElement.textContent = /** @type {string} */ (event.data
); |
| 83 this._treeElement.applyStyleText(this._treeElement.renderedPropertyText(
), false); |
| 84 }, |
| 85 |
| 86 /** |
| 87 * @param {boolean} commitEdit |
| 88 */ |
| 89 _onPopoverHidden: function(commitEdit) |
| 90 { |
| 91 this._bezierEditor.removeEventListener(WebInspector.BezierEditor.Events.
BezierChanged, this._boundBezierChanged); |
| 92 delete this._bezierEditor; |
| 93 |
| 94 var propertyText = commitEdit ? this._treeElement.renderedPropertyText()
: this._originalPropertyText; |
| 95 this._treeElement.applyStyleText(propertyText, true); |
| 96 this._treeElement.parentPane().setEditingStyle(false); |
| 97 delete this._originalPropertyText; |
| 98 } |
| 99 } |
| 100 |
| 101 /** |
| 102 * @constructor |
| 103 * @param {!WebInspector.StylePropertyTreeElement} treeElement |
| 104 * @param {!WebInspector.EditorPopoverHelper} editorPopoverHelper |
| 105 * @param {string} colorText |
| 106 */ |
| 107 WebInspector.ColorSwatchPopoverIcon = function(treeElement, editorPopoverHelper,
colorText) |
| 108 { |
| 109 this._treeElement = treeElement; |
| 110 this._editorPopoverHelper = editorPopoverHelper; |
| 111 |
| 112 this._swatch = WebInspector.ColorSwatch.create(); |
| 113 this._swatch.setColorText(colorText); |
| 114 this._swatch.setFormat(WebInspector.ColorSwatchPopoverIcon._colorFormat(this
._swatch.color())); |
| 115 var shiftClickMessage = WebInspector.UIString("Shift-click to change color f
ormat."); |
| 116 this._swatch.iconElement().title = String.sprintf("%s\n%s", WebInspector.UIS
tring("Click to open a colorpicker."), shiftClickMessage); |
| 117 this._swatch.iconElement().addEventListener("click", this._iconClick.bind(th
is)); |
| 118 |
| 119 this._boundSpectrumChanged = this._spectrumChanged.bind(this); |
| 120 } |
| 121 |
| 122 /** |
| 123 * @param {!WebInspector.Color} color |
| 124 * @return {!WebInspector.Color.Format} |
| 125 */ |
| 126 WebInspector.ColorSwatchPopoverIcon._colorFormat = function(color) |
| 127 { |
| 128 const cf = WebInspector.Color.Format; |
| 129 var format; |
| 130 var formatSetting = WebInspector.moduleSetting("colorFormat").get(); |
| 131 if (formatSetting === cf.Original) |
| 132 format = cf.Original; |
| 133 else if (formatSetting === cf.RGB) |
| 134 format = (color.hasAlpha() ? cf.RGBA : cf.RGB); |
| 135 else if (formatSetting === cf.HSL) |
| 136 format = (color.hasAlpha() ? cf.HSLA : cf.HSL); |
| 137 else if (!color.hasAlpha()) |
| 138 format = (color.canBeShortHex() ? cf.ShortHEX : cf.HEX); |
| 139 else |
| 140 format = cf.RGBA; |
| 141 |
| 142 return format; |
| 143 } |
| 144 |
| 145 WebInspector.ColorSwatchPopoverIcon.prototype = { |
| 146 /** |
| 147 * @return {!Element} |
| 148 */ |
| 149 element: function() |
| 150 { |
| 151 return this._swatch; |
| 152 }, |
| 153 |
| 154 /** |
| 155 * @param {!Event} event |
| 156 */ |
| 157 _iconClick: function(event) |
| 158 { |
| 159 event.consume(true); |
| 160 if (this._editorPopoverHelper.isShowing()) { |
| 161 this._editorPopoverHelper.hide(true); |
| 162 return; |
| 163 } |
| 164 |
| 165 var color = this._swatch.color(); |
| 166 var format = this._swatch.format(); |
| 167 if (format === WebInspector.Color.Format.Original) |
| 168 format = color.format(); |
| 169 this._spectrum = new WebInspector.Spectrum(); |
| 170 this._spectrum.setColor(color); |
| 171 this._spectrum.setColorFormat(format); |
| 172 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange
d, this._boundSpectrumChanged); |
| 173 var scrollerElement = this._swatch.iconElement().enclosingNodeOrSelfWith
Class("style-panes-wrapper"); |
| 174 this._editorPopoverHelper.show(this._spectrum, this._swatch.iconElement(
), scrollerElement, this._onPopoverHidden.bind(this)); |
| 175 |
| 176 this._originalPropertyText = this._treeElement.property.propertyText; |
| 177 this._treeElement.parentPane().setEditingStyle(true); |
| 178 }, |
| 179 |
| 180 /** |
| 181 * @param {!WebInspector.Event} event |
| 182 */ |
| 183 _spectrumChanged: function(event) |
| 184 { |
| 185 var colorString = /** @type {string} */ (event.data); |
| 186 this._swatch.setColorText(colorString); |
| 187 this._treeElement.applyStyleText(this._treeElement.renderedPropertyText(
), false); |
| 188 }, |
| 189 |
| 190 /** |
| 191 * @param {boolean} commitEdit |
| 192 */ |
| 193 _onPopoverHidden: function(commitEdit) |
| 194 { |
| 195 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha
nged, this._boundSpectrumChanged); |
| 196 delete this._spectrum; |
| 197 |
| 198 var propertyText = commitEdit ? this._treeElement.renderedPropertyText()
: this._originalPropertyText; |
| 199 this._treeElement.applyStyleText(propertyText, true); |
| 200 this._treeElement.parentPane().setEditingStyle(false); |
| 201 delete this._originalPropertyText; |
| 202 } |
| 203 } |
| OLD | NEW |