Package com.openhtmltopdf.css.newmatch
Class Selector
java.lang.Object
com.openhtmltopdf.css.newmatch.Selector
public class Selector extends Object
A Selector is really a chain of CSS selectors that all need to be valid for
the selector to match.
- Author:
- Torbjoern Gannholm
-
Field Summary
Fields Modifier and Type Field Description static intACTIVE_PSEUDOCLASSstatic intCHILD_AXISstatic intDESCENDANT_AXISstatic intFOCUS_PSEUDOCLASSstatic intHOVER_PSEUDOCLASSstatic intIMMEDIATE_SIBLING_AXISstatic intVISITED_PSEUDOCLASS -
Constructor Summary
Constructors Constructor Description Selector() -
Method Summary
Modifier and Type Method Description voidaddAttributeEqualsCondition(String namespaceURI, String name, String value)the CSS condition [attribute=value]voidaddAttributeExistsCondition(String namespaceURI, String name)the CSS condition [attribute]voidaddAttributeMatchesFirstPartCondition(String namespaceURI, String name, String value)the CSS condition [attribute|=value]voidaddAttributeMatchesListCondition(String namespaceURI, String name, String value)the CSS condition [attribute~=value]voidaddAttributePrefixCondition(String namespaceURI, String name, String value)the CSS condition [attribute^=value]voidaddAttributeSubstringCondition(String namespaceURI, String name, String value)the CSS condition [attribute*=value]voidaddAttributeSuffixCondition(String namespaceURI, String name, String value)the CSS condition [attribute$=value]voidaddClassCondition(String className)the CSS condition .classvoidaddEvenChildCondition()the CSS condition that element has pseudo-class :evenvoidaddFirstChildCondition()the CSS condition that element has pseudo-class :first-childvoidaddIDCondition(String id)the CSS condition #IDvoidaddLangCondition(String lang)the CSS condition :lang(Xx)voidaddLastChildCondition()the CSS condition that element has pseudo-class :last-childvoidaddLinkCondition()the CSS condition that element has pseudo-class :linkvoidaddNthChildCondition(String number)the CSS condition that element has pseudo-class :nth-child(an+b)voidaddOddChildCondition()the CSS condition that element has pseudo-class :oddvoidaddUnsupportedCondition()for unsupported or invalid CSSSelectorgetAncestorSelector()intgetAxis()get the axis that this selector should be evaluated onSelectorgetChainedSelector()get the next selector in the chain, for matching against elements along the appropriate axisStringgetPseudoElement()Gets the pseudoElement attribute of the Selector objectRulesetgetRuleset()get the Ruleset that this Selector is part ofintgetSelectorID()intgetSpecificityB()The correct specificity value for this selector and its sibling-axis selectorsintgetSpecificityC()The correct specificity value for this selector and its sibling-axis selectorsintgetSpecificityD()The correct specificity value for this selector and its sibling-axis selectorsbooleanisPseudoClass(int pc)query if a pseudoclass must apply for this selectorbooleanmatches(Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector.booleanmatchesDynamic(Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector's dynamic properties.voidsetAncestorSelector(Selector ancestor)voidsetAxis(int axis)voidsetChainedSelector(Selector selector)voidsetName(String name)voidsetNamespaceURI(String namespaceURI)voidsetParent(Ruleset ruleset)voidsetPos(int pos)voidsetPseudoClass(int pc)set which pseudoclasses must apply for this selectorvoidsetPseudoElement(String pseudoElement)check if selector queries for dynamic propertiesvoidsetSiblingSelector(Selector selector)voidsetSpecificityB(int b)voidsetSpecificityC(int c)voidsetSpecificityD(int d)voidtoCSS(StringBuilder sb, Set<Selector> stopAt)Prints the selector chain to a StringBuilder, stopping when it hits a selector in the stopAt set.StringtoString()For debugging, prints the entire selector chain.
-
Field Details
-
DESCENDANT_AXIS
public static final int DESCENDANT_AXIS- See Also:
- Constant Field Values
-
CHILD_AXIS
public static final int CHILD_AXIS- See Also:
- Constant Field Values
-
IMMEDIATE_SIBLING_AXIS
public static final int IMMEDIATE_SIBLING_AXIS- See Also:
- Constant Field Values
-
VISITED_PSEUDOCLASS
public static final int VISITED_PSEUDOCLASS- See Also:
- Constant Field Values
-
HOVER_PSEUDOCLASS
public static final int HOVER_PSEUDOCLASS- See Also:
- Constant Field Values
-
ACTIVE_PSEUDOCLASS
public static final int ACTIVE_PSEUDOCLASS- See Also:
- Constant Field Values
-
FOCUS_PSEUDOCLASS
public static final int FOCUS_PSEUDOCLASS- See Also:
- Constant Field Values
-
-
Constructor Details
-
Selector
public Selector()
-
-
Method Details
-
matches
Check if the given Element matches this selector. Note: the parser should give all class -
matchesDynamic
Check if the given Element matches this selector's dynamic properties. Note: the parser should give all class -
addUnsupportedCondition
public void addUnsupportedCondition()for unsupported or invalid CSS -
addLinkCondition
public void addLinkCondition()the CSS condition that element has pseudo-class :link -
addFirstChildCondition
public void addFirstChildCondition()the CSS condition that element has pseudo-class :first-child -
addLastChildCondition
public void addLastChildCondition()the CSS condition that element has pseudo-class :last-child -
addNthChildCondition
the CSS condition that element has pseudo-class :nth-child(an+b) -
addEvenChildCondition
public void addEvenChildCondition()the CSS condition that element has pseudo-class :even -
addOddChildCondition
public void addOddChildCondition()the CSS condition that element has pseudo-class :odd -
addLangCondition
the CSS condition :lang(Xx) -
addIDCondition
the CSS condition #ID -
addClassCondition
the CSS condition .class -
addAttributeExistsCondition
the CSS condition [attribute] -
addAttributeEqualsCondition
the CSS condition [attribute=value] -
addAttributePrefixCondition
the CSS condition [attribute^=value] -
addAttributeSuffixCondition
the CSS condition [attribute$=value] -
addAttributeSubstringCondition
the CSS condition [attribute*=value] -
addAttributeMatchesListCondition
the CSS condition [attribute~=value] -
addAttributeMatchesFirstPartCondition
the CSS condition [attribute|=value] -
setPseudoClass
public void setPseudoClass(int pc)set which pseudoclasses must apply for this selector- Parameters:
pc- the values from AttributeResolver should be used. Once set they cannot be unset. Note that the pseudo-classes should be set one at a time, otherwise specificity of declaration becomes wrong.
-
setPseudoElement
check if selector queries for dynamic properties- Parameters:
pseudoElement- The new pseudoElement value
-
isPseudoClass
public boolean isPseudoClass(int pc)query if a pseudoclass must apply for this selector- Parameters:
pc- the values from AttributeResolver should be used.- Returns:
- The pseudoClass value
-
getPseudoElement
Gets the pseudoElement attribute of the Selector object- Returns:
- The pseudoElement value
-
getChainedSelector
get the next selector in the chain, for matching against elements along the appropriate axis- Returns:
- The chainedSelector value
-
getRuleset
get the Ruleset that this Selector is part of- Returns:
- The ruleset value
-
getAxis
public int getAxis()get the axis that this selector should be evaluated on- Returns:
- The axis value
-
getSpecificityB
public int getSpecificityB()The correct specificity value for this selector and its sibling-axis selectors -
getSpecificityD
public int getSpecificityD()The correct specificity value for this selector and its sibling-axis selectors -
getSpecificityC
public int getSpecificityC()The correct specificity value for this selector and its sibling-axis selectors -
toCSS
Prints the selector chain to a StringBuilder, stopping when it hits a selector in the stopAt set. For example, given the selector 'body svg rect' and the stop set contains 'svg' then this will print 'rect' to the builder. This method is used to recreate CSS selectors to pass to SVG or other plugins. FIXME: Does not handle sibling selector. -
getSelectorID
public int getSelectorID() -
setName
-
setPos
public void setPos(int pos) -
setParent
-
setAxis
public void setAxis(int axis) -
setSpecificityB
public void setSpecificityB(int b) -
setSpecificityC
public void setSpecificityC(int c) -
setSpecificityD
public void setSpecificityD(int d) -
setChainedSelector
-
setSiblingSelector
-
setNamespaceURI
-
setAncestorSelector
-
getAncestorSelector
-
toString
For debugging, prints the entire selector chain. FIXME: Does not handle sibling selectors.
-