Search in sources :

Example 1 with ICSSStyleRule

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

the class SelectorsCollector method preNode.

/**
 */
protected short preNode(ICSSNode node) {
    if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
        ICSSStyleRule rule = (ICSSStyleRule) node;
        ICSSSelectorList list = rule.getSelectors();
        Iterator it = list.getIterator();
        while (it.hasNext()) {
            Object obj = it.next();
            if (selectorsToAvoid != null && selectorsToAvoid.contains(obj))
                continue;
            if (!selectors.contains(obj))
                selectors.add(obj);
        }
        return TRAV_PRUNE;
    } else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
        return TRAV_CONT;
    }
    return TRAV_PRUNE;
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) Iterator(java.util.Iterator) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 2 with ICSSStyleRule

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

the class CSSMetaModelUtil method getMetaModelNodeFor.

public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
    if (node instanceof ICSSStyleDeclaration) {
        node = node.getParentNode();
    }
    if (node instanceof ICSSStyleDeclItem) {
        ICSSNode parent = node.getParentNode();
        if (parent != null) {
            parent = parent.getParentNode();
        }
        if (parent instanceof ICSSStyleRule) {
            return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
        } else if (parent instanceof CSSFontFaceRule) {
            return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
        }
    }
    if (node == null) {
        return null;
    }
    if (fTypeMap == null) {
        fTypeMap = new HashMap();
        fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
        fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
        fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
    }
    String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
    if (nodeType == null) {
        return null;
    }
    Iterator iNodes = collectNodesByType(nodeType);
    if (iNodes.hasNext()) {
        CSSMMNode targetNode = (CSSMMNode) iNodes.next();
        if (!iNodes.hasNext()) {
            // it's only one
            return targetNode;
        }
    }
    return null;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) HashMap(java.util.HashMap) Iterator(java.util.Iterator) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 3 with ICSSStyleRule

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

the class CSSQueryTraverser method preNode.

/**
 */
protected short preNode(ICSSNode node) {
    if (node instanceof ICSSStyleRule) {
        // style rule
        ICSSStyleRule style = (ICSSStyleRule) node;
        ICSSSelectorList list = style.getSelectors();
        int nSelectors = list.getLength();
        int maxSpecificity = -1;
        for (int iSelector = 0; iSelector < nSelectors; iSelector++) {
            // Check each Selector Lists
            ICSSSelector selector = list.getSelector(iSelector);
            int specificity = selector.getSpecificity();
            if (maxSpecificity < specificity && selector.match(element, pseudoName)) {
                maxSpecificity = specificity;
            }
        }
        if (maxSpecificity >= 0) {
            // apply this style to the element
            overwriteDeclaration((ICSSStyleDeclaration) style.getStyle(), maxSpecificity);
        }
        return TRAV_PRUNE;
    }
    return TRAV_CONT;
}
Also used : ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 4 with ICSSStyleRule

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

the class CSSModelImpl method valueChanged.

void valueChanged(CSSNodeImpl node, String oldValue) {
    if (!fStructuredDocumentUpdate) {
        CSSModelUpdater updater = getUpdater();
        updater.valueChanged(node, oldValue);
    }
    ICSSSelector[] removed = null, added = null;
    if (node != null) {
        if (node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSStyleRule.SELECTOR)) {
            CSSAttrImpl attr = (CSSAttrImpl) node;
            // 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);
            // get old value
            list = new CSSSelectorListImpl(oldValue);
            removed = new ICSSSelector[list.getLength()];
            for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
        } else if (node instanceof ICSSValue) {
            ICSSNode rule = node;
            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);
    }
    // for href attribute
    if (getStyleListeners() != null && getStyleListeners().size() > 0) {
        if (node != null && node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSImportRule.HREF)) {
            ((ICSSImportRule) ((ICSSAttr) node).getOwnerCSSNode()).getStyleSheet();
        }
    }
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 5 with ICSSStyleRule

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule 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)

Aggregations

ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)13 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)6 Iterator (java.util.Iterator)5 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)4 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)3 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)3 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)3 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)2 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Preferences (org.eclipse.core.runtime.Preferences)1