| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 */ | 8 */ |
| 9 WebInspector.CSSShadowEditor = function() | 9 WebInspector.CSSShadowEditor = function() |
| 10 { | 10 { |
| 11 WebInspector.VBox.call(this, true); | 11 WebInspector.VBox.call(this, true); |
| 12 this.registerRequiredCSS("ui/cssShadowEditor.css"); | 12 this.registerRequiredCSS("ui/cssShadowEditor.css"); |
| 13 this.contentElement.tabIndex = 0; | 13 this.contentElement.tabIndex = 0; |
| 14 | 14 |
| 15 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel
d"); | 15 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel
d"); |
| 16 this._typeField.createChild("label", "shadow-editor-label").textContent = We
bInspector.UIString("Type"); | 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"); | 17 this._outsetButton = this._typeField.createChild("button", "shadow-editor-bu
tton-left"); |
| 18 this._outsetButton.textContent = WebInspector.UIString("Outset"); | 18 this._outsetButton.textContent = WebInspector.UIString("Outset"); |
| 19 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this),
false); | 19 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this),
false); |
| 20 this._insetButton = this._typeField.createChild("button", "shadow-editor-but
ton-right"); | 20 this._insetButton = this._typeField.createChild("button", "shadow-editor-but
ton-right"); |
| 21 this._insetButton.textContent = WebInspector.UIString("Inset"); | 21 this._insetButton.textContent = WebInspector.UIString("Inset"); |
| 22 this._insetButton.addEventListener("click", this._onButtonClick.bind(this),
false); | 22 this._insetButton.addEventListener("click", this._onButtonClick.bind(this),
false); |
| 23 | 23 |
| 24 var inputs; | 24 var xField = this.contentElement.createChild("div", "shadow-editor-field"); |
| 25 inputs = this._createSliderField(WebInspector.UIString("X offset"), true); | 25 this._xInput = this._createTextInput(xField, WebInspector.UIString("X offset
")); |
| 26 this._xInput = inputs.textInput; | 26 var yField = this.contentElement.createChild("div", "shadow-editor-field"); |
| 27 this._xSlider = inputs.rangeInput; | 27 this._yInput = this._createTextInput(yField, WebInspector.UIString("Y offset
")); |
| 28 inputs = this._createSliderField(WebInspector.UIString("Y offset"), true); | 28 this._xySlider = xField.createChild("canvas", "shadow-editor-2D-slider"); |
| 29 this._yInput = inputs.textInput; | 29 this._xySlider.width = WebInspector.CSSShadowEditor.canvasSize; |
| 30 this._ySlider = inputs.rangeInput; | 30 this._xySlider.height = WebInspector.CSSShadowEditor.canvasSize; |
| 31 inputs = this._createSliderField(WebInspector.UIString("Blur"), false); | 31 this._xySlider.tabIndex = -1; |
| 32 this._blurInput = inputs.textInput; | 32 this._halfCanvasSize = WebInspector.CSSShadowEditor.canvasSize / 2; |
| 33 this._blurSlider = inputs.rangeInput; | 33 this._innerCanvasSize = this._halfCanvasSize - WebInspector.CSSShadowEditor.
sliderThumbRadius; |
| 34 inputs = this._createSliderField(WebInspector.UIString("Spread"), false); | 34 WebInspector.installDragHandle(this._xySlider, this._dragStart.bind(this), t
his._dragMove.bind(this), null, "default"); |
| 35 this._spreadInput = inputs.textInput; | 35 this._xySlider.addEventListener("keydown", this._onCanvasArrowKey.bind(this)
, false); |
| 36 this._spreadSlider = inputs.rangeInput; | 36 this._xySlider.addEventListener("blur", this._onCanvasBlur.bind(this), false
); |
| 37 this._spreadField = inputs.field; | 37 |
| 38 var blurField = this.contentElement.createChild("div", "shadow-editor-blur-f
ield"); |
| 39 this._blurInput = this._createTextInput(blurField, WebInspector.UIString("Bl
ur")); |
| 40 this._blurSlider = this._createSlider(blurField); |
| 41 |
| 42 this._spreadField = this.contentElement.createChild("div", "shadow-editor-fi
eld"); |
| 43 this._spreadInput = this._createTextInput(this._spreadField, WebInspector.UI
String("Spread")); |
| 44 this._spreadSlider = this._createSlider(this._spreadField); |
| 38 } | 45 } |
| 39 | 46 |
| 40 /** @enum {symbol} */ | 47 /** @enum {symbol} */ |
| 41 WebInspector.CSSShadowEditor.Events = { | 48 WebInspector.CSSShadowEditor.Events = { |
| 42 ShadowChanged: Symbol("ShadowChanged") | 49 ShadowChanged: Symbol("ShadowChanged") |
| 43 } | 50 } |
| 44 | 51 |
| 45 /** @type {number} */ | 52 /** @type {number} */ |
| 46 WebInspector.CSSShadowEditor.maxRange = 40; | 53 WebInspector.CSSShadowEditor.maxRange = 20; |
| 47 /** @type {string} */ | 54 /** @type {string} */ |
| 48 WebInspector.CSSShadowEditor.defaultUnit = "px"; | 55 WebInspector.CSSShadowEditor.defaultUnit = "px"; |
| 56 /** @type {number} */ |
| 57 WebInspector.CSSShadowEditor.sliderThumbRadius = 6; |
| 58 /** @type {number} */ |
| 59 WebInspector.CSSShadowEditor.canvasSize = 88; |
| 49 | 60 |
| 50 WebInspector.CSSShadowEditor.prototype = { | 61 WebInspector.CSSShadowEditor.prototype = { |
| 51 /** | 62 /** |
| 63 * @param {!Element} field |
| 52 * @param {string} propertyName | 64 * @param {string} propertyName |
| 53 * @param {boolean} negativeAllowed | 65 * @return {!Element} |
| 54 * @return {{textInput: !Element, rangeInput: !Element, field: !Element}} | |
| 55 */ | 66 */ |
| 56 _createSliderField: function(propertyName, negativeAllowed) | 67 _createTextInput: function(field, propertyName) |
| 57 { | 68 { |
| 58 var field = this.contentElement.createChild("div", "shadow-editor-field"
); | |
| 59 var label = field.createChild("label", "shadow-editor-label"); | 69 var label = field.createChild("label", "shadow-editor-label"); |
| 60 label.textContent = propertyName; | 70 label.textContent = propertyName; |
| 61 label.setAttribute("for", propertyName); | 71 label.setAttribute("for", propertyName); |
| 62 var textInput = field.createChild("input", "shadow-editor-text-input"); | 72 var textInput = field.createChild("input", "shadow-editor-text-input"); |
| 63 textInput.type = "text"; | 73 textInput.type = "text"; |
| 64 textInput.id = propertyName; | 74 textInput.id = propertyName; |
| 65 textInput.addEventListener("keydown", this._handleValueModification.bind
(this), false); | 75 textInput.addEventListener("keydown", this._handleValueModification.bind
(this), false); |
| 66 textInput.addEventListener("mousewheel", this._handleValueModification.b
ind(this), false); | 76 textInput.addEventListener("mousewheel", this._handleValueModification.b
ind(this), false); |
| 67 textInput.addEventListener("input", this._onTextInput.bind(this), false)
; | 77 textInput.addEventListener("input", this._onTextInput.bind(this), false)
; |
| 68 textInput.addEventListener("blur", this._onTextBlur.bind(this), false); | 78 textInput.addEventListener("blur", this._onTextBlur.bind(this), false); |
| 69 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2; | 79 return textInput; |
| 70 var slider = negativeAllowed ? createSliderLabel(-halfRange, halfRange)
: createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange); | |
| 71 slider.addEventListener("input", this._onSliderInput.bind(this), false); | |
| 72 field.appendChild(slider); | |
| 73 return {field: field, textInput: textInput, rangeInput: slider}; | |
| 74 }, | 80 }, |
| 75 | 81 |
| 76 /** | 82 /** |
| 83 * @param {!Element} field |
| 84 * @return {!Element} |
| 85 */ |
| 86 _createSlider: function(field) |
| 87 { |
| 88 var slider = createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange,
-1); |
| 89 slider.addEventListener("input", this._onSliderInput.bind(this), false); |
| 90 field.appendChild(slider); |
| 91 return slider; |
| 92 }, |
| 93 |
| 94 /** |
| 77 * @override | 95 * @override |
| 78 */ | 96 */ |
| 79 wasShown: function() | 97 wasShown: function() |
| 80 { | 98 { |
| 81 this._updateUI(); | 99 this._updateUI(); |
| 82 }, | 100 }, |
| 83 | 101 |
| 84 /** | 102 /** |
| 85 * @param {!WebInspector.CSSShadowModel} model | 103 * @param {!WebInspector.CSSShadowModel} model |
| 86 */ | 104 */ |
| 87 setModel: function(model) | 105 setModel: function(model) |
| 88 { | 106 { |
| 89 this._model = model; | 107 this._model = model; |
| 90 this._typeField.hidden = !model.isBoxShadow(); | 108 this._typeField.hidden = !model.isBoxShadow(); |
| 91 this._spreadField.hidden = !model.isBoxShadow(); | 109 this._spreadField.hidden = !model.isBoxShadow(); |
| 92 this._updateUI(); | 110 this._updateUI(); |
| 93 }, | 111 }, |
| 94 | 112 |
| 95 _updateUI: function() | 113 _updateUI: function() |
| 96 { | 114 { |
| 97 this._updateButtons(); | 115 this._updateButtons(); |
| 98 this._xInput.value = this._model.offsetX().asCSSText(); | 116 this._xInput.value = this._model.offsetX().asCSSText(); |
| 99 this._yInput.value = this._model.offsetY().asCSSText(); | 117 this._yInput.value = this._model.offsetY().asCSSText(); |
| 100 this._blurInput.value = this._model.blurRadius().asCSSText(); | 118 this._blurInput.value = this._model.blurRadius().asCSSText(); |
| 101 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | 119 this._spreadInput.value = this._model.spreadRadius().asCSSText(); |
| 102 this._xSlider.value = this._model.offsetX().amount; | |
| 103 this._ySlider.value = this._model.offsetY().amount; | |
| 104 this._blurSlider.value = this._model.blurRadius().amount; | 120 this._blurSlider.value = this._model.blurRadius().amount; |
| 105 this._spreadSlider.value = this._model.spreadRadius().amount; | 121 this._spreadSlider.value = this._model.spreadRadius().amount; |
| 122 this._updateCanvas(false); |
| 106 }, | 123 }, |
| 107 | 124 |
| 108 _updateButtons: function() | 125 _updateButtons: function() |
| 109 { | 126 { |
| 110 this._insetButton.classList.toggle("enabled", this._model.inset()); | 127 this._insetButton.classList.toggle("enabled", this._model.inset()); |
| 111 this._outsetButton.classList.toggle("enabled", !this._model.inset()); | 128 this._outsetButton.classList.toggle("enabled", !this._model.inset()); |
| 112 }, | 129 }, |
| 113 | 130 |
| 114 /** | 131 /** |
| 132 * @param {boolean} drawFocus |
| 133 */ |
| 134 _updateCanvas: function(drawFocus) |
| 135 { |
| 136 var context = this._xySlider.getContext("2d"); |
| 137 context.clearRect(0, 0, this._xySlider.width, this._xySlider.height); |
| 138 |
| 139 // Draw dashed axes. |
| 140 context.save(); |
| 141 context.setLineDash([1, 1]); |
| 142 context.strokeStyle = "rgba(0, 0, 0, 0.2)"; |
| 143 context.beginPath(); |
| 144 context.moveTo(this._halfCanvasSize, 0); |
| 145 context.lineTo(this._halfCanvasSize, WebInspector.CSSShadowEditor.canvas
Size); |
| 146 context.moveTo(0, this._halfCanvasSize); |
| 147 context.lineTo(WebInspector.CSSShadowEditor.canvasSize, this._halfCanvas
Size); |
| 148 context.stroke(); |
| 149 context.restore(); |
| 150 |
| 151 var thumbPoint = this._sliderThumbPosition(); |
| 152 // Draw 2D slider line. |
| 153 context.save(); |
| 154 context.translate(this._halfCanvasSize, this._halfCanvasSize); |
| 155 context.lineWidth = 2; |
| 156 context.strokeStyle = "rgba(0, 0, 0, 0.3)"; |
| 157 context.beginPath(); |
| 158 context.moveTo(0, 0); |
| 159 context.lineTo(thumbPoint.x, thumbPoint.y); |
| 160 context.stroke(); |
| 161 // Draw 2D slider thumb. |
| 162 if (drawFocus) { |
| 163 context.beginPath(); |
| 164 context.fillStyle = "rgba(66, 133, 244, 0.4)"; |
| 165 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor
.sliderThumbRadius + 2, 0, 2 * Math.PI); |
| 166 context.fill(); |
| 167 } |
| 168 context.beginPath() |
| 169 context.fillStyle = "#4285F4"; |
| 170 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor.sli
derThumbRadius, 0, 2 * Math.PI); |
| 171 context.fill(); |
| 172 context.restore(); |
| 173 }, |
| 174 |
| 175 /** |
| 115 * @param {!Event} event | 176 * @param {!Event} event |
| 116 */ | 177 */ |
| 117 _onButtonClick: function(event) | 178 _onButtonClick: function(event) |
| 118 { | 179 { |
| 119 var insetClicked = (event.currentTarget === this._insetButton); | 180 var insetClicked = (event.currentTarget === this._insetButton); |
| 120 if (insetClicked && this._model.inset() || !insetClicked && !this._model
.inset()) | 181 if (insetClicked && this._model.inset() || !insetClicked && !this._model
.inset()) |
| 121 return; | 182 return; |
| 122 this._model.setInset(insetClicked); | 183 this._model.setInset(insetClicked); |
| 123 this._updateButtons(); | 184 this._updateButtons(); |
| 124 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); | 185 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return prefix + number + suffix; | 217 return prefix + number + suffix; |
| 157 } | 218 } |
| 158 }, | 219 }, |
| 159 | 220 |
| 160 /** | 221 /** |
| 161 * @param {!Event} event | 222 * @param {!Event} event |
| 162 */ | 223 */ |
| 163 _onTextInput: function(event) | 224 _onTextInput: function(event) |
| 164 { | 225 { |
| 165 this._changedElement = event.currentTarget; | 226 this._changedElement = event.currentTarget; |
| 166 this._changedElement.classList.toggle("invalid", false); | 227 this._changedElement.classList.remove("invalid"); |
| 167 var length = WebInspector.CSSLength.parse(event.currentTarget.value); | 228 var length = WebInspector.CSSLength.parse(event.currentTarget.value); |
| 168 if (!length || event.currentTarget === this._blurInput && length.amount
< 0) | 229 if (!length || event.currentTarget === this._blurInput && length.amount
< 0) |
| 169 return; | 230 return; |
| 170 if (event.currentTarget === this._xInput) { | 231 if (event.currentTarget === this._xInput) { |
| 171 this._model.setOffsetX(length); | 232 this._model.setOffsetX(length); |
| 172 this._xSlider.value = length.amount; | 233 this._updateCanvas(false); |
| 173 } else if (event.currentTarget === this._yInput) { | 234 } else if (event.currentTarget === this._yInput) { |
| 174 this._model.setOffsetY(length); | 235 this._model.setOffsetY(length); |
| 175 this._ySlider.value = length.amount; | 236 this._updateCanvas(false); |
| 176 } else if (event.currentTarget === this._blurInput) { | 237 } else if (event.currentTarget === this._blurInput) { |
| 177 this._model.setBlurRadius(length); | 238 this._model.setBlurRadius(length); |
| 178 this._blurSlider.value = length.amount; | 239 this._blurSlider.value = length.amount; |
| 179 } else if (event.currentTarget === this._spreadInput) { | 240 } else if (event.currentTarget === this._spreadInput) { |
| 180 this._model.setSpreadRadius(length); | 241 this._model.setSpreadRadius(length); |
| 181 this._spreadSlider.value = length.amount; | 242 this._spreadSlider.value = length.amount; |
| 182 } | 243 } |
| 183 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); | 244 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 184 }, | 245 }, |
| 185 | 246 |
| 186 _onTextBlur: function() | 247 _onTextBlur: function() |
| 187 { | 248 { |
| 188 if (!this._changedElement) | 249 if (!this._changedElement) |
| 189 return; | 250 return; |
| 190 var length = !this._changedElement.value ? WebInspector.CSSLength.zero()
: WebInspector.CSSLength.parse(this._changedElement.value); | 251 var length = !this._changedElement.value.trim() ? WebInspector.CSSLength
.zero() : WebInspector.CSSLength.parse(this._changedElement.value); |
| 191 if (!length) | 252 if (!length) |
| 192 length = WebInspector.CSSLength.parse(this._changedElement.value + W
ebInspector.CSSShadowEditor.defaultUnit); | 253 length = WebInspector.CSSLength.parse(this._changedElement.value + W
ebInspector.CSSShadowEditor.defaultUnit); |
| 193 if (!length) { | 254 if (!length) { |
| 194 this._changedElement.classList.add("invalid"); | 255 this._changedElement.classList.add("invalid"); |
| 195 this._changedElement = null; | 256 this._changedElement = null; |
| 196 return; | 257 return; |
| 197 } | 258 } |
| 198 if (this._changedElement === this._xInput) { | 259 if (this._changedElement === this._xInput) { |
| 199 this._model.setOffsetX(length); | 260 this._model.setOffsetX(length); |
| 200 this._xInput.value = length.asCSSText(); | 261 this._xInput.value = length.asCSSText(); |
| 201 this._xSlider.value = length.amount; | 262 this._updateCanvas(false); |
| 202 } else if (this._changedElement === this._yInput) { | 263 } else if (this._changedElement === this._yInput) { |
| 203 this._model.setOffsetY(length); | 264 this._model.setOffsetY(length); |
| 204 this._yInput.value = length.asCSSText(); | 265 this._yInput.value = length.asCSSText(); |
| 205 this._ySlider.value = length.amount; | 266 this._updateCanvas(false); |
| 206 } else if (this._changedElement === this._blurInput) { | 267 } else if (this._changedElement === this._blurInput) { |
| 207 if (length.amount < 0) | 268 if (length.amount < 0) |
| 208 length = WebInspector.CSSLength.zero(); | 269 length = WebInspector.CSSLength.zero(); |
| 209 this._model.setBlurRadius(length); | 270 this._model.setBlurRadius(length); |
| 210 this._blurInput.value = length.asCSSText(); | 271 this._blurInput.value = length.asCSSText(); |
| 211 this._blurSlider.value = length.amount; | 272 this._blurSlider.value = length.amount; |
| 212 } else if (this._changedElement === this._spreadInput) { | 273 } else if (this._changedElement === this._spreadInput) { |
| 213 this._model.setSpreadRadius(length); | 274 this._model.setSpreadRadius(length); |
| 214 this._spreadInput.value = length.asCSSText(); | 275 this._spreadInput.value = length.asCSSText(); |
| 215 this._spreadSlider.value = length.amount; | 276 this._spreadSlider.value = length.amount; |
| 216 } | 277 } |
| 217 this._changedElement = null; | 278 this._changedElement = null; |
| 218 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); | 279 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 219 }, | 280 }, |
| 220 | 281 |
| 221 /** | 282 /** |
| 222 * @param {!Event} event | 283 * @param {!Event} event |
| 223 */ | 284 */ |
| 224 _onSliderInput: function(event) | 285 _onSliderInput: function(event) |
| 225 { | 286 { |
| 226 if (event.currentTarget === this._xSlider) { | 287 if (event.currentTarget === this._blurSlider) { |
| 227 this._model.setOffsetX(new WebInspector.CSSLength(this._xSlider.valu
e, this._model.offsetX().unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 228 this._xInput.value = this._model.offsetX().asCSSText(); | |
| 229 this._xInput.classList.toggle("invalid", false); | |
| 230 } else if (event.currentTarget === this._ySlider) { | |
| 231 this._model.setOffsetY(new WebInspector.CSSLength(this._ySlider.valu
e, this._model.offsetY().unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 232 this._yInput.value = this._model.offsetY().asCSSText(); | |
| 233 this._yInput.classList.toggle("invalid", false); | |
| 234 } else if (event.currentTarget === this._blurSlider) { | |
| 235 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide
r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn
it)); | 288 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide
r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn
it)); |
| 236 this._blurInput.value = this._model.blurRadius().asCSSText(); | 289 this._blurInput.value = this._model.blurRadius().asCSSText(); |
| 237 this._blurInput.classList.toggle("invalid", false); | 290 this._blurInput.classList.remove("invalid"); |
| 238 } else if (event.currentTarget === this._spreadSlider) { | 291 } else if (event.currentTarget === this._spreadSlider) { |
| 239 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS
lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def
aultUnit)); | 292 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS
lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def
aultUnit)); |
| 240 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | 293 this._spreadInput.value = this._model.spreadRadius().asCSSText(); |
| 241 this._spreadInput.classList.toggle("invalid", false); | 294 this._spreadInput.classList.remove("invalid"); |
| 242 } | 295 } |
| 243 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); | 296 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 244 }, | 297 }, |
| 245 | 298 |
| 299 /** |
| 300 * @param {!Event} event |
| 301 * @return {boolean} |
| 302 */ |
| 303 _dragStart: function(event) |
| 304 { |
| 305 this._xySlider.focus(); |
| 306 this._updateCanvas(true); |
| 307 this._canvasOrigin = new WebInspector.Geometry.Point(this._xySlider.tota
lOffsetLeft() + this._halfCanvasSize, this._xySlider.totalOffsetTop() + this._ha
lfCanvasSize); |
| 308 var clickedPoint = new WebInspector.Geometry.Point(event.x - this._canva
sOrigin.x, event.y - this._canvasOrigin.y); |
| 309 var thumbPoint = this._sliderThumbPosition(); |
| 310 if (clickedPoint.distanceTo(thumbPoint) >= WebInspector.CSSShadowEditor.
sliderThumbRadius) |
| 311 this._dragMove(event); |
| 312 return true; |
| 313 }, |
| 314 |
| 315 /** |
| 316 * @param {!Event} event |
| 317 */ |
| 318 _dragMove: function(event) |
| 319 { |
| 320 var point = new WebInspector.Geometry.Point(event.x - this._canvasOrigin
.x, event.y - this._canvasOrigin.y); |
| 321 var constrainedPoint = this._constrainPoint(point, this._innerCanvasSize
); |
| 322 var newX = Math.round((constrainedPoint.x / this._innerCanvasSize) * Web
Inspector.CSSShadowEditor.maxRange); |
| 323 var newY = Math.round((constrainedPoint.y / this._innerCanvasSize) * Web
Inspector.CSSShadowEditor.maxRange); |
| 324 this._model.setOffsetX(new WebInspector.CSSLength(newX, this._model.offs
etX().unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 325 this._model.setOffsetY(new WebInspector.CSSLength(newY, this._model.offs
etY().unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 326 this._xInput.value = this._model.offsetX().asCSSText(); |
| 327 this._yInput.value = this._model.offsetY().asCSSText(); |
| 328 this._xInput.classList.remove("invalid"); |
| 329 this._yInput.classList.remove("invalid"); |
| 330 this._updateCanvas(true); |
| 331 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 332 }, |
| 333 |
| 334 _onCanvasBlur: function() |
| 335 { |
| 336 this._updateCanvas(false); |
| 337 }, |
| 338 |
| 339 /** |
| 340 * @param {!Event} event |
| 341 */ |
| 342 _onCanvasArrowKey: function(event) |
| 343 { |
| 344 var shiftX = 0; |
| 345 var shiftY = 0; |
| 346 if (event.key === "ArrowRight") |
| 347 shiftX = 1; |
| 348 else if (event.key === "ArrowLeft") |
| 349 shiftX = -1; |
| 350 else if (event.key === "ArrowUp") |
| 351 shiftY = -1; |
| 352 else if (event.key === "ArrowDown") |
| 353 shiftY = 1; |
| 354 |
| 355 if (!shiftX && !shiftY) |
| 356 return; |
| 357 event.consume(true); |
| 358 |
| 359 if (shiftX) { |
| 360 var offsetX = this._model.offsetX(); |
| 361 var newAmount = Number.constrain(offsetX.amount + shiftX, -WebInspec
tor.CSSShadowEditor.maxRange, WebInspector.CSSShadowEditor.maxRange); |
| 362 if (newAmount === offsetX.amount) |
| 363 return; |
| 364 this._model.setOffsetX(new WebInspector.CSSLength(newAmount, offsetX
.unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 365 this._xInput.value = this._model.offsetX().asCSSText(); |
| 366 this._xInput.classList.remove("invalid"); |
| 367 } |
| 368 if (shiftY) { |
| 369 var offsetY = this._model.offsetY(); |
| 370 var newAmount = Number.constrain(offsetY.amount + shiftY, -WebInspec
tor.CSSShadowEditor.maxRange, WebInspector.CSSShadowEditor.maxRange); |
| 371 if (newAmount === offsetY.amount) |
| 372 return; |
| 373 this._model.setOffsetY(new WebInspector.CSSLength(newAmount, offsetY
.unit || WebInspector.CSSShadowEditor.defaultUnit)); |
| 374 this._yInput.value = this._model.offsetY().asCSSText(); |
| 375 this._yInput.classList.remove("invalid"); |
| 376 } |
| 377 this._updateCanvas(true); |
| 378 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow
Changed, this._model); |
| 379 }, |
| 380 |
| 381 /** |
| 382 * @param {!WebInspector.Geometry.Point} point |
| 383 * @param {number} max |
| 384 * @return {!WebInspector.Geometry.Point} |
| 385 */ |
| 386 _constrainPoint: function(point, max) |
| 387 { |
| 388 if (Math.abs(point.x) <= max && Math.abs(point.y) <= max) |
| 389 return new WebInspector.Geometry.Point(point.x, point.y); |
| 390 return point.scale(max / Math.max(Math.abs(point.x), Math.abs(point.y)))
; |
| 391 }, |
| 392 |
| 393 /** |
| 394 * @return {!WebInspector.Geometry.Point} |
| 395 */ |
| 396 _sliderThumbPosition: function() |
| 397 { |
| 398 var x = (this._model.offsetX().amount / WebInspector.CSSShadowEditor.max
Range) * this._innerCanvasSize; |
| 399 var y = (this._model.offsetY().amount / WebInspector.CSSShadowEditor.max
Range) * this._innerCanvasSize; |
| 400 return this._constrainPoint(new WebInspector.Geometry.Point(x, y), this.
_innerCanvasSize); |
| 401 }, |
| 402 |
| 246 __proto__: WebInspector.VBox.prototype | 403 __proto__: WebInspector.VBox.prototype |
| 247 } | 404 } |
| OLD | NEW |