use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSStyleDeclarationImpl method getDeclItemNode.
public ICSSStyleDeclItem getDeclItemNode(String propertyName) {
ICSSNode node = getLastChild();
propertyName = propertyName.trim();
while (node != null) {
if (node instanceof CSSStyleDeclItemImpl) {
ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
if (propertyName.compareToIgnoreCase(item.getPropertyName().trim()) == 0)
return item;
}
node = node.getPreviousSibling();
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method formatChildren.
/**
*/
protected final void formatChildren(ICSSNode node, IRegion region, StringBuffer source) {
ICSSNode child = node.getFirstChild();
int start = region.getOffset();
int end = region.getOffset() + region.getLength();
boolean first = true;
while (child != null) {
int curEnd = ((IndexedRegion) child).getEndOffset();
StringBuffer childSource = null;
boolean toFinish = false;
if (start < curEnd) {
int curStart = ((IndexedRegion) child).getStartOffset();
if (curStart < end) {
// append child
CSSSourceFormatter formatter = (CSSSourceFormatter) ((INodeNotifier) child).getAdapterFor(CSSSourceFormatter.class);
if (formatter == null) {
formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) child);
}
if (includes(region, curStart, curEnd))
childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child);
else
childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child, overlappedRegion(region, curStart, curEnd));
} else
toFinish = true;
}
// append between children
if (!first) {
// change
curEnd = ((IndexedRegion) child).getStartOffset();
// start
if (start < curEnd) {
int curStart = ((IndexedRegion) child.getPreviousSibling()).getEndOffset();
if (curStart < end) {
// $NON-NLS-1$
String toAppend = (childSource != null) ? new String(childSource) : "";
if (includes(region, curStart, curEnd))
formatBefore(node, child, toAppend, source, null);
else
formatBefore(node, child, overlappedRegion(region, curStart, curEnd), toAppend, source);
}
}
}
if (childSource != null) {
source.append(childSource);
}
first = false;
if (toFinish)
break;
child = child.getNextSibling();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getIndent.
/**
*/
protected String getIndent(ICSSNode node) {
if (node == null)
// $NON-NLS-1$
return "";
ICSSNode parent = node.getParentNode();
if (node instanceof ICSSAttr)
parent = ((ICSSAttr) node).getOwnerCSSNode();
if (parent == null)
// $NON-NLS-1$
return "";
if (node instanceof org.w3c.dom.css.CSSStyleDeclaration)
parent = parent.getParentNode();
if (parent == null)
// $NON-NLS-1$
return "";
String parentIndent = getIndent(parent);
if (parent instanceof org.w3c.dom.css.CSSRule)
return parentIndent + getIndentString();
if (node.getParentNode() instanceof ICSSStyleDeclaration)
return parentIndent + getIndentString();
return parentIndent;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSFormatUtil method collectCSSNodes.
public List collectCSSNodes(IStructuredModel model, int start, int length) {
List nodes = new ArrayList();
IndexedRegion startNode = model.getIndexedRegion(start);
IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
if (startNode == null || endNode == null) {
return nodes;
}
if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
// CSS model
ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
if (ca != null) {
for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
if (start < ((IndexedRegion) node).getEndOffset()) {
nodes.add(node);
}
}
}
} else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
if (startNode instanceof Text) {
startNode = (IndexedRegion) ((Text) startNode).getParentNode();
}
if (endNode instanceof Text) {
endNode = (IndexedRegion) ((Text) endNode).getParentNode();
}
// HTML model, maybe
IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
findCSS(nodes, ca);
}
return nodes;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSSourceFormatterFactory method getSourceFormatter.
/**
*/
public CSSSourceGenerator getSourceFormatter(INodeNotifier target) {
ICSSNode node = (ICSSNode) target;
short type = node.getNodeType();
switch(type) {
case ICSSNode.CHARSETRULE_NODE:
return CharsetRuleFormatter.getInstance();
case ICSSNode.FONTFACERULE_NODE:
return FontFaceRuleFormatter.getInstance();
case ICSSNode.IMPORTRULE_NODE:
return ImportRuleFormatter.getInstance();
case ICSSNode.MEDIALIST_NODE:
return MediaListFormatter.getInstance();
case ICSSNode.MEDIARULE_NODE:
return MediaRuleFormatter.getInstance();
case ICSSNode.PRIMITIVEVALUE_NODE:
ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_COUNTER)
return CounterFormatter.getInstance();
else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RECT)
return RectFormatter.getInstance();
else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RGBCOLOR)
return RGBFormatter.getInstance();
else
return PrimitiveValueFormatter.getInstance();
case ICSSNode.PAGERULE_NODE:
return PageRuleFormatter.getInstance();
case ICSSNode.STYLEDECLARATION_NODE:
return StyleDeclarationFormatter.getInstance();
case ICSSNode.STYLEDECLITEM_NODE:
return StyleDeclItemFormatter.getInstance();
case ICSSNode.STYLERULE_NODE:
return StyleRuleFormatter.getInstance();
case ICSSNode.STYLESHEET_NODE:
return StyleSheetFormatter.getInstance();
case ICSSNode.ATTR_NODE:
return AttrFormatter.getInstance();
default:
return UnknownRuleFormatter.getInstance();
}
}
Aggregations