Search in sources :

Example 6 with ICSSNode

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

the class CSSStyleDeclarationImpl method getDeclItemNode.

public ICSSStyleDeclItem getDeclItemNode(String propertyName) {
    ICSSNode node = getLastChild();
    propertyName = propertyName.trim();
    while (node != null) {
        if (node instanceof CSSStyleDeclItemImpl) {
            ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
            if (propertyName.compareToIgnoreCase(item.getPropertyName().trim()) == 0)
                return item;
        }
        node = node.getPreviousSibling();
    }
    return null;
}
Also used : ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 7 with ICSSNode

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

the class AbstractCSSSourceFormatter method formatChildren.

/**
 */
protected final void formatChildren(ICSSNode node, IRegion region, StringBuffer source) {
    ICSSNode child = node.getFirstChild();
    int start = region.getOffset();
    int end = region.getOffset() + region.getLength();
    boolean first = true;
    while (child != null) {
        int curEnd = ((IndexedRegion) child).getEndOffset();
        StringBuffer childSource = null;
        boolean toFinish = false;
        if (start < curEnd) {
            int curStart = ((IndexedRegion) child).getStartOffset();
            if (curStart < end) {
                // append child
                CSSSourceFormatter formatter = (CSSSourceFormatter) ((INodeNotifier) child).getAdapterFor(CSSSourceFormatter.class);
                if (formatter == null) {
                    formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) child);
                }
                if (includes(region, curStart, curEnd))
                    childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child);
                else
                    childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child, overlappedRegion(region, curStart, curEnd));
            } else
                toFinish = true;
        }
        // append between children
        if (!first) {
            // change
            curEnd = ((IndexedRegion) child).getStartOffset();
            // start
            if (start < curEnd) {
                int curStart = ((IndexedRegion) child.getPreviousSibling()).getEndOffset();
                if (curStart < end) {
                    // $NON-NLS-1$
                    String toAppend = (childSource != null) ? new String(childSource) : "";
                    if (includes(region, curStart, curEnd))
                        formatBefore(node, child, toAppend, source, null);
                    else
                        formatBefore(node, child, overlappedRegion(region, curStart, curEnd), toAppend, source);
                }
            }
        }
        if (childSource != null) {
            source.append(childSource);
        }
        first = false;
        if (toFinish)
            break;
        child = child.getNextSibling();
    }
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 8 with ICSSNode

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

the class AbstractCSSSourceFormatter method getIndent.

/**
 */
protected String getIndent(ICSSNode node) {
    if (node == null)
        // $NON-NLS-1$
        return "";
    ICSSNode parent = node.getParentNode();
    if (node instanceof ICSSAttr)
        parent = ((ICSSAttr) node).getOwnerCSSNode();
    if (parent == null)
        // $NON-NLS-1$
        return "";
    if (node instanceof org.w3c.dom.css.CSSStyleDeclaration)
        parent = parent.getParentNode();
    if (parent == null)
        // $NON-NLS-1$
        return "";
    String parentIndent = getIndent(parent);
    if (parent instanceof org.w3c.dom.css.CSSRule)
        return parentIndent + getIndentString();
    if (node.getParentNode() instanceof ICSSStyleDeclaration)
        return parentIndent + getIndentString();
    return parentIndent;
}
Also used : ICSSAttr(org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)

Example 9 with ICSSNode

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

the class CSSFormatUtil method collectCSSNodes.

public List collectCSSNodes(IStructuredModel model, int start, int length) {
    List nodes = new ArrayList();
    IndexedRegion startNode = model.getIndexedRegion(start);
    IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
    if (startNode == null || endNode == null) {
        return nodes;
    }
    if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
        // CSS model
        ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
        if (ca != null) {
            for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
                if (start < ((IndexedRegion) node).getEndOffset()) {
                    nodes.add(node);
                }
            }
        }
    } else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
        if (startNode instanceof Text) {
            startNode = (IndexedRegion) ((Text) startNode).getParentNode();
        }
        if (endNode instanceof Text) {
            endNode = (IndexedRegion) ((Text) endNode).getParentNode();
        }
        // HTML model, maybe
        IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
        findCSS(nodes, ca);
    }
    return nodes;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 10 with ICSSNode

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

the class CSSSourceFormatterFactory method getSourceFormatter.

/**
 */
public CSSSourceGenerator getSourceFormatter(INodeNotifier target) {
    ICSSNode node = (ICSSNode) target;
    short type = node.getNodeType();
    switch(type) {
        case ICSSNode.CHARSETRULE_NODE:
            return CharsetRuleFormatter.getInstance();
        case ICSSNode.FONTFACERULE_NODE:
            return FontFaceRuleFormatter.getInstance();
        case ICSSNode.IMPORTRULE_NODE:
            return ImportRuleFormatter.getInstance();
        case ICSSNode.MEDIALIST_NODE:
            return MediaListFormatter.getInstance();
        case ICSSNode.MEDIARULE_NODE:
            return MediaRuleFormatter.getInstance();
        case ICSSNode.PRIMITIVEVALUE_NODE:
            ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
            if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_COUNTER)
                return CounterFormatter.getInstance();
            else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RECT)
                return RectFormatter.getInstance();
            else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RGBCOLOR)
                return RGBFormatter.getInstance();
            else
                return PrimitiveValueFormatter.getInstance();
        case ICSSNode.PAGERULE_NODE:
            return PageRuleFormatter.getInstance();
        case ICSSNode.STYLEDECLARATION_NODE:
            return StyleDeclarationFormatter.getInstance();
        case ICSSNode.STYLEDECLITEM_NODE:
            return StyleDeclItemFormatter.getInstance();
        case ICSSNode.STYLERULE_NODE:
            return StyleRuleFormatter.getInstance();
        case ICSSNode.STYLESHEET_NODE:
            return StyleSheetFormatter.getInstance();
        case ICSSNode.ATTR_NODE:
            return AttrFormatter.getInstance();
        default:
            return UnknownRuleFormatter.getInstance();
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Aggregations

ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)95 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)21 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)13 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)12 DOMException (org.w3c.dom.DOMException)12 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)11 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)11 Iterator (java.util.Iterator)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)9 Region (org.eclipse.jface.text.Region)8 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)6 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)5 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)5 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5