private static void flattenSelector(List<SelectorPart> collect, Selector selector) { Selector.Combinator combinator = selector.getCombinator(); for (Selector.SelectorPart part : selector) { flattenSelector(collect, combinator, part); combinator = null; } }
/** * Computes specificity of selector */ public Specificity computeSpecificity() { Specificity spec = new SpecificityImpl(); for(Selector s: list) s.computeSpecificity(spec); return spec; }
public PseudoDeclaration getPseudoElement() { return getLastSelector().getPseudoElement(); //pseudo-elements may only be appended after the last simple selector of the selector }
retval = s.matches(e); } else if (combinator == Selector.Combinator.ADJACENT) { Node adjacent = e.getPreviousSibling(); retval = false; if (adjacent != null && adjacent.getNodeType() == Node.ELEMENT_NODE) retval = s.matches((Element) adjacent); } else if (combinator == Selector.Combinator.DESCENDANT) { Node ancestor = e.getParentNode(); if (ancestor.getNodeType() == Node.ELEMENT_NODE && s.matches((Element) ancestor)) retval = true; else retval = false; if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) retval = s.matches((Element) parent); combinator = s.getCombinator();
public RuleBlock<?> prepareInlineRuleSet(List<Declaration> dlist, List<PseudoPage> pseudos) { if(dlist==null || dlist.isEmpty()) { log.debug("Empty RuleSet (inline) was ommited"); return null; } // create selector with element CombinedSelector cs = (CombinedSelector) rf.createCombinedSelector() .unlock(); Selector sel = (Selector) rf.createSelector().unlock(); sel.add(rf.createElementDOM(elem, inlinePriority)); if(pseudos!=null) sel.addAll(pseudos); cs.add(sel); Priority prio = ps.getAndIncrement(); RuleSet rs = rf.createSet(prio); rs.replaceAll(dlist); rs.setSelectors(Arrays.asList(cs)); log.info("Create @media as {}th with:\n{}", prio, rs); return (RuleBlock<?>) rs; }
final String element = last.getElementName(); if (element != null) { final String className = last.getClassName(); if (className != null) hs.add(new HolderSelector(HolderItem.CLASS, className final String id = last.getIDName(); if (id != null) hs.add(new HolderSelector(HolderItem.ID, id.toLowerCase()));
private PseudoClassImpl(String name, String functionValue, Selector nestedSelector) { this.name = name; type = PseudoClassType.forName(name); this.functionValue = functionValue; this.nestedSelector = nestedSelector; // Type-specific initialization if (type != null) { switch (type) { case NOT: if (nestedSelector == null && functionValue != null) { nestedSelector = new SelectorImpl(); nestedSelector.unlock(); nestedSelector.add(new ElementNameImpl(functionValue)); } break; case NTH_CHILD: case NTH_LAST_CHILD: case NTH_OF_TYPE: case NTH_LAST_OF_TYPE: elementIndex = decodeIndex(functionValue); break; } } }
protected boolean elementSelectorMatches(final Selector s, final Element e) { return s.matches(e, matcher, matchCond); }
ident = extractIdUnescaped(ctx.HASH().getText()); if (ident != null) { selector_stack.peek().s.add(rf.createID(ident)); } else { combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(rf.createClass(extractTextUnescaped(ctx.CLASSKEYWORD().getText()))); } else if (ctx.attribute() != null) { Selector.ElementAttribute ea = visitAttribute(ctx.attribute()); selector_stack.peek().s.add(ea); if (p.getDeclaration() != null && p.getDeclaration().isPseudoElement() && selector_stack.peek().s.getPseudoElement() != null) { log.warn("Invalid selector with multiple pseudo-elements"); combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(p); } else { combined_selector_stack.peek().invalid = true;
combinator = s.getCombinator(); break; } else if (current == targetAncestor) { return s.hasPseudoClass(pd);
combinator = s.getCombinator(); break; } else if (current == targetAncestor) { return s.hasPseudoDeclaration(pd);
c = visitCombinator(ctx.combinator(i - 1)); s = visitSelector(ctx.selector(i)); s.setCombinator(c); combinedSelector.add(s);
ident = extractIdUnescaped(ctx.HASH().getText()); if (ident != null) { selector_stack.peek().s.add(rf.createID(ident)); } else { combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(rf.createClass(extractTextUnescaped(ctx.CLASSKEYWORD().getText()))); } else if (ctx.attribute() != null) { Selector.ElementAttribute ea = visitAttribute(ctx.attribute()); selector_stack.peek().s.add(ea); if (p instanceof PseudoElement && selector_stack.peek().s.getPseudoElementType() != null) { log.warn("Invalid selector with multiple pseudo-elements"); combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(p); } else { combined_selector_stack.peek().invalid = true;
private PseudoElementImpl(String name, String functionValue, Selector nestedSelector) { this.name = name; type = PseudoElementType.forName(name); this.functionValue = functionValue; this.nestedSelector = nestedSelector; // Type-specific initialization if (type != null) { switch (type) { case CUE: if (nestedSelector == null && functionValue != null) { nestedSelector = new SelectorImpl(); nestedSelector.add(new ElementNameImpl(functionValue)); } break; } } }
public RuleBlock<?> prepareInlineRuleSet(List<Declaration> dlist, List<PseudoPage> pseudos) { if(dlist==null || dlist.isEmpty()) { log.debug("Empty RuleSet (inline) was ommited"); return null; } // create selector with element CombinedSelector cs = (CombinedSelector) rf.createCombinedSelector() .unlock(); Selector sel = (Selector) rf.createSelector().unlock(); sel.add(rf.createElementDOM(elem, inlinePriority)); if(pseudos!=null) sel.addAll(pseudos); cs.add(sel); RuleSet rs = rf.createSet(); rs.replaceAll(dlist); rs.setSelectors(Arrays.asList(cs)); log.info("Create @media as with:\n{}", rs); return (RuleBlock<?>) rs; }
final String element = last.getElementName(); if (element != null) { final String className = last.getClassName(); if (className != null) hs.add(new HolderSelector(HolderItem.CLASS, className final String id = last.getIDName(); if (id != null) hs.add(new HolderSelector(HolderItem.ID, id.toLowerCase()));
/** * selector * : (IDENT | ASTERISK) selpart* S* * | selpart+ S* * ; */ public Selector visitSelector(CSSParser.SelectorContext ctx) { if (ctxHasErrorNode(ctx)) { statement_stack.peek().invalid = true; return null; } selector_stack.push(new selector_scope()); cz.vutbr.web.css.Selector sel; logEnter("selector"); selector_stack.peek().s = sel = (cz.vutbr.web.css.Selector) rf.createSelector().unlock(); if (ctx.IDENT() != null || ctx.ASTERISK() != null) { cz.vutbr.web.css.Selector.ElementName en = rf.createElement(cz.vutbr.web.css.Selector.ElementName.WILDCARD); if (ctx.IDENT() != null) { en.setName(extractTextUnescaped(ctx.IDENT().getText())); } //log.debug("Adding element name: {}.", en.getName()); selector_stack.peek().s.add(en); } for (CSSParser.SelpartContext selpartctx : ctx.selpart()) { visitSelpart(selpartctx); } logLeave("selector"); selector_stack.pop(); return sel; }
retval = s.matches(e); } else if (combinator == Selector.Combinator.ADJACENT) { Element adjacent = (Element) w.previousSibling(); retval = false; if (adjacent != null) retval = s.matches(adjacent); } else if (combinator == Selector.Combinator.PRECEDING) { Element preceding; retval = false; while (!retval && (preceding = (Element) w.previousSibling()) != null) { retval = s.matches(preceding); retval = false; while (!retval && (ancestor = (Element) w.parentNode()) != null) { retval = s.matches(ancestor); retval = false; if (parent != null) retval = s.matches(parent); combinator = s.getCombinator();
static boolean elementSelectorMatches(final Selector s, final Element e, final ElementMatcher matcher, final MatchCondition matchCond) { return s.matches(e, matcher, matchCond); }
c = visitCombinator(ctx.combinator(i - 1)); s = visitSelector(ctx.selector(i)); s.setCombinator(c); combinedSelector.add(s);