use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.
the class CSSModelImpl method attrReplaced.
void attrReplaced(CSSNodeImpl parentNode, CSSNodeImpl newAttr, CSSNodeImpl oldAttr) {
if (!fStructuredDocumentUpdate) {
CSSModelUpdater updater = getUpdater();
updater.attrReplaced(parentNode, newAttr, oldAttr);
}
ICSSSelector[] removed = null, added = null;
if (oldAttr != null && oldAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) oldAttr).getName().equals(ICSSStyleRule.SELECTOR)) {
CSSAttrImpl attr = (CSSAttrImpl) oldAttr;
// collect changed selector
ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
removed = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
}
if (newAttr != null && newAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) newAttr).getName().equals(ICSSStyleRule.SELECTOR)) {
CSSAttrImpl attr = (CSSAttrImpl) newAttr;
// 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);
}
if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
getStyleNotifier().fire(removed, added, null);
}
// for href attribute
if (getStyleListeners() != null && getStyleListeners().size() > 0) {
boolean update = false;
if (oldAttr != null && oldAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) oldAttr).getName().equals(ICSSImportRule.HREF)) {
update = true;
}
if (newAttr != null && newAttr.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) newAttr).getName().equals(ICSSImportRule.HREF)) {
update = true;
}
if (update)
((ICSSImportRule) parentNode).getStyleSheet();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector 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);
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.
the class CSSSelectorTest method testSelector29.
public void testSelector29() {
ICSSSelectorList list = createSelectorList("P#hoge98 + *:hover > A:link, A.external:visited");
checkSelectorList(list, "P#hoge98 + *:hover > A:link, A.external:visited", 2, 0);
ICSSSelector selector;
ICSSSelectorItem item;
selector = list.getSelector(0);
checkSelector(selector, "P#hoge98 + *:hover > A:link", 5, 10202, 0);
item = selector.getItem(0);
checkSimpleSelector(item, "P", false, 0, 0, 1, 0);
checkSimpleSelectorIDs(item, new String[] { "hoge98" });
item = selector.getItem(1);
checkSelectorCombinator(item, "+", ICSSSelectorCombinator.ADJACENT);
item = selector.getItem(2);
checkSimpleSelector(item, "*", true, 0, 0, 0, 1);
checkSimpleSelectorPseudoNames(item, new String[] { "hover" });
item = selector.getItem(3);
checkSelectorCombinator(item, ">", ICSSSelectorCombinator.CHILD);
item = selector.getItem(4);
checkSimpleSelector(item, "A", false, 0, 0, 0, 1);
checkSimpleSelectorPseudoNames(item, new String[] { "link" });
selector = list.getSelector(1);
checkSelector(selector, "A.external:visited", 1, 201, 0);
item = selector.getItem(0);
checkSimpleSelector(item, "A", false, 0, 1, 0, 1);
checkSimpleSelectorClasses(item, new String[] { "external" });
checkSimpleSelectorPseudoNames(item, new String[] { "visited" });
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.
the class CSSSelectorTest method testSelector38.
public void testSelector38() {
ICSSSelectorList list = createSelectorList(".123");
checkSelectorList(list, ".123", 1, 1);
ICSSSelector selector;
ICSSSelectorItem item;
selector = list.getSelector(0);
checkSelector(selector, ".123", 1, 100, 1);
item = selector.getItem(0);
checkSimpleSelector(item, "", true, 0, 1, 0, 0);
checkSimpleSelectorClasses(item, new String[] { "123" });
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector in project webtools.sourceediting by eclipse.
the class CSSSelectorTest method testSelector22.
public void testSelector22() {
ICSSSelectorList list = createSelectorList("P:first-child EM");
checkSelectorList(list, "P:first-child EM", 1, 0);
ICSSSelector selector;
ICSSSelectorItem item;
selector = list.getSelector(0);
checkSelector(selector, "P:first-child EM", 3, 102, 0);
item = selector.getItem(0);
checkSimpleSelector(item, "P", false, 0, 0, 0, 1);
checkSimpleSelectorPseudoNames(item, new String[] { "first-child" });
item = selector.getItem(1);
checkSelectorCombinator(item, " ", ICSSSelectorCombinator.DESCENDANT);
item = selector.getItem(2);
checkSimpleSelector(item, "EM", false, 0, 0, 0, 0);
}
Aggregations