Package com.openhtmltopdf.css.newmatch
Class Selector
java.lang.Object
com.openhtmltopdf.css.newmatch.Selector
A Selector is really a chain of CSS selectors that all need to be valid for
the selector to match.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Selector
private int
private String
private String
private Ruleset
private int
private String
private int
private int
private int
private int
static final int
private Selector
static final int
static final int
static final int
static final int
static final int
private static int
private int
Give each a unique ID to be able to create a key to internalize Matcher.Mappersprivate Selector
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeEqualsCondition
(String namespaceURI, String name, String value) the CSS condition [attribute=value]void
addAttributeExistsCondition
(String namespaceURI, String name) the CSS condition [attribute]void
addAttributeMatchesFirstPartCondition
(String namespaceURI, String name, String value) the CSS condition [attribute|=value]void
addAttributeMatchesListCondition
(String namespaceURI, String name, String value) the CSS condition [attribute~=value]void
addAttributePrefixCondition
(String namespaceURI, String name, String value) the CSS condition [attribute^=value]void
addAttributeSubstringCondition
(String namespaceURI, String name, String value) the CSS condition [attribute*=value]void
addAttributeSuffixCondition
(String namespaceURI, String name, String value) the CSS condition [attribute$=value]void
addClassCondition
(String className) the CSS condition .classprivate void
Adds a feature to the Condition attribute of the Selector objectvoid
the CSS condition that element has pseudo-class :evenvoid
the CSS condition that element has pseudo-class :first-childvoid
addIDCondition
(String id) the CSS condition #IDvoid
addLangCondition
(String lang) the CSS condition :lang(Xx)void
the CSS condition that element has pseudo-class :last-childvoid
the CSS condition that element has pseudo-class :linkvoid
addNthChildCondition
(String number) the CSS condition that element has pseudo-class :nth-child(an+b)void
the CSS condition that element has pseudo-class :oddvoid
for unsupported or invalid CSS(package private) Object
getAppropriateSibling
(Object e, TreeResolver treeRes) Gets the appropriateSibling attribute of the Selector objectint
getAxis()
get the axis that this selector should be evaluated onget the next selector in the chain, for matching against elements along the appropriate axis(package private) static String
Gets the elementStylingOrder attribute of the Selector class(package private) String
getOrder()
returns "a number in a large base" with specificity and specification order of selectorGets the pseudoElement attribute of the Selector objectget the Ruleset that this Selector is part ofint
int
The correct specificity value for this selector and its sibling-axis selectorsint
The correct specificity value for this selector and its sibling-axis selectorsint
The correct specificity value for this selector and its sibling-axis selectorsboolean
isPseudoClass
(int pc) query if a pseudoclass must apply for this selectorboolean
matches
(Object e, AttributeResolver attRes, TreeResolver treeRes) Check if the given Element matches this selector.boolean
matchesDynamic
(Object e, AttributeResolver attRes, TreeResolver treeRes) Check if the given Element matches this selector's dynamic properties.void
setAncestorSelector
(Selector ancestor) void
setAxis
(int axis) void
setChainedSelector
(Selector selector) void
void
setNamespaceURI
(String namespaceURI) void
void
setPos
(int pos) void
setPseudoClass
(int pc) set which pseudoclasses must apply for this selectorvoid
setPseudoElement
(String pseudoElement) check if selector queries for dynamic propertiesvoid
setSiblingSelector
(Selector selector) void
setSpecificityB
(int b) void
setSpecificityC
(int c) void
setSpecificityD
(int d) void
toCSS
(StringBuilder sb, Set<Selector> stopAt) Prints the selector chain to a StringBuilder, stopping when it hits a selector in the stopAt set.toString()
For debugging, prints the entire selector chain.
-
Field Details
-
_parent
-
chainedSelector
-
siblingSelector
-
_axis
private int _axis -
_name
-
_namespaceURI
-
_pc
private int _pc -
_pe
-
_specificityB
private int _specificityB -
_specificityC
private int _specificityC -
_specificityD
private int _specificityD -
_pos
private int _pos -
conditions
-
DESCENDANT_AXIS
public static final int DESCENDANT_AXIS- See Also:
-
CHILD_AXIS
public static final int CHILD_AXIS- See Also:
-
IMMEDIATE_SIBLING_AXIS
public static final int IMMEDIATE_SIBLING_AXIS- See Also:
-
VISITED_PSEUDOCLASS
public static final int VISITED_PSEUDOCLASS- See Also:
-
HOVER_PSEUDOCLASS
public static final int HOVER_PSEUDOCLASS- See Also:
-
ACTIVE_PSEUDOCLASS
public static final int ACTIVE_PSEUDOCLASS- See Also:
-
FOCUS_PSEUDOCLASS
public static final int FOCUS_PSEUDOCLASS- See Also:
-
selectorID
private int selectorIDGive each a unique ID to be able to create a key to internalize Matcher.Mappers -
_ancestorSelector
-
selectorCount
private static int selectorCount
-
-
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 -
getOrder
String getOrder()returns "a number in a large base" with specificity and specification order of selector- Returns:
- The order value
-
getAppropriateSibling
Gets the appropriateSibling attribute of the Selector object- Parameters:
e
- PARAMtreeRes
-- Returns:
- The appropriateSibling value
-
addCondition
Adds a feature to the Condition attribute of the Selector object- Parameters:
c
- The feature to be added to the Condition attribute
-
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. -
getElementStylingOrder
Gets the elementStylingOrder attribute of the Selector class- Returns:
- The elementStylingOrder value
-
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.
-