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