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;
}
}
}
}
}
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;
}
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);
}
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());
}
}
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);
}
}
Aggregations