OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 * @extends {WebInspector.VBox} |
| 8 */ |
| 9 WebInspector.CSSShadowEditor = function() |
| 10 { |
| 11 WebInspector.VBox.call(this, true); |
| 12 this.registerRequiredCSS("ui/cssShadowEditor.css"); |
| 13 this.contentElement.tabIndex = 0; |
| 14 |
| 15 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel
d"); |
| 16 this._typeField.createChild("label", "shadow-editor-label").textContent = We
bInspector.UIString("Type"); |
| 17 this._outsetButton = this._typeField.createChild("button", "shadow-editor-bu
tton-left"); |
| 18 this._outsetButton.textContent = WebInspector.UIString("Outset"); |
| 19 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this),
false); |
| 20 this._insetButton = this._typeField.createChild("button", "shadow-editor-but
ton-right"); |
| 21 this._insetButton.textContent = WebInspector.UIString("Inset"); |
| 22 this._insetButton.addEventListener("click", this._onButtonClick.bind(this),
false); |
| 23 |
| 24 var inputs; |
| 25 inputs = this._createSliderField(WebInspector.UIString("X offset"), true); |
| 26 this._xInput = inputs.textInput; |
| 27 this._xSlider = inputs.rangeInput; |
| 28 inputs = this._createSliderField(WebInspector.UIString("Y offset"), true); |
| 29 this._yInput = inputs.textInput; |
| 30 this._ySlider = inputs.rangeInput; |
| 31 inputs = this._createSliderField(WebInspector.UIString("Blur"), false); |
| 32 this._blurInput = inputs.textInput; |
| 33 this._blurSlider = inputs.rangeInput; |
| 34 inputs = this._createSliderField(WebInspector.UIString("Spread"), false); |
| 35 this._spreadInput = inputs.textInput; |
| 36 this._spreadSlider = inputs.rangeInput; |
| 37 this._spreadField = inputs.field; |
| 38 } |
| 39 |
| 40 /** @enum {symbol} */ |
| 41 WebInspector.CSSShadowEditor.Events = { |
| 42 ShadowChanged: Symbol("ShadowChanged") |
| 43 } |
| 44 |
| 45 /** @type {number} */ |
| 46 WebInspector.CSSShadowEditor.maxRange = 40; |
| 47 /** @type {string} */ |
| 48 WebInspector.CSSShadowEditor.defaultUnit = "px"; |
| 49 |
| 50 WebInspector.CSSShadowEditor.prototype = { |
| 51 /** |
| 52 * @param {string} propertyName |
| 53 * @param {boolean} negativeAllowed |
| 54 * @return {{textInput: !Element, rangeInput: !Element, field: !Element}} |
| 55 */ |
| 56 _createSliderField: function(propertyName, negativeAllowed) |
| 57 { |
| 58 var field = this.contentElement.createChild("div", "shadow-editor-field"
); |
| 59 var label = field.createChild("label", "shadow-editor-label"); |
| 60 label.textContent = propertyName; |
| 61 label.setAttribute("for", propertyName); |
| 62 var textInput = field.createChild("input", "shadow-editor-text-input"); |
| 63 textInput.type = "text"; |
| 64 textInput.id = propertyName; |
| 65 textInput.addEventListener("input", this._onTextInput.bind(this), false)
; |
| 66 textInput.addEventListener("blur", this._onTextBlur.bind(this), false); |
| 67 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2; |
| 68 var slider = negativeAllowed ? createSliderLabel(-halfRange, halfRange)
: createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange); |
| 69 slider.addEventListener("input", this._onSliderInput.bind(this), false); |
| 70 field.appendChild(slider); |
| 71 return {field: field, textInput: textInput, rangeInput: slider}; |
| 72 }, |
| 73 |
| 74 /** |
| 75 * @override |
| 76 */ |
| 77 wasShown: function() |
| 78 { |
| 79 this._updateUI(); |
| 80 }, |
| 81 |
| 82 /** |
| 83 * @param {!WebInspector.CSSShadowModel} model |
| 84 */ |
| 85 setModel: function(model) |
| 86 { |
| 87 this._model = model; |
| 88 this._typeField.hidden = !model.isBoxShadow(); |
| 89 this._spreadField.hidden = !model.isBoxShadow(); |
| 90 this._updateUI(); |
| 91 }, |
| 92 |
| 93 _updateUI: function() |
| 94 { |
| 95 this._updateButtons(); |
| 96 this._xInput.value = this._model.offsetX().asCSSText(); |
| 97 this._yInput.value = this._model.offsetY().asCSSText(); |
| 98 this._blurInput.value = this._model.blurRadius().asCSSText(); |
| 99 this._spreadInput.value = this._model.spreadRadius().asCSSText(); |
| 100 this._xSlider.value = this._model.offsetX().amount; |
| 101 this._ySlider.value = this._model.offsetY().amount; |
| 102 this._blurSlider.value = this._model.blurRadius().amount; |
| 103 this._spreadSlider.value = this._model.spreadRadius().amount; |
| 104 }, |
| 105 |
| 106 _updateButtons: function() |
| 107 { |
| 108 this._insetButton.classList.toggle("enabled", this._model.inset()); |
| 109 this._outsetButton.classList.toggle("enabled", !this._model.inset()); |
| 110 }, |
| 111 |
| 112 /** |
| 113 * @param {!Event} event |
| 114 */ |
| 115 _onButtonClick: function(event) |
| 116 { |
| 117 var insetClicked = (event.currentTarget === this._insetButton); |
| 118 if (insetClicked && this._model.inset() || !insetClicked && !this._model
.inset()) |
| 119 return; |
| 120 this._model.setInset(insetClicked); |
| 121 this._updateButtons(); |
| 122 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 123 }, |
| 124 |
| 125 /** |
| 126 * @param {!Event} event |
| 127 */ |
| 128 _onTextInput: function(event) |
| 129 { |
| 130 this._changedElement = event.currentTarget; |
| 131 this._changedElement.classList.toggle("invalid", false); |
| 132 var length = WebInspector.CSSLength.parse(event.currentTarget.value); |
| 133 if (!length || event.currentTarget === this._blurInput && length.amount
< 0) |
| 134 return; |
| 135 if (event.currentTarget === this._xInput) { |
| 136 this._model.setOffsetX(length); |
| 137 this._xSlider.value = length.amount; |
| 138 } else if (event.currentTarget === this._yInput) { |
| 139 this._model.setOffsetY(length); |
| 140 this._ySlider.value = length.amount; |
| 141 } else if (event.currentTarget === this._blurInput) { |
| 142 this._model.setBlurRadius(length); |
| 143 this._blurSlider.value = length.amount; |
| 144 } else if (event.currentTarget === this._spreadInput) { |
| 145 this._model.setSpreadRadius(length); |
| 146 this._spreadSlider.value = length.amount; |
| 147 } |
| 148 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 149 }, |
| 150 |
| 151 _onTextBlur: function() |
| 152 { |
| 153 if (!this._changedElement) |
| 154 return; |
| 155 var length = !this._changedElement.value ? WebInspector.CSSLength.zero()
: WebInspector.CSSLength.parse(this._changedElement.value); |
| 156 if (!length) |
| 157 length = WebInspector.CSSLength.parse(this._changedElement.value + W
ebInspector.CSSShadowEditor.defaultUnit); |
| 158 if (!length) { |
| 159 this._changedElement.classList.add("invalid"); |
| 160 this._changedElement = null; |
| 161 return; |
| 162 } |
| 163 if (this._changedElement === this._xInput) { |
| 164 this._model.setOffsetX(length); |
| 165 this._xInput.value = length.asCSSText(); |
| 166 this._xSlider.value = length.amount; |
| 167 } else if (this._changedElement === this._yInput) { |
| 168 this._model.setOffsetY(length); |
| 169 this._yInput.value = length.asCSSText(); |
| 170 this._ySlider.value = length.amount; |
| 171 } else if (this._changedElement === this._blurInput) { |
| 172 if (length.amount < 0) |
| 173 length = WebInspector.CSSLength.zero(); |
| 174 this._model.setBlurRadius(length); |
| 175 this._blurInput.value = length.asCSSText(); |
| 176 this._blurSlider.value = length.amount; |
| 177 } else if (this._changedElement === this._spreadInput) { |
| 178 this._model.setSpreadRadius(length); |
| 179 this._spreadInput.value = length.asCSSText(); |
| 180 this._spreadSlider.value = length.amount; |
| 181 } |
| 182 this._changedElement = null; |
| 183 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 184 }, |
| 185 |
| 186 /** |
| 187 * @param {!Event} event |
| 188 */ |
| 189 _onSliderInput: function(event) |
| 190 { |
| 191 if (event.currentTarget === this._xSlider) { |
| 192 this._model.setOffsetX(new WebInspector.CSSLength(this._xSlider.valu
e, this._model.offsetX().unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 193 this._xInput.value = this._model.offsetX().asCSSText(); |
| 194 this._xInput.classList.toggle("invalid", false); |
| 195 } else if (event.currentTarget === this._ySlider) { |
| 196 this._model.setOffsetY(new WebInspector.CSSLength(this._ySlider.valu
e, this._model.offsetY().unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 197 this._yInput.value = this._model.offsetY().asCSSText(); |
| 198 this._yInput.classList.toggle("invalid", false); |
| 199 } else if (event.currentTarget === this._blurSlider) { |
| 200 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide
r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn
it)); |
| 201 this._blurInput.value = this._model.blurRadius().asCSSText(); |
| 202 this._blurInput.classList.toggle("invalid", false); |
| 203 } else if (event.currentTarget === this._spreadSlider) { |
| 204 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS
lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def
aultUnit)); |
| 205 this._spreadInput.value = this._model.spreadRadius().asCSSText(); |
| 206 this._spreadInput.classList.toggle("invalid", false); |
| 207 } |
| 208 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 209 }, |
| 210 |
| 211 __proto__: WebInspector.VBox.prototype |
| 212 } |
OLD | NEW |