Search in sources :

Example 6 with ICSSRuleContainer

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

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

the class CSSModelParser method insertCharsetRule.

/**
 */
private CSSNodeImpl insertCharsetRule(IStructuredDocumentRegion beginDocRegion, IStructuredDocumentRegion endDocRegion) {
    CSSNodeImpl parent = fCreationContext.getTargetNode();
    if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    ITextRegionList regions = new TextRegionListImpl(beginDocRegion.getRegions());
    // must be "@charset"
    regions.remove(0);
    ITextRegion encodingRegion = null;
    while (!regions.isEmpty()) {
        ITextRegion textRegion = regions.remove(0);
        if (textRegion == null) {
            continue;
        }
        String type = textRegion.getType();
        if (type == CSSRegionContexts.CSS_S || type == CSSRegionContexts.CSS_COMMENT) {
            continue;
        }
        if (type == CSSRegionContexts.CSS_STRING) {
            encodingRegion = textRegion;
            break;
        } else {
            break;
        }
    }
    if (encodingRegion == null) {
        return null;
    }
    CSSCharsetRuleImpl rule = fFeeder.getCSSCharsetRule();
    if (rule == null) {
        return null;
    }
    if (!fUpdateContext.isActive()) {
        rule.setAttribute(ICSSCharsetRule.ENCODING, beginDocRegion.getText(encodingRegion));
    }
    // setup flat container
    rule.setRangeStructuredDocumentRegion(beginDocRegion, endDocRegion);
    CSSAttrImpl attr = rule.getAttributeNode(ICSSCharsetRule.ENCODING);
    if (attr != null) {
        attr.setRangeRegion(beginDocRegion, encodingRegion, encodingRegion);
    }
    // insert to tree
    if (!fUpdateContext.isActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = fCreationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 8 with ICSSRuleContainer

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

the class CSSModelParser method insertStyleRule.

/**
 */
private CSSNodeImpl insertStyleRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
    CSSNodeImpl parent = fCreationContext.getTargetNode();
    if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    // get selector regions
    ITextRegionList selectorRegions = new TextRegionListImpl(flatNode.getRegions());
    CSSUtil.stripSurroundingSpace(selectorRegions);
    CSSStyleRuleImpl rule = fFeeder.getCSSStyleRule();
    if (rule == null) {
        return null;
    }
    if (!fUpdateContext.isActive()) {
        String selectorStr = CSSUtil.getRegionText(flatNode, selectorRegions);
        if (selectorStr != null && 0 < selectorStr.length()) {
            rule.setSelectorText(selectorStr);
        }
    }
    // setup flat container
    rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
    CSSAttrImpl attr = rule.getAttributeNode(ICSSPageRule.SELECTOR);
    if (attr != null && selectorRegions != null && !selectorRegions.isEmpty()) {
        attr.setRangeRegion(flatNode, selectorRegions.get(0), selectorRegions.get(selectorRegions.size() - 1));
    }
    // insert to tree
    if (!fUpdateContext.isActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = fCreationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    fCreationContext.setTargetNode(rule);
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)

Aggregations

ICSSRuleContainer (org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer)8 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)5 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 CSSModelCreationContext (org.eclipse.wst.css.core.internal.document.CSSModelCreationContext)1 CSSNodeImpl (org.eclipse.wst.css.core.internal.document.CSSNodeImpl)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)1 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 BasicStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion)1 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)1