/// <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; }
internal ulong InsertRule(CssRule rule, ulong index) { /* TODO: * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified index e.g. if an @import rule is inserted after a standard rule set or other at-rule. * SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable */ if (ReadOnly) { throw new DomException(DomExceptionType.NoModificationAllowedErr); } if (index > Length || index < 0) { throw new DomException(DomExceptionType.IndexSizeErr); } if (index == Length) { cssRules.Add(rule); } else { cssRules.Insert((int)index, rule); } return(index); }
public CssStyleDeclaration(string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin) { _origin = origin; _readOnly = readOnly; _parentRule = parentRule; parseString(css); }
/// <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> internal void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { ulong len = Length; for (ulong i = 0; i < len; i++) { CssRule csr = (CssRule)this[i]; csr.GetStylesForElement(elt, pseudoElt, ml, csd); } }
protected CssRule(object parent, bool readOnly, IList <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; _isReadOnly = readOnly; }
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; }
/* 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("{", StringComparison.OrdinalIgnoreCase)) { 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("}", StringComparison.OrdinalIgnoreCase)) { // end of block; css = css.Substring(1); break; } else if (css.StartsWith("@", StringComparison.OrdinalIgnoreCase)) { // 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); } 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("{", StringComparison.OrdinalIgnoreCase); int endBracket = css.IndexOf("}", StringComparison.OrdinalIgnoreCase); int endSemiColon = css.IndexOf(";", StringComparison.OrdinalIgnoreCase); 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"); } } } } }
internal ulong InsertRule(CssRule rule) { return(InsertRule(rule, Length)); }
internal ulong InsertRule(CssRule rule) { return InsertRule(rule, Length); }
internal ulong InsertRule(CssRule rule, ulong index) { /* TODO: * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified index e.g. if an @import rule is inserted after a standard rule set or other at-rule. * SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable */ if(ReadOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr); if(index > Length || index<0) throw new DomException(DomExceptionType.IndexSizeErr); if(index == Length) { cssRules.Add(rule); } else { cssRules.Insert((int) index, rule); } return index; }