public override SelectorMatcher GetCombinator(SelectorMatcher left) { // 14.2. Child combinator (>) // https://www.w3.org/TR/selectors-4/#child-combinators return((in SelectorMatcherContext ctx) => { return ctx.Node.Parent != null && left(ctx.WithSyntaxNode(ctx.Node.Parent)); });
public override SelectorMatcher GetMatcher() { SelectorMatcher matcher = (in SelectorMatcherContext ctx) => false; foreach (var selector in Children) { matcher = SelectorCompilerHelper.ComposeOr(SelectorCompiler.Compile(selector), matcher); } return(matcher); }
public override SelectorMatcher GetMatcher() { SelectorMatcher composedMatcher = (in SelectorMatcherContext _) => true; for (var i = Children.Count - 1; i >= 0; i--) { var child = Children[i]; var matcher = child.GetMatcher(); composedMatcher = SelectorCompilerHelper.ComposeAnd(composedMatcher, matcher); } return(composedMatcher); }
public override SelectorMatcher GetMatcher() { SelectorMatcher matcher = (in SelectorMatcherContext _) => false; foreach (var selector in _relativeSelectors) { matcher = SelectorCompilerHelper.ComposeOr(matcher, selector.GetMatcher()); } var query = new QulalySelector(matcher, this); return((in SelectorMatcherContext ctx) => { return ctx.Node.QuerySelector(query) != null; });
public override SelectorMatcher GetCombinator(SelectorMatcher left) { // 14.1. Descendant combinator ( ) // https://www.w3.org/TR/selectors-4/#descendant-combinators return((in SelectorMatcherContext ctx) => { var parent = ctx.Node.Parent; while (parent != null) { if (left(ctx.WithSyntaxNode(parent))) { return true; } parent = parent.Parent; } return false; });
public override SelectorMatcher GetCombinator(SelectorMatcher left) { // 14.3. Next-sibling combinator (+) // The elements represented by the two compound selectors share the same parent // in the document tree and the element represented by the first compound selector // immediately precedes the element represented by the second one. // https://www.w3.org/TR/selectors-4/#adjacent-sibling-combinators return((in SelectorMatcherContext ctx) => { var node = ctx.Node; if (ctx.Node.Parent == null) { return false; } var beforeNode = ctx.Node.Parent.ChildNodes().TakeWhile(x => x != node).LastOrDefault(); return beforeNode != null && left(ctx.WithSyntaxNode(beforeNode)); });
public override SelectorMatcher GetCombinator(SelectorMatcher left) { // Subsequent-sibling combinator (~) // The elements represented by the two compound selectors share the same parent // in the document tree and the element represented by the first compound selector // precedes (not necessarily immediately) the element represented by the second one. // https://www.w3.org/TR/selectors-4/#general-sibling-combinators return((in SelectorMatcherContext ctx) => { var node = ctx.Node; if (ctx.Node.Parent == null) { return false; } var beforeNodes = ctx.Node.Parent.ChildNodes().TakeWhile(x => x != node).ToList(); // before self. var ctx_ = ctx; return beforeNodes.Any(x => left(ctx_.WithSyntaxNode(x))); });
public override void OnValueReady(CssLexer lexer) { // Create the set: List <SelectorMatcher> multi = new List <SelectorMatcher>(); for (int i = 0; i < Count; i++) { // Read and add: SelectorMatcher sm = Css.CssLexer.ReadSelectorMatcher(this[i]); if (sm == null) { // Entire any should be ignored. return; } multi.Add(sm); } Matchers = multi.ToArray(); }
public static SelectorMatcher Compile(SelectorElement selector) { SelectorMatcher composedMatcher = (in SelectorMatcherContext _) => true; if (selector is SelectorList <SelectorElement> selectorList) { for (var i = 0; i < selectorList.Children.Count; i++) { var child = selectorList.Children[i]; if (child is Combinator combinator) { var matcher = combinator.GetCombinator(composedMatcher); composedMatcher = SelectorCompilerHelper.ComposeAnd(matcher, Compile(selectorList.Children[i + 1])); } else if (child is Selector childSelector) { var matcher = childSelector.GetMatcher(); composedMatcher = SelectorCompilerHelper.ComposeAnd(composedMatcher, matcher); } } } return(composedMatcher); }
public static SelectorMatcher ComposeOr(SelectorMatcher left, SelectorMatcher right) { return((in SelectorMatcherContext ctx) => right(ctx) || left(ctx)); }
public QulalySelector(SelectorMatcher matcher, Selector selector) { Matcher = matcher; Selector = selector; }
private static bool MatchesOnVisualTree(SelectorMatcher lastFragment) { return(lastFragment.Type == CssParsing.CssNodeType.PseudoSelector && lastFragment.Text == ":visualtree"); }
public abstract SelectorMatcher GetCombinator(SelectorMatcher left);