Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCss/Css/CssCollectedProperty.cs @ 13825

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

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

File size: 3.2 KB
RevLine 
[12762]1using System;
2using System.Xml;
3using System.Collections;
4
5namespace SharpVectors.Dom.Css
6{
7  /// <summary>
8  /// Used internally to store collected properties.
9  /// </summary>
10  public class CssCollectedProperty
11  {
12    #region Constructors
13    internal CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority)
14    {
15      Name = name;
16      Specificity = specificity;
17      Origin = origin;
18      CssValue = cssValue;
19      Priority = priority;
20    }
21    #endregion
22
23    #region Public properties
24    /// <summary>
25    /// The name of the property
26    /// </summary>
27    public string Name;
28    /// <summary>
29    /// The calculated specificity
30    /// </summary>
31    public int Specificity;
32    /// <summary>
33    /// The origin of the collected property.
34    /// </summary>
35    public CssStyleSheetType Origin;
36    /// <summary>
37    /// The value of the property
38    /// </summary>
39        public CssValue CssValue;
40    /// <summary>
41    /// The priority of the property, e.g. "important"
42    /// </summary>
43    public string Priority;
44    #endregion
45
46    #region Internal methods
47    internal bool IsBetterThen(CssCollectedProperty existing)
48    {
49      bool yes = false;
50      #region sorting according to the rules at http://www.w3.org/TR/CSS21/cascade.html#cascading-order
51      bool gotHigherSpecificity = (Specificity>=existing.Specificity);
52     
53      switch(existing.Origin)
54      {
55        case CssStyleSheetType.UserAgent:
56          yes = (Origin == CssStyleSheetType.UserAgent) ? gotHigherSpecificity : true;
57          break;
58        case CssStyleSheetType.NonCssPresentationalHints:
59          yes = (Origin != CssStyleSheetType.UserAgent);
60          break;
61        case CssStyleSheetType.Inline:
62          yes = (Origin != CssStyleSheetType.UserAgent &&
63            Origin != CssStyleSheetType.NonCssPresentationalHints);
64          break;
65        case CssStyleSheetType.Author:
66          if(Origin == CssStyleSheetType.Author &&
67            Priority == existing.Priority &&
68            gotHigherSpecificity)
69          {
70            // author rules of the same priority
71            yes = true;
72          }
73          else if(Origin == CssStyleSheetType.Inline)
74          {
75            // inline rules override author rules
76            yes = true;
77          }
78          else if(Origin == CssStyleSheetType.User && Priority == "important")
79          {
80            // !important user rules overrides author rules
81            yes = true;
82          }
83          else if(Origin == CssStyleSheetType.Author &&
84            existing.Priority != "important" &&
85            Priority == "important"
86            )
87          {
88            // !important author rules override non-!important author rules
89            yes = true;
90          }
91          break;
92        case CssStyleSheetType.User:
93          if(Origin == CssStyleSheetType.User &&
94            existing.Priority == Priority &&
95            gotHigherSpecificity)
96          {
97            yes = true;
98          }
99          else if((Origin == CssStyleSheetType.Author || Origin == CssStyleSheetType.Inline) &&
100            existing.Priority != "important")
101          {
102            // author rules overrides not !important user rules
103            yes = true;
104          }
105          else if(Origin == CssStyleSheetType.User &&
106            Priority == "important")
107          {
108            // !important user rules override non-!important user rules
109            yes = true;
110          }
111          break;
112      }
113      #endregion
114
115      return yes;
116    }
117    #endregion
118  }
119
120}
Note: See TracBrowser for help on using the repository browser.