CssRule.cs :  » GUI » SharpVectorGraphics » SharpVectors » Dom » Css » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SharpVectorGraphics 
SharpVectorGraphics » SharpVectors » Dom » Css » CssRule.cs
using System;
using System.Xml;
using SharpVectors.Dom.Stylesheets;
using System.Text.RegularExpressions;

namespace SharpVectors.Dom.Css{
  public abstract class CssRule : ICssRule
  {
    #region Constructors
    protected CssRule(object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
    {
      if(parent is CssRule)
      {
        _ParentRule = (CssRule)parent;
      }
      else if(parent is CssStyleSheet)
      {
        _ParentStyleSheet = (CssStyleSheet)parent;
      }
      else
      {
        throw new Exception("The CssRule constructor can only take a CssRule or CssStyleSheet as it's second argument " + parent.GetType());
      }
      Origin = origin;
      ReplacedStrings = replacedStrings;
      ReadOnly = readOnly;
    }
    #endregion

    #region Private and protected fields
    /// <summary>
    /// The origin stylesheet type of this rule
    /// </summary>
    protected CssStyleSheetType Origin;
    private string[] ReplacedStrings;
    /// <summary>
    /// Specifies the read/write state of the instance
    /// </summary>
    protected bool ReadOnly = false;
    #endregion

    #region Private and internal methods
    private string StringReplaceEvaluator(Match match)
    {
            int i = Convert.ToInt32(match.Groups["number"].Value);
      string r = ReplacedStrings[i];
      if(!match.Groups["quote"].Success) r = r.Trim(new char[2]{'\'', '"'});
      return r;
    }

    internal string DeReplaceStrings(string s)
    {
      Regex re = new Regex(@"(?<quote>"")?<<<(?<number>[0-9]+)>>>""?");
      return re.Replace(s, new MatchEvaluator(StringReplaceEvaluator));
    }

    /// <summary>
    /// Used to find matching style rules in the cascading order
    /// </summary>
    /// <param name="elt">The element to find styles for</param>
    /// <param name="pseudoElt">The pseudo-element to find styles for</param>
    /// <param name="ml">The medialist that the document is using</param>
    /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
    protected internal virtual void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd)
    {
    }

    #endregion

    #region Public methods
    /// <summary>
    /// Finds the owner node of this rule
    /// </summary>
    /// <returns>The owner XmlNode</returns>
    public XmlNode ResolveOwnerNode()
    {
      if(ParentRule != null)
      {
        return ((CssRule)ParentRule).ResolveOwnerNode();
      }
      else
      {
        return ((StyleSheet)ParentStyleSheet).ResolveOwnerNode();
      }
    }

    #endregion
    
    #region Implementation of ICssRule
    private CssStyleSheet _ParentStyleSheet = null;
    /// <summary>
    /// The style sheet that contains this rule
    /// </summary>
    public ICssStyleSheet ParentStyleSheet
    {
      get
      {
        return _ParentStyleSheet;
      }
    }

    private CssRule _ParentRule = null;
    /// <summary>
    /// 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
    /// </summary>
    public ICssRule ParentRule
    {
      get
      {
        return _ParentRule;
      }
    }

    /// <summary>
    /// 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.
    /// </summary>
    public abstract CssRuleType Type
    {
      get;
    }

    /// <summary>
    /// The parsable textual representation of the rule. This reflects the current state of the rule and not its initial value.
    /// </summary>
    public virtual string CssText
    {
      get
      {
        throw new NotImplementedException("CssText");
        //return _CssText;
      }
      set
      {
                throw new NotImplementedException("CssText");
      }
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.