Search in sources :

Example 1 with ElementSelector

use of org.w3c.css.sac.ElementSelector 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());
    }
}
Also used : SimpleSelector(org.w3c.css.sac.SimpleSelector) AttributeCondition(org.w3c.css.sac.AttributeCondition) CSSException(org.w3c.css.sac.CSSException) ElementSelector(org.w3c.css.sac.ElementSelector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector)

Example 2 with ElementSelector

use of org.w3c.css.sac.ElementSelector in project eclipse.platform.ui by eclipse-platform.

the class MockDocumentHandler method endSelector.

public void endSelector(SelectorList selectors) throws CSSException {
    int length = selectors.getLength();
    System.out.println("[MockDocumentHandler#endSelector], selectors=" + selectors + ", length=" + length);
    for (int i = 0; i < length; i++) {
        Selector selector = selectors.item(i);
        if (selector instanceof ElementSelector) {
            // Element selector
            ElementSelector elementSelector = (ElementSelector) selector;
            System.out.println("\tElementSelector=> localName=" + elementSelector.getLocalName());
        } else if (selector instanceof ConditionalSelector) {
            ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
            System.out.println("\tConditionalSelector");
            Condition condition = conditionalSelector.getCondition();
            if (condition instanceof AttributeCondition) {
                AttributeCondition attributeCondition = (AttributeCondition) condition;
                System.out.println("\t\tCondition (type=AttributeCondition)=> localName=" + attributeCondition.getLocalName() + ", value=" + attributeCondition.getValue());
            } else {
                System.out.println("\t\tCondition=>" + condition);
            }
        } else
            System.out.println(selector);
    }
}
Also used : Condition(org.w3c.css.sac.Condition) AttributeCondition(org.w3c.css.sac.AttributeCondition) AttributeCondition(org.w3c.css.sac.AttributeCondition) ElementSelector(org.w3c.css.sac.ElementSelector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector) ElementSelector(org.w3c.css.sac.ElementSelector) Selector(org.w3c.css.sac.Selector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector)

Aggregations

AttributeCondition (org.w3c.css.sac.AttributeCondition)2 ConditionalSelector (org.w3c.css.sac.ConditionalSelector)2 ElementSelector (org.w3c.css.sac.ElementSelector)2 CSSException (org.w3c.css.sac.CSSException)1 Condition (org.w3c.css.sac.Condition)1 Selector (org.w3c.css.sac.Selector)1 SimpleSelector (org.w3c.css.sac.SimpleSelector)1