Search in sources :

Example 1 with ConditionalSelector

use of org.w3c.css.sac.ConditionalSelector 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 ConditionalSelector

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

the class DocumentCSSImpl method querySelector.

protected List<Selector> querySelector(CSSRuleList ruleList, int selectorType, int selectorConditionType) {
    List<Selector> list = new ArrayList<>();
    if (selectorType == Selector.SAC_CONDITIONAL_SELECTOR) {
        int length = ruleList.getLength();
        for (int i = 0; i < length; i++) {
            CSSRule rule = ruleList.item(i);
            if (rule.getType() == CSSRule.STYLE_RULE && rule instanceof ExtendedCSSRule) {
                ExtendedCSSRule r = (ExtendedCSSRule) rule;
                SelectorList selectorList = r.getSelectorList();
                // Loop for SelectorList
                int l = selectorList.getLength();
                for (int j = 0; j < l; j++) {
                    Selector selector = selectorList.item(j);
                    if (selector.getSelectorType() == selectorType) {
                        // It's conditional selector
                        ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
                        short conditionType = conditionalSelector.getCondition().getConditionType();
                        if (selectorConditionType == conditionType) {
                            // current selector match the current CSS
                            // Rule
                            // CSSStyleRule styleRule = (CSSStyleRule)
                            // rule;
                            list.add(selector);
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : ExtendedCSSRule(org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule) ExtendedCSSRule(org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule) CSSRule(org.w3c.dom.css.CSSRule) SelectorList(org.w3c.css.sac.SelectorList) ArrayList(java.util.ArrayList) ConditionalSelector(org.w3c.css.sac.ConditionalSelector) Selector(org.w3c.css.sac.Selector) ConditionalSelector(org.w3c.css.sac.ConditionalSelector)

Example 3 with ConditionalSelector

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

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

use of org.w3c.css.sac.ConditionalSelector 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

ConditionalSelector (org.w3c.css.sac.ConditionalSelector)5 AttributeCondition (org.w3c.css.sac.AttributeCondition)4 Selector (org.w3c.css.sac.Selector)3 Condition (org.w3c.css.sac.Condition)2 ElementSelector (org.w3c.css.sac.ElementSelector)2 SelectorList (org.w3c.css.sac.SelectorList)2 ArrayList (java.util.ArrayList)1 ExtendedCSSRule (org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule)1 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 SimpleSelector (org.w3c.css.sac.SimpleSelector)1 CSSRule (org.w3c.dom.css.CSSRule)1