use of com.gargoylesoftware.css.parser.condition.Condition in project LoboEvolution by LoboEvolution.
the class CSS3Parser method negation_arg.
//
// negation_arg
// : type_selector | universal | HASH | class | attrib | pseudo
// ;
//
public final String negation_arg() throws ParseException {
Condition c = null;
SimpleSelector simpleSel = null;
Object o;
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case IDENT:
case ASTERISK:
{
simpleSel = elementName();
return simpleSel.toString();
}
case HASH:
{
c = hash(false);
return c.toString();
}
case DOT:
{
c = _class(false);
return c.toString();
}
case LSQUARE:
{
c = attrib(false);
return c.toString();
}
case COLON:
{
o = pseudo(false);
if (o instanceof Condition) {
return o.toString();
}
return new DescendantSelector(null, (SimpleSelector) o).toString();
}
default:
jj_la1[182] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
use of com.gargoylesoftware.css.parser.condition.Condition in project LoboEvolution by LoboEvolution.
the class StyleSheetAggregator method selects.
private boolean selects(final Selector selector, final HTMLElement element, final String pseudoElement, final boolean mouseOver) {
switch(selector.getSelectorType()) {
case ELEMENT_NODE_SELECTOR:
final ElementSelector es = (ElementSelector) selector;
final String name = es.getLocalNameLowerCase();
if (name == null || name.equals(element.getNodeName().toLowerCase())) {
final List<Condition> conditions = es.getConditions();
if (conditions != null) {
for (Condition condition : conditions) {
if (!selects(condition, element, mouseOver)) {
return false;
}
}
}
return true;
}
return false;
case CHILD_SELECTOR:
final Node parentNode = element.getParentNode();
if (!(parentNode instanceof HTMLElement)) {
// for instance parent is a DocumentFragment
return false;
}
final ChildSelector cs = (ChildSelector) selector;
return selects(cs.getSimpleSelector(), element, pseudoElement, mouseOver) && selects(cs.getAncestorSelector(), (HTMLElement) parentNode, pseudoElement, mouseOver);
case DESCENDANT_SELECTOR:
final DescendantSelector ds = (DescendantSelector) selector;
final SimpleSelector simpleSelector = ds.getSimpleSelector();
if (selects(simpleSelector, element, pseudoElement, mouseOver)) {
Node ancestor = element;
if (simpleSelector.getSelectorType() != SelectorType.PSEUDO_ELEMENT_SELECTOR) {
ancestor = ancestor.getParentNode();
}
final Selector dsAncestorSelector = ds.getAncestorSelector();
while (ancestor instanceof HTMLElement) {
if (selects(dsAncestorSelector, (HTMLElement) ancestor, pseudoElement, mouseOver)) {
return true;
}
ancestor = ancestor.getParentNode();
}
}
return false;
case DIRECT_ADJACENT_SELECTOR:
final DirectAdjacentSelector das = (DirectAdjacentSelector) selector;
if (selects(das.getSimpleSelector(), element, pseudoElement, mouseOver)) {
Node prev = element.getPreviousSibling();
while (prev != null && !(prev instanceof HTMLElement)) {
prev = prev.getPreviousSibling();
}
return prev != null && selects(das.getSelector(), (HTMLElement) prev, pseudoElement, mouseOver);
}
return false;
case GENERAL_ADJACENT_SELECTOR:
final GeneralAdjacentSelector gas = (GeneralAdjacentSelector) selector;
if (selects(gas.getSimpleSelector(), element, pseudoElement, mouseOver)) {
for (Node prev1 = element.getPreviousSibling(); prev1 != null; prev1 = prev1.getPreviousSibling()) {
if (prev1 instanceof HTMLElement && selects(gas.getSelector(), (HTMLElement) prev1, pseudoElement, mouseOver)) {
return true;
}
}
}
return false;
case PSEUDO_ELEMENT_SELECTOR:
if (pseudoElement != null && pseudoElement.length() != 0 && pseudoElement.charAt(0) == ':') {
final String pseudoName = ((PseudoElementSelector) selector).getLocalName();
return pseudoName.equals(pseudoElement.substring(1));
}
return false;
default:
return false;
}
}
use of com.gargoylesoftware.css.parser.condition.Condition in project LoboEvolution by LoboEvolution.
the class SelectorSpecificity method readSelectorSpecificity.
private void readSelectorSpecificity(final Selector selector) {
switch(selector.getSelectorType()) {
case DESCENDANT_SELECTOR:
final DescendantSelector ds = (DescendantSelector) selector;
readSelectorSpecificity(ds.getAncestorSelector());
readSelectorSpecificity(ds.getSimpleSelector());
return;
case CHILD_SELECTOR:
final ChildSelector cs = (ChildSelector) selector;
readSelectorSpecificity(cs.getAncestorSelector());
readSelectorSpecificity(cs.getSimpleSelector());
return;
case ELEMENT_NODE_SELECTOR:
final ElementSelector es = (ElementSelector) selector;
if (es.getLocalName() != null) {
fieldD_++;
}
if (es.getConditions() != null) {
for (final Condition condition : es.getConditions()) {
readSelectorSpecificity(condition);
}
}
return;
case PSEUDO_ELEMENT_SELECTOR:
final PseudoElementSelector pes = (PseudoElementSelector) selector;
final String pesName = pes.getLocalName();
if (pesName != null) {
fieldD_++;
}
return;
case DIRECT_ADJACENT_SELECTOR:
final DirectAdjacentSelector das = (DirectAdjacentSelector) selector;
readSelectorSpecificity(das.getSelector());
readSelectorSpecificity(das.getSimpleSelector());
return;
case GENERAL_ADJACENT_SELECTOR:
final GeneralAdjacentSelector gas = (GeneralAdjacentSelector) selector;
readSelectorSpecificity(gas.getSelector());
readSelectorSpecificity(gas.getSimpleSelector());
return;
default:
throw new RuntimeException("Unhandled CSS selector type for specificity computation: '" + selector.getSelectorType() + "'.");
}
}
use of com.gargoylesoftware.css.parser.condition.Condition in project LoboEvolution by LoboEvolution.
the class ElementSelector method toString.
/**
* {@inheritDoc}
*/
@Override
public String toString() {
final StringBuilder result = new StringBuilder();
result.append(getElementName());
if (conditions_ != null) {
for (final Condition condition : conditions_) {
result.append(condition);
}
}
return result.toString();
}
Aggregations