Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCss/Css/CssRule.cs @ 13918

Last change on this file since 13918 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 3.9 KB
Line 
1using System;
2using System.Xml;
3using System.Collections.Generic;
4using System.Text.RegularExpressions;
5
6using SharpVectors.Dom.Stylesheets;
7
8namespace SharpVectors.Dom.Css
9{
10  public abstract class CssRule : ICssRule
11  {
12    #region Constructors
13
14    protected CssRule(object parent, bool readOnly,
15            IList<string> replacedStrings, CssStyleSheetType origin)
16    {
17      if(parent is CssRule)
18      {
19        _ParentRule = (CssRule)parent;
20      }
21      else if(parent is CssStyleSheet)
22      {
23        _ParentStyleSheet = (CssStyleSheet)parent;
24      }
25      else
26      {
27        throw new Exception("The CssRule constructor can only take a CssRule or CssStyleSheet as it's second argument " + parent.GetType());
28      }
29      this.origin = origin;
30            this.replacedStrings = replacedStrings;
31            this.readOnly = readOnly;
32    }
33
34    #endregion
35
36    #region Private and protected fields
37    /// <summary>
38    /// The origin stylesheet type of this rule
39    /// </summary>
40    protected CssStyleSheetType origin;
41    private IList<string> replacedStrings;
42    /// <summary>
43    /// Specifies the read/write state of the instance
44    /// </summary>
45    protected bool readOnly;
46
47    #endregion
48
49    #region Private and internal methods
50    private string StringReplaceEvaluator(Match match)
51    {
52            int i = Convert.ToInt32(match.Groups["number"].Value);
53            string r = replacedStrings[i];
54      if(!match.Groups["quote"].Success) r = r.Trim(new char[2]{'\'', '"'});
55      return r;
56    }
57
58    internal string DeReplaceStrings(string s)
59    {
60      Regex re = new Regex(@"(?<quote>"")?<<<(?<number>[0-9]+)>>>""?");
61      return re.Replace(s, new MatchEvaluator(StringReplaceEvaluator));
62    }
63
64    /// <summary>
65    /// Used to find matching style rules in the cascading order
66    /// </summary>
67    /// <param name="elt">The element to find styles for</param>
68    /// <param name="pseudoElt">The pseudo-element to find styles for</param>
69    /// <param name="ml">The medialist that the document is using</param>
70    /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
71    protected internal virtual void GetStylesForElement(XmlElement elt,
72            string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd)
73    {
74    }
75
76    #endregion
77
78    #region Public methods
79    /// <summary>
80    /// Finds the owner node of this rule
81    /// </summary>
82    /// <returns>The owner XmlNode</returns>
83    public XmlNode ResolveOwnerNode()
84    {
85      if(ParentRule != null)
86      {
87        return ((CssRule)ParentRule).ResolveOwnerNode();
88      }
89      else
90      {
91        return ((StyleSheet)ParentStyleSheet).ResolveOwnerNode();
92      }
93    }
94
95    #endregion
96   
97    #region Implementation of ICssRule
98    private CssStyleSheet _ParentStyleSheet = null;
99    /// <summary>
100    /// The style sheet that contains this rule
101    /// </summary>
102    public ICssStyleSheet ParentStyleSheet
103    {
104      get
105      {
106        return _ParentStyleSheet;
107      }
108    }
109
110    private CssRule _ParentRule = null;
111    /// <summary>
112    /// If this rule is contained inside another rule (e.g. a style rule inside an @media block), this is the containing rule. If this rule is not nested inside any other rules, this returns null
113    /// </summary>
114    public ICssRule ParentRule
115    {
116      get
117      {
118        return _ParentRule;
119      }
120    }
121
122    /// <summary>
123    /// The type of the rule, as defined above. The expectation is that binding-specific casting methods can be used to cast down from an instance of the CSSRule interface to the specific derived interface implied by the type.
124    /// </summary>
125    public abstract CssRuleType Type
126    {
127      get;
128    }
129
130    /// <summary>
131    /// The parsable textual representation of the rule. This reflects the current state of the rule and not its initial value.
132    /// </summary>
133    public virtual string CssText
134    {
135      get
136      {
137        throw new NotImplementedException("CssText");
138        //return _CssText;
139      }
140      set
141      {
142                throw new NotImplementedException("CssText");
143      }
144    }
145    #endregion
146  }
147}
Note: See TracBrowser for help on using the repository browser.