Exemple #1
0
        /// <summary>Gets a style definition by css selector from the StyleSheet.
        /// If it's not found in the style sheet, the default stylesheet is checked.</summary>
        /// <param name="selector">The css selector to search for.</param>
        /// <returns>If found, a selector style definition; null otherwise.</returns>
        public List <Css.Style> getStylesBySelector(string selectorText)
        {
            // Create the lexer:
            Css.CssLexer lexer = new Css.CssLexer(selectorText, documentElement);

            // Read a selector:
            Css.Selector selector = lexer.ReadSelector();

            return(getStylesBySelector(selector));
        }
Exemple #2
0
        /// <summary>Attempts to get one or more styles from this sheet by selector.</summary>
        /// <param name="selector">The selector to lookup.</param>
        /// <returns>A style for the selector if its found; null otherwise.</returns>
        public List <Css.Style> getStylesBySelector(Css.Selector selector)
        {
            // NOTE: The given selector is *not* an object we can match by reference (via ==).
            // We must compare it for it's actual components.

            string styleText = selector.LastRoot.StyleText;

            List <Css.StyleRule> selectors;

            if (styleText == "*")
            {
                selectors = AnySelectors;
            }
            else
            {
                // Stubs provide our first (and often sizeable) filtering.
                if (!SelectorStubs.TryGetValue(styleText, out selectors))
                {
                    return(null);
                }
            }

            if (selectors.Count == 0)
            {
                return(null);
            }

            List <Css.Style> res = new List <Css.Style>();

            // For each potential matcher..
            foreach (Css.StyleRule compare in selectors)
            {
                if (compare.Selector.Equals(selector))
                {
                    res.Add(compare.Style);
                }
            }

            if (res.Count == 0)
            {
                return(null);
            }

            return(res);
        }