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 * @param {!WebInspector.ShadowEditor.Shadow} shadow | |
| 8 * @extends {WebInspector.VBox} | |
| 7 */ | 9 */ |
| 8 WebInspector.ShadowEditor = function() {} | 10 WebInspector.ShadowEditor = function(shadow) |
| 11 { | |
| 12 WebInspector.VBox.call(this, true); | |
| 13 this._shadow = shadow; | |
|
lushnikov
2016/08/17 17:07:21
this._model = ..
flandy
2016/08/24 18:10:07
Done.
| |
| 14 this._type = shadow.type(); | |
| 15 this.registerRequiredCSS("ui/shadowEditor.css"); | |
|
lushnikov
2016/08/17 17:07:21
this should go as the first line after super-call
flandy
2016/08/24 18:10:07
Done.
| |
| 16 | |
| 17 var field, label, slider; | |
| 18 if (this._type === "box-shadow") { | |
| 19 field = this.contentElement.createChild("div", "shadow-editor-field"); | |
| 20 label = field.createChild("label"); | |
| 21 label.textContent = WebInspector.UIString("Type"); | |
| 22 this._outsetButton = field.createChild("div", "shadow-editor-button left "); | |
| 23 this._outsetButton.textContent = WebInspector.UIString("Outset"); | |
| 24 this._outsetButton.addEventListener("click", this._onInsetOutsetClicked. bind(this), true); | |
| 25 this._insetButton = field.createChild("div", "shadow-editor-button right "); | |
| 26 this._insetButton.textContent = WebInspector.UIString("Inset"); | |
| 27 this._insetButton.addEventListener("click", this._onInsetOutsetClicked.b ind(this), true); | |
| 28 } | |
| 29 | |
| 30 field = this.contentElement.createChild("div", "shadow-editor-field"); | |
|
lushnikov
2016/08/17 17:07:21
these look strikingly similar. Maybe it's possible
flandy
2016/08/24 18:10:07
Done.
| |
| 31 label = field.createChild("label"); | |
| 32 label.textContent = WebInspector.UIString("X offset"); | |
| 33 label.for = "shadow-editor-x"; | |
| 34 this._xInput = field.createChild("input"); | |
| 35 this._xInput.type = "text"; | |
| 36 this._xInput.id = "shadow-editor-x"; | |
| 37 this._xInput.addEventListener("input", this._onTextInput.bind(this), true); | |
| 38 slider = field.createChild("div", "shadow-editor-slider"); | |
| 39 this._xSliderTrack = slider.createChild("div", "shadow-editor-slider-track") ; | |
| 40 this._xSliderThumb = this._xSliderTrack.createChild("div", "shadow-editor-sl ider-thumb"); | |
| 41 WebInspector.installDragHandle(slider, this._dragStart.bind(this), this._dra gX.bind(this), this._dragX.bind(this), "default"); | |
|
lushnikov
2016/08/17 17:07:21
can you please attach a screenshot - it's hard to
flandy
2016/08/24 18:10:07
Done.
| |
| 42 | |
| 43 field = this.contentElement.createChild("div", "shadow-editor-field"); | |
| 44 label = field.createChild("label"); | |
| 45 label.textContent = WebInspector.UIString("Y offset"); | |
| 46 label.for = "shadow-editor-y"; | |
| 47 this._yInput = field.createChild("input"); | |
| 48 this._yInput.type = "text"; | |
| 49 this._yInput.id = "shadow-editor-y"; | |
| 50 this._yInput.addEventListener("input", this._onTextInput.bind(this), true); | |
| 51 slider = field.createChild("div", "shadow-editor-slider"); | |
| 52 this._ySliderTrack = slider.createChild("div", "shadow-editor-slider-track") ; | |
| 53 this._ySliderThumb = this._ySliderTrack.createChild("div", "shadow-editor-sl ider-thumb"); | |
| 54 WebInspector.installDragHandle(slider, this._dragStart.bind(this), this._dra gY.bind(this), this._dragY.bind(this), "default"); | |
|
lushnikov
2016/08/17 17:07:21
Why not listen to default slider changed events?
flandy
2016/08/24 18:10:07
Done.
| |
| 55 | |
| 56 field = this.contentElement.createChild("div", "shadow-editor-field"); | |
| 57 label = field.createChild("label"); | |
| 58 label.textContent = WebInspector.UIString("Blur"); | |
| 59 label.for = "shadow-editor-blur"; | |
| 60 this._blurInput = field.createChild("input"); | |
| 61 this._blurInput.type = "text"; | |
| 62 this._blurInput.id = "shadow-editor-blur"; | |
| 63 this._blurInput.addEventListener("input", this._onTextInput.bind(this), true ); | |
| 64 slider = field.createChild("div", "shadow-editor-slider"); | |
| 65 this._blurSliderTrack = slider.createChild("div", "shadow-editor-slider-trac k"); | |
| 66 this._blurSliderThumb = this._blurSliderTrack.createChild("div", "shadow-edi tor-slider-thumb"); | |
| 67 WebInspector.installDragHandle(slider, this._dragStart.bind(this), this._dra gBlur.bind(this), this._dragBlur.bind(this), "default"); | |
| 68 | |
| 69 if (this._type === "box-shadow") { | |
| 70 field = this.contentElement.createChild("div", "shadow-editor-field"); | |
| 71 label = field.createChild("label"); | |
| 72 label.textContent = WebInspector.UIString("Spread"); | |
| 73 label.for = "shadow-editor-spread"; | |
| 74 this._spreadInput = field.createChild("input"); | |
| 75 this._spreadInput.type = "text"; | |
| 76 this._spreadInput.id = "shadow-editor-spread"; | |
| 77 this._spreadInput.addEventListener("input", this._onTextInput.bind(this) , true); | |
| 78 slider = field.createChild("div", "shadow-editor-slider"); | |
| 79 this._spreadSliderTrack = slider.createChild("div", "shadow-editor-slide r-track"); | |
| 80 this._spreadSliderThumb = this._spreadSliderTrack.createChild("div", "sh adow-editor-slider-thumb"); | |
| 81 WebInspector.installDragHandle(slider, this._dragStart.bind(this), this. _dragSpread.bind(this), this._dragSpread.bind(this), "default"); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 WebInspector.ShadowEditor.Events = { | |
| 86 ShadowChanged: "ShadowChanged" | |
| 87 } | |
| 88 | |
| 89 /** @type {number} */ | |
| 90 WebInspector.ShadowEditor.maxSliderValue = 25; | |
| 91 | |
| 92 WebInspector.ShadowEditor.prototype = { | |
| 93 /** | |
| 94 * @override | |
| 95 */ | |
| 96 wasShown: function() | |
| 97 { | |
| 98 this._sliderTrackWidth = this._blurSliderTrack.offsetWidth; | |
|
dgozman
2016/08/17 17:42:09
Should we use measureElement instead?
flandy
2016/08/24 18:10:06
Removed.
| |
| 99 this._halfSliderThumbWidth = this._blurSliderThumb.offsetWidth / 2; | |
| 100 this._updateUI(); | |
| 101 }, | |
| 102 | |
| 103 _updateUI: function() | |
| 104 { | |
| 105 this._updateTextInputs(); | |
| 106 this._updateSliders(); | |
| 107 if (this._type === "box-shadow") { | |
| 108 this._insetButton.classList.toggle("enabled", this._shadow.inset()); | |
| 109 this._outsetButton.classList.toggle("enabled", !this._shadow.inset() ); | |
| 110 } | |
| 111 }, | |
| 112 | |
| 113 _updateTextInputs: function() | |
| 114 { | |
| 115 this._xInput.value = this._shadow.xOffset().toString(); | |
| 116 this._yInput.value = this._shadow.yOffset().toString(); | |
| 117 this._blurInput.value = this._shadow.blur().toString(); | |
| 118 if (this._type === "box-shadow") | |
|
dgozman
2016/08/17 17:42:09
We should either make "box-shadow" a named constan
flandy
2016/08/24 18:10:07
Let's hide fields that are not needed.
| |
| 119 this._spreadInput.value = this._shadow.spread().toString(); | |
| 120 }, | |
| 121 | |
| 122 _updateSliders: function() | |
| 123 { | |
| 124 updateSlider.call(this, this._xSliderThumb, this._shadow.xOffset().amoun t, true); | |
| 125 updateSlider.call(this, this._ySliderThumb, this._shadow.yOffset().amoun t, true); | |
| 126 updateSlider.call(this, this._blurSliderThumb, this._shadow.blur().amoun t, false); | |
| 127 if (this._type === "box-shadow") | |
| 128 updateSlider.call(this, this._spreadSliderThumb, this._shadow.sprea d().amount, false); | |
| 129 | |
| 130 /** | |
| 131 * @param {!Element} thumb | |
| 132 * @param {number} amount | |
| 133 * @param {boolean} negativeAllowed | |
| 134 * @this {WebInspector.ShadowEditor} | |
| 135 */ | |
| 136 function updateSlider(thumb, amount, negativeAllowed) | |
| 137 { | |
| 138 amount = Number.constrain(amount, WebInspector.ShadowEditor.maxSlide rValue * -1, WebInspector.ShadowEditor.maxSliderValue); | |
| 139 var percent = amount / WebInspector.ShadowEditor.maxSliderValue; | |
| 140 if (negativeAllowed) { | |
| 141 if (amount < 0) | |
| 142 percent = (amount + WebInspector.ShadowEditor.maxSliderValue ) / WebInspector.ShadowEditor.maxSliderValue / 2; | |
| 143 else | |
| 144 percent = amount / WebInspector.ShadowEditor.maxSliderValue / 2 + 0.5; | |
| 145 } | |
| 146 thumb.style.left = (Number.constrain(percent, 0, 1) * this._sliderTr ackWidth - this._halfSliderThumbWidth) + "px"; | |
| 147 } | |
| 148 }, | |
| 149 | |
| 150 /** | |
| 151 * @param {!MouseEvent} event | |
| 152 * @return {boolean} | |
| 153 */ | |
| 154 _dragStart: function(event) | |
| 155 { | |
| 156 this._sliderTrackLeft = this._blurSliderTrack.totalOffsetLeft(); | |
| 157 return true; | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {!MouseEvent} event | |
| 162 */ | |
| 163 _dragX: function(event) | |
| 164 { | |
| 165 this._shadow.setXAmount(this._amountFromSlider(event, true)); | |
| 166 this._onSliderChange(); | |
| 167 }, | |
| 168 | |
| 169 /** | |
| 170 * @param {!MouseEvent} event | |
| 171 */ | |
| 172 _dragY: function(event) | |
| 173 { | |
| 174 this._shadow.setYAmount(this._amountFromSlider(event, true)); | |
| 175 this._onSliderChange(); | |
| 176 }, | |
| 177 | |
| 178 /** | |
| 179 * @param {!MouseEvent} event | |
| 180 */ | |
| 181 _dragBlur: function(event) | |
| 182 { | |
| 183 this._shadow.setBlurAmount(this._amountFromSlider(event, false)); | |
| 184 this._onSliderChange(); | |
| 185 }, | |
| 186 | |
| 187 /** | |
| 188 * @param {!MouseEvent} event | |
| 189 */ | |
| 190 _dragSpread: function(event) | |
|
dgozman
2016/08/17 17:42:09
I'm curious why default slider handling doesn't wo
flandy
2016/08/24 18:10:07
Changed to use a default range input with custom s
| |
| 191 { | |
| 192 this._shadow.setSpreadAmount(this._amountFromSlider(event, false)); | |
| 193 this._onSliderChange(); | |
| 194 }, | |
| 195 | |
| 196 /** | |
| 197 * @param {!MouseEvent} event | |
| 198 * @param {boolean} negativeAllowed | |
| 199 * @return {number} | |
| 200 */ | |
| 201 _amountFromSlider: function(event, negativeAllowed) | |
| 202 { | |
| 203 var offsetX = event.x - this._sliderTrackLeft; | |
| 204 var percent = Number.constrain(offsetX / this._sliderTrackWidth, 0, 1); | |
| 205 if (!negativeAllowed) | |
| 206 return Math.round(percent * WebInspector.ShadowEditor.maxSliderValue ); | |
| 207 | |
| 208 var amount; | |
| 209 if (percent < 0.5) { | |
| 210 percent = percent * 2; | |
| 211 amount = percent * WebInspector.ShadowEditor.maxSliderValue - WebIns pector.ShadowEditor.maxSliderValue; | |
| 212 } else { | |
| 213 percent = (percent - 0.5) * 2; | |
| 214 amount = percent * WebInspector.ShadowEditor.maxSliderValue | |
| 215 } | |
| 216 return Math.round(amount); | |
| 217 }, | |
| 218 | |
| 219 _onSliderChange: function() | |
| 220 { | |
| 221 this._updateSliders(); | |
| 222 this._updateTextInputs(); | |
| 223 this.dispatchEventToListeners(WebInspector.ShadowEditor.Events.ShadowCha nged, this._shadow); | |
| 224 }, | |
| 225 | |
| 226 _onInsetOutsetClicked: function() | |
| 227 { | |
| 228 this._insetButton.classList.toggle("enabled"); | |
| 229 this._outsetButton.classList.toggle("enabled"); | |
| 230 this._shadow.setInset(this._insetButton.classList.contains("enabled")); | |
| 231 this.dispatchEventToListeners(WebInspector.ShadowEditor.Events.ShadowCha nged, this._shadow); | |
| 232 }, | |
| 233 | |
| 234 /** | |
| 235 * @param {!Event} event | |
| 236 */ | |
| 237 _onTextInput: function(event) | |
| 238 { | |
| 239 if (WebInspector.ShadowEditor.Length.parse(event.currentTarget.value)) { | |
| 240 this._shadow.setXOffset(this._xInput.value); | |
| 241 this._shadow.setYOffset(this._yInput.value); | |
| 242 this._shadow.setBlur(this._blurInput.value); | |
| 243 if (this._type === "box-shadow") | |
| 244 this._shadow.setSpread(this._spreadInput.value); | |
| 245 this._updateSliders(); | |
| 246 this.dispatchEventToListeners(WebInspector.ShadowEditor.Events.Shado wChanged, this._shadow); | |
| 247 } | |
| 248 }, | |
| 249 | |
| 250 __proto__: WebInspector.VBox.prototype | |
| 251 } | |
| 9 | 252 |
| 10 /** | 253 /** |
| 11 * @constructor | 254 * @constructor |
| 12 */ | 255 */ |
| 13 WebInspector.ShadowEditor.Shadow = function(type) | 256 WebInspector.ShadowEditor.Shadow = function(type) |
| 14 { | 257 { |
| 15 this.type = type; | 258 this._type = type; |
| 16 this.order = []; | 259 this._order = []; |
| 17 } | 260 } |
| 18 | 261 |
| 19 /** | 262 /** |
| 20 * @enum {string} | 263 * @enum {string} |
| 21 */ | 264 */ |
| 22 WebInspector.ShadowEditor.Shadow.Parts = { | 265 WebInspector.ShadowEditor.Shadow.Parts = { |
| 23 Inset: "inset", | 266 Inset: "inset", |
| 24 Length: "length", | 267 Length: "length", |
| 25 Color: "color" | 268 Color: "color" |
| 26 }; | 269 }; |
| 27 | 270 |
| 28 /** | 271 /** |
| 29 * @param {string} text | 272 * @param {string} text |
| 30 * @param {string} type | 273 * @param {string} type |
| 31 * @return {?Array<!WebInspector.ShadowEditor.Shadow>} | 274 * @return {!Array<!WebInspector.ShadowEditor.Shadow>} |
| 32 */ | 275 */ |
| 33 WebInspector.ShadowEditor.Shadow.parse = function(text, type) | 276 WebInspector.ShadowEditor.Shadow.parse = function(text, type) |
| 34 { | 277 { |
| 35 var shadowTexts = []; | 278 var shadowTexts = []; |
| 36 // Split by commas that aren't inside of color values to get the individual shadow values. | 279 // Split by commas that aren't inside of color values to get the individual shadow values. |
| 37 var splits = WebInspector.TextUtils.splitStringByRegexes(text, [WebInspector .Color.Regex, /,/g]); | 280 var splits = WebInspector.TextUtils.splitStringByRegexes(text, [WebInspector .Color.Regex, /,/g]); |
| 38 var currentIndex = 0; | 281 var currentIndex = 0; |
| 39 for (var i = 0; i < splits.length; i++) { | 282 for (var i = 0; i < splits.length; i++) { |
| 40 if (splits[i].regexIndex === 1) { | 283 if (splits[i].regexIndex === 1) { |
| 41 var comma = splits[i]; | 284 var comma = splits[i]; |
| 42 shadowTexts.push(text.substring(currentIndex, comma.position)); | 285 shadowTexts.push(text.substring(currentIndex, comma.position)); |
| 43 currentIndex = comma.position + 1; | 286 currentIndex = comma.position + 1; |
| 44 } | 287 } |
| 45 } | 288 } |
| 46 shadowTexts.push(text.substring(currentIndex, text.length)); | 289 shadowTexts.push(text.substring(currentIndex, text.length)); |
| 47 | 290 |
| 48 var shadows = []; | 291 var shadows = []; |
| 49 for (var i = 0; i < shadowTexts.length; i++) { | 292 for (var i = 0; i < shadowTexts.length; i++) { |
| 50 var shadow = new WebInspector.ShadowEditor.Shadow(type); | 293 var shadow = new WebInspector.ShadowEditor.Shadow(type); |
| 294 var order = []; | |
| 51 var regexes = [/inset/g, WebInspector.Color.Regex, WebInspector.ShadowEd itor.Length.Regex]; | 295 var regexes = [/inset/g, WebInspector.Color.Regex, WebInspector.ShadowEd itor.Length.Regex]; |
| 52 var results = WebInspector.TextUtils.splitStringByRegexes(shadowTexts[i] , regexes); | 296 var results = WebInspector.TextUtils.splitStringByRegexes(shadowTexts[i] , regexes); |
| 297 var numLengths = 0; | |
| 53 for (var j = 0; j < results.length; j++) { | 298 for (var j = 0; j < results.length; j++) { |
| 54 var result = results[j]; | 299 var result = results[j]; |
| 55 if (result.regexIndex === 0) { | 300 if (result.regexIndex === 0) { |
| 56 shadow.setInset(result.value); | 301 shadow.setInset(true); |
| 302 order.push(WebInspector.ShadowEditor.Shadow.Parts.Inset); | |
| 57 } else if (result.regexIndex === 1) { | 303 } else if (result.regexIndex === 1) { |
| 58 var color = WebInspector.Color.parse(result.value); | 304 shadow.setColor(result.value) |
| 59 if (!color) | 305 order.push(WebInspector.ShadowEditor.Shadow.Parts.Color); |
| 60 return null; | |
| 61 shadow.setColor(color); | |
| 62 } else if (result.regexIndex === 2) { | 306 } else if (result.regexIndex === 2) { |
| 63 var length = WebInspector.ShadowEditor.Length.parse(result.value ); | 307 switch (numLengths) { |
| 64 if (!length) | 308 case 0: |
| 65 return null; | 309 shadow.setXOffset(result.value); |
| 66 shadow.addLength(length); | 310 order.push(WebInspector.ShadowEditor.Shadow.Parts.Length); |
| 311 break; | |
| 312 case 1: | |
| 313 shadow.setYOffset(result.value); | |
| 314 break; | |
| 315 case 2: | |
| 316 shadow.setBlur(result.value); | |
| 317 break; | |
| 318 case 3: | |
| 319 shadow.setSpread(result.value); | |
| 320 } | |
| 321 numLengths++; | |
| 67 } | 322 } |
| 68 } | 323 } |
| 324 // If inset is not specified, set inset to appear first in the css text by default. | |
| 325 if (!order.find(part => part === WebInspector.ShadowEditor.Shadow.Parts. Inset)) | |
| 326 order.unshift(WebInspector.ShadowEditor.Shadow.Parts.Inset); | |
| 327 // If color is not specified, set color to appear last in the css text b y default. | |
| 328 if (!order.find(part => part === WebInspector.ShadowEditor.Shadow.Parts. Color)) | |
| 329 order.push(WebInspector.ShadowEditor.Shadow.Parts.Color); | |
| 330 shadow.setOrder(order); | |
| 69 shadows.push(shadow); | 331 shadows.push(shadow); |
| 70 } | 332 } |
| 71 return shadows; | 333 return shadows; |
| 72 } | 334 } |
| 73 | 335 |
| 74 WebInspector.ShadowEditor.Shadow.prototype = { | 336 WebInspector.ShadowEditor.Shadow.prototype = { |
| 75 /** | 337 /** |
| 76 * @param {string} inset | 338 * @param {!Array<string>} order |
| 339 */ | |
| 340 setOrder: function(order) | |
| 341 { | |
| 342 this._order = order; | |
| 343 }, | |
| 344 | |
| 345 /** | |
| 346 * @param {boolean} inset | |
| 77 */ | 347 */ |
| 78 setInset: function(inset) | 348 setInset: function(inset) |
| 79 { | 349 { |
| 80 if (!this.inset) | 350 this._inset = inset; |
| 81 this.order.push(WebInspector.ShadowEditor.Shadow.Parts.Inset); | |
| 82 this.inset = inset; | |
| 83 }, | 351 }, |
| 84 | 352 |
| 85 /** | 353 /** |
| 86 * @param {!WebInspector.Color} color | 354 * @param {string} text |
| 87 */ | 355 */ |
| 88 setColor: function(color) | 356 setColor: function(text) |
| 89 { | 357 { |
| 90 if (!this.color) | 358 var color = WebInspector.Color.parse(text); |
| 91 this.order.push(WebInspector.ShadowEditor.Shadow.Parts.Color); | 359 if (color) |
| 92 this.color = color; | 360 this._color = color; |
| 93 }, | 361 }, |
| 94 | 362 |
| 95 /** | 363 /** |
| 96 * @param {!WebInspector.ShadowEditor.Length} length | 364 * @param {string} text |
| 97 */ | 365 */ |
| 98 addLength: function(length) | 366 setXOffset: function(text) |
| 99 { | 367 { |
| 100 if (!this.xOffset) { | 368 var length = WebInspector.ShadowEditor.Length.parse(text); |
| 101 this.order.push(WebInspector.ShadowEditor.Shadow.Parts.Length); | 369 if (length) |
| 102 this.xOffset = length; | 370 this._xOffset = length; |
| 103 } else if (!this.yOffset) { | 371 }, |
| 104 this.yOffset = length; | 372 |
| 105 } else if (!this.blur) { | 373 /** |
| 106 this.blur = length; | 374 * @param {string} text |
| 107 } else if (!this.spread) { | 375 */ |
| 108 this.spread = length; | 376 setYOffset: function(text) |
| 377 { | |
| 378 var length = WebInspector.ShadowEditor.Length.parse(text); | |
| 379 if (length) | |
| 380 this._yOffset = length; | |
| 381 }, | |
| 382 | |
| 383 /** | |
| 384 * @param {string} text | |
| 385 */ | |
| 386 setBlur: function(text) | |
| 387 { | |
| 388 var length = WebInspector.ShadowEditor.Length.parse(text); | |
| 389 if (length) | |
| 390 this._blur = length; | |
| 391 }, | |
| 392 | |
| 393 /** | |
| 394 * @param {string} text | |
| 395 */ | |
| 396 setSpread: function(text) | |
| 397 { | |
| 398 var length = WebInspector.ShadowEditor.Length.parse(text); | |
| 399 if (length) { | |
| 400 if (!this._blur) | |
| 401 this._blur = new WebInspector.ShadowEditor.Length(0, ""); | |
| 402 this._spread = length; | |
| 109 } | 403 } |
| 110 }, | 404 }, |
| 111 | 405 |
| 112 /** | 406 /** |
| 407 * @param {number} amount | |
| 408 */ | |
| 409 setXAmount: function(amount) | |
| 410 { | |
| 411 if (this._xOffset && this._xOffset.unit) | |
| 412 this._xOffset.amount = amount; | |
| 413 else | |
| 414 this._xOffset = new WebInspector.ShadowEditor.Length(amount, "px"); | |
| 415 }, | |
| 416 | |
| 417 /** | |
| 418 * @param {number} amount | |
| 419 */ | |
| 420 setYAmount: function(amount) | |
| 421 { | |
| 422 if (this._yOffset && this._yOffset.unit) | |
| 423 this._yOffset.amount = amount; | |
| 424 else | |
| 425 this._yOffset = new WebInspector.ShadowEditor.Length(amount, "px"); | |
| 426 }, | |
| 427 | |
| 428 | |
| 429 /** | |
| 430 * @param {number} amount | |
| 431 */ | |
| 432 setBlurAmount: function(amount) | |
| 433 { | |
| 434 if (this._blur && this._blur.unit) | |
| 435 this._blur.amount = amount; | |
| 436 else | |
| 437 this._blur = new WebInspector.ShadowEditor.Length(amount, "px"); | |
| 438 }, | |
| 439 | |
| 440 /** | |
| 441 * @param {number} amount | |
| 442 */ | |
| 443 setSpreadAmount: function(amount) | |
| 444 { | |
| 445 if (!this._blur) | |
| 446 this._blur = new WebInspector.ShadowEditor.Length(0, ""); | |
| 447 if (this._spread && this._spread.unit) | |
| 448 this._spread.amount = amount; | |
| 449 else | |
| 450 this._spread = new WebInspector.ShadowEditor.Length(amount, "px"); | |
| 451 }, | |
| 452 | |
| 453 /** | |
| 454 * @return {string} | |
| 455 */ | |
| 456 type: function() | |
| 457 { | |
| 458 return this._type; | |
| 459 }, | |
| 460 | |
| 461 /** | |
| 462 * @return {boolean} | |
| 463 */ | |
| 464 inset: function() | |
| 465 { | |
| 466 return !!this._inset; | |
| 467 }, | |
| 468 | |
| 469 /** | |
| 470 * @return {!WebInspector.ShadowEditor.Length} | |
| 471 */ | |
| 472 xOffset: function() | |
| 473 { | |
| 474 return this._xOffset ? this._xOffset : new WebInspector.ShadowEditor.Len gth(0, ""); | |
| 475 }, | |
| 476 | |
| 477 /** | |
| 478 * @return {!WebInspector.ShadowEditor.Length} | |
| 479 */ | |
| 480 yOffset: function() | |
| 481 { | |
| 482 return this._yOffset ? this._yOffset : new WebInspector.ShadowEditor.Len gth(0, ""); | |
| 483 }, | |
| 484 | |
| 485 /** | |
| 486 * @return {!WebInspector.ShadowEditor.Length} | |
| 487 */ | |
| 488 blur: function() | |
| 489 { | |
| 490 return this._blur ? this._blur : new WebInspector.ShadowEditor.Length(0, ""); | |
| 491 }, | |
| 492 | |
| 493 /** | |
| 494 * @return {!WebInspector.ShadowEditor.Length} | |
| 495 */ | |
| 496 spread: function() | |
| 497 { | |
| 498 return this._spread ? this._spread : new WebInspector.ShadowEditor.Lengt h(0, ""); | |
| 499 }, | |
| 500 | |
| 501 /** | |
| 113 * @return {!Array<!WebInspector.ShadowEditor.Length>} | 502 * @return {!Array<!WebInspector.ShadowEditor.Length>} |
| 114 */ | 503 */ |
| 115 lengths: function() | 504 _lengths: function() |
| 116 { | 505 { |
| 117 var lengthValues = []; | 506 var lengthValues = []; |
| 118 if (this.xOffset) | 507 if (this._xOffset) |
| 119 lengthValues.push(this.xOffset); | 508 lengthValues.push(this._xOffset); |
| 120 if (this.yOffset) | 509 if (this._yOffset) |
| 121 lengthValues.push(this.yOffset); | 510 lengthValues.push(this._yOffset); |
| 122 if (this.blur) | 511 if (this._blur) |
| 123 lengthValues.push(this.blur); | 512 lengthValues.push(this._blur); |
| 124 if (this.spread) | 513 if (this._spread) |
| 125 lengthValues.push(this.spread); | 514 lengthValues.push(this._spread); |
| 126 return lengthValues; | 515 return lengthValues; |
| 127 }, | 516 }, |
| 128 | 517 |
| 129 /** | 518 /** |
| 130 * @return {!Array<{type: string, text: string}>} | 519 * @return {!Array<{type: string, text: string}>} |
| 131 */ | 520 */ |
| 132 textParts: function() | 521 textParts: function() |
| 133 { | 522 { |
| 134 var parts = []; | 523 var parts = []; |
| 135 for (var i = 0; i < this.order.length; i++) { | 524 for (var i = 0; i < this._order.length; i++) { |
| 136 var currentPart = this.order[i]; | 525 var currentPart = this._order[i]; |
| 137 var textValue; | 526 var textValue = null; |
| 138 if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Inset) | 527 if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Inset && this._inset) |
| 139 textValue = this.inset; | 528 textValue = "inset"; |
| 140 else if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Leng th) | 529 else if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Leng th) |
| 141 textValue = this.lengths().join(" "); | 530 textValue = this._lengths().join(" "); |
| 142 else if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Colo r) | 531 else if (currentPart === WebInspector.ShadowEditor.Shadow.Parts.Colo r && this._color) |
| 143 textValue = this.color.asString(this.color.format()); | 532 textValue = this._color.asString(this._color.format()); |
| 144 parts.push({ | 533 if (textValue !== null) { |
| 145 type: currentPart, | 534 parts.push({ |
| 146 text: textValue | 535 type: currentPart, |
| 147 }); | 536 text: textValue |
| 537 }); | |
| 538 } | |
| 148 } | 539 } |
| 149 return parts; | 540 return parts; |
| 150 } | 541 } |
| 151 } | 542 } |
| 152 | 543 |
| 153 | 544 |
| 154 /** | 545 /** |
| 155 * @constructor | 546 * @constructor |
| 156 * @param {number} amount | 547 * @param {number} amount |
| 157 * @param {string} unit | 548 * @param {string} unit |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 WebInspector.ShadowEditor.Length.prototype = { | 581 WebInspector.ShadowEditor.Length.prototype = { |
| 191 /** | 582 /** |
| 192 * @override | 583 * @override |
| 193 * @return {string} | 584 * @return {string} |
| 194 */ | 585 */ |
| 195 toString: function() | 586 toString: function() |
| 196 { | 587 { |
| 197 return this.amount + this.unit; | 588 return this.amount + this.unit; |
| 198 } | 589 } |
| 199 } | 590 } |
| OLD | NEW |