Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCss/Stylesheets/StyleSheetList.cs @ 12762

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

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

File size: 3.4 KB
Line 
1// <developer>niklas@protocol7.com</developer>
2// <completed>80</completed>
3
4using System;
5using System.Xml;
6using System.Collections.Generic;
7using System.Diagnostics;
8using System.Text.RegularExpressions;
9using SharpVectors.Dom.Css;
10
11namespace SharpVectors.Dom.Stylesheets
12{
13  /// <summary>
14  /// The StyleSheetList interface provides the abstraction of an ordered collection of style sheets.
15  /// The items in the StyleSheetList are accessible via an integral index, starting from 0.
16  /// </summary>
17    public sealed class StyleSheetList : IStyleSheetList
18  {
19        #region Private Fields
20
21        private List<StyleSheet> styleSheets;
22        private CssXmlDocument doc;
23
24        #endregion
25
26    #region Constructors and Destructor
27
28    internal StyleSheetList(CssXmlDocument document)
29    {
30      doc = document;
31      XmlNodeList pis = document.SelectNodes("/processing-instruction()");
32      styleSheets = new List<StyleSheet>();
33
34      foreach (XmlProcessingInstruction pi in pis)
35      {
36        if (Regex.IsMatch(pi.Data, "type=[\"']text\\/css[\"']"))
37        {
38          styleSheets.Add(new CssStyleSheet(pi, CssStyleSheetType.Author));
39        }
40        else
41        {
42          styleSheets.Add(new StyleSheet(pi));
43        }
44
45      }
46
47      XmlNodeList styleNodes;
48      foreach(string[] name in document.styleElements)
49      {
50        styleNodes = document.SelectNodes(
51          "//*[local-name()='" + name[1] + "' and namespace-uri()='" + name[0] + "'][@type='text/css']");
52
53        foreach(XmlElement elm in styleNodes)
54        {
55                    styleSheets.Add(new CssStyleSheet(elm, CssStyleSheetType.Author));
56        }
57      }
58    }
59
60    #endregion
61
62    #region Public Methods
63
64    public void AddCssStyleSheet(CssStyleSheet ss)
65    {
66      styleSheets.Add(ss);
67    }
68
69    /// <summary>
70    /// Used to find matching style rules in the cascading order
71    /// </summary>
72    /// <param name="elt">The element to find styles for</param>
73    /// <param name="pseudoElt">The pseudo-element to find styles for</param>
74    /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
75    public void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd)
76    {
77      GetStylesForElement(elt, pseudoElt, csd, doc.Media);
78    }
79
80    /// <summary>
81    /// Used to find matching style rules in the cascading order
82    /// </summary>
83    /// <param name="elt">The element to find styles for</param>
84    /// <param name="pseudoElt">The pseudo-element to find styles for</param>
85    /// <param name="ml">The medialist that the document is using</param>
86    /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
87    internal void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd, MediaList ml)
88    {
89      foreach (StyleSheet ss in styleSheets)
90      {
91        ss.GetStylesForElement(elt, pseudoElt, ml, csd);
92      }
93    }
94   
95    #endregion
96
97    #region IStyleSheetList Members
98
99    /// <summary>
100    /// The number of StyleSheets in the list. The range of valid child stylesheet indices is 0 to length-1 inclusive.
101    /// </summary>
102    public ulong Length
103    {
104      get
105      {
106        return (ulong)styleSheets.Count;
107      }
108    }
109
110    /// <summary>
111    /// Used to retrieve a style sheet by ordinal index. If index is greater than or equal to the number of style sheets in the list, this returns null.
112    /// </summary>
113    public IStyleSheet this[ulong index]
114    {
115      get
116      {
117        return styleSheets[(int)index];
118      }
119    }
120
121    #endregion
122  }
123}
Note: See TracBrowser for help on using the repository browser.