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());
}
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
}
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;
}
Aggregations