KHtml

css_value.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * This file includes excerpts from the Document Object Model (DOM)
22  * Level 2 Specification (Style)
23  * https://www.w3.org/TR/DOM-Level-2-Style/
24  * Copyright © 2000 W3C® (MIT, INRIA, Keio), All Rights Reserved.
25  *
26  */
27 #ifndef _CSS_css_value_h_
28 #define _CSS_css_value_h_
29 
30 #include <dom/dom_string.h>
31 
32 #include <QColor>
33 
34 namespace DOM
35 {
36 
37 class CSSStyleDeclarationImpl;
38 class CSSRule;
39 class CSSValue;
40 
41 /**
42  * The \c CSSStyleDeclaration interface represents a
43  * single <a href="https://www.w3.org/TR/CSS2/syndata.html#block">
44  * CSS declaration block </a> . This interface may be used to
45  * determine the style properties currently set in a block or to set
46  * style properties explicitly within the block.
47  *
48  * While an implementation may not recognize all CSS properties
49  * within a CSS declaration block, it is expected to provide access to
50  * all specified properties through the \c CSSStyleDeclaration
51  * interface. Furthermore, implementations that support a
52  * specific level of CSS should correctly handle <a
53  * href="https://www.w3.org/TR/CSS2/about.html#shorthand"> CSS
54  * shorthand </a> properties for that level. For a further discussion
55  * of shorthand properties, see the \c CSS2Properties
56  * interface.
57  *
58  */
59 class KHTML_EXPORT CSSStyleDeclaration
60 {
61 public:
64  CSSStyleDeclaration(CSSStyleDeclarationImpl *impl);
65 public:
66 
67  CSSStyleDeclaration &operator = (const CSSStyleDeclaration &other);
68 
70 
71  /**
72  * The parsable textual representation of the declaration block
73  * (including the surrounding curly braces). Setting this
74  * attribute will result in the parsing of the new value and
75  * resetting of the properties in the declaration block.
76  *
77  */
78  DOM::DOMString cssText() const;
79 
80  /**
81  * see cssText
82  * @exception CSSException
83  * SYNTAX_ERR: Raised if the specified CSS string value has a
84  * syntax error and is unparsable.
85  *
86  * @exception DOMException
87  * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is
88  * readonly.
89  *
90  */
91  void setCssText(const DOM::DOMString &);
92 
93  /**
94  * The number of properties that have been explicitly set in this
95  * declaration block.
96  *
97  */
98  unsigned long length() const;
99 
100  /**
101  * The CSS rule that contains this declaration block.
102  *
103  */
104  CSSRule parentRule() const;
105 
106  /**
107  * Used to retrieve the value of a CSS property if it has been
108  * explicitly set within this declaration block.
109  *
110  * @param propertyName The name of the CSS property. See the <a
111  * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property
112  * index </a> .
113  *
114  * @return Returns the value of the property if it has been
115  * explicitly set for this declaration block. Returns the empty
116  * string if the property has not been set.
117  *
118  */
119  DOM::DOMString getPropertyValue(const DOM::DOMString &propertyName) const;
120 
121  /**
122  * Used to retrieve the object representation of the value of a
123  * CSS property if it has been explicitly set within this
124  * declaration block. This method returns null if the property is
125  * a <a href="https://www.w3.org/TR/CSS2/about.html#shorthand">
126  * shorthand </a> property. Shorthand property values can only be
127  * accessed and modified as strings, using the
128  * \c getPropertyValue and \c setProperty
129  * methods.
130  *
131  * @param propertyName The name of the CSS property. See the <a
132  * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property
133  * index </a> .
134  *
135  * @return Returns the value of the property if it has been
136  * explicitly set for this declaration block. Returns the
137  * \c null if the property has not been set.
138  *
139  */
140  CSSValue getPropertyCSSValue(const DOM::DOMString &propertyName) const;
141 
142  /**
143  * Used to remove a CSS property if it has been explicitly set
144  * within this declaration block.
145  *
146  * @param propertyName The name of the CSS property. See the <a
147  * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property
148  * index </a> .
149  *
150  * @return Returns the value of the property if it has been
151  * explicitly set for this declaration block. Returns the empty
152  * string if the property has not been set or the property name
153  * does not correspond to a valid CSS2 property.
154  *
155  * @exception DOMException
156  * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is
157  * readonly.
158  *
159  */
160  DOM::DOMString removeProperty(const DOM::DOMString &propertyName);
161 
162  /**
163  * Used to retrieve the priority of a CSS property (e.g. the
164  * \c "important" qualifier) if the property has been
165  * explicitly set in this declaration block.
166  *
167  * @param propertyName The name of the CSS property. See the <a
168  * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property
169  * index </a> .
170  *
171  * @return A string representing the priority (e.g.
172  * \c "important" ) if one exists. The empty string if none
173  * exists.
174  *
175  */
176  DOM::DOMString getPropertyPriority(const DOM::DOMString &propertyName) const;
177 
178  /**
179  * Used to set a property value and priority within this
180  * declaration block.
181  *
182  * @param propertyName The name of the CSS property. See the <a
183  * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property
184  * index </a> .
185  *
186  * @param value The new value of the property.
187  *
188  * @param priority The new priority of the property (e.g.
189  * \c "important" ).
190  *
191  * @return
192  *
193  * @exception CSSException
194  * SYNTAX_ERR: Raised if the specified value has a syntax error
195  * and is unparsable.
196  *
197  * @exception DOMException
198  * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is
199  * readonly.
200  *
201  */
202  void setProperty(const DOM::DOMString &propertyName, const DOM::DOMString &value, const DOM::DOMString &priority);
203 
204  /**
205  * Used to retrieve the properties that have been explicitly set
206  * in this declaration block. The order of the properties
207  * retrieved using this method does not have to be the order in
208  * which they were set. This method can be used to iterate over
209  * all properties in this declaration block.
210  *
211  * @param index Index of the property name to retrieve.
212  *
213  * @return The name of the property at this ordinal position. The
214  * empty string if no property exists at this position.
215  *
216  */
217  DOM::DOMString item(unsigned long index) const;
218 
219  /**
220  * @internal
221  * not part of the DOM
222  */
223  CSSStyleDeclarationImpl *handle() const;
224  bool isNull() const;
225 
226 protected:
227  CSSStyleDeclarationImpl *impl;
228 };
229 
230 class CSSValueImpl;
231 
232 /**
233  * The \c CSSValue interface represents a simple or a
234  * complexe value.
235  *
236  */
237 class KHTML_EXPORT CSSValue
238 {
239 public:
240  CSSValue();
241  CSSValue(const CSSValue &other);
242  CSSValue(CSSValueImpl *impl);
243 public:
244 
245  CSSValue &operator = (const CSSValue &other);
246 
247  ~CSSValue();
248  /**
249  * An integer indicating which type of unit applies to the value.
250  *
251  * All CSS2 constants are not supposed to be required by the
252  * implementation since all CSS2 interfaces are optionals.
253  *
254  */
255  enum UnitTypes {
256  CSS_INHERIT = 0,
257  CSS_PRIMITIVE_VALUE = 1,
258  CSS_VALUE_LIST = 2,
259  CSS_CUSTOM = 3,
260  CSS_INITIAL = 4,
261 
262  CSS_SVG_VALUE = 1001 ///< Not part of DOM
263  };
264 
265  /**
266  * A string representation of the current value.
267  *
268  */
269  DOM::DOMString cssText() const;
270 
271  /**
272  * see cssText
273  * @exception CSSException
274  * SYNTAX_ERR: Raised if the specified CSS string value has a
275  * syntax error and is unparsable.
276  *
277  * @exception DOMException
278  * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is
279  * readonly.
280  *
281  */
282  void setCssText(const DOM::DOMString &);
283 
284  /**
285  * A code defining the type of the value as defined above.
286  *
287  */
288  unsigned short cssValueType() const;
289 
290  /**
291  * @internal
292  * not part of the DOM
293  */
294  bool isCSSValueList() const;
295  bool isCSSPrimitiveValue() const;
296  CSSValueImpl *handle() const;
297  bool isNull() const;
298 
299 protected:
300  CSSValueImpl *impl;
301 };
302 
303 class CSSValueListImpl;
304 class CSSValue;
305 
306 /**
307  * The \c CSSValueList interface provides the absraction
308  * of an ordered collection of CSS values.
309  *
310  */
311 class KHTML_EXPORT CSSValueList : public CSSValue
312 {
313 public:
314  CSSValueList();
315  CSSValueList(const CSSValueList &other);
316  CSSValueList(const CSSValue &other);
317  CSSValueList(CSSValueListImpl *impl);
318 public:
319 
320  CSSValueList &operator = (const CSSValueList &other);
321  CSSValueList &operator = (const CSSValue &other);
322 
323  ~CSSValueList();
324 
325  /**
326  * The number of \c CSSValue s in the list. The range
327  * of valid values indices is \c 0 to \c length-1
328  * inclusive.
329  *
330  */
331  unsigned long length() const;
332 
333  /**
334  * Used to retrieve a CSS rule by ordinal index. The order in this
335  * collection represents the order of the values in the CSS style
336  * property.
337  *
338  * @param index Index into the collection.
339  *
340  * @return The style rule at the \c index position in
341  * the \c CSSValueList , or \c null if
342  * that is not valid index.
343  *
344  */
345  CSSValue item(unsigned long index);
346 
347 protected:
348  CSSValueListImpl *vimpl;
349 };
350 
351 class CSSPrimitiveValueImpl;
352 class Counter;
353 class RGBColor;
354 class Rect;
355 
356 /**
357  * The \c CSSPrimitiveValue interface represents a single
358  * <a href="https://www.w3.org/TR/CSS2/syndata.html#values"> CSS
359  * value </a> . This interface may be used to determine the value of a
360  * specific style property currently set in a block or to set a
361  * specific style properties explicitly within the block. An instance
362  * of this interface can be obtained from the
363  * \c getPropertyCSSValue method of the
364  * \c CSSStyleDeclaration interface.
365  *
366  */
367 class KHTML_EXPORT CSSPrimitiveValue : public CSSValue
368 {
369 public:
371  CSSPrimitiveValue(const CSSPrimitiveValue &other);
372  CSSPrimitiveValue(const CSSValue &other);
373  CSSPrimitiveValue(CSSPrimitiveValueImpl *impl);
374 public:
375 
376  CSSPrimitiveValue &operator = (const CSSPrimitiveValue &other);
377  CSSPrimitiveValue &operator = (const CSSValue &other);
378 
380  /**
381  * An integer indicating which type of unit applies to the value.
382  *
383  */
384  enum UnitTypes {
385  CSS_UNKNOWN = 0,
386  CSS_NUMBER = 1,
387  CSS_PERCENTAGE = 2,
388  CSS_EMS = 3,
389  CSS_EXS = 4,
390  CSS_CHS = 5,
391  CSS_REMS = 6,
392  CSS_PX = 7,
393  CSS_CM = 8,
394  CSS_MM = 9,
395  CSS_IN = 10,
396  CSS_PT = 11,
397  CSS_PC = 12,
398  CSS_DEG = 13,
399  CSS_RAD = 14,
400  CSS_GRAD = 15,
401  CSS_MS = 16,
402  CSS_S = 17,
403  CSS_HZ = 18,
404  CSS_KHZ = 19,
405  CSS_DIMENSION = 20,
406  CSS_STRING = 21,
407  CSS_URI = 22,
408  CSS_IDENT = 23,
409  CSS_ATTR = 24,
410  CSS_COUNTER = 25,
411  CSS_RECT = 26,
412  CSS_RGBCOLOR = 27,
413  CSS_DPI = 28,
414  CSS_DPCM = 29,
415  CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs
416  CSS_HTML_RELATIVE = 255
417  };
418 
419  /**
420  * The type of the value as defined by the constants specified
421  * above.
422  *
423  */
424  unsigned short primitiveType() const;
425 
426  /**
427  * A method to set the float value with a specified unit. If the
428  * property attached with this value can not accept the specified
429  * unit or the float value, the value will be unchanged and a
430  * \c DOMException will be raised.
431  *
432  * @param unitType A unit code as defined above. The unit code can
433  * only be a float unit type (e.g. \c NUMBER ,
434  * \c PERCENTAGE , \c CSS_EMS , \c CSS_EXS
435  * , \c CSS_PX , \c CSS_PX ,
436  * \c CSS_CM , \c CSS_MM , \c CSS_IN
437  * , \c CSS_PT , \c CSS_PC ,
438  * \c CSS_DEG , \c CSS_RAD ,
439  * \c CSS_GRAD , \c CSS_MS , \c CSS_S
440  * , \c CSS_HZ , \c CSS_KHZ ,
441  * \c CSS_DIMENSION ).
442  *
443  * @param floatValue The new float value.
444  *
445  * @return
446  * @exception DOMException
447  * INVALID_ACCESS_ERR: Raises if the attached property doesn't
448  * support the float value or the unit type.
449  *
450  * NO_MODIFICATION_ALLOWED_ERR: Raised if this property is
451  * readonly.
452  *
453  */
454  void setFloatValue(unsigned short unitType, float floatValue);
455 
456  /**
457  * This method is used to get a float value in a specified unit.
458  * If this CSS value doesn't contain a float value or can't be
459  * converted into the specified unit, a \c DOMException
460  * is raised.
461  *
462  * @param unitType A unit code to get the float value. The unit
463  * code can only be a float unit type (e.g. \c CSS_NUMBER
464  * , \c CSS_PERCENTAGE , \c CSS_EMS
465  * , \c CSS_EXS , \c CSS_PX ,
466  * \c CSS_PX , \c CSS_CM , \c CSS_MM
467  * , \c CSS_IN , \c CSS_PT ,
468  * \c CSS_PC , \c CSS_DEG , \c CSS_RAD
469  * , \c CSS_GRAD , \c CSS_MS ,
470  * \c CSS_S , \c CSS_HZ , \c CSS_KHZ
471  * , \c CSS_DIMENSION ).
472  *
473  * @return The float value in the specified unit.
474  *
475  * @exception DOMException
476  * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a
477  * float value or if the float value can't be converted into the
478  * specified unit.
479  *
480  */
481  float getFloatValue(unsigned short unitType) const;
482 
483  /**
484  * A method to set the string value with a specified unit. If the
485  * property attached to this value can't accept the specified unit
486  * or the string value, the value will be unchanged and a
487  * \c DOMException will be raised.
488  *
489  * @param stringType A string code as defined above. The string
490  * code can only be a string unit type (e.g. \c CSS_URI
491  * , \c CSS_IDENT , \c CSS_INHERIT
492  * and \c CSS_ATTR ).
493  *
494  * @param stringValue The new string value. If the
495  * \c stringType is equal to \c CSS_INHERIT , the
496  * \c stringValue should be \c inherit .
497  *
498  * @return
499  * @exception DOMException
500  * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a
501  * string value or if the string value can't be converted into the
502  * specified unit.
503  *
504  * NO_MODIFICATION_ALLOWED_ERR: Raised if this property is
505  * readonly.
506  *
507  */
508  void setStringValue(unsigned short stringType, const DOM::DOMString &stringValue);
509 
510  /**
511  * This method is used to get the string value in a specified
512  * unit. If the CSS value doesn't contain a string value, a
513  * \c DOMException is raised.
514  *
515  * @return The string value in the current unit. The current
516  * \c valueType can only be a string unit type (e.g.
517  * \c CSS_URI , \c CSS_IDENT and
518  * \c CSS_ATTR ).
519  *
520  * @exception DOMException
521  * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a
522  * string value.
523  *
524  */
525  DOM::DOMString getStringValue() const;
526 
527  /**
528  * This method is used to get the Counter value. If this CSS value
529  * doesn't contain a counter value, a \c DOMException
530  * is raised. Modification to the corresponding style property can
531  * be achieved using the \c Counter interface.
532  *
533  * @return The Counter value.
534  *
535  * @exception DOMException
536  * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a
537  * Counter value.
538  *
539  */
540  Counter getCounterValue() const;
541 
542  /**
543  * This method is used to get the Rect value. If this CSS value
544  * doesn't contain a rect value, a \c DOMException is
545  * raised. Modification to the corresponding style property can be
546  * achieved using the \c Rect interface.
547  *
548  * @return The Rect value.
549  *
550  * @exception DOMException
551  * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a
552  * Rect value.
553  *
554  */
555  Rect getRectValue() const;
556 
557  /**
558  * This method is used to get the RGB color. If this CSS value
559  * doesn't contain a RGB color value, a \c DOMException
560  * is raised. Modification to the corresponding style
561  * property can be achieved using the \c RGBColor
562  * interface.
563  *
564  * @return the RGB color value.
565  *
566  * @exception DOMException
567  * INVALID_ACCESS_ERR: Raises if the attached property can't
568  * return a RGB color value.
569  *
570  */
571  RGBColor getRGBColorValue() const;
572 };
573 
574 /**
575  * The \c RGBColor interface is used to represent any <a
576  * href="https://www.w3.org/TR/CSS2/syndata.html#value-def-color">
577  * RGB color </a> value. This interface reflects the values in the
578  * underlying style property. Hence, modifications made through this
579  * interface modify the style property.
580  *
581  */
582 class KHTML_EXPORT RGBColor
583 {
584 public:
585  RGBColor();
586  /**
587  * @deprecated
588  */
589  RGBColor(const QColor &c)
590  {
591  m_color = c.rgb();
592  }
593  RGBColor(QRgb color);
594 
595  RGBColor(const RGBColor &other);
596  RGBColor &operator = (const RGBColor &other);
597 
598  ~RGBColor();
599 
600  /**
601  * This attribute is used for the red value of the RGB color.
602  *
603  */
604  CSSPrimitiveValue red() const;
605 
606  /**
607  * This attribute is used for the green value of the RGB color.
608  *
609  */
610  CSSPrimitiveValue green() const;
611 
612  /**
613  * This attribute is used for the blue value of the RGB color.
614  *
615  */
616  CSSPrimitiveValue blue() const;
617 
618  /**
619  * @internal
620  */
621  QRgb color() const
622  {
623  return m_color;
624  }
625 protected:
626  QRgb m_color;
627 };
628 
629 class RectImpl;
630 
631 /**
632  * The \c Rect interface is used to represent any <a
633  * href="https://www.w3.org/TR/CSS2/visufx.html#value-def-shape">
634  * rect </a> value. This interface reflects the values in the
635  * underlying style property. Hence, modifications made through this
636  * interface modify the style property.
637  *
638  */
639 class KHTML_EXPORT Rect
640 {
641  friend class CSSPrimitiveValue;
642 public:
643  Rect();
644  Rect(const Rect &other);
645 
646  Rect &operator = (const Rect &other);
647 
648  ~Rect();
649 
650  /**
651  * This attribute is used for the top of the rect.
652  *
653  */
654  CSSPrimitiveValue top() const;
655 
656  /**
657  * This attribute is used for the right of the rect.
658  *
659  */
660  CSSPrimitiveValue right() const;
661 
662  /**
663  * This attribute is used for the bottom of the rect.
664  *
665  */
666  CSSPrimitiveValue bottom() const;
667 
668  /**
669  * This attribute is used for the left of the rect.
670  *
671  */
672  CSSPrimitiveValue left() const;
673 
674  /**
675  * @internal
676  * not part of the DOM
677  */
678  RectImpl *handle() const;
679  bool isNull() const;
680 
681 protected:
682  RectImpl *impl;
683  Rect(RectImpl *i);
684 };
685 
686 class CounterImpl;
687 
688 /**
689  * The \c Counter interface is used to represent any <a
690  * href="https://www.w3.org/TR/CSS2/syndata.html#value-def-counter">
691  * counter or counters function </a> value. This interface reflects
692  * the values in the underlying style property. Hence, modifications
693  * made through this interface modify the style property.
694  *
695  */
696 class KHTML_EXPORT Counter
697 {
698  friend class CSSPrimitiveValue;
699 public:
700  Counter();
701  Counter(const Counter &other);
702 public:
703 
704  Counter &operator = (const Counter &other);
705 
706  ~Counter();
707 
708  /**
709  * This attribute is used for the identifier of the counter.
710  *
711  */
712  DOM::DOMString identifier() const;
713 
714  /**
715  * This attribute is used for the style of the list.
716  *
717  */
718  DOM::DOMString listStyle() const;
719 
720  /**
721  * This attribute is used for the separator of nested counters.
722  *
723  */
724  DOM::DOMString separator() const;
725 
726  /**
727  * @internal
728  * not part of the DOM
729  */
730  CounterImpl *handle() const;
731  bool isNull() const;
732 
733 protected:
734  CounterImpl *impl;
735  Counter(CounterImpl *i);
736 };
737 
738 } // namespace
739 
740 #endif
UnitTypes
An integer indicating which type of unit applies to the value.
Definition: css_value.h:255
The CSSStyleDeclaration interface represents a single CSS declaration block .
Definition: css_value.h:59
QRgb color() const
Definition: css_value.h:621
The CSSValueList interface provides the absraction of an ordered collection of CSS values...
Definition: css_value.h:311
QRgb rgb() const const
The CSSPrimitiveValue interface represents a single CSS value .
Definition: css_value.h:367
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
RGBColor(const QColor &c)
Definition: css_value.h:589
The Rect interface is used to represent any rect value.
Definition: css_value.h:639
This library provides a full-featured HTML parser and widget.
The CSSRule interface is the abstract base interface for any type of CSS statement ...
Definition: css_rule.h:53
The RGBColor interface is used to represent any RGB color value.
Definition: css_value.h:582
QCA_EXPORT void setProperty(const QString &name, const QVariant &value)
The CSSValue interface represents a simple or a complexe value.
Definition: css_value.h:237
The Counter interface is used to represent any counter or counters function value.
Definition: css_value.h:696
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Apr 13 2021 22:45:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.