public interface

CSSPrimitiveValue

implements CSSValue
org.w3c.dom.css.CSSPrimitiveValue

Class Overview

The CSSPrimitiveValue interface represents a single CSS value . This interface may be used to determine the value of a specific style property currently set in a block or to set a specific style property explicitly within the block. An instance of this interface might be obtained from the getPropertyCSSValue method of the CSSStyleDeclaration interface. A CSSPrimitiveValue object only occurs in a context of a CSS property.

Conversions are allowed between absolute values (from millimeters to centimeters, from degrees to radians, and so on) but not between relative values. (For example, a pixel value cannot be converted to a centimeter value.) Percentage values can't be converted since they are relative to the parent value (or another property value). There is one exception for color percentage values: since a color percentage value is relative to the range 0-255, a color percentage value can be converted to a number; (see also the RGBColor interface).

See also the Document Object Model (DOM) Level 2 Style Specification.

Summary

Constants
short CSS_ATTR The value is a attribute function.
short CSS_CM The value is a length (cm).
short CSS_COUNTER The value is a counter or counters function.
short CSS_DEG The value is an angle (deg).
short CSS_DIMENSION The value is a number with an unknown dimension.
short CSS_EMS The value is a length (ems).
short CSS_EXS The value is a length (exs).
short CSS_GRAD The value is an angle (grad).
short CSS_HZ The value is a frequency (Hz).
short CSS_IDENT The value is an identifier.
short CSS_IN The value is a length (in).
short CSS_KHZ The value is a frequency (kHz).
short CSS_MM The value is a length (mm).
short CSS_MS The value is a time (ms).
short CSS_NUMBER The value is a simple number.
short CSS_PC The value is a length (pc).
short CSS_PERCENTAGE The value is a percentage.
short CSS_PT The value is a length (pt).
short CSS_PX The value is a length (px).
short CSS_RAD The value is an angle (rad).
short CSS_RECT The value is a rect function.
short CSS_RGBCOLOR The value is a RGB color.
short CSS_S The value is a time (s).
short CSS_STRING The value is a STRING.
short CSS_UNKNOWN The value is not a recognized CSS2 value.
short CSS_URI The value is a URI.
[Expand]
Inherited Constants
From interface org.w3c.dom.css.CSSValue
Public Methods
abstract Counter getCounterValue()
This method is used to get the Counter value.
abstract float getFloatValue(short unitType)
This method is used to get a float value in a specified unit.
abstract short getPrimitiveType()
The type of the value as defined by the constants specified above.
abstract RGBColor getRGBColorValue()
This method is used to get the RGB color.
abstract Rect getRectValue()
This method is used to get the Rect value.
abstract String getStringValue()
This method is used to get the string value.
abstract void setFloatValue(short unitType, float floatValue)
A method to set the float value with a specified unit.
abstract void setStringValue(short stringType, String stringValue)
A method to set the string value with the specified unit.
[Expand]
Inherited Methods
From interface org.w3c.dom.css.CSSValue

Constants

public static final short CSS_ATTR

The value is a attribute function. The value can be obtained by using the getStringValue method.

Constant Value: 22 (0x00000016)

public static final short CSS_CM

The value is a length (cm). The value can be obtained by using the getFloatValue method.

Constant Value: 6 (0x00000006)

public static final short CSS_COUNTER

The value is a counter or counters function. The value can be obtained by using the getCounterValue method.

Constant Value: 23 (0x00000017)

public static final short CSS_DEG

The value is an angle (deg). The value can be obtained by using the getFloatValue method.

Constant Value: 11 (0x0000000b)

public static final short CSS_DIMENSION

The value is a number with an unknown dimension. The value can be obtained by using the getFloatValue method.

Constant Value: 18 (0x00000012)

public static final short CSS_EMS

The value is a length (ems). The value can be obtained by using the getFloatValue method.

Constant Value: 3 (0x00000003)

public static final short CSS_EXS

The value is a length (exs). The value can be obtained by using the getFloatValue method.

Constant Value: 4 (0x00000004)

public static final short CSS_GRAD

The value is an angle (grad). The value can be obtained by using the getFloatValue method.

Constant Value: 13 (0x0000000d)

public static final short CSS_HZ

The value is a frequency (Hz). The value can be obtained by using the getFloatValue method.

Constant Value: 16 (0x00000010)

public static final short CSS_IDENT

The value is an identifier. The value can be obtained by using the getStringValue method.

Constant Value: 21 (0x00000015)

public static final short CSS_IN

The value is a length (in). The value can be obtained by using the getFloatValue method.

Constant Value: 8 (0x00000008)

public static final short CSS_KHZ

The value is a frequency (kHz). The value can be obtained by using the getFloatValue method.

Constant Value: 17 (0x00000011)

public static final short CSS_MM

The value is a length (mm). The value can be obtained by using the getFloatValue method.

Constant Value: 7 (0x00000007)

public static final short CSS_MS

The value is a time (ms). The value can be obtained by using the getFloatValue method.

Constant Value: 14 (0x0000000e)

public static final short CSS_NUMBER

The value is a simple number. The value can be obtained by using the getFloatValue method.

Constant Value: 1 (0x00000001)

public static final short CSS_PC

The value is a length (pc). The value can be obtained by using the getFloatValue method.

Constant Value: 10 (0x0000000a)

public static final short CSS_PERCENTAGE

The value is a percentage. The value can be obtained by using the getFloatValue method.

Constant Value: 2 (0x00000002)

public static final short CSS_PT

The value is a length (pt). The value can be obtained by using the getFloatValue method.

Constant Value: 9 (0x00000009)

public static final short CSS_PX

The value is a length (px). The value can be obtained by using the getFloatValue method.

Constant Value: 5 (0x00000005)

public static final short CSS_RAD

The value is an angle (rad). The value can be obtained by using the getFloatValue method.

Constant Value: 12 (0x0000000c)

public static final short CSS_RECT

The value is a rect function. The value can be obtained by using the getRectValue method.

Constant Value: 24 (0x00000018)

public static final short CSS_RGBCOLOR

The value is a RGB color. The value can be obtained by using the getRGBColorValue method.

Constant Value: 25 (0x00000019)

public static final short CSS_S

The value is a time (s). The value can be obtained by using the getFloatValue method.

Constant Value: 15 (0x0000000f)

public static final short CSS_STRING

The value is a STRING. The value can be obtained by using the getStringValue method.

Constant Value: 19 (0x00000013)

public static final short CSS_UNKNOWN

The value is not a recognized CSS2 value. The value can only be obtained by using the cssText attribute.

Constant Value: 0 (0x00000000)

public static final short CSS_URI

The value is a URI. The value can be obtained by using the getStringValue method.

Constant Value: 20 (0x00000014)

Public Methods

public abstract Counter getCounterValue ()

This method is used to get the Counter value. If this CSS value doesn't contain a counter value, a DOMException is raised. Modification to the corresponding style property can be achieved using the Counter interface.

Returns
  • The Counter value.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Counter value (e.g. this is not CSS_COUNTER).

public abstract float getFloatValue (short unitType)

This method is used to get a float value in a specified unit. If this CSS value doesn't contain a float value or can't be converted into the specified unit, a DOMException is raised.

Parameters
unitType A unit code to get the float value. The unit code can only be a float unit type (i.e. CSS_NUMBER, CSS_PERCENTAGE, CSS_EMS, CSS_EXS, CSS_PX, CSS_CM, CSS_MM, CSS_IN, CSS_PT, CSS_PC, CSS_DEG, CSS_RAD, CSS_GRAD, CSS_MS, CSS_S, CSS_HZ, CSS_KHZ, CSS_DIMENSION).
Returns
  • The float value in the specified unit.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a float value or if the float value can't be converted into the specified unit.

public abstract short getPrimitiveType ()

The type of the value as defined by the constants specified above.

public abstract RGBColor getRGBColorValue ()

This method is used to get the RGB color. If this CSS value doesn't contain a RGB color value, a DOMException is raised. Modification to the corresponding style property can be achieved using the RGBColor interface.

Returns
  • the RGB color value.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the attached property can't return a RGB color value (e.g. this is not CSS_RGBCOLOR).

public abstract Rect getRectValue ()

This method is used to get the Rect value. If this CSS value doesn't contain a rect value, a DOMException is raised. Modification to the corresponding style property can be achieved using the Rect interface.

Returns
  • The Rect value.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Rect value. (e.g. this is not CSS_RECT).

public abstract String getStringValue ()

This method is used to get the string value. If the CSS value doesn't contain a string value, a DOMException is raised. Some properties (like 'font-family' or 'voice-family') convert a whitespace separated list of idents to a string.

Returns
  • The string value in the current unit. The current primitiveType can only be a string unit type (i.e. CSS_STRING, CSS_URI, CSS_IDENT and CSS_ATTR).
Throws
DOMException INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value.

public abstract void setFloatValue (short unitType, float floatValue)

A method to set the float value with a specified unit. If the property attached with this value can not accept the specified unit or the float value, the value will be unchanged and a DOMException will be raised.

Parameters
unitType A unit code as defined above. The unit code can only be a float unit type (i.e. CSS_NUMBER, CSS_PERCENTAGE, CSS_EMS, CSS_EXS, CSS_PX, CSS_CM, CSS_MM, CSS_IN, CSS_PT, CSS_PC, CSS_DEG, CSS_RAD, CSS_GRAD, CSS_MS, CSS_S, CSS_HZ, CSS_KHZ, CSS_DIMENSION).
floatValue The new float value.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the attached property doesn't support the float value or the unit type.
NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.

public abstract void setStringValue (short stringType, String stringValue)

A method to set the string value with the specified unit. If the property attached to this value can't accept the specified unit or the string value, the value will be unchanged and a DOMException will be raised.

Parameters
stringType A string code as defined above. The string code can only be a string unit type (i.e. CSS_STRING, CSS_URI, CSS_IDENT, and CSS_ATTR).
stringValue The new string value.
Throws
DOMException INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value or if the string value can't be converted into the specified unit.
NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.