Search in sources :

Example 6 with Condition

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();
    }
}
Also used : SubstringAttributeCondition(com.gargoylesoftware.css.parser.condition.SubstringAttributeCondition) Condition(com.gargoylesoftware.css.parser.condition.Condition) IdCondition(com.gargoylesoftware.css.parser.condition.IdCondition) AttributeCondition(com.gargoylesoftware.css.parser.condition.AttributeCondition) PseudoClassCondition(com.gargoylesoftware.css.parser.condition.PseudoClassCondition) SuffixAttributeCondition(com.gargoylesoftware.css.parser.condition.SuffixAttributeCondition) BeginHyphenAttributeCondition(com.gargoylesoftware.css.parser.condition.BeginHyphenAttributeCondition) ClassCondition(com.gargoylesoftware.css.parser.condition.ClassCondition) LangCondition(com.gargoylesoftware.css.parser.condition.LangCondition) PrefixAttributeCondition(com.gargoylesoftware.css.parser.condition.PrefixAttributeCondition) OneOfAttributeCondition(com.gargoylesoftware.css.parser.condition.OneOfAttributeCondition) SimpleSelector(com.gargoylesoftware.css.parser.selector.SimpleSelector) CSSParseException(com.gargoylesoftware.css.parser.CSSParseException) DescendantSelector(com.gargoylesoftware.css.parser.selector.DescendantSelector)

Example 7 with Condition

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;
    }
}
Also used : Condition(com.gargoylesoftware.css.parser.condition.Condition) Node(org.loboevolution.html.node.Node)

Example 8 with Condition

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() + "'.");
    }
}
Also used : Condition(com.gargoylesoftware.css.parser.condition.Condition)

Example 9 with Condition

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();
}
Also used : Condition(com.gargoylesoftware.css.parser.condition.Condition)

Aggregations

Condition (com.gargoylesoftware.css.parser.condition.Condition)9 DescendantSelector (com.gargoylesoftware.css.parser.selector.DescendantSelector)4 SimpleSelector (com.gargoylesoftware.css.parser.selector.SimpleSelector)4 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)3 AttributeCondition (com.gargoylesoftware.css.parser.condition.AttributeCondition)3 BeginHyphenAttributeCondition (com.gargoylesoftware.css.parser.condition.BeginHyphenAttributeCondition)3 ClassCondition (com.gargoylesoftware.css.parser.condition.ClassCondition)3 IdCondition (com.gargoylesoftware.css.parser.condition.IdCondition)3 LangCondition (com.gargoylesoftware.css.parser.condition.LangCondition)3 OneOfAttributeCondition (com.gargoylesoftware.css.parser.condition.OneOfAttributeCondition)3 PrefixAttributeCondition (com.gargoylesoftware.css.parser.condition.PrefixAttributeCondition)3 PseudoClassCondition (com.gargoylesoftware.css.parser.condition.PseudoClassCondition)3 SubstringAttributeCondition (com.gargoylesoftware.css.parser.condition.SubstringAttributeCondition)3 SuffixAttributeCondition (com.gargoylesoftware.css.parser.condition.SuffixAttributeCondition)3 ChildSelector (com.gargoylesoftware.css.parser.selector.ChildSelector)3 DirectAdjacentSelector (com.gargoylesoftware.css.parser.selector.DirectAdjacentSelector)3 ElementSelector (com.gargoylesoftware.css.parser.selector.ElementSelector)3 GeneralAdjacentSelector (com.gargoylesoftware.css.parser.selector.GeneralAdjacentSelector)3 PseudoElementSelector (com.gargoylesoftware.css.parser.selector.PseudoElementSelector)3 Selector (com.gargoylesoftware.css.parser.selector.Selector)2