Example #1
0
        /// <summary>Selects elements from this document using the given CSS selector.
        /// Do note that this is not designed to be used in high-performance situations and
        /// you should cache the results as much as possible.</summary>
        public Dom.NodeList querySelectorAll(string selector, bool one)
        {
            // Create results set:
            Dom.NodeList results = new Dom.NodeList();

            if (string.IsNullOrEmpty(selector))
            {
                // Empty set:
                return(results);
            }

            Node root = documentElement;

            // Create the lexer:
            Css.CssLexer lexer = new Css.CssLexer(selector, root);

            List <Css.Selector> all = new List <Css.Selector>();

            // Read selectors:
            lexer.ReadSelectors(all);

            if (all.Count == 0)
            {
                // Invalid selector:
                return(results);
            }

            // Create a blank event to store the targets, if any:
            CssEvent e = new CssEvent();

            // Perform the selection process:
            (root as IRenderableNode).querySelectorAll(all.ToArray(), results, e, one);

            return(results);
        }
        /// <summary>True if this element matches the given selector.</summary>
        public bool matches(string selectorText)
        {
            // Create the lexer:
            Css.CssLexer lexer = new Css.CssLexer(selectorText, this);

            // Read a value:
            Css.Value value = lexer.ReadValue();

            // Read the selectors from the value:
            List <Css.Selector> selectors = new List <Css.Selector>();

            Css.CssLexer.ReadSelectors(null, value, selectors);

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

            // Get renderable node:
            Css.IRenderableNode irn = (this as Css.IRenderableNode);

            if (irn == null)
            {
                // Can't select this element.
                return(false);
            }

            // Get the computed style:
            Css.ComputedStyle cs = irn.ComputedStyle;

            // Try and match it!
            return(selectors[0].StructureMatch(cs, new Css.CssEvent()));
        }
Example #3
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));
        }