- All Superinterfaces:
CSSValue
public interface CSSPrimitiveValue extends CSSValue
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.
- Since:
- 1.4, DOM Level 2
-
Field Summary
Fields Modifier and Type Field Description static shortCSS_ATTRThe value is a attribute function.static shortCSS_CMThe value is a length (cm).static shortCSS_COUNTERThe value is a counter or counters function.static shortCSS_DEGThe value is an angle (deg).static shortCSS_DIMENSIONThe value is a number with an unknown dimension.static shortCSS_EMSThe value is a length (ems).static shortCSS_EXSThe value is a length (exs).static shortCSS_GRADThe value is an angle (grad).static shortCSS_HZThe value is a frequency (Hz).static shortCSS_IDENTThe value is an identifier.static shortCSS_INThe value is a length (in).static shortCSS_KHZThe value is a frequency (kHz).static shortCSS_MMThe value is a length (mm).static shortCSS_MSThe value is a time (ms).static shortCSS_NUMBERThe value is a simple number.static shortCSS_PCThe value is a length (pc).static shortCSS_PERCENTAGEThe value is a percentage.static shortCSS_PTThe value is a length (pt).static shortCSS_PXThe value is a length (px).static shortCSS_RADThe value is an angle (rad).static shortCSS_RECTThe value is a rect function.static shortCSS_RGBCOLORThe value is a RGB color.static shortCSS_SThe value is a time (s).static shortCSS_STRINGThe value is a STRING.static shortCSS_UNKNOWNThe value is not a recognized CSS2 value.static shortCSS_URIThe value is a URI.Fields declared in interface org.w3c.dom.css.CSSValue
CSS_CUSTOM, CSS_INHERIT, CSS_PRIMITIVE_VALUE, CSS_VALUE_LIST -
Method Summary
Modifier and Type Method Description CountergetCounterValue()This method is used to get the Counter value.floatgetFloatValue(short unitType)This method is used to get a float value in a specified unit.shortgetPrimitiveType()The type of the value as defined by the constants specified above.RectgetRectValue()This method is used to get the Rect value.RGBColorgetRGBColorValue()This method is used to get the RGB color.StringgetStringValue()This method is used to get the string value.voidsetFloatValue(short unitType, float floatValue)A method to set the float value with a specified unit.voidsetStringValue(short stringType, String stringValue)A method to set the string value with the specified unit.
-
Field Details
-
CSS_UNKNOWN
static final short CSS_UNKNOWNThe value is not a recognized CSS2 value. The value can only be obtained by using thecssTextattribute.- See Also:
- Constant Field Values
-
CSS_NUMBER
static final short CSS_NUMBERThe value is a simple number. The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_PERCENTAGE
static final short CSS_PERCENTAGEThe value is a percentage. The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_EMS
static final short CSS_EMSThe value is a length (ems). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_EXS
static final short CSS_EXSThe value is a length (exs). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_PX
static final short CSS_PXThe value is a length (px). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_CM
static final short CSS_CMThe value is a length (cm). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_MM
static final short CSS_MMThe value is a length (mm). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_IN
static final short CSS_INThe value is a length (in). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_PT
static final short CSS_PTThe value is a length (pt). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_PC
static final short CSS_PCThe value is a length (pc). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_DEG
static final short CSS_DEGThe value is an angle (deg). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_RAD
static final short CSS_RADThe value is an angle (rad). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_GRAD
static final short CSS_GRADThe value is an angle (grad). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_MS
static final short CSS_MSThe value is a time (ms). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_S
static final short CSS_SThe value is a time (s). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_HZ
static final short CSS_HZThe value is a frequency (Hz). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_KHZ
static final short CSS_KHZThe value is a frequency (kHz). The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_DIMENSION
static final short CSS_DIMENSIONThe value is a number with an unknown dimension. The value can be obtained by using thegetFloatValuemethod.- See Also:
- Constant Field Values
-
CSS_STRING
static final short CSS_STRINGThe value is a STRING. The value can be obtained by using thegetStringValuemethod.- See Also:
- Constant Field Values
-
CSS_URI
static final short CSS_URIThe value is a URI. The value can be obtained by using thegetStringValuemethod.- See Also:
- Constant Field Values
-
CSS_IDENT
static final short CSS_IDENTThe value is an identifier. The value can be obtained by using thegetStringValuemethod.- See Also:
- Constant Field Values
-
CSS_ATTR
static final short CSS_ATTRThe value is a attribute function. The value can be obtained by using thegetStringValuemethod.- See Also:
- Constant Field Values
-
CSS_COUNTER
static final short CSS_COUNTERThe value is a counter or counters function. The value can be obtained by using thegetCounterValuemethod.- See Also:
- Constant Field Values
-
CSS_RECT
static final short CSS_RECTThe value is a rect function. The value can be obtained by using thegetRectValuemethod.- See Also:
- Constant Field Values
-
CSS_RGBCOLOR
static final short CSS_RGBCOLORThe value is a RGB color. The value can be obtained by using thegetRGBColorValuemethod.- See Also:
- Constant Field Values
-
-
Method Details
-
getPrimitiveType
short getPrimitiveType()The type of the value as defined by the constants specified above. -
setFloatValue
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 aDOMExceptionwill 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.
-
getFloatValue
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, aDOMExceptionis 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.
-
setStringValue
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 aDOMExceptionwill 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, andCSS_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.
-
getStringValue
This method is used to get the string value. If the CSS value doesn't contain a string value, aDOMExceptionis 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
primitiveTypecan only be a string unit type (i.e.CSS_STRING,CSS_URI,CSS_IDENTandCSS_ATTR). - Throws:
DOMException- INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value.
-
getCounterValue
This method is used to get the Counter value. If this CSS value doesn't contain a counter value, aDOMExceptionis raised. Modification to the corresponding style property can be achieved using theCounterinterface.- Returns:
- The Counter value.
- Throws:
DOMException- INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Counter value (e.g. this is notCSS_COUNTER).
-
getRectValue
This method is used to get the Rect value. If this CSS value doesn't contain a rect value, aDOMExceptionis raised. Modification to the corresponding style property can be achieved using theRectinterface.- Returns:
- The Rect value.
- Throws:
DOMException- INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Rect value. (e.g. this is notCSS_RECT).
-
getRGBColorValue
This method is used to get the RGB color. If this CSS value doesn't contain a RGB color value, aDOMExceptionis raised. Modification to the corresponding style property can be achieved using theRGBColorinterface.- 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 notCSS_RGBCOLOR).
-