use of org.w3c.css.sac.SimpleSelector in project org.eclipse.rap by eclipse-rap.
the class Parser method parseSelector.
/**
* Parses a selector.
*/
protected Selector parseSelector() {
SimpleSelector ss = parseSimpleSelector();
Selector result = ss;
pseudoElement = null;
loop: for (; ; ) {
switch(current) {
default:
break loop;
case LexicalUnits.IDENTIFIER:
case LexicalUnits.ANY:
case LexicalUnits.HASH:
case LexicalUnits.DOT:
case LexicalUnits.LEFT_BRACKET:
case LexicalUnits.COLON:
result = selectorFactory.createDescendantSelector(result, parseSimpleSelector());
break;
case LexicalUnits.PLUS:
nextIgnoreSpaces();
result = selectorFactory.createDirectAdjacentSelector((short) 1, result, parseSimpleSelector());
break;
case LexicalUnits.PRECEDE:
nextIgnoreSpaces();
result = selectorFactory.createChildSelector(result, parseSimpleSelector());
}
}
if (pseudoElement != null) {
result = selectorFactory.createChildSelector(result, selectorFactory.createPseudoElementSelector(null, pseudoElement));
}
return result;
}
use of org.w3c.css.sac.SimpleSelector in project CodenameOne by codenameone.
the class CSSTheme method getElementForSelector.
Element getElementForSelector(String media, Selector sel) {
switch(sel.getSelectorType()) {
case Selector.SAC_ANY_NODE_SELECTOR:
return anyNodeStyle;
case Selector.SAC_ELEMENT_NODE_SELECTOR:
{
ElementSelector esel = (ElementSelector) sel;
if (media != null && !media.isEmpty()) {
return getElementByName(media + "-" + esel.getLocalName());
} else {
return getElementByName(esel.getLocalName());
}
}
case Selector.SAC_CONDITIONAL_SELECTOR:
{
ConditionalSelector csel = (ConditionalSelector) sel;
SimpleSelector simple = csel.getSimpleSelector();
switch(simple.getSelectorType()) {
case Selector.SAC_ANY_NODE_SELECTOR:
{
Element parent = anyNodeStyle;
switch(csel.getCondition().getConditionType()) {
case Condition.SAC_CLASS_CONDITION:
AttributeCondition clsCond = (AttributeCondition) csel.getCondition();
switch(clsCond.getLocalName()) {
case "selected":
return parent.getSelected();
case "unselected":
return parent.getUnselected();
case "pressed":
return parent.getPressed();
case "disabled":
return parent.getDisabled();
default:
throw new RuntimeException("Unsupported style class " + clsCond.getLocalName());
}
default:
throw new RuntimeException("Unsupported CSS condition type " + csel.getCondition().getConditionType());
}
}
case Selector.SAC_ELEMENT_NODE_SELECTOR:
{
ElementSelector esel = (ElementSelector) simple;
Element parent = getElementForSelector(media, esel);
switch(csel.getCondition().getConditionType()) {
case Condition.SAC_CLASS_CONDITION:
AttributeCondition clsCond = (AttributeCondition) csel.getCondition();
switch(clsCond.getValue()) {
case "selected":
return parent.getSelected();
case "unselected":
return parent.getUnselected();
case "pressed":
return parent.getPressed();
case "disabled":
return parent.getDisabled();
default:
throw new RuntimeException("Unsupported style class " + clsCond.getValue());
}
default:
throw new CSSException("Unsupported CSS condition type " + csel.getCondition().getConditionType() + " for " + csel.getSimpleSelector());
}
}
default:
throw new RuntimeException("Unsupported selector type " + simple.getSelectorType());
}
}
default:
throw new RuntimeException("Unsupported selector type " + sel.getSelectorType());
}
}
use of org.w3c.css.sac.SimpleSelector in project gwtproject by treblereel.
the class Parser method simple_selector.
/**
* @exception ParseException exception during the parse
*/
public final Selector simple_selector(Selector selector, char comb) throws ParseException {
SimpleSelector simple_current = null;
Condition cond = null;
pseudoElt = null;
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case ANY:
case IDENT:
simple_current = element_name();
label_44: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LBRACKET:
case DOT:
case COLON:
case HASH:
break;
default:
jj_la1[60] = jj_gen;
break label_44;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case HASH:
cond = hash(cond);
break;
case DOT:
cond = _class(cond);
break;
case LBRACKET:
cond = attrib(cond);
break;
case COLON:
cond = pseudo(cond);
break;
default:
jj_la1[61] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
break;
case HASH:
cond = hash(cond);
label_45: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LBRACKET:
case DOT:
case COLON:
break;
default:
jj_la1[62] = jj_gen;
break label_45;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case DOT:
cond = _class(cond);
break;
case LBRACKET:
cond = attrib(cond);
break;
case COLON:
cond = pseudo(cond);
break;
default:
jj_la1[63] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
break;
case DOT:
cond = _class(cond);
label_46: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LBRACKET:
case DOT:
case COLON:
case HASH:
break;
default:
jj_la1[64] = jj_gen;
break label_46;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case HASH:
cond = hash(cond);
break;
case DOT:
cond = _class(cond);
break;
case LBRACKET:
cond = attrib(cond);
break;
case COLON:
cond = pseudo(cond);
break;
default:
jj_la1[65] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
break;
case COLON:
cond = pseudo(cond);
label_47: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LBRACKET:
case DOT:
case COLON:
case HASH:
break;
default:
jj_la1[66] = jj_gen;
break label_47;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case HASH:
cond = hash(cond);
break;
case DOT:
cond = _class(cond);
break;
case LBRACKET:
cond = attrib(cond);
break;
case COLON:
cond = pseudo(cond);
break;
default:
jj_la1[67] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
break;
case LBRACKET:
cond = attrib(cond);
label_48: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LBRACKET:
case DOT:
case COLON:
case HASH:
break;
default:
jj_la1[68] = jj_gen;
break label_48;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case HASH:
cond = hash(cond);
break;
case DOT:
cond = _class(cond);
break;
case LBRACKET:
cond = attrib(cond);
break;
case COLON:
cond = pseudo(cond);
break;
default:
jj_la1[69] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
break;
default:
jj_la1[70] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
if (simple_current == null) {
simple_current = selectorFactory.createElementSelector(null, null);
}
if (cond != null) {
simple_current = selectorFactory.createConditionalSelector(simple_current, cond);
}
if (selector != null) {
switch(comb) {
case ' ':
selector = selectorFactory.createDescendantSelector(selector, simple_current);
break;
case '+':
selector = selectorFactory.createDirectAdjacentSelector((short) 1, selector, simple_current);
break;
case '>':
selector = selectorFactory.createChildSelector(selector, simple_current);
break;
default:
{
if (true)
throw new ParseException("invalid state. send a bug report");
}
}
} else {
selector = simple_current;
}
if (pseudoElt != null) {
selector = selectorFactory.createChildSelector(selector, selectorFactory.createPseudoElementSelector(null, pseudoElt));
}
{
if (true)
return selector;
}
throw new Error("Missing return statement in function");
}
use of org.w3c.css.sac.SimpleSelector in project org.eclipse.rap by eclipse-rap.
the class Parser method parseSimpleSelector.
/**
* Parses a simple selector.
*/
protected SimpleSelector parseSimpleSelector() {
SimpleSelector result;
switch(current) {
case LexicalUnits.IDENTIFIER:
result = selectorFactory.createElementSelector(null, scanner.getStringValue());
next();
break;
case LexicalUnits.ANY:
next();
default:
result = selectorFactory.createElementSelector(null, null);
}
Condition cond = null;
loop: for (; ; ) {
Condition c = null;
switch(current) {
case LexicalUnits.HASH:
c = conditionFactory.createIdCondition(scanner.getStringValue());
next();
break;
case LexicalUnits.DOT:
if (next() != LexicalUnits.IDENTIFIER) {
throw createCSSParseException("identifier");
}
c = conditionFactory.createClassCondition(null, scanner.getStringValue());
next();
break;
case LexicalUnits.LEFT_BRACKET:
if (nextIgnoreSpaces() != LexicalUnits.IDENTIFIER) {
throw createCSSParseException("identifier");
}
String name = scanner.getStringValue();
int op = nextIgnoreSpaces();
switch(op) {
default:
throw createCSSParseException("right.bracket");
case LexicalUnits.RIGHT_BRACKET:
nextIgnoreSpaces();
c = conditionFactory.createAttributeCondition(name, null, false, null);
break;
case LexicalUnits.EQUAL:
case LexicalUnits.INCLUDES:
case LexicalUnits.DASHMATCH:
String val = null;
switch(nextIgnoreSpaces()) {
default:
throw createCSSParseException("identifier.or.string");
case LexicalUnits.STRING:
case LexicalUnits.IDENTIFIER:
val = scanner.getStringValue();
nextIgnoreSpaces();
}
if (current != LexicalUnits.RIGHT_BRACKET) {
throw createCSSParseException("right.bracket");
}
next();
switch(op) {
case LexicalUnits.EQUAL:
c = conditionFactory.createAttributeCondition(name, null, false, val);
break;
case LexicalUnits.INCLUDES:
c = conditionFactory.createOneOfAttributeCondition(name, null, false, val);
break;
default:
c = conditionFactory.createBeginHyphenAttributeCondition(name, null, false, val);
}
}
break;
case LexicalUnits.COLON:
switch(nextIgnoreSpaces()) {
case LexicalUnits.IDENTIFIER:
String val = scanner.getStringValue();
if (isPseudoElement(val)) {
if (pseudoElement != null) {
throw createCSSParseException("duplicate.pseudo.element");
}
pseudoElement = val;
} else {
c = conditionFactory.createPseudoClassCondition(null, val);
}
next();
break;
case LexicalUnits.FUNCTION:
String func = scanner.getStringValue();
if (nextIgnoreSpaces() != LexicalUnits.IDENTIFIER) {
throw createCSSParseException("identifier");
}
String lang = scanner.getStringValue();
if (nextIgnoreSpaces() != LexicalUnits.RIGHT_BRACE) {
throw createCSSParseException("right.brace");
}
if (!func.equalsIgnoreCase("lang")) {
throw createCSSParseException("pseudo.function");
}
c = conditionFactory.createLangCondition(lang);
next();
break;
default:
throw createCSSParseException("identifier");
}
break;
default:
break loop;
}
if (c != null) {
if (cond == null) {
cond = c;
} else {
cond = conditionFactory.createAndCondition(cond, c);
}
}
}
skipSpaces();
if (cond != null) {
result = selectorFactory.createConditionalSelector(result, cond);
}
return result;
}
Aggregations