Class CssStyleSheet

java.lang.Object
org.htmlunit.css.CssStyleSheet
All Implemented Interfaces:
Serializable

public class CssStyleSheet extends Object implements Serializable
A css StyleSheet.
Author:
Marc Guillemot, Daniel Gredler, Ahmed Ashour, Ronald Brill, Guy Burton, Frank Danek, Carsten Steul
See Also:
  • Field Details

  • 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 node
      source - the input source which contains the CSS stylesheet which this stylesheet host object represents
      uri - this stylesheet's URI (used to resolved contained @import rules)
    • CssStyleSheet

      public CssStyleSheet(HtmlElement element, String styleSheet, String uri)
      Creates a new stylesheet representing the CSS stylesheet for the specified input source.
      Parameters:
      element - the owning node
      styleSheet - the source which contains the CSS stylesheet which this stylesheet host object represents
      uri - 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 node
      wrapped - the CSS stylesheet which this stylesheet host object represents
      uri - 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

      public 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()
      Returns true if this stylesheet is enabled.
      Returns:
      true if 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, String url)
      Loads the stylesheet at the specified link or href.
      Parameters:
      element - the parent DOM element
      link - the stylesheet's link (may be null if a url is specified)
      url - the stylesheet's url (may be null if a link is 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)
      Returns true if the specified selector selects the specified element.
      Parameters:
      browserVersion - the browser version
      selector - the selector to test
      element - the element to test
      pseudoElement - the pseudo element to match, (can be null)
      fromQuerySelectorAll - whether this is called from DomNode.querySelectorAll(String)
      throwOnSyntax - throw exception if the selector syntax is incorrect
      Returns:
      true if it does apply, false if 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 parsed
      webClient - the WebClient to 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; use parseMedia(String, WebClient) instead
      Parses the given media string. If anything at all goes wrong, this method returns an empty MediaList list.
      Parameters:
      errorHandler - the CSSErrorHandler to be used
      mediaString - 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 selectors
      documentMode - see Document.getDocumentMode()
      domNode - the dom node the query should work on
      Throws:
      org.htmlunit.cssparser.parser.CSSException - if a selector is invalid
    • getImportedStyleSheet

      public CssStyleSheet getImportedStyleSheet(org.htmlunit.cssparser.dom.CSSImportRuleImpl importRule)
    • isActive

      public boolean isActive()
      Returns true if this stylesheet is active, based on the media types it is associated with (if any).
      Returns:
      true if 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 specified MediaList is active or not.
      Parameters:
      mediaList - the media list
      webWindow - the WebWindow for some basic data
      Returns:
      whether the specified MediaList is active or not
    • 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 modify
      element - the element to which style rules must apply in order for them to be added to the specified style
      pseudoElement - a string specifying the pseudo-element to match (may be null)