Class CssStyleSheet
java.lang.Object
org.htmlunit.css.CssStyleSheet
- All Implemented Interfaces:
Serializable
A css StyleSheet.
- Author:
- Marc Guillemot, Daniel Gredler, Ahmed Ashour, Ronald Brill, Guy Burton, Frank Danek, Carsten Steul
- 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.static final String"fixed".static final String"inherit".static final String"initial".static final String"inline".static final String"none".static final String"relative".static final String"repeat".static final String"scroll".static final String"static". -
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) getUri()Returns this stylesheet's URI (used to resolved contained @import rules).org.htmlunit.cssparser.dom.CSSStyleSheetImplReturns the wrapped stylesheet.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.booleanReturnstrueif this stylesheet is enabled.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.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.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.voidsetEnabled(boolean enabled) Sets whether this sheet is enabled or not.static voidvalidateSelectors(org.htmlunit.cssparser.parser.selector.SelectorList selectorList, int documentMode, DomNode domNode) Validates the list of selectors.
-
Field Details
-
NONE
-
AUTO
-
STATIC
-
INHERIT
-
INITIAL
-
RELATIVE
-
FIXED
-
ABSOLUTE
-
REPEAT
-
BLOCK
-
INLINE
-
SCROLL
-
CSS2_PSEUDO_CLASSES
-
CSS4_PSEUDO_CLASSES
-
-
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
-
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
-
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
-
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
-
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)
-
parseMedia(String, WebClient)instead