Search in sources :

Example 1 with ICSSMediaRule

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

the class CSSMediaRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    ICSSMediaRule newRule = doc.createCSSMediaRule();
    MediaList newList = newRule.getMedia();
    newList.appendMedium("media1");
    newList.appendMedium("media2");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSMediaRule);
    CSSMediaRule mediaRule = (CSSMediaRule) rule;
    MediaList mediaList = mediaRule.getMedia();
    assertEquals(2, mediaList.getLength());
    assertEquals("media1", mediaList.item(0));
    assertEquals("media2", mediaList.item(1));
    assertEquals("@media media1, media2 {" + FileUtil.commonEOL + "}", mediaRule.getCssText());
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) MediaList(org.w3c.dom.stylesheets.MediaList) CSSRule(org.w3c.dom.css.CSSRule) ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) CSSMediaRule(org.w3c.dom.css.CSSMediaRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 2 with ICSSMediaRule

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

the class CSSProposalArranger method buildProposals.

/**
 */
void buildProposals() {
    fProposals.clear();
    /*
		 * String text; ICompletionProposal item; text = "---- Test
		 * Information ----"; item = new CompletionProposal("",
		 * fContext.getReplaceBegin(), 0, 0, null, text, null, null);
		 * fProposals.add(item);
		 * 
		 * text = "Target: \"" + fContext.getRegionText() + "\"";
		 * 
		 * item = new CompletionProposal("", fContext.getReplaceBegin(), 0, 0,
		 * null, text, null, null); fProposals.add(item);
		 * 
		 * text = fContext.getTargetNode().getClass().toString(); int
		 * lastPeriodPos = text.lastIndexOf('.'); text = "Node: " +
		 * text.substring(lastPeriodPos + 1); item = new
		 * CompletionProposal("", fContext.getReplaceBegin(), 0, 0, null,
		 * text, null, null); fProposals.add(item);
		 */
    ICSSNode targetNode = fContext.getTargetNode();
    // int targetPos = fContext.getTargetPos();
    if (targetNode instanceof ICSSStyleSheet) {
        buildProposalsForAnyRule();
    } else if ((targetNode instanceof ICSSMediaRule && fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_LBRACE)) || (targetNode instanceof ICSSStyleRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForAnyRule();
    // buildProposalsForStyleRule();
    } else if ((targetNode instanceof ICSSPageRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForPageRulePseudoClass();
    } else if ((targetNode instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule || targetNode instanceof ICSSPageRule || targetNode instanceof ICSSStyleDeclaration) && (targetNode.getOwnerDocument() instanceof ICSSStyleDeclaration || fContext.targetFollows(CSSRegionContexts.CSS_DECLARATION_DELIMITER) || fContext.targetFollows(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForDeclarationName();
    } else if (targetNode instanceof ICSSStyleDeclItem) {
        if (fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
            buildProposalsForDeclarationValue();
        } else {
            buildProposalsForDeclarationName();
        }
    } else if (targetNode instanceof ICSSPrimitiveValue) {
        buildProposalsForDeclarationValue();
    }
/*
		 * else if (targetNode instanceof ICSSPrimitiveValue || ((targetNode
		 * instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule ||
		 * targetNode instanceof ICSSStyleDeclaration || targetNode instanceof
		 * ICSSStyleDeclItem) &&
		 * fContext.isTargetPosAfterOf(CSSRegionContexts.COLON))) {
		 * buildProposalsForDeclarationValue(); }
		 */
// for Test
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 3 with ICSSMediaRule

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

the class CSSModelParser method insertBraceClose.

/**
 */
private CSSNodeImpl insertBraceClose(IStructuredDocumentRegion region) {
    ICSSNode target = CSSModelUtil.findBraceContainer(fCreationContext.getTargetNode());
    if (!(target instanceof CSSStructuredDocumentRegionContainer)) {
        return null;
    }
    CSSStructuredDocumentRegionContainer parent = (CSSStructuredDocumentRegionContainer) target;
    if (CSSModelUtil.isInterruption(parent, region)) {
        ICSSNode node = parent.getParentNode();
        if (node instanceof CSSNodeImpl) {
            fCreationContext.setReparseStart(parent.getStartOffset());
            fCreationContext.setReparseEnd(parent.getEndOffset());
            ((CSSNodeImpl) node).removeChild(parent);
        }
        return null;
    }
    if (parent instanceof ICSSPageRule || parent instanceof ICSSMediaRule || parent instanceof CSSFontFaceRule || parent instanceof ICSSStyleRule) {
        CSSModelUtil.expandStructuredDocumentRegionContainer(parent, region);
        if (!CSSModelUtil.isBraceClosed(target)) {
            fCreationContext.setTargetNode(parent.getParentNode());
            fCreationContext.setNextNode(parent.getNextSibling());
            return parent;
        }
    }
    return null;
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) 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)

Aggregations

ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)2 ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)2 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)2 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)1 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)1 CSSMediaRule (org.w3c.dom.css.CSSMediaRule)1 CSSRule (org.w3c.dom.css.CSSRule)1 CSSRuleList (org.w3c.dom.css.CSSRuleList)1 MediaList (org.w3c.dom.stylesheets.MediaList)1