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 WebInspector.CSSShadowModel.PropertyRegex = /((?:-webkit-)?box|text)-shadow\s*?:
.+?[;\n\r]/g; |
| 22 |
21 /** | 23 /** |
22 * @enum {string} | 24 * @enum {string} |
23 */ | 25 */ |
24 WebInspector.CSSShadowModel._Part = { | 26 WebInspector.CSSShadowModel._Part = { |
25 Inset: "I", | 27 Inset: "I", |
26 OffsetX: "X", | 28 OffsetX: "X", |
27 OffsetY: "Y", | 29 OffsetY: "Y", |
28 BlurRadius: "B", | 30 BlurRadius: "B", |
29 SpreadRadius: "S", | 31 SpreadRadius: "S", |
30 Color: "C" | 32 Color: "C" |
(...skipping 10 matching lines...) Expand all Loading... |
41 | 43 |
42 /** | 44 /** |
43 * @param {string} text | 45 * @param {string} text |
44 * @return {!Array<!WebInspector.CSSShadowModel>} | 46 * @return {!Array<!WebInspector.CSSShadowModel>} |
45 */ | 47 */ |
46 WebInspector.CSSShadowModel.parseBoxShadow = function(text) | 48 WebInspector.CSSShadowModel.parseBoxShadow = function(text) |
47 { | 49 { |
48 return WebInspector.CSSShadowModel._parseShadow(text, true); | 50 return WebInspector.CSSShadowModel._parseShadow(text, true); |
49 } | 51 } |
50 | 52 |
| 53 /** |
| 54 * @param {string} text |
| 55 * @return {!Array<{text: string, position: number}>} |
| 56 */ |
| 57 WebInspector.CSSShadowModel.splitShadows = function(text) |
| 58 { |
| 59 // This function removes the whitespace around each shadow but not inside. |
| 60 var shadowTexts = WebInspector.CSSShadowModel._splitShadowsByCommas(text); |
| 61 var shadowPositions = []; |
| 62 var index = 0; |
| 63 for (var i = 0; i < shadowTexts.length; i++) { |
| 64 var shadowText = shadowTexts[i]; |
| 65 var position = shadowText.search(/\S/); |
| 66 if (position === -1) |
| 67 return [] |
| 68 shadowPositions.push({ |
| 69 text: shadowText.trim(), |
| 70 position: index + position |
| 71 }); |
| 72 // +1 for the comma that was removed. |
| 73 index = index + shadowText.length + 1; |
| 74 } |
| 75 return shadowPositions; |
| 76 } |
| 77 |
51 WebInspector.CSSShadowModel.prototype = { | 78 WebInspector.CSSShadowModel.prototype = { |
52 /** | 79 /** |
53 * @param {boolean} inset | 80 * @param {boolean} inset |
54 */ | 81 */ |
55 setInset: function(inset) | 82 setInset: function(inset) |
56 { | 83 { |
57 this._inset = inset; | 84 this._inset = inset; |
58 if (this._format.indexOf(WebInspector.CSSShadowModel._Part.Inset) === -1
) | 85 if (this._format.indexOf(WebInspector.CSSShadowModel._Part.Inset) === -1
) |
59 this._format.unshift(WebInspector.CSSShadowModel._Part.Inset); | 86 this._format.unshift(WebInspector.CSSShadowModel._Part.Inset); |
60 }, | 87 }, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 218 } |
192 } | 219 } |
193 | 220 |
194 /** | 221 /** |
195 * @param {string} text | 222 * @param {string} text |
196 * @param {boolean} isBoxShadow | 223 * @param {boolean} isBoxShadow |
197 * @return {!Array<!WebInspector.CSSShadowModel>} | 224 * @return {!Array<!WebInspector.CSSShadowModel>} |
198 */ | 225 */ |
199 WebInspector.CSSShadowModel._parseShadow = function(text, isBoxShadow) | 226 WebInspector.CSSShadowModel._parseShadow = function(text, isBoxShadow) |
200 { | 227 { |
201 var shadowTexts = []; | 228 var shadowTexts = WebInspector.CSSShadowModel._splitShadowsByCommas(text); |
202 // Split by commas that aren't inside of color values to get the individual
shadow values. | |
203 var splits = WebInspector.TextUtils.splitStringByRegexes(text, [WebInspector
.Color.Regex, /,/g]); | |
204 var currentIndex = 0; | |
205 for (var i = 0; i < splits.length; i++) { | |
206 if (splits[i].regexIndex === 1) { | |
207 var comma = splits[i]; | |
208 shadowTexts.push(text.substring(currentIndex, comma.position)); | |
209 currentIndex = comma.position + 1; | |
210 } | |
211 } | |
212 shadowTexts.push(text.substring(currentIndex, text.length)); | |
213 | |
214 var shadows = []; | 229 var shadows = []; |
215 for (var i = 0; i < shadowTexts.length; i++) { | 230 for (var i = 0; i < shadowTexts.length; i++) { |
216 var shadow = new WebInspector.CSSShadowModel(isBoxShadow); | 231 var shadow = new WebInspector.CSSShadowModel(isBoxShadow); |
217 shadow._format = []; | 232 shadow._format = []; |
218 var nextPartAllowed = true; | 233 var nextPartAllowed = true; |
219 var regexes = [/inset/gi, WebInspector.Color.Regex, WebInspector.CSSLeng
th.Regex]; | 234 var regexes = [/inset/gi, WebInspector.Color.Regex, WebInspector.CSSLeng
th.Regex]; |
220 var results = WebInspector.TextUtils.splitStringByRegexes(shadowTexts[i]
, regexes); | 235 var results = WebInspector.TextUtils.splitStringByRegexes(shadowTexts[i]
, regexes); |
221 for (var j = 0; j < results.length; j++) { | 236 for (var j = 0; j < results.length; j++) { |
222 var result = results[j]; | 237 var result = results[j]; |
223 if (result.regexIndex === -1) { | 238 if (result.regexIndex === -1) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 var count = 0; | 298 var count = 0; |
284 for (var i = 0; i < shadow._format.length; i++) { | 299 for (var i = 0; i < shadow._format.length; i++) { |
285 if (shadow._format[i] === part) | 300 if (shadow._format[i] === part) |
286 count++; | 301 count++; |
287 } | 302 } |
288 return count < min || count > max; | 303 return count < min || count > max; |
289 } | 304 } |
290 } | 305 } |
291 | 306 |
292 /** | 307 /** |
| 308 * @param {string} text |
| 309 * @return {!Array<string>} |
| 310 */ |
| 311 WebInspector.CSSShadowModel._splitShadowsByCommas = function(text) |
| 312 { |
| 313 var shadowTexts = []; |
| 314 // Split by commas that aren't inside of color values to get the individual
shadow values. |
| 315 var splits = WebInspector.TextUtils.splitStringByRegexes(text, [WebInspector
.Color.Regex, /,/g]); |
| 316 var currentIndex = 0; |
| 317 for (var i = 0; i < splits.length; i++) { |
| 318 if (splits[i].regexIndex === 1) { |
| 319 var comma = splits[i]; |
| 320 shadowTexts.push(text.substring(currentIndex, comma.position)); |
| 321 currentIndex = comma.position + 1; |
| 322 } |
| 323 } |
| 324 shadowTexts.push(text.substring(currentIndex, text.length)); |
| 325 return shadowTexts; |
| 326 } |
| 327 |
| 328 /** |
293 * @constructor | 329 * @constructor |
294 * @param {number} amount | 330 * @param {number} amount |
295 * @param {string} unit | 331 * @param {string} unit |
296 */ | 332 */ |
297 WebInspector.CSSLength = function(amount, unit) | 333 WebInspector.CSSLength = function(amount, unit) |
298 { | 334 { |
299 this.amount = amount; | 335 this.amount = amount; |
300 this.unit = unit; | 336 this.unit = unit; |
301 } | 337 } |
302 | 338 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 370 |
335 WebInspector.CSSLength.prototype = { | 371 WebInspector.CSSLength.prototype = { |
336 /** | 372 /** |
337 * @return {string} | 373 * @return {string} |
338 */ | 374 */ |
339 asCSSText: function() | 375 asCSSText: function() |
340 { | 376 { |
341 return this.amount + this.unit; | 377 return this.amount + this.unit; |
342 } | 378 } |
343 } | 379 } |
OLD | NEW |