Package org.htmlunit.css
Class CssStyleSheet
- java.lang.Object
-
- org.htmlunit.css.CssStyleSheet
-
- All Implemented Interfaces:
java.io.Serializable
public class CssStyleSheet extends java.lang.Object implements java.io.SerializableA css StyleSheet.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringABSOLUTE"absolute".static java.lang.StringAUTO"auto".static java.lang.StringBLOCK"block".static java.util.Set<java.lang.String>CSS2_PSEUDO_CLASSESSet of CSS2 pseudo class names.private static java.util.Set<java.lang.String>CSS3_PSEUDO_CLASSESstatic java.util.Set<java.lang.String>CSS4_PSEUDO_CLASSESSet of CSS4 pseudo class names.private booleanenabled_static java.lang.StringFIXED"fixed".private java.util.Map<org.htmlunit.cssparser.dom.CSSImportRuleImpl,CssStyleSheet>imports_The CSS import rules and their corresponding stylesheets.static java.lang.StringINHERIT"inherit".static java.lang.StringINITIAL"initial".static java.lang.StringINLINE"inline".private static org.apache.commons.logging.LogLOGprivate static java.util.Map<java.lang.String,org.htmlunit.cssparser.dom.MediaListImpl>media_cache parsed media stringsstatic java.lang.StringNONE"none".private static java.util.regex.PatternNTH_COMPLEXprivate static java.util.regex.PatternNTH_NUMERICprivate HtmlElementowner_The HTML element which owns this stylesheet.static java.lang.StringRELATIVE"relative".static java.lang.StringREPEAT"repeat".static java.lang.StringSCROLL"scroll".static java.lang.StringSTATIC"static".private static java.util.regex.PatternUNESCAPE_SELECTORprivate java.lang.Stringuri_This stylesheet's URI (used to resolved contained @import rules).private org.htmlunit.cssparser.dom.CSSStyleSheetImplwrapped_The parsed stylesheet which this host object wraps.
-
Constructor Summary
Constructors Constructor Description CssStyleSheet(HtmlElement element, java.lang.String styleSheet, java.lang.String uri)Creates a new stylesheet representing the CSS stylesheet for the specified input source.CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.dom.CSSStyleSheetImpl wrapped, java.lang.String uri)Creates a new stylesheet representing the specified CSS stylesheet.CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.parser.InputSource source, java.lang.String uri)Creates a new stylesheet representing the CSS stylesheet for the specified input source.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CssStyleSheetgetImportedStyleSheet(org.htmlunit.cssparser.dom.CSSImportRuleImpl importRule)private static booleangetNthElement(java.lang.String nth, int index)private org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndexgetRuleIndex()java.lang.StringgetUri()Returns this stylesheet's URI (used to resolved contained @import rules).org.htmlunit.cssparser.dom.CSSStyleSheetImplgetWrappedSheet()Returns the wrapped stylesheet.private voidindex(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, org.htmlunit.cssparser.dom.CSSRuleListImpl ruleList, java.util.Set<java.lang.String> alreadyProcessing)booleanisActive()Returnstrueif this stylesheet is active, based on the media types it is associated with (if any).static booleanisActive(org.htmlunit.cssparser.dom.MediaListImpl mediaList, WebWindow webWindow)Returns whether the specifiedMediaListis active or not.private static booleanisActive(org.htmlunit.cssparser.parser.media.MediaQuery mediaQuery, WebWindow webWindow)private static booleanisEmpty(DomElement element)booleanisEnabled()Returnstrueif this stylesheet is enabled.private static booleanisValidCondition(org.htmlunit.cssparser.parser.condition.Condition condition, int documentMode, DomNode domNode)private static booleanisValidSelector(org.htmlunit.cssparser.parser.selector.Selector selector, int documentMode, DomNode domNode)static CssStyleSheetloadStylesheet(HtmlElement element, HtmlLink link, java.lang.String url)Loads the stylesheet at the specified link or href.voidmodifyIfNecessary(ComputedCssStyleDeclaration style, DomElement element, java.lang.String pseudoElement)Modifies the specified style object by adding any style rules which apply to the specified element.private static org.htmlunit.cssparser.dom.CSSStyleSheetImplparseCSS(org.htmlunit.cssparser.parser.InputSource source, WebClient client)Parses the CSS at the specified input source.static org.htmlunit.cssparser.dom.MediaListImplparseMedia(java.lang.String mediaString, WebClient webClient)Parses the given media string.static org.htmlunit.cssparser.dom.MediaListImplparseMedia(org.htmlunit.cssparser.parser.CSSErrorHandler errorHandler, java.lang.String mediaString)Deprecated.as of version 3.8.0; useparseMedia(String, WebClient)insteadprivate static doublepixelValue(org.htmlunit.cssparser.dom.CSSValueImpl cssValue, WebWindow webWindow)private static doubleresolutionValue(org.htmlunit.cssparser.dom.CSSValueImpl cssValue)(package private) static booleanselects(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element, boolean fromQuerySelectorAll, boolean throwOnSyntax)INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returnstrueif the specified condition selects the specified element.static booleanselects(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.selector.Selector selector, DomElement element, java.lang.String pseudoElement, boolean fromQuerySelectorAll, boolean throwOnSyntax)Returnstrueif the specified selector selects the specified element.private java.util.List<org.htmlunit.cssparser.dom.CSSStyleSheetImpl.SelectorEntry>selects(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, BrowserVersion browserVersion, DomElement element, java.lang.String pseudoElement, boolean fromQuerySelectorAll)private static booleanselectsHyphenSeparated(java.lang.String condition, java.lang.String attribute)private static booleanselectsOneOf(java.lang.String condition, java.lang.String attribute)private static booleanselectsPseudoClass(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element)private static booleanselectsWhitespaceSeparated(java.lang.String condition, java.lang.String attribute)voidsetEnabled(boolean enabled)Sets whether this sheet is enabled or not.private static java.lang.StringtoString(org.htmlunit.cssparser.parser.InputSource source)Returns the contents of the specified input source, ignoring anyIOExceptions.static voidvalidateSelectors(org.htmlunit.cssparser.parser.selector.SelectorList selectorList, int documentMode, DomNode domNode)Validates the list of selectors.
-
-
-
Field Detail
-
NONE
public static final java.lang.String NONE
"none".- See Also:
- Constant Field Values
-
AUTO
public static final java.lang.String AUTO
"auto".- See Also:
- Constant Field Values
-
STATIC
public static final java.lang.String STATIC
"static".- See Also:
- Constant Field Values
-
INHERIT
public static final java.lang.String INHERIT
"inherit".- See Also:
- Constant Field Values
-
INITIAL
public static final java.lang.String INITIAL
"initial".- See Also:
- Constant Field Values
-
RELATIVE
public static final java.lang.String RELATIVE
"relative".- See Also:
- Constant Field Values
-
FIXED
public static final java.lang.String FIXED
"fixed".- See Also:
- Constant Field Values
-
ABSOLUTE
public static final java.lang.String ABSOLUTE
"absolute".- See Also:
- Constant Field Values
-
REPEAT
public static final java.lang.String REPEAT
"repeat".- See Also:
- Constant Field Values
-
BLOCK
public static final java.lang.String BLOCK
"block".- See Also:
- Constant Field Values
-
INLINE
public static final java.lang.String INLINE
"inline".- See Also:
- Constant Field Values
-
SCROLL
public static final java.lang.String SCROLL
"scroll".- See Also:
- Constant Field Values
-
LOG
private static final org.apache.commons.logging.Log LOG
-
NTH_NUMERIC
private static final java.util.regex.Pattern NTH_NUMERIC
-
NTH_COMPLEX
private static final java.util.regex.Pattern NTH_COMPLEX
-
UNESCAPE_SELECTOR
private static final java.util.regex.Pattern UNESCAPE_SELECTOR
-
wrapped_
private final org.htmlunit.cssparser.dom.CSSStyleSheetImpl wrapped_
The parsed stylesheet which this host object wraps.
-
owner_
private final HtmlElement owner_
The HTML element which owns this stylesheet.
-
imports_
private final java.util.Map<org.htmlunit.cssparser.dom.CSSImportRuleImpl,CssStyleSheet> imports_
The CSS import rules and their corresponding stylesheets.
-
media_
private static final transient java.util.Map<java.lang.String,org.htmlunit.cssparser.dom.MediaListImpl> media_
cache parsed media strings
-
uri_
private final java.lang.String uri_
This stylesheet's URI (used to resolved contained @import rules).
-
enabled_
private boolean enabled_
-
CSS2_PSEUDO_CLASSES
public static final java.util.Set<java.lang.String> CSS2_PSEUDO_CLASSES
Set of CSS2 pseudo class names.
-
CSS3_PSEUDO_CLASSES
private static final java.util.Set<java.lang.String> CSS3_PSEUDO_CLASSES
-
CSS4_PSEUDO_CLASSES
public static final java.util.Set<java.lang.String> CSS4_PSEUDO_CLASSES
Set of CSS4 pseudo class names.
-
-
Constructor Detail
-
CssStyleSheet
public CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.parser.InputSource source, java.lang.String uri)
Creates a new stylesheet representing the CSS stylesheet for the specified input source.- Parameters:
element- the owning nodesource- the input source which contains the CSS stylesheet which this stylesheet host object representsuri- this stylesheet's URI (used to resolved contained @import rules)
-
CssStyleSheet
public CssStyleSheet(HtmlElement element, java.lang.String styleSheet, java.lang.String uri)
Creates a new stylesheet representing the CSS stylesheet for the specified input source.- Parameters:
element- the owning nodestyleSheet- the source which contains the CSS stylesheet which this stylesheet host object representsuri- this stylesheet's URI (used to resolved contained @import rules)
-
CssStyleSheet
public CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.dom.CSSStyleSheetImpl wrapped, java.lang.String uri)
Creates a new stylesheet representing the specified CSS stylesheet.- Parameters:
element- the owning nodewrapped- the CSS stylesheet which this stylesheet host object representsuri- this stylesheet's URI (used to resolved contained @import rules)
-
-
Method Detail
-
getWrappedSheet
public org.htmlunit.cssparser.dom.CSSStyleSheetImpl getWrappedSheet()
Returns the wrapped stylesheet.- Returns:
- the wrapped stylesheet
-
getUri
public java.lang.String getUri()
Returns this stylesheet's URI (used to resolved contained @import rules). For inline styles this is the page uri.- Returns:
- this stylesheet's URI (used to resolved contained @import rules)
-
isEnabled
public boolean isEnabled()
Returnstrueif this stylesheet is enabled.- Returns:
trueif this stylesheet is enabled
-
setEnabled
public void setEnabled(boolean enabled)
Sets whether this sheet is enabled or not.- Parameters:
enabled- enabled or not
-
loadStylesheet
public static CssStyleSheet loadStylesheet(HtmlElement element, HtmlLink link, java.lang.String url)
Loads the stylesheet at the specified link or href.- Parameters:
element- the parent DOM elementlink- the stylesheet's link (may benullif aurlis specified)url- the stylesheet's url (may benullif alinkis specified)- Returns:
- the loaded stylesheet
-
selects
public static boolean selects(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.selector.Selector selector, DomElement element, java.lang.String pseudoElement, boolean fromQuerySelectorAll, boolean throwOnSyntax)
Returnstrueif the specified selector selects the specified element.- Parameters:
browserVersion- the browser versionselector- the selector to testelement- the element to testpseudoElement- the pseudo element to match, (can benull)fromQuerySelectorAll- whether this is called fromDomNode.querySelectorAll(String)throwOnSyntax- throw exception if the selector syntax is incorrect- Returns:
trueif it does apply,falseif it doesn't apply
-
selects
static boolean selects(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element, boolean fromQuerySelectorAll, boolean throwOnSyntax)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returnstrueif the specified condition selects the specified element.- Parameters:
browserVersion- the browser versioncondition- the condition to testelement- the element to testfromQuerySelectorAll- whether this is called fromDomNode.querySelectorAll(String)throwOnSyntax- throw exception if the selector syntax is incorrect- Returns:
trueif it does apply,falseif it doesn't apply
-
selectsOneOf
private static boolean selectsOneOf(java.lang.String condition, java.lang.String attribute)
-
selectsHyphenSeparated
private static boolean selectsHyphenSeparated(java.lang.String condition, java.lang.String attribute)
-
selectsWhitespaceSeparated
private static boolean selectsWhitespaceSeparated(java.lang.String condition, java.lang.String attribute)
-
selectsPseudoClass
private static boolean selectsPseudoClass(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element)
-
isEmpty
private static boolean isEmpty(DomElement element)
-
getNthElement
private static boolean getNthElement(java.lang.String nth, int index)
-
parseCSS
private static org.htmlunit.cssparser.dom.CSSStyleSheetImpl parseCSS(org.htmlunit.cssparser.parser.InputSource source, WebClient client)Parses the CSS at the specified input source. If anything at all goes wrong, this method returns an empty stylesheet.- Parameters:
source- the source from which to retrieve the CSS to be parsedclient- the client- Returns:
- the stylesheet parsed from the specified input source
-
parseMedia
public static org.htmlunit.cssparser.dom.MediaListImpl parseMedia(java.lang.String mediaString, WebClient webClient)Parses the given media string. If anything at all goes wrong, this method returns an empty MediaList list.- Parameters:
mediaString- the source from which to retrieve the media to be parsedwebClient- theWebClientto be used- Returns:
- the media parsed from the specified input source
-
parseMedia
@Deprecated public static org.htmlunit.cssparser.dom.MediaListImpl parseMedia(org.htmlunit.cssparser.parser.CSSErrorHandler errorHandler, java.lang.String mediaString)Deprecated.as of version 3.8.0; useparseMedia(String, WebClient)insteadParses the given media string. If anything at all goes wrong, this method returns an empty MediaList list.- Parameters:
mediaString- the source from which to retrieve the media to be parsederrorHandler- theCSSErrorHandlerto be used- Returns:
- the media parsed from the specified input source
-
toString
private static java.lang.String toString(org.htmlunit.cssparser.parser.InputSource source)
Returns the contents of the specified input source, ignoring anyIOExceptions.- Parameters:
source- the input source from which to read- Returns:
- the contents of the specified input source, or an empty string if an
IOExceptionoccurs
-
validateSelectors
public static void validateSelectors(org.htmlunit.cssparser.parser.selector.SelectorList selectorList, int documentMode, DomNode domNode) throws org.htmlunit.cssparser.parser.CSSExceptionValidates the list of selectors.- Parameters:
selectorList- the selectorsdocumentMode- seeDocument.getDocumentMode()domNode- the dom node the query should work on- Throws:
org.htmlunit.cssparser.parser.CSSException- if a selector is invalid
-
isValidSelector
private static boolean isValidSelector(org.htmlunit.cssparser.parser.selector.Selector selector, int documentMode, DomNode domNode)- Parameters:
documentMode- seeDocument.getDocumentMode()
-
isValidCondition
private static boolean isValidCondition(org.htmlunit.cssparser.parser.condition.Condition condition, int documentMode, DomNode domNode)- Parameters:
documentMode- seeDocument.getDocumentMode()
-
getImportedStyleSheet
public CssStyleSheet getImportedStyleSheet(org.htmlunit.cssparser.dom.CSSImportRuleImpl importRule)
-
isActive
public boolean isActive()
Returnstrueif this stylesheet is active, based on the media types it is associated with (if any).- Returns:
trueif this stylesheet is active, based on the media types it is associated with (if any)
-
isActive
public static boolean isActive(org.htmlunit.cssparser.dom.MediaListImpl mediaList, WebWindow webWindow)Returns whether the specifiedMediaListis active or not.
-
isActive
private static boolean isActive(org.htmlunit.cssparser.parser.media.MediaQuery mediaQuery, WebWindow webWindow)
-
pixelValue
private static double pixelValue(org.htmlunit.cssparser.dom.CSSValueImpl cssValue, WebWindow webWindow)
-
resolutionValue
private static double resolutionValue(org.htmlunit.cssparser.dom.CSSValueImpl cssValue)
-
modifyIfNecessary
public void modifyIfNecessary(ComputedCssStyleDeclaration style, DomElement element, java.lang.String pseudoElement)
Modifies the specified style object by adding any style rules which apply to the specified element.- Parameters:
style- the style to modifyelement- the element to which style rules must apply in order for them to be added to the specified stylepseudoElement- a string specifying the pseudo-element to match (may benull)
-
getRuleIndex
private org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex getRuleIndex()
-
index
private void index(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, org.htmlunit.cssparser.dom.CSSRuleListImpl ruleList, java.util.Set<java.lang.String> alreadyProcessing)
-
selects
private java.util.List<org.htmlunit.cssparser.dom.CSSStyleSheetImpl.SelectorEntry> selects(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, BrowserVersion browserVersion, DomElement element, java.lang.String pseudoElement, boolean fromQuerySelectorAll)
-
-