Search in sources :

Example 16 with ICSSStyleDeclItem

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

the class StyleDeclItemFormatter method formatPost.

/**
 */
protected void formatPost(ICSSNode node, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int end = ((IndexedRegion) node).getEndOffset();
    int start = (node.getLastChild() != null && ((IndexedRegion) node.getLastChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getLastChild()).getEndOffset() : getChildInsertPos(node);
    if (end > 0 && start < end) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            appendSpaceBefore(node, regions[i], source);
            String decorateIndetRegion = decoratedIdentRegion(regions[i], stgy);
            if (decorateIndetRegion.trim().length() == 0)
                // $NON-NLS-1$
                decorateIndetRegion = " ";
            if (!source.toString().endsWith(decorateIndetRegion))
                source.append(decorateIndetRegion);
        }
    } else {
        // generate source
        // append "!important"
        String priority = ((ICSSStyleDeclItem) node).getPriority();
        if (priority != null && priority.length() > 0) {
            appendSpaceBefore(node, priority, source);
            source.append(priority);
        }
    }
}
Also used : ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 17 with ICSSStyleDeclItem

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

the class CSSModelParser method insertStructuredDocumentRegion.

/**
 * currently public but may be made default access protected in future.
 */
protected CSSNodeImpl insertStructuredDocumentRegion(IStructuredDocumentRegion region) {
    if (fCreationContext == null || region == null) {
        return null;
    }
    String type = ((BasicStructuredDocumentRegion) region).getType();
    CSSNodeImpl modified = null;
    ICSSNode target = fCreationContext.getTargetNode();
    if ((fParseFloating && target == null) || target instanceof ICSSRuleContainer) {
        if (type == CSSRegionContexts.CSS_DELIMITER) {
            modified = insertSemiColonForRule(region);
        } else if (type == CSSRegionContexts.CSS_LBRACE) {
            modified = insertBraceOpen(region);
        } else if (type == CSSRegionContexts.CSS_RBRACE) {
            modified = insertBraceClose(region);
        } else if (type == CSSRegionContexts.CSS_MEDIA || type == CSSRegionContexts.CSS_PAGE || type == CSSRegionContexts.CSS_FONT_FACE || CSSUtil.isSelectorText(region)) {
            checkNextNode(region, CSSRegionContexts.CSS_LBRACE);
        } else if (type == CSSRegionContexts.CSS_IMPORT || type == CSSRegionContexts.CSS_CHARSET) {
            checkNextNode(region, CSSRegionContexts.CSS_DELIMITER);
        }
    } else if ((target instanceof CSSRuleDeclContainer || target instanceof CSSStyleDeclaration) && type == CSSRegionContexts.CSS_DECLARATION_PROPERTY) {
        modified = insertStyleDeclarationItem(region);
    } else if (target instanceof ICSSStyleDeclItem && type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        modified = insertSemiColonForStyleDeclarationItem(region);
    } else if (type == CSSRegionContexts.CSS_RBRACE) {
        modified = insertBraceClose(region);
    }
    // post process
    if (modified != null) {
        if (modified instanceof CSSStructuredDocumentRegionContainer) {
            ((CSSStructuredDocumentRegionContainer) modified).propagateRangeStructuredDocumentRegion();
        }
    }
    return modified;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) BasicStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration)

Example 18 with ICSSStyleDeclItem

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

the class CSSQueryContext method overrideWithExpand.

/**
 */
public void overrideWithExpand(ICSSStyleDeclaration decl, int specificity) {
    if (decl == null)
        return;
    CSSLinkConverter conv = new CSSLinkConverter(decl.getOwnerDocument().getModel());
    int nProperties = decl.getLength();
    for (int i = 0; i < nProperties; i++) {
        String propName = decl.item(i);
        if (propName != null) {
            String propN = propName.trim().toLowerCase();
            if (propN.length() != 0) {
                PropCMProperty prop = PropCMProperty.getInstanceOf(propN);
                String priority = decl.getPropertyPriority(propName);
                boolean important = priority != null && priority.length() > 0;
                if (prop != null && prop.isShorthand()) {
                    // expand shorthand property
                    CSSQueryContext context = new CSSQueryContext();
                    expandToLeaf(prop, decl.getPropertyValue(propName), context);
                    Enumeration properties = context.properties();
                    while (properties.hasMoreElements()) {
                        propN = properties.nextElement().toString();
                        if (check(propN, important, specificity)) {
                            fProperties.put(propN, new CSSQueryValueData(conv.toAbsolute(context.get(propN)), important, specificity));
                        }
                    }
                } else {
                    if (check(propN, important, specificity)) {
                        ICSSStyleDeclItem declItem = (ICSSStyleDeclItem) decl.getDeclItemNode(propName).cloneNode(true);
                        int nValues = declItem.getLength();
                        for (int j = 0; j < nValues; j++) {
                            conv.toAbsolute(declItem.item(j));
                        }
                        declItem.setPriority(null);
                        fProperties.put(propN, new CSSQueryDeclarationData(declItem, important, specificity));
                    }
                }
            }
        }
    }
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) Enumeration(java.util.Enumeration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) CSSLinkConverter(org.eclipse.wst.css.core.internal.util.CSSLinkConverter)

Aggregations

ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)18 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Preferences (org.eclipse.core.runtime.Preferences)4 Iterator (java.util.Iterator)3 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)3 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)3 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)3 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)3 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)3 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)3 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2