Search in sources :

Example 1 with AttributeCondition

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

the class AbstractCSSEngine method applyConditionalPseudoStyle.

private void applyConditionalPseudoStyle(ExtendedCSSRule parentRule, String pseudoInstance, Object element, CSSStyleDeclaration styleWithPseudoInstance) {
    SelectorList selectorList = parentRule.getSelectorList();
    for (int j = 0; j < selectorList.getLength(); j++) {
        Selector item = selectorList.item(j);
        // search for conditional selectors
        ConditionalSelector conditional = null;
        if (item instanceof ConditionalSelector) {
            conditional = (ConditionalSelector) item;
        } else if (item instanceof DescendantSelector) {
            if (((DescendantSelector) item).getSimpleSelector() instanceof ConditionalSelector) {
                conditional = (ConditionalSelector) ((DescendantSelector) item).getSimpleSelector();
            } else if (((DescendantSelector) item).getAncestorSelector() instanceof ConditionalSelector) {
                conditional = (ConditionalSelector) ((DescendantSelector) item).getAncestorSelector();
            }
        }
        if (conditional != null) {
            Condition condition = conditional.getCondition();
            // we're only interested in attribute selector conditions
            AttributeCondition attr = null;
            if (condition instanceof AttributeCondition) {
                attr = (AttributeCondition) condition;
            } else if (condition instanceof CombinatorCondition) {
                if (((CombinatorCondition) condition).getSecondCondition() instanceof AttributeCondition) {
                    attr = (AttributeCondition) ((CombinatorCondition) condition).getSecondCondition();
                } else if (((CombinatorCondition) condition).getFirstCondition() instanceof AttributeCondition) {
                    attr = (AttributeCondition) ((CombinatorCondition) condition).getFirstCondition();
                }
            }
            if (attr != null) {
                String value = attr.getValue();
                if (value.equals(pseudoInstance)) {
                    // if we match the pseudo, apply the style
                    applyStyleDeclaration(element, styleWithPseudoInstance, pseudoInstance);
                    return;
                }
            }
        }
    }
}
Also used : Condition(org.w3c.css.sac.Condition) AttributeCondition(org.w3c.css.sac.AttributeCondition) CombinatorCondition(org.w3c.css.sac.CombinatorCondition) CombinatorCondition(org.w3c.css.sac.CombinatorCondition) SelectorList(org.w3c.css.sac.SelectorList) AttributeCondition(org.w3c.css.sac.AttributeCondition) DescendantSelector(org.w3c.css.sac.DescendantSelector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector) DescendantSelector(org.w3c.css.sac.DescendantSelector) Selector(org.w3c.css.sac.Selector) ExtendedSelector(org.eclipse.e4.ui.css.core.impl.sac.ExtendedSelector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector)

Example 2 with AttributeCondition

use of org.w3c.css.sac.AttributeCondition in project CodenameOne by codenameone.

the class CSSTheme method apply.

public void apply(String media, Selector sel, String property, LexicalUnit value) {
    if (sel.getSelectorType() == Selector.SAC_CONDITIONAL_SELECTOR) {
        ConditionalSelector csel = (ConditionalSelector) sel;
        if (csel.getCondition().getConditionType() == Condition.SAC_ID_CONDITION) {
            AttributeCondition acond = (AttributeCondition) csel.getCondition();
            if ("Device".equalsIgnoreCase(acond.getValue())) {
                switch(property) {
                    case "min-resolution":
                        minDpi = ((ScaledUnit) value).getNumericValue();
                        break;
                    case "max-resolution":
                        maxDpi = ((ScaledUnit) value).getNumericValue();
                        break;
                    case "resolution":
                        currentDpi = ((ScaledUnit) value).getNumericValue();
                        break;
                }
                return;
            }
            if ("Constants".equalsIgnoreCase(acond.getValue())) {
                constants.put(property, value);
                return;
            }
        }
    }
    Element el = getElementForSelector(media, sel);
    apply(el, property, value);
}
Also used : AttributeCondition(org.w3c.css.sac.AttributeCondition) ConditionalSelector(org.w3c.css.sac.ConditionalSelector)

Example 3 with AttributeCondition

use of org.w3c.css.sac.AttributeCondition 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 4 with AttributeCondition

use of org.w3c.css.sac.AttributeCondition 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)4 ConditionalSelector (org.w3c.css.sac.ConditionalSelector)4 Condition (org.w3c.css.sac.Condition)2 ElementSelector (org.w3c.css.sac.ElementSelector)2 Selector (org.w3c.css.sac.Selector)2 ExtendedSelector (org.eclipse.e4.ui.css.core.impl.sac.ExtendedSelector)1 CSSException (org.w3c.css.sac.CSSException)1 CombinatorCondition (org.w3c.css.sac.CombinatorCondition)1 DescendantSelector (org.w3c.css.sac.DescendantSelector)1 SelectorList (org.w3c.css.sac.SelectorList)1 SimpleSelector (org.w3c.css.sac.SimpleSelector)1