use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector in project webtools.sourceediting by eclipse.
the class CSSSelector method match.
/**
* @return boolean
* @param element
* org.w3c.dom.Element
*/
public boolean match(org.w3c.dom.Element element, java.lang.String pseudoName) {
Element target = element;
char combinatorType = ICSSSelectorCombinator.UNKNOWN;
// for CHILD and ADJACENT
Element chunkStartElement = null;
// combinator
// for CHILD and ADJACENT combinator
int chunkStartItem = -1;
int numItems = getLength();
for (int iItem = numItems - 1; iItem >= 0; iItem--) {
// Check Selector Items
ICSSSelectorItem item = getItem(iItem);
if (item instanceof ICSSSimpleSelector) {
// Simple Selector
if (target == null)
return false;
if (!matchExactly((ICSSSimpleSelector) item, target, pseudoName)) {
switch(combinatorType) {
case ICSSSelectorCombinator.DESCENDANT:
do {
target = getParentElement(target);
if (target == null)
return false;
} while (!matchExactly((ICSSSimpleSelector) item, target, pseudoName));
break;
case ICSSSelectorCombinator.CHILD:
case ICSSSelectorCombinator.ADJACENT:
if (chunkStartElement != null && chunkStartElement != element) {
// previous conbinator must be DESCENDENT.
// goto parent
target = getParentElement(chunkStartElement);
iItem = chunkStartItem + 1;
chunkStartElement = null;
chunkStartItem = -1;
break;
}
default:
// other combinators are not supported yet.
return false;
}
}
} else if (item instanceof ICSSSelectorCombinator) {
// Combinator ( "+", ">", " ", ...)
if (iItem == numItems - 1)
// last item is combinator
return false;
ICSSSelectorCombinator sc = (ICSSSelectorCombinator) item;
combinatorType = sc.getCombinatorType();
switch(combinatorType) {
case ICSSSelectorCombinator.DESCENDANT:
target = getParentElement(target);
break;
case ICSSSelectorCombinator.CHILD:
case ICSSSelectorCombinator.ADJACENT:
if (chunkStartElement == null) {
chunkStartElement = target;
// safe because this
chunkStartItem = iItem + 1;
// is not a last item.
}
if (combinatorType == ICSSSelectorCombinator.CHILD) {
target = getParentElement(target);
} else {
target = getPreviousElement(target);
}
break;
}
} else {
// what is this item ???
return false;
}
}
// OK this selector maches the element.
return true;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector in project webtools.sourceediting by eclipse.
the class CSSSelector method getErrors.
public Iterator getErrors() {
if (fNameErrors == null) {
fNameErrors = new ArrayList();
Iterator iItem = getIterator();
while (iItem.hasNext()) {
ICSSSelectorItem item = (ICSSSelectorItem) iItem.next();
if (item instanceof ICSSSimpleSelector) {
if (!((ICSSSimpleSelector) item).isUniversal()) {
String name = ((ICSSSimpleSelector) item).getName();
if (!NameValidator.isValid(name)) {
fNameErrors.add(item);
}
}
}
}
}
List errors = new ArrayList(fParseErrors);
errors.addAll(fNameErrors);
return errors.iterator();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector in project webtools.sourceediting by eclipse.
the class CSSClassTraverser method addClassNames.
/**
*/
private void addClassNames(ICSSStyleRule rule) {
ICSSSelectorList selectorList = rule.getSelectors();
Iterator iSelector = selectorList.getIterator();
while (iSelector.hasNext()) {
ICSSSelector selector = (ICSSSelector) iSelector.next();
Iterator iItem = selector.getIterator();
while (iItem.hasNext()) {
ICSSSelectorItem item = (ICSSSelectorItem) iItem.next();
if (item.getItemType() == ICSSSelectorItem.SIMPLE) {
ICSSSimpleSelector sel = (ICSSSimpleSelector) item;
int nClasses = sel.getNumOfClasses();
for (int iClass = 0; iClass < nClasses; iClass++) {
String className = sel.getClass(iClass);
if (!fClassNames.contains(className))
fClassNames.add(className);
}
}
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector in project webtools.sourceediting by eclipse.
the class SelectorValidator method getOnlyOneSimpleSelector.
private ICSSSimpleSelector getOnlyOneSimpleSelector() {
parse();
if (fSelectorList != null && fSelectorList.getLength() == 1) {
ICSSSelector selector = fSelectorList.getSelector(0);
int nItem = selector.getLength();
if (nItem == 1) {
ICSSSelectorItem item = selector.getItem(0);
if (item instanceof ICSSSimpleSelector) {
return (ICSSSimpleSelector) item;
}
}
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector in project webtools.sourceediting by eclipse.
the class CSSImageType method getImageType.
public static CSSImageType getImageType(ICSSSelector selector) {
CSSImageType imageType = SELECTOR_DEFAULT;
if (selector == null || selector.getLength() == 0) {
return imageType;
}
ICSSSelectorItem item = selector.getItem(selector.getLength() - 1);
if (item.getItemType() == ICSSSelectorItem.SIMPLE) {
ICSSSimpleSelector ss = (ICSSSimpleSelector) item;
if (0 < ss.getNumOfIDs()) {
imageType = SELECTOR_ID;
} else if (0 < ss.getNumOfClasses()) {
imageType = SELECTOR_CLASS;
} else if (0 < ss.getNumOfPseudoNames()) {
imageType = SELECTOR_PSEUDO;
} else {
imageType = SELECTOR_TAG;
}
}
return imageType;
}
Aggregations