Package org.htmlunit.css
Class CssStyleSheet
java.lang.Object
org.htmlunit.css.CssStyleSheet
- All Implemented Interfaces:
Serializable
A css StyleSheet.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String"absolute".static final String"auto".static final String"block".Set of CSS2 pseudo class names.Set of CSS4 pseudo class names.private booleanstatic final String"fixed".private final Map<org.htmlunit.cssparser.dom.CSSImportRuleImpl, CssStyleSheet> The CSS import rules and their corresponding stylesheets.static final String"inherit".static final String"initial".static final String"inline".private static final org.apache.commons.logging.Logcache parsed media stringsstatic final String"none".private static final Patternprivate static final Patternprivate final HtmlElementThe HTML element which owns this stylesheet.static final String"relative".static final String"repeat".static final String"scroll".static final String"static".private static final Patternprivate final StringThis stylesheet's URI (used to resolved contained @import rules).private final org.htmlunit.cssparser.dom.CSSStyleSheetImplThe parsed stylesheet which this host object wraps. -
Constructor Summary
ConstructorsConstructorDescriptionCssStyleSheet(HtmlElement element, String styleSheet, String uri) Creates a new stylesheet representing the CSS stylesheet for the specified input source.CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.dom.CSSStyleSheetImpl wrapped, String uri) Creates a new stylesheet representing the specified CSS stylesheet.CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.parser.InputSource source, String uri) Creates a new stylesheet representing the CSS stylesheet for the specified input source. -
Method Summary
Modifier and TypeMethodDescriptiongetImportedStyleSheet(org.htmlunit.cssparser.dom.CSSImportRuleImpl importRule) private static booleangetNthElement(String nth, int index) private org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndexgetUri()Returns this stylesheet's URI (used to resolved contained @import rules).org.htmlunit.cssparser.dom.CSSStyleSheetImplReturns the wrapped stylesheet.private voidindex(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, org.htmlunit.cssparser.dom.CSSRuleListImpl ruleList, Set<String> alreadyProcessing) booleanisActive()Returnstrueif this stylesheet is active, based on the media types it is associated with (if any).static booleanReturns whether the specifiedMediaListis active or not.private static booleanprivate static booleanisEmpty(DomElement element) booleanReturnstrueif 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, String url) Loads the stylesheet at the specified link or href.voidmodifyIfNecessary(ComputedCssStyleDeclaration style, DomElement element, String pseudoElement) Modifies the specified style object by adding any style rules which apply to the specified element.private static org.htmlunit.cssparser.dom.CSSStyleSheetImplParses the CSS at the specified input source.static org.htmlunit.cssparser.dom.MediaListImplparseMedia(String mediaString, WebClient webClient) Parses the given media string.static org.htmlunit.cssparser.dom.MediaListImplparseMedia(org.htmlunit.cssparser.parser.CSSErrorHandler errorHandler, String mediaString) Deprecated.private 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, String pseudoElement, boolean fromQuerySelectorAll, boolean throwOnSyntax) Returnstrueif the specified selector selects the specified element.private List<org.htmlunit.cssparser.dom.CSSStyleSheetImpl.SelectorEntry> selects(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, BrowserVersion browserVersion, DomElement element, String pseudoElement, boolean fromQuerySelectorAll) private static booleanselectsHyphenSeparated(String condition, String attribute) private static booleanselectsOneOf(String condition, String attribute) private static booleanselectsPseudoClass(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element) private static booleanselectsWhitespaceSeparated(String condition, String attribute) voidsetEnabled(boolean enabled) Sets whether this sheet is enabled or not.private static 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 Details
-
NONE
"none".- See Also:
-
AUTO
"auto".- See Also:
-
STATIC
"static".- See Also:
-
INHERIT
"inherit".- See Also:
-
INITIAL
"initial".- See Also:
-
RELATIVE
"relative".- See Also:
-
FIXED
"fixed".- See Also:
-
ABSOLUTE
"absolute".- See Also:
-
REPEAT
"repeat".- See Also:
-
BLOCK
"block".- See Also:
-
INLINE
"inline".- See Also:
-
SCROLL
"scroll".- See Also:
-
LOG
private static final org.apache.commons.logging.Log LOG -
NTH_NUMERIC
-
NTH_COMPLEX
-
UNESCAPE_SELECTOR
-
wrapped_
private final org.htmlunit.cssparser.dom.CSSStyleSheetImpl wrapped_The parsed stylesheet which this host object wraps. -
owner_
The HTML element which owns this stylesheet. -
imports_
The CSS import rules and their corresponding stylesheets. -
media_
cache parsed media strings -
uri_
This stylesheet's URI (used to resolved contained @import rules). -
enabled_
private boolean enabled_ -
CSS2_PSEUDO_CLASSES
Set of CSS2 pseudo class names. -
CSS3_PSEUDO_CLASSES
-
CSS4_PSEUDO_CLASSES
Set of CSS4 pseudo class names.
-
-
Constructor Details
-
CssStyleSheet
public CssStyleSheet(HtmlElement element, org.htmlunit.cssparser.parser.InputSource source, 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
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, 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 Details
-
getWrappedSheet
public org.htmlunit.cssparser.dom.CSSStyleSheetImpl getWrappedSheet()Returns the wrapped stylesheet.- Returns:
- the wrapped stylesheet
-
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
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, 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
-
selectsHyphenSeparated
-
selectsWhitespaceSeparated
-
selectsPseudoClass
private static boolean selectsPseudoClass(BrowserVersion browserVersion, org.htmlunit.cssparser.parser.condition.Condition condition, DomElement element) -
isEmpty
-
getNthElement
-
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(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, 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:
errorHandler- theCSSErrorHandlerto be usedmediaString- the source from which to retrieve the media to be parsed- Returns:
- the media parsed from the specified input source
-
toString
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.CSSException Validates 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
-
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, 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
-
selects
private List<org.htmlunit.cssparser.dom.CSSStyleSheetImpl.SelectorEntry> selects(org.htmlunit.cssparser.dom.CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, BrowserVersion browserVersion, DomElement element, String pseudoElement, boolean fromQuerySelectorAll)
-
parseMedia(String, WebClient)instead