Search in sources :

Example 26 with ICSSSelector

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.

the class CSSModelImpl method attrReplaced.

void attrReplaced(CSSNodeImpl parentNode, CSSNodeImpl newAttr, CSSNodeImpl oldAttr) {
    if (!fStructuredDocumentUpdate) {
        CSSModelUpdater updater = getUpdater();
        updater.attrReplaced(parentNode, newAttr, oldAttr);
    }
    ICSSSelector[] removed = null, added = null;
    if (oldAttr != null && oldAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) oldAttr).getName().equals(ICSSStyleRule.SELECTOR)) {
        CSSAttrImpl attr = (CSSAttrImpl) oldAttr;
        // collect changed selector
        ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
        removed = new ICSSSelector[list.getLength()];
        for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
    }
    if (newAttr != null && newAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) newAttr).getName().equals(ICSSStyleRule.SELECTOR)) {
        CSSAttrImpl attr = (CSSAttrImpl) newAttr;
        // collect changed selector
        ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
        added = new ICSSSelector[list.getLength()];
        for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
    }
    if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
        getStyleNotifier().fire(removed, added, null);
    }
    // for href attribute
    if (getStyleListeners() != null && getStyleListeners().size() > 0) {
        boolean update = false;
        if (oldAttr != null && oldAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) oldAttr).getName().equals(ICSSImportRule.HREF)) {
            update = true;
        }
        if (newAttr != null && newAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) newAttr).getName().equals(ICSSImportRule.HREF)) {
            update = true;
        }
        if (update)
            ((ICSSImportRule) parentNode).getStyleSheet();
    }
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)

Example 27 with ICSSSelector

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.

the class CSSModelImpl method childReplaced.

void childReplaced(CSSNodeImpl parentNode, CSSNodeImpl newChild, CSSNodeImpl oldChild) {
    if (!fStructuredDocumentUpdate) {
        CSSModelUpdater updater = getUpdater();
        updater.childReplaced(parentNode, newChild, oldChild);
    }
    // always check and send selector event
    ICSSSelector[] removed = null, added = null;
    if (parentNode.getNodeType() == ICSSNode.STYLESHEET_NODE || parentNode.getNodeType() == ICSSNode.MEDIARULE_NODE) {
        // collect old selectors
        SelectorsCollector selTrav = new SelectorsCollector();
        selTrav.apply(oldChild);
        int nSel = selTrav.getSelectors().size();
        if (nSel > 0) {
            removed = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) removed[i] = (ICSSSelector) selTrav.getSelectors().get(i);
        }
        // collect new selectors
        selTrav = new SelectorsCollector();
        selTrav.apply(newChild);
        nSel = selTrav.getSelectors().size();
        if (nSel > 0) {
            added = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) added[i] = (ICSSSelector) selTrav.getSelectors().get(i);
        }
    } else {
        // modification
        ICSSNode rule = parentNode;
        while (rule != null) {
            if (rule instanceof ICSSStyleRule)
                break;
            rule = rule.getParentNode();
        }
        if (rule != null) {
            ICSSSelectorList list = ((ICSSStyleRule) rule).getSelectors();
            added = new ICSSSelector[list.getLength()];
            for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
        }
    }
    if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
        // send selector changed event
        getStyleNotifier().fire(removed, added, null);
    }
    // close removed import-rule's external style sheets
    {
        ImportRuleCollector trav = new ImportRuleCollector();
        trav.apply(oldChild);
        Iterator it = trav.getRules().iterator();
        while (it.hasNext()) {
            ((CSSImportRuleImpl) it.next()).closeStyleSheet();
        }
    }
    // send events to listener for new import-rules
    if (getStyleListeners() != null && getStyleListeners().size() > 0) {
        ImportedCollector trav = new ImportedCollector();
        trav.apply(newChild);
    }
}
Also used : ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ImportRuleCollector(org.eclipse.wst.css.core.internal.util.ImportRuleCollector) SelectorsCollector(org.eclipse.wst.css.core.internal.util.SelectorsCollector) Iterator(java.util.Iterator) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 28 with ICSSSelector

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.

the class CSSSelectorTest method testSelector29.

public void testSelector29() {
    ICSSSelectorList list = createSelectorList("P#hoge98 + *:hover > A:link, A.external:visited");
    checkSelectorList(list, "P#hoge98 + *:hover > A:link, A.external:visited", 2, 0);
    ICSSSelector selector;
    ICSSSelectorItem item;
    selector = list.getSelector(0);
    checkSelector(selector, "P#hoge98 + *:hover > A:link", 5, 10202, 0);
    item = selector.getItem(0);
    checkSimpleSelector(item, "P", false, 0, 0, 1, 0);
    checkSimpleSelectorIDs(item, new String[] { "hoge98" });
    item = selector.getItem(1);
    checkSelectorCombinator(item, "+", ICSSSelectorCombinator.ADJACENT);
    item = selector.getItem(2);
    checkSimpleSelector(item, "*", true, 0, 0, 0, 1);
    checkSimpleSelectorPseudoNames(item, new String[] { "hover" });
    item = selector.getItem(3);
    checkSelectorCombinator(item, ">", ICSSSelectorCombinator.CHILD);
    item = selector.getItem(4);
    checkSimpleSelector(item, "A", false, 0, 0, 0, 1);
    checkSimpleSelectorPseudoNames(item, new String[] { "link" });
    selector = list.getSelector(1);
    checkSelector(selector, "A.external:visited", 1, 201, 0);
    item = selector.getItem(0);
    checkSimpleSelector(item, "A", false, 0, 1, 0, 1);
    checkSimpleSelectorClasses(item, new String[] { "external" });
    checkSimpleSelectorPseudoNames(item, new String[] { "visited" });
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSSelectorItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorItem)

Example 29 with ICSSSelector

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.

the class CSSSelectorTest method testSelector38.

public void testSelector38() {
    ICSSSelectorList list = createSelectorList(".123");
    checkSelectorList(list, ".123", 1, 1);
    ICSSSelector selector;
    ICSSSelectorItem item;
    selector = list.getSelector(0);
    checkSelector(selector, ".123", 1, 100, 1);
    item = selector.getItem(0);
    checkSimpleSelector(item, "", true, 0, 1, 0, 0);
    checkSimpleSelectorClasses(item, new String[] { "123" });
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSSelectorItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorItem)

Example 30 with ICSSSelector

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.

the class CSSSelectorTest method testSelector22.

public void testSelector22() {
    ICSSSelectorList list = createSelectorList("P:first-child EM");
    checkSelectorList(list, "P:first-child EM", 1, 0);
    ICSSSelector selector;
    ICSSSelectorItem item;
    selector = list.getSelector(0);
    checkSelector(selector, "P:first-child EM", 3, 102, 0);
    item = selector.getItem(0);
    checkSimpleSelector(item, "P", false, 0, 0, 0, 1);
    checkSimpleSelectorPseudoNames(item, new String[] { "first-child" });
    item = selector.getItem(1);
    checkSelectorCombinator(item, " ", ICSSSelectorCombinator.DESCENDANT);
    item = selector.getItem(2);
    checkSimpleSelector(item, "EM", false, 0, 0, 0, 0);
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSSelectorItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorItem)

Aggregations

ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)52 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)48 ICSSSelectorItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorItem)42 Iterator (java.util.Iterator)7 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)3 ImportedCollector (org.eclipse.wst.css.core.internal.util.ImportedCollector)3 SelectorsCollector (org.eclipse.wst.css.core.internal.util.SelectorsCollector)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)2 ICSSSimpleSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 Vector (java.util.Vector)1 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)1 CSSTextToken (org.eclipse.wst.css.core.internal.parserz.CSSTextToken)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)1 ImportRuleCollector (org.eclipse.wst.css.core.internal.util.ImportRuleCollector)1