Interface CSSColorValue

All Superinterfaces:
Cloneable, CSSPrimitiveValue, CSSTypedValue, CSSValue
All Known Subinterfaces:
HSLColorValue, HWBColorValue, LABColorValue, LCHColorValue, RGBColorValue
All Known Implementing Classes:
ColorValue, HSLColorValue, HWBColorValue, LABColorValue, LCHColorValue, RGBColorValue

public interface CSSColorValue extends CSSTypedValue
Represents a color value (not including color identifiers).

When the value is a COLOR, cast it to this interface, obtain the color with getColor() and cast it to the appropriate sub-interface (like RGBAColor or LABColor) according to the color model given by getColorModel().

For any color model, you can access the color components also through the base CSSColor interface, without the need to cast it to any sub-interface (and there is no sub-interface for PROFILE colors, so in that case you must use the base interface).

  • Method Details

    • getColor

      CSSColor getColor()
      Get the color represented by this value.
      Returns:
      the color.
    • getColorModel

      CSSColorValue.ColorModel getColorModel()
      Get the color model with which this value was set.
      Returns:
      the color model.
    • deltaE2000

      float deltaE2000(CSSColorValue color)
      Compute the difference to the given color, according to CIE Delta E 2000.
      Parameters:
      color - the color to compute the delta from.
      Returns:
      the CIE Delta E 2000.
    • toLABColorValue

      LABColorValue toLABColorValue() throws DOMException
      Convert this value to a LABColorValue, if possible.
      Returns:
      the converted LABColorValue.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted.
    • toLCHColorValue

      LCHColorValue toLCHColorValue() throws DOMException
      Convert this value to a LCHColorValue, if possible.
      Returns:
      the converted LCHColorValue.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted.
    • toRGBColor

      default RGBAColor toRGBColor(boolean clamp) throws DOMException
      Get the RGB(A) color representation of this value.

      The returned value is implicitly in the sRGB color space, unless stated otherwise.

      Parameters:
      clamp - true if the converted value has to be clamped when it does not fall into the sRGB color gamut.
      Returns:
      the RGBA color value.
      Throws:
      DOMException - INVALID_ACCESS_ERR: if this value can't return a RGB color value (either is not a COLOR, not a typed value, or clamp is false and the color does not map into the -implicit- sRGB color space).
      NOT_SUPPORTED_ERR: if the conversion needs device color space information to be performed accurately.
    • clone

      CSSColorValue clone()
      Description copied from interface: CSSValue
      Creates and returns a copy of this value.
      Specified by:
      clone in interface CSSValue
      Returns:
      a clone of this value.