-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathCssStyleDeclaration.cs
718 lines (634 loc) · 30.4 KB
/
CssStyleDeclaration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace SharpVectors.Dom.Css
{
/// <summary>
/// <para>
/// The <see cref="ICssStyleDeclaration"/> interface represents a single CSS declaration block.
/// This interface may be used to determine the style properties currently set in a block or
/// to set style properties explicitly within the block.
/// </para>
/// <para>
/// While an implementation may not recognize all CSS properties within a CSS declaration block,
/// it is expected to provide access to all specified properties in the style sheet through the
/// <see cref="ICssStyleDeclaration"/> interface. Furthermore, implementations that support a
/// specific level of CSS should correctly handle CSS shorthand properties for that level.
/// For a further discussion of shorthand properties, see the CSS2Properties interface.
/// </para>
/// <para>
/// This interface is also used to provide a read-only access to the computed values of an element.
/// See also the ViewCSS interface.
/// </para>
/// <para>
/// Note: The CSS Object Model doesn't provide an access to the specified or actual values of the CSS cascade
/// </para>
/// </summary>
public class CssStyleDeclaration : ICssStyleDeclaration
{
#region Static Members
[ThreadStatic]
private static CssStyleDeclaration _emptyCssStyle;
internal const string UrlName = "url:Name";
internal const string UrlMime = "url:Mime";
internal const string UrlData = "url:Data";
internal const string UrlEncoding = "url:Encoding";
private static readonly Regex _reComment = new Regex(@"(//.*)|(/\*(.|\n)*?\*/)");
private static readonly Regex _styleRegex = new Regex(
@"^(?<name>[A-Za-z\-0-9]+)\s*:(?<value>[^;\}!]+)(!\s?(?<priority>important))?;?");
// We'll use your regex for extracting the valid URLs
private static readonly Regex _reUrls = new Regex(@"(?nx)
url \s* \( \s*
(
(?! ['""] )
(?<Url> [^\)]+ )
(?<! ['""] )
|
(?<Quote> ['""] )
(?<Url> .+? )
\k<Quote>
)
\s* \)");
//private static readonly Regex _reSplitCss = new Regex(@"([^:\s]+)*\s*:\s*([^;]+);");
private static readonly Regex _reSplitCss = new Regex(@"([^:\s]+)\s*:\s*([^;]+);");
private static readonly Regex _reSplitCssOther = new Regex(@"({|;)([^:{;]+:[^;}]+)(;|})");
private static readonly Regex _reUrlTidy = new Regex(@"(^|{|})(\\s*{[^}]*})");
//private static readonly Regex _reEmbeddedUrl = new Regex(
// @"^(?<name>[A-Za-z\-0-9]+)\s*:\s*url\(data:(?<mime>[\w/\-\.]+);(?<encoding>\w+),(?<data>[^;\}!]+)(!\s?(?<priority>important))?;?");
private static readonly Regex _reEmbeddedUrl = new Regex(
@"^(?<name>[A-Za-z\-0-9]+)\s*:\s*url\(['""]?data:(?<mime>[\w/\-\.]+);(?<encoding>\w+),(?<data>[^;\}!]+)(!\s?(?<priority>important))?;?");
// Enter properties that can validly contain a URL here (in lowercase):
private static readonly ISet<string> _validUrlProps = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"src", "background", "background-image"
};
// font: font-style font-variant font-weight font-size/line-height font-family
// NOTE: font-stretch is not yet supported!
private static readonly Regex _reFont = new Regex(@"^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)"
+ @"(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)"
+ @"(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00\b))?)"
+ @"(?:(?:normal|\1|\2|\3)\s*){0,3}"
+ @"((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])?)?"
+ @"(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])?))?\s*([-,\""\sa-z]+|(['""])(?:(?!\1|\\).|\\.)*\1?)?\s*$",
RegexOptions.IgnoreCase);
private static readonly Regex _reFontStretch = new Regex(
@"\s*(ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded)?$",
RegexOptions.IgnoreCase);
private static readonly Regex _reFontWeight = new Regex(
@"\s*(bold(?:er)?|lighter|[1-9]00)?$", RegexOptions.IgnoreCase);
#endregion
#region Private Fields
private bool _readOnly;
private CssStyleSheetType _origin;
private IDictionary<string, CssStyleBlock> _styles;
private ICssRule _parentRule;
#endregion
#region Constructors
/// <summary>
/// The constructor used internally when collecting styles for a specified element
/// </summary>
protected CssStyleDeclaration()
{
_origin = CssStyleSheetType.Collector;
_readOnly = true;
_parentRule = null;
_styles = new Dictionary<string, CssStyleBlock>(StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// The constructor for CssStyleDeclaration
/// </summary>
/// <param name="css">The string to parse for CSS</param>
/// <param name="parentRule">The parent rule or parent stylesheet</param>
/// <param name="readOnly">True if this instance is readonly</param>
/// <param name="origin">The type of CssStyleSheet</param>
public CssStyleDeclaration(ref string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin)
: this()
{
_origin = origin;
_readOnly = readOnly;
_parentRule = parentRule;
css = ParseString(css);
}
public CssStyleDeclaration(string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin)
: this()
{
_origin = origin;
_readOnly = readOnly;
_parentRule = parentRule;
ParseString(css);
}
#endregion
#region Public Properties
public bool ReadOnly
{
get {
return _readOnly;
}
}
public CssStyleSheetType Origin
{
get {
return _origin;
}
}
#endregion
#region Public Methods
/// <summary>
/// Used to find matching style rules in the cascading order
/// </summary>
public void GetStylesForElement(CssCollectedStyleDeclaration csd, int specificity)
{
foreach (KeyValuePair<string, CssStyleBlock> de in _styles)
{
CssStyleBlock scs = de.Value;
csd.CollectProperty(scs.Name, specificity,
(CssValue)GetPropertyCssValue(scs.Name), scs.Origin, scs.Priority);
}
}
/// <summary>
/// Parsing CSS in C#: extracting all URLs
/// </summary>
/// <param name="cssStr"></param>
/// <param name="validProperty"></param>
/// <returns></returns>
/// <remarks>
/// https://stackoverflow.com/questions/18262390/parsing-css-in-c-extracting-all-urls
/// </remarks>
public static string GetValidUrlFromCSS(string cssStr, string validProperty)
{
// First, remove all the comments
cssStr = _reComment.Replace(cssStr, string.Empty).Trim();
// Next remove all the the property groups with no selector
string oldStr;
do
{
oldStr = cssStr;
cssStr = _reUrlTidy.Replace(cssStr, "$1");
} while (cssStr != oldStr);
// Get properties
var matches = _reSplitCss.Matches(cssStr);
foreach (Match match in matches)
{
// Matches: (0)=src:url(woffs/ZCSB.woff) format("woff"); | (1)=src | (2)=url(woffs/ZCSB.woff) format("woff")
if (match.Groups != null && match.Groups.Count == 3)
{
if (string.Equals(validProperty, match.Groups[1].Value, StringComparison.OrdinalIgnoreCase))
{
// Since this is a valid property, extract the URL (if there is one)
MatchCollection validUrlCollection = _reUrls.Matches(match.Groups[2].Value);
if (validUrlCollection.Count > 0)
{
return validUrlCollection[0].Groups["Url"].Value;
}
}
}
}
// Get properties
matches = _reSplitCssOther.Matches(cssStr);
foreach (Match match in matches)
{
string matchVal = match.Groups[2].Value;
string[] matchArr = matchVal.Split(':');
if (string.Equals(validProperty, matchArr[0].Trim(), StringComparison.OrdinalIgnoreCase))
{
// Since this is a valid property, extract the URL (if there is one)
MatchCollection validUrlCollection = _reUrls.Matches(matchVal);
if (validUrlCollection.Count > 0)
{
return validUrlCollection[0].Groups["Url"].Value;
}
}
}
return null;
}
public static IList<string> GetValidUrlsFromCSS(string cssStr)
{
List<string> validUrls = new List<string>();
// First, remove all the comments
cssStr = _reComment.Replace(cssStr, string.Empty).Trim();
// Next remove all the the property groups with no selector
string oldStr;
do
{
oldStr = cssStr;
cssStr = _reUrlTidy.Replace(cssStr, "$1");
} while (cssStr != oldStr);
// Get properties
var matches = _reSplitCss.Matches(cssStr);
foreach (Match match in matches)
{
// Matches: (0)=src:url(woffs/ZCSB.woff) format("woff"); | (1)=src | (2)=url(woffs/ZCSB.woff) format("woff")
if (match.Groups != null && match.Groups.Count == 3)
{
if (_validUrlProps.Contains(match.Groups[1].Value))
{
// Since this is a valid property, extract the URL (if there is one)
MatchCollection validUrlCollection = _reUrls.Matches(match.Groups[2].Value);
if (validUrlCollection.Count > 0)
{
validUrls.Add(validUrlCollection[0].Groups["Url"].Value);
}
}
}
}
if (validUrls.Count != 0)
{
return validUrls;
}
// Get properties
matches = _reSplitCssOther.Matches(cssStr);
foreach (Match match in matches)
{
string matchVal = match.Groups[2].Value;
string[] matchArr = matchVal.Split(':');
if (_validUrlProps.Contains(matchArr[0].Trim()))
{
// Since this is a valid property, extract the URL (if there is one)
MatchCollection validUrlCollection = _reUrls.Matches(matchVal);
if (validUrlCollection.Count > 0)
{
validUrls.Add(validUrlCollection[0].Groups["Url"].Value);
}
}
}
return validUrls;
}
#endregion
#region Private Methods
private string ParseString(string cssText)
{
if (string.IsNullOrWhiteSpace(cssText))
{
return string.Empty;
}
bool startedWithABracket = false;
cssText = cssText.Trim();
if (cssText.StartsWith("{", StringComparison.OrdinalIgnoreCase))
{
cssText = cssText.Substring(1).Trim();
startedWithABracket = true;
}
var quotes = new char[2] { '\'', '"' };
Match match = _styleRegex.Match(cssText);
while (match.Success)
{
string name = match.Groups["name"].Value.Trim();
string value = match.Groups["value"].Value.Trim();
if (_parentRule != null)
{
value = ((CssRule)_parentRule).DeReplaceStrings(value);
}
value = value.Trim(quotes);
if (value.StartsWith("url(", StringComparison.OrdinalIgnoreCase))
{
if (value.IndexOf("data:", StringComparison.OrdinalIgnoreCase) > 0)
{
var matchUrl = _reEmbeddedUrl.Match(cssText);
if (matchUrl != null && matchUrl.Groups != null && matchUrl.Groups.Count >= 3)
{
var nameUrl = matchUrl.Groups["name"].Value;
var mimeUrl = matchUrl.Groups["mime"].Value;
var encodingUrl = matchUrl.Groups["encoding"].Value;
var dataUrl = matchUrl.Groups["data"].Value;
if (string.Equals(name, nameUrl, StringComparison.Ordinal)
&& !string.IsNullOrWhiteSpace(mimeUrl)
&& !string.IsNullOrWhiteSpace(encodingUrl)
&& !string.IsNullOrWhiteSpace(dataUrl))
{
value = matchUrl.Groups[0].Value.Remove(0, name.Length + 1).TrimEnd(';');
match = matchUrl;
int foundAt = dataUrl.IndexOf(")", StringComparison.Ordinal);
if (!_styles.ContainsKey(UrlName) && foundAt > 0)
{
_styles.Add(UrlName, new CssStyleBlock(UrlName, nameUrl, string.Empty, _origin));
_styles.Add(UrlMime, new CssStyleBlock(UrlMime, mimeUrl, string.Empty, _origin));
_styles.Add(UrlData, new CssStyleBlock(UrlData, dataUrl.Substring(0, foundAt).Trim(quotes), string.Empty, _origin));
_styles.Add(UrlEncoding, new CssStyleBlock(UrlEncoding, encodingUrl, string.Empty, _origin));
}
}
}
else
{
}
}
}
else if (string.Equals(name, "font"))
{
var fontParts = new string[] {
"font", "font-style", "font-variant", "font-weight",
"font-size", "line-height", "font-family", "font-family", "font-stretch"
};
int count = 0;
// The font CSS shorthand property sets all the different properties of an element's font.
var matchFont = _reFont.Match(value);
if (!matchFont.Success)
{
var fontValue = value.Trim();
var indexSel = fontValue.IndexOf(' ');
if (indexSel > 0)
{
var preText = fontValue.Substring(0, indexSel).TrimStart();
fontValue = fontValue.Substring(indexSel).TrimStart();
var tempMatch = _reFontStretch.Match(preText);
if (tempMatch.Success)
{
var fontStretch = fontParts[8];
_styles.Add(fontStretch, new CssStyleBlock(fontStretch, tempMatch.Value, string.Empty, _origin));
}
else
{
tempMatch = _reFontWeight.Match(preText);
if (tempMatch.Success)
{
var fontWeight = fontParts[3];
_styles.Add(fontWeight, new CssStyleBlock(fontWeight, tempMatch.Value, string.Empty, _origin));
}
}
}
matchFont = _reFont.Match(fontValue);
}
if (matchFont.Success)
{
foreach (Group group in matchFont.Groups)
{
if (group.Success)
{
var fontPart = fontParts[count];
_styles.Add(fontPart, new CssStyleBlock(fontPart, group.Value, string.Empty, _origin));
}
count++;
}
}
}
string prio = match.Groups["priority"].Value;
CssStyleBlock style = new CssStyleBlock(name, value, prio, _origin);
bool addStyle = false;
if (_styles.ContainsKey(name))
{
string existingPrio = _styles[name].Priority;
if (existingPrio != "important" || prio == "important")
{
_styles.Remove(name);
addStyle = true;
}
}
else
{
addStyle = true;
}
if (addStyle)
{
_styles.Add(name, style);
}
cssText = cssText.Substring(match.Length).Trim();
match = _styleRegex.Match(cssText);
}
cssText = cssText.Trim();
if (cssText.StartsWith("}", StringComparison.OrdinalIgnoreCase))
{
cssText = cssText.Substring(1);
}
else if (startedWithABracket)
{
throw new DomException(DomExceptionType.SyntaxErr, "Style declaration ending bracket missing");
}
return cssText;
}
#endregion
#region ICssStyleDeclaration Members
/// <summary>
/// Used to set a property value and priority within this declaration block
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <param name="value">The new value of the property.</param>
/// <param name="priority">The new priority of the property (e.g. "important").</param>
/// <exception cref="DomException"><c>SYNTAX_ERR:</c> Raised if the specified value has a syntax error and is unparsable.</exception>
/// <exception cref="DomException"><c>NO_MODIFICATION_ALLOWED_ERR:</c> Raised if this declaration is readonly or the property is readonly.</exception>
public void SetProperty(string propertyName, string value, string priority)
{
if (_readOnly)
throw new DomException(DomExceptionType.NoModificationAllowedErr);
_styles[propertyName] = new CssStyleBlock(propertyName, value, priority, _origin);
}
/// <summary>
/// Used to set a property value and priority within this declaration block
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <param name="value">The new value of the property.</param>
/// <exception cref="DomException"><c>SYNTAX_ERR:</c> Raised if the specified value has a syntax error and is unparsable.</exception>
/// <exception cref="DomException"><c>NO_MODIFICATION_ALLOWED_ERR:</c> Raised if this declaration is readonly or the property is readonly.</exception>
public void SetPropertyValue(string propertyName, string value)
{
if (_readOnly)
throw new DomException(DomExceptionType.NoModificationAllowedErr);
if (_styles == null || _styles.ContainsKey(propertyName) == false)
{
return;
}
var styleBlock = _styles[propertyName];
if (styleBlock != null)
{
styleBlock.Value = value;
}
}
/// <summary>
/// Used to retrieve the priority of a CSS property (e.g. the "important" qualifier) if the property
/// has been explicitly set in this declaration block.
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <returns>A string representing the priority (e.g. "important") if one exists. The empty string if none exists.</returns>
public virtual string GetPropertyPriority(string propertyName)
{
return (_styles.ContainsKey(propertyName)) ? _styles[propertyName].Priority : string.Empty;
}
/// <summary>
/// Used to remove a CSS property if it has been explicitly set within this declaration block.
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <returns>Returns the value of the property if it has been explicitly set for this declaration block.
/// Returns the empty string if the property has not been set or the property name does not correspond
/// to a known CSS property.</returns>
/// <exception cref="DomException"><c>NO_MODIFICATION_ALLOWED_ERR:</c> Raised if this declaration is readonly
/// or the property is readonly.</exception>
public string RemoveProperty(string propertyName)
{
if (_readOnly)
throw new DomException(DomExceptionType.NoModificationAllowedErr);
if (_styles.ContainsKey(propertyName))
{
CssStyleBlock s = _styles[propertyName];
_styles.Remove(propertyName);
return s.Value;
}
return string.Empty;
}
/// <summary>
/// Used to retrieve the object representation of the value of a CSS property if it has been explicitly set
/// within this declaration block. This method returns null if the property is a shorthand property.
/// Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and
/// setProperty methods.
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <returns>Returns the value of the property if it has been explicitly set for this declaration block.
/// Returns null if the property has not been set.</returns>
public virtual ICssValue GetPropertyCssValue(string propertyName)
{
if (string.IsNullOrWhiteSpace(propertyName))
{
return null;
}
if (_styles.ContainsKey(propertyName))
{
CssStyleBlock scs = _styles[propertyName];
if (propertyName.Equals(SvgConstants.AttrFontFamily, StringComparison.OrdinalIgnoreCase))
{
scs.CssValue = new CssValue(CssValueType.PrimitiveValue, scs.Value, ReadOnly);
}
else if (scs.CssValue == null)
{
scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly);
}
return scs.CssValue;
}
return null;
}
/// <summary>
/// Used to retrieve the value of a CSS property if it has been explicitly set within this declaration block.
/// </summary>
/// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
/// <returns>Returns the value of the property if it has been explicitly set for this declaration block.
/// Returns the empty string if the property has not been set.</returns>
public virtual string GetPropertyValue(string propertyName)
{
if (string.IsNullOrWhiteSpace(propertyName))
{
return string.Empty;
}
return (_styles.ContainsKey(propertyName)) ? _styles[propertyName].Value.Trim('\'') : string.Empty;
}
/// <summary>
/// Used to retrieve the value of a CSS property if it has been explicitly set within this declaration block.
/// </summary>
/// <param name="propertyNames">The name of the CSS property. See the CSS property index.</param>
/// <returns>Returns the value of the property if it has been explicitly set for this declaration block.
/// Returns the empty string if the property has not been set.</returns>
public virtual string GetPropertyValue(string[] propertyNames)
{
if (propertyNames == null || propertyNames.Length == 0)
{
return string.Empty;
}
foreach (var propertyName in propertyNames)
{
if (_styles.ContainsKey(propertyName))
return _styles[propertyName].Value.Trim('\'');
}
return string.Empty;
}
/// <summary>
/// The CSS rule that contains this declaration block or null if this CSSStyleDeclaration is not attached to a CSSRule.
/// </summary>
public ICssRule ParentRule
{
get {
return _parentRule;
}
}
/// <summary>
/// The number of properties that have been explicitly set in this declaration block.
/// The range of valid indices is 0 to length-1 inclusive.
/// </summary>
public virtual ulong Length
{
get {
return (ulong)_styles.Count;
}
}
/// <summary>
/// The parsable textual representation of the declaration block (excluding the surrounding curly braces).
/// Setting this attribute will result in the parsing of the new value and resetting of all the properties
/// in the declaration block including the removal or addition of properties.
/// </summary>
/// <exception cref="DomException"><c>SYNTAX_ERR:</c> Raised if the specified CSS string value has a syntax error and is unparsable.</exception>
/// <exception cref="DomException"><c>NO_MODIFICATION_ALLOWED_ERR:</c> Raised if this declaration is readonly or a property is readonly.</exception>
public virtual string CssText
{
get {
StringBuilder builder = new StringBuilder();
IEnumerator<KeyValuePair<string, CssStyleBlock>> enu = _styles.GetEnumerator();
while (enu.MoveNext())
{
CssStyleBlock style = enu.Current.Value;
builder.Append(style.CssText);
builder.Append(";");
}
return builder.ToString();
}
set {
throw new NotImplementedException();
}
}
/// <summary>
/// Used to retrieve the properties that have been explicitly set in this declaration block.
/// The order of the properties retrieved using this method does not have to be the order in which they were set.
/// This method can be used to iterate over all properties in this declaration block.
/// The name of the property at this ordinal position. The empty string if no property exists at this position.
/// </summary>
public virtual string this[ulong index]
{
get {
if (index >= Length)
return string.Empty;
int ind = (int)index;
IEnumerator<KeyValuePair<string, CssStyleBlock>> iterator = _styles.GetEnumerator();
iterator.MoveNext();
KeyValuePair<string, CssStyleBlock> enu = iterator.Current;
for (int i = 0; i < ind; i++)
{
iterator.MoveNext();
enu = iterator.Current;
}
return enu.Key;
}
}
#endregion
#region Internal Properties and Methods
internal static CssStyleDeclaration EmptyCssStyle
{
get {
if (_emptyCssStyle == null)
{
_emptyCssStyle = new CssStyleDeclaration();
}
return _emptyCssStyle;
}
}
internal CssStyleBlock Get(string key)
{
if (_styles != null && _styles.Count != 0 && _styles.ContainsKey(key))
{
return _styles[key];
}
return null;
}
internal string GetValue(string key)
{
if (_styles != null && _styles.Count != 0 && _styles.ContainsKey(key))
{
return _styles[key].Value;
}
return null;
}
internal bool Contains(string key)
{
if (_styles != null && _styles.Count != 0)
{
return _styles.ContainsKey(key);
}
return false;
}
#endregion
}
}