Chromium Code Reviews| 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._onCanvasUpDown.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(); | |
| 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 | 
| 131 _updateCanvas: function() | |
| 132 { | |
| 133 var context = this._xySlider.getContext("2d"); | |
| 134 context.clearRect(0, 0, this._xySlider.width, this._xySlider.height); | |
| 135 | |
| 136 // Draw dashed axes. | |
| 137 context.save(); | |
| 138 context.setLineDash([1, 1]); | |
| 139 context.strokeStyle = "rgba(0, 0, 0, 0.2)"; | |
| 140 context.beginPath(); | |
| 141 context.moveTo(this._halfCanvasSize, 0); | |
| 142 context.lineTo(this._halfCanvasSize, WebInspector.CSSShadowEditor.canvas Size); | |
| 143 context.moveTo(0, this._halfCanvasSize); | |
| 144 context.lineTo(WebInspector.CSSShadowEditor.canvasSize, this._halfCanvas Size); | |
| 145 context.stroke(); | |
| 146 context.restore(); | |
| 147 | |
| 148 var thumbPoint = this._sliderThumbPosition(); | |
| 149 // Draw 2D slider line. | |
| 150 context.save(); | |
| 151 context.translate(this._halfCanvasSize, this._halfCanvasSize); | |
| 152 context.lineWidth = 2; | |
| 153 context.strokeStyle = "rgba(0, 0, 0, 0.3)"; | |
| 154 context.beginPath(); | |
| 155 context.moveTo(0, 0); | |
| 156 context.lineTo(thumbPoint.x, thumbPoint.y); | |
| 157 context.stroke(); | |
| 158 // Draw 2D slider thumb. | |
| 159 context.beginPath(); | |
| 160 if (this._xySlider.hasFocus) { | |
| 161 context.fillStyle = "rgba(66, 133, 244, 0.4)"; | |
| 162 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor .sliderThumbRadius + 2, 0, 2 * Math.PI); | |
| 163 context.fill(); | |
| 164 } | |
| 165 context.beginPath() | |
| 166 context.fillStyle = "#4285F4"; | |
| 167 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor.sli derThumbRadius, 0, 2 * Math.PI); | |
| 168 context.fill(); | |
| 169 context.restore(); | |
| 170 }, | |
| 171 | |
| 114 /** | 172 /** | 
| 115 * @param {!Event} event | 173 * @param {!Event} event | 
| 116 */ | 174 */ | 
| 117 _onButtonClick: function(event) | 175 _onButtonClick: function(event) | 
| 118 { | 176 { | 
| 119 var insetClicked = (event.currentTarget === this._insetButton); | 177 var insetClicked = (event.currentTarget === this._insetButton); | 
| 120 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset()) | 178 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset()) | 
| 121 return; | 179 return; | 
| 122 this._model.setInset(insetClicked); | 180 this._model.setInset(insetClicked); | 
| 123 this._updateButtons(); | 181 this._updateButtons(); | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 */ | 220 */ | 
| 163 _onTextInput: function(event) | 221 _onTextInput: function(event) | 
| 164 { | 222 { | 
| 165 this._changedElement = event.currentTarget; | 223 this._changedElement = event.currentTarget; | 
| 166 this._changedElement.classList.toggle("invalid", false); | 224 this._changedElement.classList.toggle("invalid", false); | 
| 167 var length = WebInspector.CSSLength.parse(event.currentTarget.value); | 225 var length = WebInspector.CSSLength.parse(event.currentTarget.value); | 
| 168 if (!length || event.currentTarget === this._blurInput && length.amount < 0) | 226 if (!length || event.currentTarget === this._blurInput && length.amount < 0) | 
| 169 return; | 227 return; | 
| 170 if (event.currentTarget === this._xInput) { | 228 if (event.currentTarget === this._xInput) { | 
| 171 this._model.setOffsetX(length); | 229 this._model.setOffsetX(length); | 
| 172 this._xSlider.value = length.amount; | 230 this._updateCanvas(); | 
| 173 } else if (event.currentTarget === this._yInput) { | 231 } else if (event.currentTarget === this._yInput) { | 
| 174 this._model.setOffsetY(length); | 232 this._model.setOffsetY(length); | 
| 175 this._ySlider.value = length.amount; | 233 this._updateCanvas(); | 
| 176 } else if (event.currentTarget === this._blurInput) { | 234 } else if (event.currentTarget === this._blurInput) { | 
| 177 this._model.setBlurRadius(length); | 235 this._model.setBlurRadius(length); | 
| 178 this._blurSlider.value = length.amount; | 236 this._blurSlider.value = length.amount; | 
| 179 } else if (event.currentTarget === this._spreadInput) { | 237 } else if (event.currentTarget === this._spreadInput) { | 
| 180 this._model.setSpreadRadius(length); | 238 this._model.setSpreadRadius(length); | 
| 181 this._spreadSlider.value = length.amount; | 239 this._spreadSlider.value = length.amount; | 
| 182 } | 240 } | 
| 183 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 241 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 
| 184 }, | 242 }, | 
| 185 | 243 | 
| 186 _onTextBlur: function() | 244 _onTextBlur: function() | 
| 187 { | 245 { | 
| 188 if (!this._changedElement) | 246 if (!this._changedElement) | 
| 189 return; | 247 return; | 
| 190 var length = !this._changedElement.value ? WebInspector.CSSLength.zero() : WebInspector.CSSLength.parse(this._changedElement.value); | 248 var length = !this._changedElement.value.trim() ? WebInspector.CSSLength .zero() : WebInspector.CSSLength.parse(this._changedElement.value); | 
| 191 if (!length) | 249 if (!length) | 
| 192 length = WebInspector.CSSLength.parse(this._changedElement.value + W ebInspector.CSSShadowEditor.defaultUnit); | 250 length = WebInspector.CSSLength.parse(this._changedElement.value + W ebInspector.CSSShadowEditor.defaultUnit); | 
| 193 if (!length) { | 251 if (!length) { | 
| 194 this._changedElement.classList.add("invalid"); | 252 this._changedElement.classList.add("invalid"); | 
| 195 this._changedElement = null; | 253 this._changedElement = null; | 
| 196 return; | 254 return; | 
| 197 } | 255 } | 
| 198 if (this._changedElement === this._xInput) { | 256 if (this._changedElement === this._xInput) { | 
| 199 this._model.setOffsetX(length); | 257 this._model.setOffsetX(length); | 
| 200 this._xInput.value = length.asCSSText(); | 258 this._xInput.value = length.asCSSText(); | 
| 201 this._xSlider.value = length.amount; | 259 this._updateCanvas(); | 
| 202 } else if (this._changedElement === this._yInput) { | 260 } else if (this._changedElement === this._yInput) { | 
| 203 this._model.setOffsetY(length); | 261 this._model.setOffsetY(length); | 
| 204 this._yInput.value = length.asCSSText(); | 262 this._yInput.value = length.asCSSText(); | 
| 205 this._ySlider.value = length.amount; | 263 this._updateCanvas(); | 
| 206 } else if (this._changedElement === this._blurInput) { | 264 } else if (this._changedElement === this._blurInput) { | 
| 207 if (length.amount < 0) | 265 if (length.amount < 0) | 
| 208 length = WebInspector.CSSLength.zero(); | 266 length = WebInspector.CSSLength.zero(); | 
| 209 this._model.setBlurRadius(length); | 267 this._model.setBlurRadius(length); | 
| 210 this._blurInput.value = length.asCSSText(); | 268 this._blurInput.value = length.asCSSText(); | 
| 211 this._blurSlider.value = length.amount; | 269 this._blurSlider.value = length.amount; | 
| 212 } else if (this._changedElement === this._spreadInput) { | 270 } else if (this._changedElement === this._spreadInput) { | 
| 213 this._model.setSpreadRadius(length); | 271 this._model.setSpreadRadius(length); | 
| 214 this._spreadInput.value = length.asCSSText(); | 272 this._spreadInput.value = length.asCSSText(); | 
| 215 this._spreadSlider.value = length.amount; | 273 this._spreadSlider.value = length.amount; | 
| 216 } | 274 } | 
| 217 this._changedElement = null; | 275 this._changedElement = null; | 
| 218 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 276 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 
| 219 }, | 277 }, | 
| 220 | 278 | 
| 221 /** | 279 /** | 
| 222 * @param {!Event} event | 280 * @param {!Event} event | 
| 223 */ | 281 */ | 
| 224 _onSliderInput: function(event) | 282 _onSliderInput: function(event) | 
| 225 { | 283 { | 
| 226 if (event.currentTarget === this._xSlider) { | 284 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)); | 285 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(); | 286 this._blurInput.value = this._model.blurRadius().asCSSText(); | 
| 237 this._blurInput.classList.toggle("invalid", false); | 287 this._blurInput.classList.toggle("invalid", false); | 
| 238 } else if (event.currentTarget === this._spreadSlider) { | 288 } 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)); | 289 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(); | 290 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | 
| 241 this._spreadInput.classList.toggle("invalid", false); | 291 this._spreadInput.classList.toggle("invalid", false); | 
| 242 } | 292 } | 
| 243 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 293 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | 
| 244 }, | 294 }, | 
| 245 | 295 | 
| 296 /** | |
| 297 * @param {!Event} event | |
| 298 * @return {boolean} | |
| 299 */ | |
| 300 _dragStart: function(event) | |
| 301 { | |
| 302 if (event.currentTarget === this._xySlider) { | |
| 303 this._xySlider.focus(); | |
| 304 this._xySlider.hasFocus = true; | |
| 
 
lushnikov
2016/08/30 19:22:19
let's not add fields to the DOM wrappers - i think
 
flandy
2016/08/30 22:50:42
Done. I've added Document.prototype.deepActiveElem
 
 | |
| 305 } | |
| 306 this._canvasOrigin = new WebInspector.Geometry.Point(this._xySlider.tota lOffsetLeft() + this._halfCanvasSize, this._xySlider.totalOffsetTop() + this._ha lfCanvasSize); | |
| 307 var clickedPoint = new WebInspector.Geometry.Point(event.x - this._canva sOrigin.x, event.y - this._canvasOrigin.y); | |
| 308 var thumbPoint = this._sliderThumbPosition(); | |
| 309 if (clickedPoint.distanceTo(thumbPoint) >= WebInspector.CSSShadowEditor. sliderThumbRadius) | |
| 310 this._dragMove(event); | |
| 311 return true; | |
| 312 }, | |
| 313 | |
| 314 /** | |
| 315 * @param {!Event} event | |
| 316 */ | |
| 317 _dragMove: function(event) | |
| 318 { | |
| 319 var point = new WebInspector.Geometry.Point(event.x - this._canvasOrigin .x, event.y - this._canvasOrigin.y); | |
| 
 
lushnikov
2016/08/30 19:22:19
nit: excessive spaces
 
flandy
2016/08/30 22:50:42
Done.
 
 | |
| 320 var constrainedPoint = this._constrainPoint(point, this._innerCanvasSize ); | |
| 321 var newX = Math.round((constrainedPoint.x / this._innerCanvasSize) * Web Inspector.CSSShadowEditor.maxRange); | |
| 322 var newY = Math.round((constrainedPoint.y / this._innerCanvasSize) * Web Inspector.CSSShadowEditor.maxRange); | |
| 323 this._model.setOffsetX(new WebInspector.CSSLength(newX, this._model.offs etX().unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 324 this._model.setOffsetY(new WebInspector.CSSLength(newY, this._model.offs etY().unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 325 this._xInput.value = this._model.offsetX().asCSSText(); | |
| 326 this._yInput.value = this._model.offsetY().asCSSText(); | |
| 327 this._xInput.classList.toggle("invalid", false); | |
| 
 
lushnikov
2016/08/30 19:22:19
nit: this._xInput.classList.remove("invalid")
 
flandy
2016/08/30 22:50:42
Done.
 
 | |
| 328 this._yInput.classList.toggle("invalid", false); | |
| 329 this._updateCanvas(); | |
| 330 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
| 331 }, | |
| 332 | |
| 333 _onCanvasBlur: function() | |
| 334 { | |
| 335 this._xySlider.hasFocus = false; | |
| 336 this._updateCanvas(); | |
| 337 }, | |
| 338 | |
| 339 /** | |
| 340 * @param {!Event} event | |
| 341 */ | |
| 342 _onCanvasUpDown: function(event) | |
| 343 { | |
| 344 var upDown = (event.key === "ArrowUp" || event.key === "ArrowDown"); | |
| 
 
lushnikov
2016/08/30 19:22:19
can we use WI.KeyboardShortcuts for key detection?
 
flandy
2016/08/30 22:50:41
This seems unnecessary here. Also, keyCode is depr
 
 | |
| 345 var leftRight = (event.key === "ArrowRight" || event.key === "ArrowLeft" ) | |
| 346 if (!upDown && !leftRight || !this._xySlider.hasFocus) | |
| 
 
lushnikov
2016/08/30 19:22:19
how could it be non-focused? doesn't even triggeri
 
flandy
2016/08/30 22:50:41
Yes good point. Removed.
 
 | |
| 347 return | |
| 
 
lushnikov
2016/08/30 19:22:19
; missing
 
flandy
2016/08/30 22:50:41
Done.
 
 | |
| 348 event.consume(true); | |
| 349 | |
| 350 var newAmount; | |
| 351 if (upDown) { | |
| 352 var offsetY = this._model.offsetY(); | |
| 353 newAmount = event.key === "ArrowUp" ? offsetY.amount - 1 : offsetY.a mount + 1; | |
| 
 
lushnikov
2016/08/30 19:22:19
Let's compare for event.key only only once, in the
 
flandy
2016/08/30 22:50:41
Done.
 
 | |
| 354 newAmount = Number.constrain(newAmount, -WebInspector.CSSShadowEdito r.maxRange, WebInspector.CSSShadowEditor.maxRange); | |
| 355 this._model.setOffsetY(new WebInspector.CSSLength(newAmount, offsetY .unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 356 this._yInput.value = this._model.offsetY().asCSSText(); | |
| 357 this._yInput.classList.toggle("invalid", false); | |
| 358 } else if (leftRight) { | |
| 359 var offsetX = this._model.offsetX() | |
| 360 newAmount = event.key === "ArrowRight" ? offsetX.amount + 1 : offset X.amount - 1; | |
| 361 newAmount = Number.constrain(newAmount, -WebInspector.CSSShadowEdito r.maxRange, WebInspector.CSSShadowEditor.maxRange); | |
| 362 this._model.setOffsetX(new WebInspector.CSSLength(newAmount, offsetX .unit || WebInspector.CSSShadowEditor.defaultUnit)); | |
| 363 this._xInput.value = this._model.offsetX().asCSSText(); | |
| 364 this._xInput.classList.toggle("invalid", false); | |
| 365 } | |
| 366 this._updateCanvas(); | |
| 367 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
| 368 }, | |
| 369 | |
| 370 /** | |
| 371 * @param {!WebInspector.Geometry.Point} point | |
| 372 * @param {number} max | |
| 373 * @return {!WebInspector.Geometry.Point} | |
| 374 */ | |
| 375 _constrainPoint: function(point, max) | |
| 376 { | |
| 377 var newPoint = new WebInspector.Geometry.Point(point.x, point.y); | |
| 378 if ((Math.abs(point.x) <= max && Math.abs(point.y) <= max) || (point.x = == 0 && point.y === 0)) | |
| 
 
lushnikov
2016/08/30 19:22:19
why special case for zeroes?
 
flandy
2016/08/30 22:50:42
To avoid divide by zero if max < 0. I never use ma
 
 | |
| 379 return newPoint; | |
| 380 if (Math.abs(point.x) > Math.abs(point.y)) { | |
| 
 
lushnikov
2016/08/30 19:22:19
the function could be written simpler:
   if (Mat
 
flandy
2016/08/30 22:50:41
Thanks! Done.
 
 | |
| 381 newPoint.x = point.x < 0 ? -max : max; | |
| 382 newPoint.y = newPoint.x * point.y / point.x; | |
| 383 } else { | |
| 384 newPoint.y = point.y < 0 ? -max : max; | |
| 385 newPoint.x = newPoint.y * point.x / point.y; | |
| 386 } | |
| 387 return newPoint; | |
| 388 }, | |
| 389 | |
| 390 /** | |
| 391 * @return {!WebInspector.Geometry.Point} | |
| 392 */ | |
| 393 _sliderThumbPosition: function() | |
| 394 { | |
| 395 var x = (this._model.offsetX().amount / WebInspector.CSSShadowEditor.max Range) * this._innerCanvasSize; | |
| 396 var y = (this._model.offsetY().amount / WebInspector.CSSShadowEditor.max Range) * this._innerCanvasSize; | |
| 397 return this._constrainPoint(new WebInspector.Geometry.Point(x, y), this. _innerCanvasSize); | |
| 398 }, | |
| 399 | |
| 246 __proto__: WebInspector.VBox.prototype | 400 __proto__: WebInspector.VBox.prototype | 
| 247 } | 401 } | 
| OLD | NEW |