use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule in project webtools.sourceediting by eclipse.
the class SelectorsCollector method preNode.
/**
*/
protected short preNode(ICSSNode node) {
if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
ICSSStyleRule rule = (ICSSStyleRule) node;
ICSSSelectorList list = rule.getSelectors();
Iterator it = list.getIterator();
while (it.hasNext()) {
Object obj = it.next();
if (selectorsToAvoid != null && selectorsToAvoid.contains(obj))
continue;
if (!selectors.contains(obj))
selectors.add(obj);
}
return TRAV_PRUNE;
} else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
return TRAV_CONT;
}
return TRAV_PRUNE;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule in project webtools.sourceediting by eclipse.
the class CSSMetaModelUtil method getMetaModelNodeFor.
public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
if (node instanceof ICSSStyleDeclaration) {
node = node.getParentNode();
}
if (node instanceof ICSSStyleDeclItem) {
ICSSNode parent = node.getParentNode();
if (parent != null) {
parent = parent.getParentNode();
}
if (parent instanceof ICSSStyleRule) {
return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
} else if (parent instanceof CSSFontFaceRule) {
return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
}
}
if (node == null) {
return null;
}
if (fTypeMap == null) {
fTypeMap = new HashMap();
fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
}
String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
if (nodeType == null) {
return null;
}
Iterator iNodes = collectNodesByType(nodeType);
if (iNodes.hasNext()) {
CSSMMNode targetNode = (CSSMMNode) iNodes.next();
if (!iNodes.hasNext()) {
// it's only one
return targetNode;
}
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule in project webtools.sourceediting by eclipse.
the class CSSQueryTraverser method preNode.
/**
*/
protected short preNode(ICSSNode node) {
if (node instanceof ICSSStyleRule) {
// style rule
ICSSStyleRule style = (ICSSStyleRule) node;
ICSSSelectorList list = style.getSelectors();
int nSelectors = list.getLength();
int maxSpecificity = -1;
for (int iSelector = 0; iSelector < nSelectors; iSelector++) {
// Check each Selector Lists
ICSSSelector selector = list.getSelector(iSelector);
int specificity = selector.getSpecificity();
if (maxSpecificity < specificity && selector.match(element, pseudoName)) {
maxSpecificity = specificity;
}
}
if (maxSpecificity >= 0) {
// apply this style to the element
overwriteDeclaration((ICSSStyleDeclaration) style.getStyle(), maxSpecificity);
}
return TRAV_PRUNE;
}
return TRAV_CONT;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule in project webtools.sourceediting by eclipse.
the class CSSModelImpl method valueChanged.
void valueChanged(CSSNodeImpl node, String oldValue) {
if (!fStructuredDocumentUpdate) {
CSSModelUpdater updater = getUpdater();
updater.valueChanged(node, oldValue);
}
ICSSSelector[] removed = null, added = null;
if (node != null) {
if (node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSStyleRule.SELECTOR)) {
CSSAttrImpl attr = (CSSAttrImpl) node;
// collect changed selector
ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
added = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
// get old value
list = new CSSSelectorListImpl(oldValue);
removed = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
} else if (node instanceof ICSSValue) {
ICSSNode rule = node;
while (rule != null) {
if (rule instanceof ICSSStyleRule)
break;
rule = rule.getParentNode();
}
if (rule != null) {
ICSSSelectorList list = ((ICSSStyleRule) rule).getSelectors();
added = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
}
}
}
if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
// send selector changed event
getStyleNotifier().fire(removed, added, null);
}
// for href attribute
if (getStyleListeners() != null && getStyleListeners().size() > 0) {
if (node != null && node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSImportRule.HREF)) {
((ICSSImportRule) ((ICSSAttr) node).getOwnerCSSNode()).getStyleSheet();
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule in project webtools.sourceediting by eclipse.
the class CSSModelImpl method childReplaced.
void childReplaced(CSSNodeImpl parentNode, CSSNodeImpl newChild, CSSNodeImpl oldChild) {
if (!fStructuredDocumentUpdate) {
CSSModelUpdater updater = getUpdater();
updater.childReplaced(parentNode, newChild, oldChild);
}
// always check and send selector event
ICSSSelector[] removed = null, added = null;
if (parentNode.getNodeType() == ICSSNode.STYLESHEET_NODE || parentNode.getNodeType() == ICSSNode.MEDIARULE_NODE) {
// collect old selectors
SelectorsCollector selTrav = new SelectorsCollector();
selTrav.apply(oldChild);
int nSel = selTrav.getSelectors().size();
if (nSel > 0) {
removed = new ICSSSelector[nSel];
for (int i = 0; i < nSel; i++) removed[i] = (ICSSSelector) selTrav.getSelectors().get(i);
}
// collect new selectors
selTrav = new SelectorsCollector();
selTrav.apply(newChild);
nSel = selTrav.getSelectors().size();
if (nSel > 0) {
added = new ICSSSelector[nSel];
for (int i = 0; i < nSel; i++) added[i] = (ICSSSelector) selTrav.getSelectors().get(i);
}
} else {
// modification
ICSSNode rule = parentNode;
while (rule != null) {
if (rule instanceof ICSSStyleRule)
break;
rule = rule.getParentNode();
}
if (rule != null) {
ICSSSelectorList list = ((ICSSStyleRule) rule).getSelectors();
added = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
}
}
if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
// send selector changed event
getStyleNotifier().fire(removed, added, null);
}
// close removed import-rule's external style sheets
{
ImportRuleCollector trav = new ImportRuleCollector();
trav.apply(oldChild);
Iterator it = trav.getRules().iterator();
while (it.hasNext()) {
((CSSImportRuleImpl) it.next()).closeStyleSheet();
}
}
// send events to listener for new import-rules
if (getStyleListeners() != null && getStyleListeners().size() > 0) {
ImportedCollector trav = new ImportedCollector();
trav.apply(newChild);
}
}
Aggregations