java.lang.Object
org.jhotdraw8.css.ast.AbstractSyntaxTree
org.jhotdraw8.css.ast.Selector
- Direct Known Subclasses:
Combinator,SelectorGroup,SimpleSelector
A "selector" is a tree of "combinator"s.
- Author:
- Werner Randelshofer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intReturns the specificity of this selector.protected abstract <T> @Nullable Tmatch(SelectorModel<T> model, T element) Returns the matching element.<T> booleanmatches(SelectorModel<T> model, T element) Returns true if the selector matches the element.Returns a qualified name, if this selector only matches on elements with a specific type name.Methods inherited from class org.jhotdraw8.css.ast.AbstractSyntaxTree
getSourceLocator, produceTokens
-
Constructor Details
-
Selector
-
-
Method Details
-
getSpecificity
public abstract int getSpecificity()Returns the specificity of this selector.A selector's specificity is calculated as follows:
- count the number of ID selectors in the selector (= a)
- count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
- count the number of type selectors and pseudo-elements in the selector (= c)
- ignore the universal selector
Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.
Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.
In this implementation we compute specificity with
specificity=100*a+10*b+c.References:
- CSS Syntax Selectors Level 3, Chapter 9. Calculating a selector's specificity
- w3.org
- Returns:
- the specificity
-
matches
Returns true if the selector matches the element.- Type Parameters:
T- the element type- Parameters:
model- The helper is used to access properties of the element and parent or sibling elements in the document.element- the element- Returns:
- true on match
-
match
Returns the matching element.- Type Parameters:
T- element type- Parameters:
model- The helper is used to access properties of the element and parent or sibling elements in the document.element- the element- Returns:
- the matching element or null
-
matchesOnlyOnASpecificType
Returns a qualified name, if this selector only matches on elements with a specific type name.This implementation returns null.
- Returns:
- a type name or null
-