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 {boolean} isBoxShadow | 7 * @param {boolean} isBoxShadow |
8 */ | 8 */ |
9 WebInspector.CSSShadowModel = function(isBoxShadow) | 9 WebInspector.CSSShadowModel = function(isBoxShadow) |
10 { | 10 { |
11 this._isBoxShadow = isBoxShadow; | 11 this._isBoxShadow = isBoxShadow; |
12 this._inset = false; | 12 this._inset = false; |
13 this._offsetX = WebInspector.CSSLength.zero(); | 13 this._offsetX = WebInspector.CSSLength.zero(); |
14 this._offsetY = WebInspector.CSSLength.zero(); | 14 this._offsetY = WebInspector.CSSLength.zero(); |
15 this._blurRadius = WebInspector.CSSLength.zero(); | 15 this._blurRadius = WebInspector.CSSLength.zero(); |
16 this._spreadRadius = WebInspector.CSSLength.zero(); | 16 this._spreadRadius = WebInspector.CSSLength.zero(); |
17 this._color = /** @type {!WebInspector.Color} */ (WebInspector.Color.parse("
black")); | 17 this._color = /** @type {!WebInspector.Color} */ (WebInspector.Color.parse("
black")); |
18 this._format = [WebInspector.CSSShadowModel._Part.OffsetX, WebInspector.CSSS
hadowModel._Part.OffsetY]; | 18 this._format = [WebInspector.CSSShadowModel._Part.OffsetX, WebInspector.CSSS
hadowModel._Part.OffsetY]; |
19 } | 19 }; |
20 | 20 |
21 /** | 21 /** |
22 * @enum {string} | 22 * @enum {string} |
23 */ | 23 */ |
24 WebInspector.CSSShadowModel._Part = { | 24 WebInspector.CSSShadowModel._Part = { |
25 Inset: "I", | 25 Inset: "I", |
26 OffsetX: "X", | 26 OffsetX: "X", |
27 OffsetY: "Y", | 27 OffsetY: "Y", |
28 BlurRadius: "B", | 28 BlurRadius: "B", |
29 SpreadRadius: "S", | 29 SpreadRadius: "S", |
30 Color: "C" | 30 Color: "C" |
31 } | 31 }; |
32 | 32 |
33 /** | 33 /** |
34 * @param {string} text | 34 * @param {string} text |
35 * @return {!Array<!WebInspector.CSSShadowModel>} | 35 * @return {!Array<!WebInspector.CSSShadowModel>} |
36 */ | 36 */ |
37 WebInspector.CSSShadowModel.parseTextShadow = function(text) | 37 WebInspector.CSSShadowModel.parseTextShadow = function(text) |
38 { | 38 { |
39 return WebInspector.CSSShadowModel._parseShadow(text, false); | 39 return WebInspector.CSSShadowModel._parseShadow(text, false); |
40 } | 40 }; |
41 | 41 |
42 /** | 42 /** |
43 * @param {string} text | 43 * @param {string} text |
44 * @return {!Array<!WebInspector.CSSShadowModel>} | 44 * @return {!Array<!WebInspector.CSSShadowModel>} |
45 */ | 45 */ |
46 WebInspector.CSSShadowModel.parseBoxShadow = function(text) | 46 WebInspector.CSSShadowModel.parseBoxShadow = function(text) |
47 { | 47 { |
48 return WebInspector.CSSShadowModel._parseShadow(text, true); | 48 return WebInspector.CSSShadowModel._parseShadow(text, true); |
49 } | 49 }; |
50 | 50 |
51 WebInspector.CSSShadowModel.prototype = { | 51 WebInspector.CSSShadowModel.prototype = { |
52 /** | 52 /** |
53 * @param {boolean} inset | 53 * @param {boolean} inset |
54 */ | 54 */ |
55 setInset: function(inset) | 55 setInset: function(inset) |
56 { | 56 { |
57 this._inset = inset; | 57 this._inset = inset; |
58 if (this._format.indexOf(WebInspector.CSSShadowModel._Part.Inset) === -1
) | 58 if (this._format.indexOf(WebInspector.CSSShadowModel._Part.Inset) === -1
) |
59 this._format.unshift(WebInspector.CSSShadowModel._Part.Inset); | 59 this._format.unshift(WebInspector.CSSShadowModel._Part.Inset); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 parts.push(this._offsetY.asCSSText()); | 182 parts.push(this._offsetY.asCSSText()); |
183 else if (part === WebInspector.CSSShadowModel._Part.BlurRadius) | 183 else if (part === WebInspector.CSSShadowModel._Part.BlurRadius) |
184 parts.push(this._blurRadius.asCSSText()); | 184 parts.push(this._blurRadius.asCSSText()); |
185 else if (part === WebInspector.CSSShadowModel._Part.SpreadRadius) | 185 else if (part === WebInspector.CSSShadowModel._Part.SpreadRadius) |
186 parts.push(this._spreadRadius.asCSSText()); | 186 parts.push(this._spreadRadius.asCSSText()); |
187 else if (part === WebInspector.CSSShadowModel._Part.Color) | 187 else if (part === WebInspector.CSSShadowModel._Part.Color) |
188 parts.push(this._color.asString(this._color.format())); | 188 parts.push(this._color.asString(this._color.format())); |
189 } | 189 } |
190 return parts.join(" "); | 190 return parts.join(" "); |
191 } | 191 } |
192 } | 192 }; |
193 | 193 |
194 /** | 194 /** |
195 * @param {string} text | 195 * @param {string} text |
196 * @param {boolean} isBoxShadow | 196 * @param {boolean} isBoxShadow |
197 * @return {!Array<!WebInspector.CSSShadowModel>} | 197 * @return {!Array<!WebInspector.CSSShadowModel>} |
198 */ | 198 */ |
199 WebInspector.CSSShadowModel._parseShadow = function(text, isBoxShadow) | 199 WebInspector.CSSShadowModel._parseShadow = function(text, isBoxShadow) |
200 { | 200 { |
201 var shadowTexts = []; | 201 var shadowTexts = []; |
202 // Split by commas that aren't inside of color values to get the individual
shadow values. | 202 // Split by commas that aren't inside of color values to get the individual
shadow values. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 */ | 280 */ |
281 function invalidCount(part, min, max) | 281 function invalidCount(part, min, max) |
282 { | 282 { |
283 var count = 0; | 283 var count = 0; |
284 for (var i = 0; i < shadow._format.length; i++) { | 284 for (var i = 0; i < shadow._format.length; i++) { |
285 if (shadow._format[i] === part) | 285 if (shadow._format[i] === part) |
286 count++; | 286 count++; |
287 } | 287 } |
288 return count < min || count > max; | 288 return count < min || count > max; |
289 } | 289 } |
290 } | 290 }; |
291 | 291 |
292 /** | 292 /** |
293 * @constructor | 293 * @constructor |
294 * @param {number} amount | 294 * @param {number} amount |
295 * @param {string} unit | 295 * @param {string} unit |
296 */ | 296 */ |
297 WebInspector.CSSLength = function(amount, unit) | 297 WebInspector.CSSLength = function(amount, unit) |
298 { | 298 { |
299 this.amount = amount; | 299 this.amount = amount; |
300 this.unit = unit; | 300 this.unit = unit; |
301 } | 301 }; |
302 | 302 |
303 /** @type {!RegExp} */ | 303 /** @type {!RegExp} */ |
304 WebInspector.CSSLength.Regex = (function() | 304 WebInspector.CSSLength.Regex = (function() |
305 { | 305 { |
306 var number = "([+-]?(?:[0-9]*[.])?[0-9]+(?:[eE][+-]?[0-9]+)?)"; | 306 var number = "([+-]?(?:[0-9]*[.])?[0-9]+(?:[eE][+-]?[0-9]+)?)"; |
307 var unit = "(ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw)"; | 307 var unit = "(ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw)"; |
308 var zero = "[+-]?(?:0*[.])?0+(?:[eE][+-]?[0-9]+)?"; | 308 var zero = "[+-]?(?:0*[.])?0+(?:[eE][+-]?[0-9]+)?"; |
309 return new RegExp(number + unit + "|" + zero, "gi"); | 309 return new RegExp(number + unit + "|" + zero, "gi"); |
310 })(); | 310 })(); |
311 | 311 |
312 /** | 312 /** |
313 * @param {string} text | 313 * @param {string} text |
314 * @return {?WebInspector.CSSLength} | 314 * @return {?WebInspector.CSSLength} |
315 */ | 315 */ |
316 WebInspector.CSSLength.parse = function(text) | 316 WebInspector.CSSLength.parse = function(text) |
317 { | 317 { |
318 var lengthRegex = new RegExp("^(?:" + WebInspector.CSSLength.Regex.source +
")$", "i"); | 318 var lengthRegex = new RegExp("^(?:" + WebInspector.CSSLength.Regex.source +
")$", "i"); |
319 var match = text.match(lengthRegex); | 319 var match = text.match(lengthRegex); |
320 if (!match) | 320 if (!match) |
321 return null; | 321 return null; |
322 if (match.length > 2 && match[2]) | 322 if (match.length > 2 && match[2]) |
323 return new WebInspector.CSSLength(parseFloat(match[1]), match[2]); | 323 return new WebInspector.CSSLength(parseFloat(match[1]), match[2]); |
324 return WebInspector.CSSLength.zero(); | 324 return WebInspector.CSSLength.zero(); |
325 } | 325 }; |
326 | 326 |
327 /** | 327 /** |
328 * @return {!WebInspector.CSSLength} | 328 * @return {!WebInspector.CSSLength} |
329 */ | 329 */ |
330 WebInspector.CSSLength.zero = function() | 330 WebInspector.CSSLength.zero = function() |
331 { | 331 { |
332 return new WebInspector.CSSLength(0, ""); | 332 return new WebInspector.CSSLength(0, ""); |
333 } | 333 }; |
334 | 334 |
335 WebInspector.CSSLength.prototype = { | 335 WebInspector.CSSLength.prototype = { |
336 /** | 336 /** |
337 * @return {string} | 337 * @return {string} |
338 */ | 338 */ |
339 asCSSText: function() | 339 asCSSText: function() |
340 { | 340 { |
341 return this.amount + this.unit; | 341 return this.amount + this.unit; |
342 } | 342 } |
343 } | 343 }; |
OLD | NEW |