use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertBraceOpen.
/**
*/
private CSSNodeImpl insertBraceOpen(IStructuredDocumentRegion region) {
IStructuredDocumentRegion keyRegion = CSSUtil.findPreviousSignificantNode(region);
if (keyRegion == null) {
return null;
}
if (!fParseFloating) {
CSSNodeImpl node = getNodeAt(keyRegion.getStartOffset());
if (node != null && !(node instanceof ICSSRuleContainer)) {
return null;
}
}
String type = CSSUtil.getStructuredDocumentRegionType(keyRegion);
CSSNodeImpl inserted = null;
if (type == CSSRegionContexts.CSS_PAGE) {
inserted = insertPageRule(keyRegion, region);
} else if (type == CSSRegionContexts.CSS_MEDIA) {
inserted = insertMediaRule(keyRegion, region);
} else if (type == CSSRegionContexts.CSS_FONT_FACE) {
inserted = insertFontFaceRule(keyRegion, region);
} else if (CSSUtil.isSelectorText(keyRegion)) {
inserted = insertStyleRule(keyRegion, region);
}
if (inserted instanceof CSSStructuredDocumentRegionContainer) {
// CSSModelUtil.expandStructuredDocumentRegionContainer((CSSStructuredDocumentRegionContainer)inserted,
// flatNode);
IStructuredDocumentRegion braceClose = findBraceClose(CSSModelUtil.getDepth(inserted), region, (type == CSSRegionContexts.CSS_MEDIA));
if (braceClose != null) {
fCreationContext.setReparseStart(region.getEnd());
fCreationContext.setReparseEnd(braceClose.getEnd());
}
}
return inserted;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertPageRule.
/**
*/
private CSSNodeImpl insertPageRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
// get selector regions
ITextRegionList selectorRegions = new TextRegionListImpl(flatNode.getRegions());
// must be "@page"
selectorRegions.remove(0);
CSSUtil.stripSurroundingSpace(selectorRegions);
CSSPageRuleImpl rule = fFeeder.getCSSPageRule();
if (rule == null) {
return null;
}
if (!fUpdateContext.isActive()) {
String selectorStr = CSSUtil.getRegionText(flatNode, selectorRegions);
if (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;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertImportRule.
/**
*/
private CSSNodeImpl insertImportRule(IStructuredDocumentRegion beginDocRegion, IStructuredDocumentRegion endDocRegion) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
ITextRegionList regions = new TextRegionListImpl(beginDocRegion.getRegions());
// must be "@import"
regions.remove(0);
ITextRegion hrefRegion = 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_URI || type == CSSRegionContexts.CSS_STRING) {
hrefRegion = textRegion;
break;
} else {
break;
}
}
if (hrefRegion == null) {
return null;
}
CSSImportRuleImpl rule = fFeeder.getCSSImportRule();
if (rule == null) {
return null;
}
CSSUtil.stripSurroundingSpace(regions);
MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
setMediaList(mediaList, beginDocRegion, regions);
if (!fUpdateContext.isActive()) {
rule.setAttribute(ICSSImportRule.HREF, beginDocRegion.getText(hrefRegion));
}
// setup flat container
rule.setRangeStructuredDocumentRegion(beginDocRegion, endDocRegion);
CSSAttrImpl attr = rule.getAttributeNode(ICSSImportRule.HREF);
if (attr != null) {
attr.setRangeRegion(beginDocRegion, hrefRegion, hrefRegion);
}
// 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;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertMediaRule.
/**
*/
private CSSNodeImpl insertMediaRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
CSSMediaRuleImpl rule = fFeeder.getCSSMediaRule();
if (rule == null) {
return null;
}
ITextRegionList regions = new TextRegionListImpl(flatNode.getRegions());
// must be "@media"
regions.remove(0);
CSSUtil.stripSurroundingSpace(regions);
MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
setMediaList(mediaList, flatNode, regions);
// setup flat container
rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
// 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;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class JSPedCSSModelParser method insertUnknownRule.
private CSSNodeImpl insertUnknownRule(IStructuredDocumentRegion flatNode) {
CSSModelCreationContext creationContext = getCreationContext();
CSSNodeImpl parent = creationContext.getTargetNode();
if (!isParseFloating() && !(parent instanceof ICSSRuleContainer)) {
return null;
}
JSPCSSNodeImpl rule = new JSPCSSNodeImpl(flatNode.getText());
rule.setOwnerDocument(parent.getOwnerDocument());
// setup flat container
rule.setRangeStructuredDocumentRegion(flatNode, flatNode);
// insert to tree
if (!isUpdateContextActive() && parent != null) {
propagateRangePreInsert(parent, rule);
CSSNodeImpl next = creationContext.getNextNode();
if (next != null) {
parent.insertBefore(rule, next);
} else {
parent.appendChild(rule);
}
}
return rule;
}
Aggregations