protected <T extends CSSProperty> boolean genericOneIdentOrLength( Class<T> type, T lengthIdentification, ValueRange range, Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() != 1) return false; return genericTermIdent(type, d.get(0), ALLOW_INH, d.getProperty(), properties) || genericTermLength(d.get(0), d.getProperty(), lengthIdentification, range, properties, values); }
/** * Creates a single property declaration. * @param property Property name. * @param term Property value. * @return The resulting declaration. */ protected Declaration createDeclaration(String property, Term<?> term) { Declaration d = CSSFactory.getRuleFactory().createDeclaration(); d.unlock(); d.setProperty(property); d.add(term); return d; }
/** * Shallow copy constructor * @param clone Declaration to share term values with */ protected DeclarationImpl(Declaration clone) { this.property = clone.getProperty(); this.important = clone.isImportant(); this.source = new Source(clone.getSource()); this.replaceAll(clone.asList()); }
/** * Shallow copy constructor * @param clone Declaration to share term values with */ protected DeclarationImpl(Declaration clone) { this.property = clone.getProperty(); this.important = clone.isImportant(); this.replaceAll(clone.asList()); }
@SuppressWarnings("unused") private boolean processTransform(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { // just a simple value (e.g. "none") if (d.size() == 1 && genericOneIdent(Transform.class, d, properties)) { return true; } else { TermList list = tf.createList(); for (Term<?> t : d.asList()) { if (t instanceof TermFunction.TransformFunction) list.add(t); else return false; } // there is nothing in list after parsing if (list.isEmpty()) return false; properties.put("transform", Transform.list_values); values.put("transform", list); return true; } }
@SuppressWarnings("unused") private boolean processGrid(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.isEmpty()) { return false; templateDecl.setProperty("grid-template"); if (processGridTemplate(templateDecl, properties, values)) { return true; Declaration autoFlowDecl = (Declaration) rf.createDeclaration().unlock(); autoFlowDecl.setProperty("grid-auto-flow"); Declaration templateRowsDecl = (Declaration) rf.createDeclaration().unlock(); templateRowsDecl.setProperty("grid-template-rows"); Declaration autoRowsDecl = (Declaration) rf.createDeclaration().unlock(); autoRowsDecl.setProperty("grid-auto-rows"); Declaration templateColumnsDecl = (Declaration) rf.createDeclaration().unlock(); templateColumnsDecl.setProperty("grid-template-columns"); Declaration autoColumnsDecl = (Declaration) rf.createDeclaration().unlock(); autoColumnsDecl.setProperty("grid-auto-columns"); for (int i = 0; i < d.size(); i++) { Term t = d.get(i); if (t.getOperator() == Term.Operator.SLASH) { beforeSlash = false; if (Grid.AUTO_FLOW.equals(property)) { if (beforeSlash) { autoFlowDecl.add(tf.createIdent("row")); } else { autoFlowDecl.add(tf.createIdent("column"));
@SuppressWarnings("unused") private boolean processOverflow(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() == 1) { Term<?> term = d.get(0); if (term instanceof TermIdent) { return genericProperty(Overflow.class, (TermIdent) term, ALLOW_INH, properties, "overflow-x") && genericProperty(Overflow.class, (TermIdent) term, ALLOW_INH, properties, "overflow-y"); } else return false; } else return false; }
@SuppressWarnings("unused") private boolean processQuotes(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() == 1 && genericTermIdent(Quotes.class, d.get(0), ALLOW_INH, "quotes", properties)) { return true; } else { TermList list = tf.createList(); for (Term<?> term : d.asList()) { if (term instanceof TermString) list.add(term); else return false; } // there are pairs of quotes if (!list.isEmpty() && list.size() % 2 == 0) { properties.put("quotes", Quotes.list_values); values.put("quotes", list); return true; } return false; } }
decl.setProperty(property); Token token = ctx.IDENT().getSymbol(); decl.setSource(extractSource((CSSToken) token)); if (ctx.terms() != null) { List<Term<?>> t = visitTerms(ctx.terms()); decl.replaceAll(t); expr.setFeature(decl.getProperty()); expr.replaceAll(decl);
@Override /** * Setting property of declaration property : MINUS? IDENT S* returns null - processed via declaration_sctack */ public Object visitProperty(CSSParser.PropertyContext ctx) { logEnter("property"); String property = extractTextUnescaped(ctx.IDENT().getText()); if (ctx.MINUS() != null) { property = ctx.MINUS().getText() + property; } declaration_stack.peek().d.setProperty(property); Token token = ctx.IDENT().getSymbol(); declaration_stack.peek().d.setSource(extractSource((CSSToken) token)); log.debug("Setting property: {}", declaration_stack.peek().d.getProperty()); logLeave("property"); //returns null return null; }
private Declaration getDeclaration(String property) { for (Declaration decl : list) { if (property.equals(decl.getProperty())) { return decl; } } return null; } }
((declaration_scope)declaration_stack.peek()).d.setProperty(extractText(i)); ((declaration_scope)declaration_stack.peek()).d.setProperty("-" + extractText(i)); log.debug("Setting property: {}", ((declaration_scope)declaration_stack.peek()).d.getProperty()); logLeave("property");
@SuppressWarnings("unused") private boolean processFontFamily(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { final Variator font = new FontVariator(); return font.tryMultiTermVariant(FontVariator.FAMILY, properties, values, d.toArray(new Term<?>[0])); }
decl.setImportant(true); log.debug("IMPORTANT"); decl.replaceAll(t);
/** * This declaration type is not about to be compared * using precise conditions */ public int compareTo(Declaration o) { if(this.isImportant() && ! o.isImportant()) return 1; else if(o.isImportant() && ! this.isImportant()) return -1; return 0; }
/** * Assigns terms from declaration * * @param d * Declaration which contains terms */ public void assignTermsFromDeclaration(Declaration d) { this.terms = d.asList(); }
@Override public List<String> getUnicodeRanges() { Declaration decl = getDeclaration(PROPERTY_UNICODE_RANGE); if (decl != null) { List<String> ret = new ArrayList<>(decl.size()); for (Term<?> term : decl) { ret.add(term.getValue().toString()); } return ret; } else return null; }
private String getStringValue(String propertyName) { Declaration decl = getDeclaration(propertyName); if (decl == null) { return null; } Term<?> term= decl.get(0); if (term == null) { return null; } Object value = term.getValue(); if (!(value instanceof String)) { return null; } return (String)value; }
@Override /** * important : EXCLAMATION S* IMPORTANT S* */ public Object visitImportant(CSSParser.ImportantContext ctx) { if (ctxHasErrorNode(ctx)) { declaration_stack.peek().invalid = true; } else { declaration_stack.peek().d.setImportant(true); log.debug("IMPORTANT"); } //returns null return null; }