java.lang.Object
org.jhotdraw8.css.ast.AbstractSyntaxTree
org.jhotdraw8.css.ast.Selector
org.jhotdraw8.css.ast.SelectorGroup
A "selector group" matches an element if one of its selectors matches the
element.
- Author:
- Werner Randelshofer
-
Constructor Summary
ConstructorsConstructorDescriptionSelectorGroup(@Nullable SourceLocator sourceLocator, List<Selector> selectors) SelectorGroup(@Nullable SourceLocator sourceLocator, Selector selector) -
Method Summary
Modifier and TypeMethodDescriptionbooleanintReturns the specificity of this selector.inthashCode()protected <T> @Nullable Tmatch(SelectorModel<T> model, T element) Returns the matching element.<T> booleanmatches(SelectorModel<T> model, T element) Returns true if the rule matches the element.@Nullable TypeSelectorThis selector matches only on a specific type, if all its selectors match on the same type.<T> @Nullable SelectormatchSelector(SelectorModel<T> model, T element) Returns the last selector with highest specificity that matches the specified element or null.voidproduceTokens(Consumer<CssToken> consumer) Produces tokens for the subtree starting at this tree node.toString()Methods inherited from class org.jhotdraw8.css.ast.AbstractSyntaxTree
getSourceLocator
-
Constructor Details
-
SelectorGroup
-
SelectorGroup
-
-
Method Details
-
toString
-
getSpecificity
public int getSpecificity()Description copied from class:SelectorReturns 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
- Specified by:
getSpecificityin classSelector- Returns:
- the specificity
-
matches
Returns true if the rule matches the element. -
match
Description copied from class:SelectorReturns the matching element. -
matchSelector
Returns the last selector with highest specificity that matches the specified element or null.If multiple selectors match, then this method returns the selector with the highest specificity value.
If multiple matching selectors have the highest specificity, then this method returns the last one.
- 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:
- the last selector with highest specificity that matches the specified element, returns null if no selector matches
-
produceTokens
Description copied from class:AbstractSyntaxTreeProduces tokens for the subtree starting at this tree node.- Overrides:
produceTokensin classAbstractSyntaxTree- Parameters:
consumer- a consumer for the tokens
-
equals
-
hashCode
public int hashCode() -
matchesOnlyOnASpecificType
This selector matches only on a specific type, if all its selectors match on the same type.- Overrides:
matchesOnlyOnASpecificTypein classSelector- Returns:
- a type name or null
-