1. /*
  2. * Copyright (c) 2000 World Wide Web Consortium,
  3. * (Massachusetts Institute of Technology, Institut National de
  4. * Recherche en Informatique et en Automatique, Keio University). All
  5. * Rights Reserved. This program is distributed under the W3C's Software
  6. * Intellectual Property License. This program is distributed in the
  7. * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  8. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11. */
  12. package org.w3c.dom.css;
  13. import org.w3c.dom.DOMException;
  14. /**
  15. * The <code>CSSPrimitiveValue</code> interface represents a single CSS value
  16. * . This interface may be used to determine the value of a specific style
  17. * property currently set in a block or to set a specific style property
  18. * explicitly within the block. An instance of this interface might be
  19. * obtained from the <code>getPropertyCSSValue</code> method of the
  20. * <code>CSSStyleDeclaration</code> interface. A
  21. * <code>CSSPrimitiveValue</code> object only occurs in a context of a CSS
  22. * property.
  23. * <p> Conversions are allowed between absolute values (from millimeters to
  24. * centimeters, from degrees to radians, and so on) but not between relative
  25. * values. (For example, a pixel value cannot be converted to a centimeter
  26. * value.) Percentage values can't be converted since they are relative to
  27. * the parent value (or another property value). There is one exception for
  28. * color percentage values: since a color percentage value is relative to
  29. * the range 0-255, a color percentage value can be converted to a number;
  30. * (see also the <code>RGBColor</code> interface).
  31. * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113'>Document Object Model (DOM) Level 2 Style Specification</a>.
  32. * @since DOM Level 2
  33. */
  34. public interface CSSPrimitiveValue extends CSSValue {
  35. // UnitTypes
  36. /**
  37. * The value is not a recognized CSS2 value. The value can only be
  38. * obtained by using the <code>cssText</code> attribute.
  39. */
  40. public static final short CSS_UNKNOWN = 0;
  41. /**
  42. * The value is a simple number. The value can be obtained by using the
  43. * <code>getFloatValue</code> method.
  44. */
  45. public static final short CSS_NUMBER = 1;
  46. /**
  47. * The value is a percentage. The value can be obtained by using the
  48. * <code>getFloatValue</code> method.
  49. */
  50. public static final short CSS_PERCENTAGE = 2;
  51. /**
  52. * The value is a length (ems). The value can be obtained by using the
  53. * <code>getFloatValue</code> method.
  54. */
  55. public static final short CSS_EMS = 3;
  56. /**
  57. * The value is a length (exs). The value can be obtained by using the
  58. * <code>getFloatValue</code> method.
  59. */
  60. public static final short CSS_EXS = 4;
  61. /**
  62. * The value is a length (px). The value can be obtained by using the
  63. * <code>getFloatValue</code> method.
  64. */
  65. public static final short CSS_PX = 5;
  66. /**
  67. * The value is a length (cm). The value can be obtained by using the
  68. * <code>getFloatValue</code> method.
  69. */
  70. public static final short CSS_CM = 6;
  71. /**
  72. * The value is a length (mm). The value can be obtained by using the
  73. * <code>getFloatValue</code> method.
  74. */
  75. public static final short CSS_MM = 7;
  76. /**
  77. * The value is a length (in). The value can be obtained by using the
  78. * <code>getFloatValue</code> method.
  79. */
  80. public static final short CSS_IN = 8;
  81. /**
  82. * The value is a length (pt). The value can be obtained by using the
  83. * <code>getFloatValue</code> method.
  84. */
  85. public static final short CSS_PT = 9;
  86. /**
  87. * The value is a length (pc). The value can be obtained by using the
  88. * <code>getFloatValue</code> method.
  89. */
  90. public static final short CSS_PC = 10;
  91. /**
  92. * The value is an angle (deg). The value can be obtained by using the
  93. * <code>getFloatValue</code> method.
  94. */
  95. public static final short CSS_DEG = 11;
  96. /**
  97. * The value is an angle (rad). The value can be obtained by using the
  98. * <code>getFloatValue</code> method.
  99. */
  100. public static final short CSS_RAD = 12;
  101. /**
  102. * The value is an angle (grad). The value can be obtained by using the
  103. * <code>getFloatValue</code> method.
  104. */
  105. public static final short CSS_GRAD = 13;
  106. /**
  107. * The value is a time (ms). The value can be obtained by using the
  108. * <code>getFloatValue</code> method.
  109. */
  110. public static final short CSS_MS = 14;
  111. /**
  112. * The value is a time (s). The value can be obtained by using the
  113. * <code>getFloatValue</code> method.
  114. */
  115. public static final short CSS_S = 15;
  116. /**
  117. * The value is a frequency (Hz). The value can be obtained by using the
  118. * <code>getFloatValue</code> method.
  119. */
  120. public static final short CSS_HZ = 16;
  121. /**
  122. * The value is a frequency (kHz). The value can be obtained by using the
  123. * <code>getFloatValue</code> method.
  124. */
  125. public static final short CSS_KHZ = 17;
  126. /**
  127. * The value is a number with an unknown dimension. The value can be
  128. * obtained by using the <code>getFloatValue</code> method.
  129. */
  130. public static final short CSS_DIMENSION = 18;
  131. /**
  132. * The value is a STRING. The value can be obtained by using the
  133. * <code>getStringValue</code> method.
  134. */
  135. public static final short CSS_STRING = 19;
  136. /**
  137. * The value is a URI. The value can be obtained by using the
  138. * <code>getStringValue</code> method.
  139. */
  140. public static final short CSS_URI = 20;
  141. /**
  142. * The value is an identifier. The value can be obtained by using the
  143. * <code>getStringValue</code> method.
  144. */
  145. public static final short CSS_IDENT = 21;
  146. /**
  147. * The value is a attribute function. The value can be obtained by using
  148. * the <code>getStringValue</code> method.
  149. */
  150. public static final short CSS_ATTR = 22;
  151. /**
  152. * The value is a counter or counters function. The value can be obtained
  153. * by using the <code>getCounterValue</code> method.
  154. */
  155. public static final short CSS_COUNTER = 23;
  156. /**
  157. * The value is a rect function. The value can be obtained by using the
  158. * <code>getRectValue</code> method.
  159. */
  160. public static final short CSS_RECT = 24;
  161. /**
  162. * The value is a RGB color. The value can be obtained by using the
  163. * <code>getRGBColorValue</code> method.
  164. */
  165. public static final short CSS_RGBCOLOR = 25;
  166. /**
  167. * The type of the value as defined by the constants specified above.
  168. */
  169. public short getPrimitiveType();
  170. /**
  171. * A method to set the float value with a specified unit. If the property
  172. * attached with this value can not accept the specified unit or the
  173. * float value, the value will be unchanged and a
  174. * <code>DOMException</code> will be raised.
  175. * @param unitType A unit code as defined above. The unit code can only
  176. * be a float unit type (i.e. <code>CSS_NUMBER</code>,
  177. * <code>CSS_PERCENTAGE</code>, <code>CSS_EMS</code>,
  178. * <code>CSS_EXS</code>, <code>CSS_PX</code>, <code>CSS_CM</code>,
  179. * <code>CSS_MM</code>, <code>CSS_IN</code>, <code>CSS_PT</code>,
  180. * <code>CSS_PC</code>, <code>CSS_DEG</code>, <code>CSS_RAD</code>,
  181. * <code>CSS_GRAD</code>, <code>CSS_MS</code>, <code>CSS_S</code>,
  182. * <code>CSS_HZ</code>, <code>CSS_KHZ</code>,
  183. * <code>CSS_DIMENSION</code>).
  184. * @param floatValue The new float value.
  185. * @exception DOMException
  186. * INVALID_ACCESS_ERR: Raised if the attached property doesn't support
  187. * the float value or the unit type.
  188. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.
  189. */
  190. public void setFloatValue(short unitType,
  191. float floatValue)
  192. throws DOMException;
  193. /**
  194. * This method is used to get a float value in a specified unit. If this
  195. * CSS value doesn't contain a float value or can't be converted into
  196. * the specified unit, a <code>DOMException</code> is raised.
  197. * @param unitType A unit code to get the float value. The unit code can
  198. * only be a float unit type (i.e. <code>CSS_NUMBER</code>,
  199. * <code>CSS_PERCENTAGE</code>, <code>CSS_EMS</code>,
  200. * <code>CSS_EXS</code>, <code>CSS_PX</code>, <code>CSS_CM</code>,
  201. * <code>CSS_MM</code>, <code>CSS_IN</code>, <code>CSS_PT</code>,
  202. * <code>CSS_PC</code>, <code>CSS_DEG</code>, <code>CSS_RAD</code>,
  203. * <code>CSS_GRAD</code>, <code>CSS_MS</code>, <code>CSS_S</code>,
  204. * <code>CSS_HZ</code>, <code>CSS_KHZ</code>,
  205. * <code>CSS_DIMENSION</code>).
  206. * @return The float value in the specified unit.
  207. * @exception DOMException
  208. * INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a float
  209. * value or if the float value can't be converted into the specified
  210. * unit.
  211. */
  212. public float getFloatValue(short unitType)
  213. throws DOMException;
  214. /**
  215. * A method to set the string value with the specified unit. If the
  216. * property attached to this value can't accept the specified unit or
  217. * the string value, the value will be unchanged and a
  218. * <code>DOMException</code> will be raised.
  219. * @param stringType A string code as defined above. The string code can
  220. * only be a string unit type (i.e. <code>CSS_STRING</code>,
  221. * <code>CSS_URI</code>, <code>CSS_IDENT</code>, and
  222. * <code>CSS_ATTR</code>).
  223. * @param stringValue The new string value.
  224. * @exception DOMException
  225. * INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string
  226. * value or if the string value can't be converted into the specified
  227. * unit.
  228. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.
  229. */
  230. public void setStringValue(short stringType,
  231. String stringValue)
  232. throws DOMException;
  233. /**
  234. * This method is used to get the string value. If the CSS value doesn't
  235. * contain a string value, a <code>DOMException</code> is raised. Some
  236. * properties (like 'font-family' or 'voice-family') convert a
  237. * whitespace separated list of idents to a string.
  238. * @return The string value in the current unit. The current
  239. * <code>primitiveType</code> can only be a string unit type (i.e.
  240. * <code>CSS_STRING</code>, <code>CSS_URI</code>,
  241. * <code>CSS_IDENT</code> and <code>CSS_ATTR</code>).
  242. * @exception DOMException
  243. * INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string
  244. * value.
  245. */
  246. public String getStringValue()
  247. throws DOMException;
  248. /**
  249. * This method is used to get the Counter value. If this CSS value
  250. * doesn't contain a counter value, a <code>DOMException</code> is
  251. * raised. Modification to the corresponding style property can be
  252. * achieved using the <code>Counter</code> interface.
  253. * @return The Counter value.
  254. * @exception DOMException
  255. * INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a
  256. * Counter value (e.g. this is not <code>CSS_COUNTER</code>).
  257. */
  258. public Counter getCounterValue()
  259. throws DOMException;
  260. /**
  261. * This method is used to get the Rect value. If this CSS value doesn't
  262. * contain a rect value, a <code>DOMException</code> is raised.
  263. * Modification to the corresponding style property can be achieved
  264. * using the <code>Rect</code> interface.
  265. * @return The Rect value.
  266. * @exception DOMException
  267. * INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Rect
  268. * value. (e.g. this is not <code>CSS_RECT</code>).
  269. */
  270. public Rect getRectValue()
  271. throws DOMException;
  272. /**
  273. * This method is used to get the RGB color. If this CSS value doesn't
  274. * contain a RGB color value, a <code>DOMException</code> is raised.
  275. * Modification to the corresponding style property can be achieved
  276. * using the <code>RGBColor</code> interface.
  277. * @return the RGB color value.
  278. * @exception DOMException
  279. * INVALID_ACCESS_ERR: Raised if the attached property can't return a
  280. * RGB color value (e.g. this is not <code>CSS_RGBCOLOR</code>).
  281. */
  282. public RGBColor getRGBColorValue()
  283. throws DOMException;
  284. }