Package com.openhtmltopdf.css.newmatch
Class CascadedStyle
- java.lang.Object
-
- com.openhtmltopdf.css.newmatch.CascadedStyle
-
public class CascadedStyle extends java.lang.ObjectHolds a set ofPropertyDeclarations for each unique CSS property name. What properties belong in the set is not determined, except that multiple entries are resolved into a single set using cascading rules. The set is cascaded during instantiation, so once you have a CascadedStyle, the PropertyDeclarations you retrieve from it will have been resolved following the CSS cascading rules. Note that this class knows nothing about CSS selector-matching rules. Before creating a CascadedStyle, you will need to determine which PropertyDeclarations belong in the set--for example, by matchingRulesets toDocumentElements via their selectors. You can get individual properties by usingpropertyByName(CSSName)or anIteratorof properties withgetCascadedPropertyDeclarations(). Check for individual property assignments usinghasProperty(CSSName). A CascadedStyle is immutable, as properties can not be added or removed from it once instantiated.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<CSSName,PropertyDeclaration>cascadedPropertiesMap of PropertyDeclarations, keyed byCSSNamestatic CascadedStyleemptyCascadedStyleGet an empty singleton, used to negate inheritance of propertiesprivate java.lang.Stringfingerprint
-
Constructor Summary
Constructors Modifier Constructor Description privateCascadedStyle()Default constructor with no initialization.privateCascadedStyle(CascadedStyle startingPoint, java.util.Iterator<PropertyDeclaration> props)(package private)CascadedStyle(java.util.Iterator<PropertyDeclaration> iter)Constructs a new CascadedStyle, given anIteratorofPropertyDeclarations already sorted by specificity of the CSS selector they came from.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddProperties(java.util.Iterator<PropertyDeclaration> iter)intcountAssigned()static CascadedStylecreateAnonymousStyle(IdentValue display)Creates an otherwise emptyCascadedStyle, setting the display property to the value of thedisplayparameter.static PropertyDeclarationcreateLayoutPropertyDeclaration(CSSName cssName, IdentValue display)Creates aPropertyDeclarationsuitable for passing tocreateLayoutStyle(PropertyDeclaration[])orcreateLayoutStyle(CascadedStyle, PropertyDeclaration[])static CascadedStylecreateLayoutStyle(CascadedStyle startingPoint, PropertyDeclaration[] decls)Creates aCascadedStyleusing style information fromstartingPointand then adding the property declarations fromdecls.static CascadedStylecreateLayoutStyle(PropertyDeclaration[] decls)Creates aCascadedStyleusing the provided property declarations.static CascadedStylecreateLayoutStyle(java.util.List<PropertyDeclaration> decls)java.util.Collection<PropertyDeclaration>getCascadedPropertyDeclarations()Returns anIteratorover the set ofPropertyDeclarations already matched in this CascadedStyle.java.lang.StringgetFingerprint()IdentValuegetIdent(CSSName cssName)Gets the ident attribute of the CascadedStyle objectbooleanhasProperty(CSSName cssName)Returns true if property has been defined in this style.PropertyDeclarationpropertyByName(CSSName cssName)Returns aPropertyDeclarationby CSS property name, e.g.
-
-
-
Field Detail
-
cascadedProperties
private final java.util.Map<CSSName,PropertyDeclaration> cascadedProperties
Map of PropertyDeclarations, keyed byCSSName
-
fingerprint
private java.lang.String fingerprint
-
emptyCascadedStyle
public static final CascadedStyle emptyCascadedStyle
Get an empty singleton, used to negate inheritance of properties
-
-
Constructor Detail
-
CascadedStyle
CascadedStyle(java.util.Iterator<PropertyDeclaration> iter)
Constructs a new CascadedStyle, given anIteratorofPropertyDeclarations already sorted by specificity of the CSS selector they came from. The Iterator can have multiple PropertyDeclarations with the same name; the property cascade will be resolved during instantiation, resulting in a set of PropertyDeclarations. Once instantiated, properties may be retrieved using the normal API for the class.- Parameters:
iter- An Iterator containing PropertyDeclarations in order of specificity.
-
CascadedStyle
private CascadedStyle(CascadedStyle startingPoint, java.util.Iterator<PropertyDeclaration> props)
-
CascadedStyle
private CascadedStyle()
Default constructor with no initialization. Don't use this to instantiate the class, as the class is immutable and this will leave it without any properties.
-
-
Method Detail
-
createLayoutStyle
public static CascadedStyle createLayoutStyle(PropertyDeclaration[] decls)
Creates aCascadedStyleusing the provided property declarations. It is used when a box requires a style that does not correspond to anything in the parsed stylesheets.- Parameters:
decls- An array of PropertyDeclaration objects created withcreateLayoutPropertyDeclaration(CSSName, IdentValue)- See Also:
createLayoutPropertyDeclaration(CSSName, IdentValue)
-
createLayoutStyle
public static CascadedStyle createLayoutStyle(java.util.List<PropertyDeclaration> decls)
-
createLayoutStyle
public static CascadedStyle createLayoutStyle(CascadedStyle startingPoint, PropertyDeclaration[] decls)
Creates aCascadedStyleusing style information fromstartingPointand then adding the property declarations fromdecls.- Parameters:
decls- An array of PropertyDeclaration objects created withcreateLayoutPropertyDeclaration(CSSName, IdentValue)- See Also:
createLayoutPropertyDeclaration(CSSName, IdentValue)
-
createLayoutPropertyDeclaration
public static PropertyDeclaration createLayoutPropertyDeclaration(CSSName cssName, IdentValue display)
Creates aPropertyDeclarationsuitable for passing tocreateLayoutStyle(PropertyDeclaration[])orcreateLayoutStyle(CascadedStyle, PropertyDeclaration[])
-
createAnonymousStyle
public static CascadedStyle createAnonymousStyle(IdentValue display)
Creates an otherwise emptyCascadedStyle, setting the display property to the value of thedisplayparameter.
-
addProperties
private void addProperties(java.util.Iterator<PropertyDeclaration> iter)
-
hasProperty
public boolean hasProperty(CSSName cssName)
Returns true if property has been defined in this style.- Parameters:
cssName- The CSS property name, e.g. "font-family".- Returns:
- True if the property is defined in this set.
-
propertyByName
public PropertyDeclaration propertyByName(CSSName cssName)
Returns aPropertyDeclarationby CSS property name, e.g. "font-family". Properties are already cascaded during instantiation, so this will return the actual property (and corresponding value) to use for CSS-based layout and rendering.- Parameters:
cssName- The CSS property name, e.g. "font-family".- Returns:
- The PropertyDeclaration, if declared in this set, or null if not found.
-
getIdent
public IdentValue getIdent(CSSName cssName)
Gets the ident attribute of the CascadedStyle object- Parameters:
cssName- PARAM- Returns:
- The ident value
-
getCascadedPropertyDeclarations
public java.util.Collection<PropertyDeclaration> getCascadedPropertyDeclarations()
Returns anIteratorover the set ofPropertyDeclarations already matched in this CascadedStyle. For a given property name, there may be no match, in which case there will be noPropertyDeclarationfor that property name in the Iterator.- Returns:
- Iterator over a set of properly cascaded PropertyDeclarations.
-
countAssigned
public int countAssigned()
-
getFingerprint
public java.lang.String getFingerprint()
-
-