/// <summary> /// Constructor for CssStyleSheet /// </summary> /// <param name="ownerNode">The node that owns this stylesheet. E.g. used for getting the BaseUri</param> /// <param name="href">The URL of the stylesheet</param> /// <param name="title">The title of the stylesheet</param> /// <param name="media">List of medias for the stylesheet</param> /// <param name="ownerRule">The rule (e.g. ImportRule) that referenced this stylesheet</param> /// <param name="origin">The type of stylesheet</param> public CssStyleSheet(XmlNode ownerNode, string href, string title, string media, CssRule ownerRule, CssStyleSheetType origin) : base(ownerNode, href, "text/css", title, media) { Origin = origin; this.ownerRule = ownerRule; }
/// <summary> /// The constructor for CssImportRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssImportRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { media = new MediaList(match.Groups["importmedia"].Value); href = DeReplaceStrings(match.Groups["importhref"].Value); styleSheet = new CssStyleSheet(ResolveOwnerNode(), Href, null, match.Groups["importmedia"].Value, this, Origin); }
internal SharpCssStyle(string name, string val, string priority, CssStyleSheetType origin) { Name = name.Trim(); Value = val.Trim(); Priority = priority.Trim(); Origin = origin; }
internal CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority) { Name = name; Specificity = specificity; Origin = origin; CssValue = cssValue; Priority = priority; }
public CssStyleDeclaration(string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin) { _origin = origin; _readOnly = readOnly; _parentRule = parentRule; parseString(css); }
/// <summary> /// Constructor for CssRuleList /// </summary> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="cssText">The CSS text containing the rules that will be in this list</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> public CssRuleList(ref string cssText, object parent, string[] replacedStrings, bool readOnly, CssStyleSheetType origin) { Origin = origin; ReadOnly = readOnly; if(parent is CssRule || parent is CssStyleSheet) { Parent = parent; } else { throw new Exception("The CssRuleList constructor can only take a CssRule or CssStyleSheet as it's first argument " + parent.GetType()); } Parse(ref cssText, parent, readOnly, replacedStrings, origin); //AppendRules(cssText, replacedStrings); }
internal static CssRule Parse(ref string css, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin) { Match match = regex.Match(css); if(match.Success) { CssCharsetRule rule = new CssCharsetRule(match, parent, readOnly, replacedStrings, origin); css = css.Substring(match.Length); return rule; } else { // didn't match => do nothing return null; } }
/// <summary> /// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content /// </summary> internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) { Match match = regex.Match(css); if(match.Success) { CssFontFaceRule rule = new CssFontFaceRule(match, parent, readOnly, replacedStrings, origin); css = css.Substring(match.Length); rule.style = new CssStyleDeclaration(ref css, rule, true, origin); return rule; } else { // didn't match => do nothing return null; } }
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; }
/// <summary> /// The constructor for CssStyleRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssStyleRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { //SelectorText = DeReplaceStrings(match.Groups["selectors"].Value.Trim()); //_Style = new CssStyleDeclaration(match, this, readOnly, Origin); Group selectorMatches = match.Groups["selector"]; int len = selectorMatches.Captures.Count; ArrayList sels = new ArrayList(); for(int i = 0; i<len; i++) { string str = DeReplaceStrings(selectorMatches.Captures[i].Value.Trim()); if(str.Length > 0) { sels.Add(new XPathSelector(str)); } } XPathSelectors = (XPathSelector[])sels.ToArray(typeof(XPathSelector)); }
/// <summary> /// Constructor for CssStyleSheet /// </summary> /// <param name="styleElement">The XML style element that references the stylesheet</param> /// <param name="origin">The type of stylesheet</param> internal CssStyleSheet(XmlElement styleElement, CssStyleSheetType origin) : base(styleElement) { Origin = origin; }
/// <summary> /// The constructor for CssCharSetRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssCharsetRule(Match match, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { _Encoding = DeReplaceStrings(match.Groups["charsetencoding"].Value); }
internal CssStyleBlock(CssStyleBlock style, int specificity, CssStyleSheetType origin) : this(style.Name, style.Value, style.Priority, origin) { Specificity = specificity; }
/// <summary> /// The constructor for CssMediaRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssMediaRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : this(match.Groups["medianames"].Value, parent, readOnly, replacedStrings, origin) { }
public CssMediaRule(string cssText, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { media = new MediaList(cssText); }
internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) { Match match = regex.Match(css); if(match.Success) { CssMediaRule rule = new CssMediaRule(match, parent, readOnly, replacedStrings, origin); css = css.Substring(match.Length); rule.cssRules = new CssRuleList(ref css, rule, replacedStrings, origin); return rule; } else { return null; } }
internal SharpCssStyle(SharpCssStyle style, int specificity, CssStyleSheetType origin) : this(style.Name, style.Value, style.Priority, origin) { Specificity = specificity; }
/// <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) { _origin = origin; _readOnly = readOnly; _parentRule = parentRule; css = parseString(css); }
/// <summary> /// The constructor used internally when collecting styles for a specified element /// </summary> internal CssStyleDeclaration() { _origin = CssStyleSheetType.Collector; _readOnly = true; _parentRule = null; }
/// <summary> /// The constructor for CssStyleRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssStyleRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { //SelectorText = DeReplaceStrings(match.Groups["selectors"].Value.Trim()); //_Style = new CssStyleDeclaration(match, this, readOnly, Origin); Group selectorMatches = match.Groups["selector"]; int len = selectorMatches.Captures.Count; ArrayList sels = new ArrayList(); for (int i = 0; i < len; i++) { string str = DeReplaceStrings(selectorMatches.Captures[i].Value.Trim()); if (str.Length > 0) { sels.Add(new XPathSelector(str)); } } XPathSelectors = (XPathSelector[])sels.ToArray(typeof(XPathSelector)); }
/// <summary> /// The constructor for CssUnknownRule /// </summary> internal CssUnknownRule(object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { }
/// <summary> /// Constructor for CssStyleSheet /// </summary> /// <param name="pi">The XML processing instruction that references the stylesheet</param> /// <param name="origin">The type of stylesheet</param> internal CssStyleSheet(XmlProcessingInstruction pi, CssStyleSheetType origin) : base(pi) { _origin = origin; }
/// <summary> /// Constructor for CssStyleSheet /// </summary> /// <param name="styleElement">The XML style element that references the stylesheet</param> /// <param name="origin">The type of stylesheet</param> internal CssStyleSheet(XmlElement styleElement, CssStyleSheetType origin) : base(styleElement) { _origin = origin; }
internal static CssRule Parse(ref string css, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin) { Match match = regex.Match(css); if(match.Success && match.Length > 0) { CssStyleRule rule = new CssStyleRule(match, parent, readOnly, replacedStrings, origin); css = css.Substring(match.Length); rule._Style = new CssStyleDeclaration(ref css, rule, readOnly, origin); return rule; } else { return null; } }
internal SharpCssStyle(string name, string val, string priority, int specificity, CssStyleSheetType origin) : this(name, val, priority, origin) { Specificity = specificity; }
/* can take two kind of structures: * rule{} * rule{} * or: * { * rule{} * rule{} * } * */ private void Parse(ref string css, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin) { bool withBrackets = false; css = css.Trim(); if(css.StartsWith("{")) { withBrackets = true; css = css.Substring(1); } while(true) { css = css.Trim(); if(css.Length == 0) { if(withBrackets) { throw new DomException(DomExceptionType.SyntaxErr, "Style block missing ending bracket"); } break; } else if(css.StartsWith("}")) { // end of block; css = css.Substring(1); break; } else if(css.StartsWith("@")) { #region Parse at-rules // @-rule CssRule rule; // creates and parses a CssMediaRule or return null rule = CssMediaRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule == null) { // create ImportRule rule = CssImportRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule == null) { // create CharSetRule rule = CssCharsetRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule == null) { rule = CssFontFaceRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule == null) { rule = CssPageRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule == null) { rule = CssUnknownRule.Parse(ref css, parent, readOnly, replacedStrings, origin); } } } } } InsertRule(rule); #endregion } else { // must be a selector or error CssRule rule = CssStyleRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if(rule != null) { InsertRule(rule); } else { // this is an unknown rule format, possibly a new kind of selector. Try to find the end of it to skip it int startBracket = css.IndexOf("{"); int endBracket = css.IndexOf("}"); int endSemiColon = css.IndexOf(";"); int endRule; if(endSemiColon > 0 && endSemiColon < startBracket) { endRule = endSemiColon; } else { endRule = endBracket; } if(endRule > -1) { css = css.Substring(endRule+1); } else { throw new DomException(DomExceptionType.SyntaxErr, "Can not parse the CSS file"); } } //} } } }
/// <summary> /// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content /// </summary> internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) { Match match = regex.Match(css); if (match.Success) { CssFontFaceRule rule = new CssFontFaceRule(match, parent, readOnly, replacedStrings, origin); css = css.Substring(match.Length); rule.style = new CssStyleDeclaration(ref css, rule, true, origin); return(rule); } else { // didn't match => do nothing return(null); } }
/// <summary> /// Constructor for CssStyleSheet /// </summary> /// <param name="pi">The XML processing instruction that references the stylesheet</param> /// <param name="origin">The type of stylesheet</param> internal CssStyleSheet(XmlProcessingInstruction pi, CssStyleSheetType origin) : base(pi) { Origin = origin; }
/// <summary> /// Constructor for CssRuleList /// </summary> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="cssText">The CSS text containing the rules that will be in this list</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssRuleList(ref string cssText, object parent, IList<string> replacedStrings, CssStyleSheetType origin) : this(ref cssText, parent, replacedStrings, false, origin) { }
/// <summary> /// The constructor for CssFontFaceRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssFontFaceRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, true, replacedStrings, origin) { // always read-only }
public void CollectProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority) { CssCollectedProperty newProp = new CssCollectedProperty(name, specificity, cssValue, origin, priority); if (!collectedStyles.ContainsKey(name)) { collectedStyles[name] = newProp; } else { CssCollectedProperty existingProp = collectedStyles[name]; if (newProp.IsBetterThen(existingProp)) { collectedStyles[name] = newProp; } } }
/// <summary> /// The constructor for CssPageRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssPageRule(Match match, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { // TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim()); }
/// <summary> /// The constructor for CssPageRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssPageRule(Match match, object parent, bool readOnly, IList <string> replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { // TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim()); }