Exemplo n.º 1
0
        public static bool CreateRule(CssStyleSheet styleSheet, IEnumerator <CssChunk> enumerator, out CssRule rule)
        {
            if (enumerator.Current.Type == CssChunkTypes.Directive)
            {
                if (enumerator.Current.Data.StartsWith("media "))
                {
                    var mediaRule = new CssMediaRule(enumerator.Current.Data, styleSheet);
                    rule = mediaRule;

                    CssRule childRule;
                    bool    cont = true;
                    enumerator.MoveNext();
                    while (enumerator.Current.Type != CssChunkTypes.End &&
                           (cont = CreateRule(styleSheet, enumerator, out childRule)))
                    {
                        mediaRule.CssRules.Add(childRule);
                    }

                    return(enumerator.Current.Type == CssChunkTypes.End ? enumerator.MoveNext() : cont);
                }
                else if (enumerator.Current.Data.StartsWith("namespace "))
                {
                    rule = null;
                    return(enumerator.MoveNext());
                }
                else                 //skip other directives
                {
                    rule = null;
                    while (enumerator.Current.Type != CssChunkTypes.End)
                    {
                        if (!enumerator.MoveNext())
                        {
                            return(false);
                        }
                    }
                    return(enumerator.MoveNext());
                }
            }

            if (enumerator.Current.Type != CssChunkTypes.Selector)
            {
                throw new Exception("Unable to parse rule");
            }

            var styleRule = new CssStyleRule(styleSheet)
            {
                SelectorText = enumerator.Current.Data
            };

            rule = styleRule;
            if (!enumerator.MoveNext())
            {
                return(false);
            }
            return(FillStyle(styleRule.Style, enumerator));
        }
Exemplo n.º 2
0
 internal CssStyleDeclaration(CssStyleRule parentRule = null)
 {
     _properties = new NameValueCollection();
     ParentRule  = parentRule;
 }