File indexing completed on 2024-04-28 11:37:41
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright 1999 Lars Knoll (knoll@kde.org) 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 * 0021 * This file includes excerpts from the Document Object Model (DOM) 0022 * Level 2 Specification (Style) 0023 * https://www.w3.org/TR/DOM-Level-2-Style/ 0024 * Copyright © 2000 W3C® (MIT, INRIA, Keio), All Rights Reserved. 0025 * 0026 */ 0027 #ifndef _CSS_css_value_h_ 0028 #define _CSS_css_value_h_ 0029 0030 #include <dom/dom_string.h> 0031 0032 #include <QColor> 0033 0034 namespace DOM 0035 { 0036 0037 class CSSStyleDeclarationImpl; 0038 class CSSRule; 0039 class CSSValue; 0040 0041 /** 0042 * The \c CSSStyleDeclaration interface represents a 0043 * single <a href="https://www.w3.org/TR/CSS2/syndata.html#block"> 0044 * CSS declaration block </a> . This interface may be used to 0045 * determine the style properties currently set in a block or to set 0046 * style properties explicitly within the block. 0047 * 0048 * While an implementation may not recognize all CSS properties 0049 * within a CSS declaration block, it is expected to provide access to 0050 * all specified properties through the \c CSSStyleDeclaration 0051 * interface. Furthermore, implementations that support a 0052 * specific level of CSS should correctly handle <a 0053 * href="https://www.w3.org/TR/CSS2/about.html#shorthand"> CSS 0054 * shorthand </a> properties for that level. For a further discussion 0055 * of shorthand properties, see the \c CSS2Properties 0056 * interface. 0057 * 0058 */ 0059 class KHTML_EXPORT CSSStyleDeclaration 0060 { 0061 public: 0062 CSSStyleDeclaration(); 0063 CSSStyleDeclaration(const CSSStyleDeclaration &other); 0064 CSSStyleDeclaration(CSSStyleDeclarationImpl *impl); 0065 public: 0066 0067 CSSStyleDeclaration &operator = (const CSSStyleDeclaration &other); 0068 0069 ~CSSStyleDeclaration(); 0070 0071 /** 0072 * The parsable textual representation of the declaration block 0073 * (including the surrounding curly braces). Setting this 0074 * attribute will result in the parsing of the new value and 0075 * resetting of the properties in the declaration block. 0076 * 0077 */ 0078 DOM::DOMString cssText() const; 0079 0080 /** 0081 * see cssText 0082 * @exception CSSException 0083 * SYNTAX_ERR: Raised if the specified CSS string value has a 0084 * syntax error and is unparsable. 0085 * 0086 * @exception DOMException 0087 * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is 0088 * readonly. 0089 * 0090 */ 0091 void setCssText(const DOM::DOMString &); 0092 0093 /** 0094 * The number of properties that have been explicitly set in this 0095 * declaration block. 0096 * 0097 */ 0098 unsigned long length() const; 0099 0100 /** 0101 * The CSS rule that contains this declaration block. 0102 * 0103 */ 0104 CSSRule parentRule() const; 0105 0106 /** 0107 * Used to retrieve the value of a CSS property if it has been 0108 * explicitly set within this declaration block. 0109 * 0110 * @param propertyName The name of the CSS property. See the <a 0111 * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property 0112 * index </a> . 0113 * 0114 * @return Returns the value of the property if it has been 0115 * explicitly set for this declaration block. Returns the empty 0116 * string if the property has not been set. 0117 * 0118 */ 0119 DOM::DOMString getPropertyValue(const DOM::DOMString &propertyName) const; 0120 0121 /** 0122 * Used to retrieve the object representation of the value of a 0123 * CSS property if it has been explicitly set within this 0124 * declaration block. This method returns null if the property is 0125 * a <a href="https://www.w3.org/TR/CSS2/about.html#shorthand"> 0126 * shorthand </a> property. Shorthand property values can only be 0127 * accessed and modified as strings, using the 0128 * \c getPropertyValue and \c setProperty 0129 * methods. 0130 * 0131 * @param propertyName The name of the CSS property. See the <a 0132 * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property 0133 * index </a> . 0134 * 0135 * @return Returns the value of the property if it has been 0136 * explicitly set for this declaration block. Returns the 0137 * \c null if the property has not been set. 0138 * 0139 */ 0140 CSSValue getPropertyCSSValue(const DOM::DOMString &propertyName) const; 0141 0142 /** 0143 * Used to remove a CSS property if it has been explicitly set 0144 * within this declaration block. 0145 * 0146 * @param propertyName The name of the CSS property. See the <a 0147 * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property 0148 * index </a> . 0149 * 0150 * @return Returns the value of the property if it has been 0151 * explicitly set for this declaration block. Returns the empty 0152 * string if the property has not been set or the property name 0153 * does not correspond to a valid CSS2 property. 0154 * 0155 * @exception DOMException 0156 * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is 0157 * readonly. 0158 * 0159 */ 0160 DOM::DOMString removeProperty(const DOM::DOMString &propertyName); 0161 0162 /** 0163 * Used to retrieve the priority of a CSS property (e.g. the 0164 * \c "important" qualifier) if the property has been 0165 * explicitly set in this declaration block. 0166 * 0167 * @param propertyName The name of the CSS property. See the <a 0168 * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property 0169 * index </a> . 0170 * 0171 * @return A string representing the priority (e.g. 0172 * \c "important" ) if one exists. The empty string if none 0173 * exists. 0174 * 0175 */ 0176 DOM::DOMString getPropertyPriority(const DOM::DOMString &propertyName) const; 0177 0178 /** 0179 * Used to set a property value and priority within this 0180 * declaration block. 0181 * 0182 * @param propertyName The name of the CSS property. See the <a 0183 * href="https://www.w3.org/TR/CSS2/propidx.html"> CSS property 0184 * index </a> . 0185 * 0186 * @param value The new value of the property. 0187 * 0188 * @param priority The new priority of the property (e.g. 0189 * \c "important" ). 0190 * 0191 * @return 0192 * 0193 * @exception CSSException 0194 * SYNTAX_ERR: Raised if the specified value has a syntax error 0195 * and is unparsable. 0196 * 0197 * @exception DOMException 0198 * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is 0199 * readonly. 0200 * 0201 */ 0202 void setProperty(const DOM::DOMString &propertyName, const DOM::DOMString &value, const DOM::DOMString &priority); 0203 0204 /** 0205 * Used to retrieve the properties that have been explicitly set 0206 * in this declaration block. The order of the properties 0207 * retrieved using this method does not have to be the order in 0208 * which they were set. This method can be used to iterate over 0209 * all properties in this declaration block. 0210 * 0211 * @param index Index of the property name to retrieve. 0212 * 0213 * @return The name of the property at this ordinal position. The 0214 * empty string if no property exists at this position. 0215 * 0216 */ 0217 DOM::DOMString item(unsigned long index) const; 0218 0219 /** 0220 * @internal 0221 * not part of the DOM 0222 */ 0223 CSSStyleDeclarationImpl *handle() const; 0224 bool isNull() const; 0225 0226 protected: 0227 CSSStyleDeclarationImpl *impl; 0228 }; 0229 0230 class CSSValueImpl; 0231 0232 /** 0233 * The \c CSSValue interface represents a simple or a 0234 * complexe value. 0235 * 0236 */ 0237 class KHTML_EXPORT CSSValue 0238 { 0239 public: 0240 CSSValue(); 0241 CSSValue(const CSSValue &other); 0242 CSSValue(CSSValueImpl *impl); 0243 public: 0244 0245 CSSValue &operator = (const CSSValue &other); 0246 0247 ~CSSValue(); 0248 /** 0249 * An integer indicating which type of unit applies to the value. 0250 * 0251 * All CSS2 constants are not supposed to be required by the 0252 * implementation since all CSS2 interfaces are optionals. 0253 * 0254 */ 0255 enum UnitTypes { 0256 CSS_INHERIT = 0, 0257 CSS_PRIMITIVE_VALUE = 1, 0258 CSS_VALUE_LIST = 2, 0259 CSS_CUSTOM = 3, 0260 CSS_INITIAL = 4, 0261 0262 CSS_SVG_VALUE = 1001 ///< Not part of DOM 0263 }; 0264 0265 /** 0266 * A string representation of the current value. 0267 * 0268 */ 0269 DOM::DOMString cssText() const; 0270 0271 /** 0272 * see cssText 0273 * @exception CSSException 0274 * SYNTAX_ERR: Raised if the specified CSS string value has a 0275 * syntax error and is unparsable. 0276 * 0277 * @exception DOMException 0278 * NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is 0279 * readonly. 0280 * 0281 */ 0282 void setCssText(const DOM::DOMString &); 0283 0284 /** 0285 * A code defining the type of the value as defined above. 0286 * 0287 */ 0288 unsigned short cssValueType() const; 0289 0290 /** 0291 * @internal 0292 * not part of the DOM 0293 */ 0294 bool isCSSValueList() const; 0295 bool isCSSPrimitiveValue() const; 0296 CSSValueImpl *handle() const; 0297 bool isNull() const; 0298 0299 protected: 0300 CSSValueImpl *impl; 0301 }; 0302 0303 class CSSValueListImpl; 0304 class CSSValue; 0305 0306 /** 0307 * The \c CSSValueList interface provides the absraction 0308 * of an ordered collection of CSS values. 0309 * 0310 */ 0311 class KHTML_EXPORT CSSValueList : public CSSValue 0312 { 0313 public: 0314 CSSValueList(); 0315 CSSValueList(const CSSValueList &other); 0316 CSSValueList(const CSSValue &other); 0317 CSSValueList(CSSValueListImpl *impl); 0318 public: 0319 0320 CSSValueList &operator = (const CSSValueList &other); 0321 CSSValueList &operator = (const CSSValue &other); 0322 0323 ~CSSValueList(); 0324 0325 /** 0326 * The number of \c CSSValue s in the list. The range 0327 * of valid values indices is \c 0 to \c length-1 0328 * inclusive. 0329 * 0330 */ 0331 unsigned long length() const; 0332 0333 /** 0334 * Used to retrieve a CSS rule by ordinal index. The order in this 0335 * collection represents the order of the values in the CSS style 0336 * property. 0337 * 0338 * @param index Index into the collection. 0339 * 0340 * @return The style rule at the \c index position in 0341 * the \c CSSValueList , or \c null if 0342 * that is not valid index. 0343 * 0344 */ 0345 CSSValue item(unsigned long index); 0346 0347 protected: 0348 CSSValueListImpl *vimpl; 0349 }; 0350 0351 class CSSPrimitiveValueImpl; 0352 class Counter; 0353 class RGBColor; 0354 class Rect; 0355 0356 /** 0357 * The \c CSSPrimitiveValue interface represents a single 0358 * <a href="https://www.w3.org/TR/CSS2/syndata.html#values"> CSS 0359 * value </a> . This interface may be used to determine the value of a 0360 * specific style property currently set in a block or to set a 0361 * specific style properties explicitly within the block. An instance 0362 * of this interface can be obtained from the 0363 * \c getPropertyCSSValue method of the 0364 * \c CSSStyleDeclaration interface. 0365 * 0366 */ 0367 class KHTML_EXPORT CSSPrimitiveValue : public CSSValue 0368 { 0369 public: 0370 CSSPrimitiveValue(); 0371 CSSPrimitiveValue(const CSSPrimitiveValue &other); 0372 CSSPrimitiveValue(const CSSValue &other); 0373 CSSPrimitiveValue(CSSPrimitiveValueImpl *impl); 0374 public: 0375 0376 CSSPrimitiveValue &operator = (const CSSPrimitiveValue &other); 0377 CSSPrimitiveValue &operator = (const CSSValue &other); 0378 0379 ~CSSPrimitiveValue(); 0380 /** 0381 * An integer indicating which type of unit applies to the value. 0382 * 0383 */ 0384 enum UnitTypes { 0385 CSS_UNKNOWN = 0, 0386 CSS_NUMBER = 1, 0387 CSS_PERCENTAGE = 2, 0388 CSS_EMS = 3, 0389 CSS_EXS = 4, 0390 CSS_CHS = 5, 0391 CSS_REMS = 6, 0392 CSS_PX = 7, 0393 CSS_CM = 8, 0394 CSS_MM = 9, 0395 CSS_IN = 10, 0396 CSS_PT = 11, 0397 CSS_PC = 12, 0398 CSS_DEG = 13, 0399 CSS_RAD = 14, 0400 CSS_GRAD = 15, 0401 CSS_MS = 16, 0402 CSS_S = 17, 0403 CSS_HZ = 18, 0404 CSS_KHZ = 19, 0405 CSS_DIMENSION = 20, 0406 CSS_STRING = 21, 0407 CSS_URI = 22, 0408 CSS_IDENT = 23, 0409 CSS_ATTR = 24, 0410 CSS_COUNTER = 25, 0411 CSS_RECT = 26, 0412 CSS_RGBCOLOR = 27, 0413 CSS_DPI = 28, 0414 CSS_DPCM = 29, 0415 CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs 0416 CSS_HTML_RELATIVE = 255 0417 }; 0418 0419 /** 0420 * The type of the value as defined by the constants specified 0421 * above. 0422 * 0423 */ 0424 unsigned short primitiveType() const; 0425 0426 /** 0427 * A method to set the float value with a specified unit. If the 0428 * property attached with this value can not accept the specified 0429 * unit or the float value, the value will be unchanged and a 0430 * \c DOMException will be raised. 0431 * 0432 * @param unitType A unit code as defined above. The unit code can 0433 * only be a float unit type (e.g. \c NUMBER , 0434 * \c PERCENTAGE , \c CSS_EMS , \c CSS_EXS 0435 * , \c CSS_PX , \c CSS_PX , 0436 * \c CSS_CM , \c CSS_MM , \c CSS_IN 0437 * , \c CSS_PT , \c CSS_PC , 0438 * \c CSS_DEG , \c CSS_RAD , 0439 * \c CSS_GRAD , \c CSS_MS , \c CSS_S 0440 * , \c CSS_HZ , \c CSS_KHZ , 0441 * \c CSS_DIMENSION ). 0442 * 0443 * @param floatValue The new float value. 0444 * 0445 * @return 0446 * @exception DOMException 0447 * INVALID_ACCESS_ERR: Raises if the attached property doesn't 0448 * support the float value or the unit type. 0449 * 0450 * NO_MODIFICATION_ALLOWED_ERR: Raised if this property is 0451 * readonly. 0452 * 0453 */ 0454 void setFloatValue(unsigned short unitType, float floatValue); 0455 0456 /** 0457 * This method is used to get a float value in a specified unit. 0458 * If this CSS value doesn't contain a float value or can't be 0459 * converted into the specified unit, a \c DOMException 0460 * is raised. 0461 * 0462 * @param unitType A unit code to get the float value. The unit 0463 * code can only be a float unit type (e.g. \c CSS_NUMBER 0464 * , \c CSS_PERCENTAGE , \c CSS_EMS 0465 * , \c CSS_EXS , \c CSS_PX , 0466 * \c CSS_PX , \c CSS_CM , \c CSS_MM 0467 * , \c CSS_IN , \c CSS_PT , 0468 * \c CSS_PC , \c CSS_DEG , \c CSS_RAD 0469 * , \c CSS_GRAD , \c CSS_MS , 0470 * \c CSS_S , \c CSS_HZ , \c CSS_KHZ 0471 * , \c CSS_DIMENSION ). 0472 * 0473 * @return The float value in the specified unit. 0474 * 0475 * @exception DOMException 0476 * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a 0477 * float value or if the float value can't be converted into the 0478 * specified unit. 0479 * 0480 */ 0481 float getFloatValue(unsigned short unitType) const; 0482 0483 /** 0484 * A method to set the string value with a specified unit. If the 0485 * property attached to this value can't accept the specified unit 0486 * or the string value, the value will be unchanged and a 0487 * \c DOMException will be raised. 0488 * 0489 * @param stringType A string code as defined above. The string 0490 * code can only be a string unit type (e.g. \c CSS_URI 0491 * , \c CSS_IDENT , \c CSS_INHERIT 0492 * and \c CSS_ATTR ). 0493 * 0494 * @param stringValue The new string value. If the 0495 * \c stringType is equal to \c CSS_INHERIT , the 0496 * \c stringValue should be \c inherit . 0497 * 0498 * @return 0499 * @exception DOMException 0500 * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a 0501 * string value or if the string value can't be converted into the 0502 * specified unit. 0503 * 0504 * NO_MODIFICATION_ALLOWED_ERR: Raised if this property is 0505 * readonly. 0506 * 0507 */ 0508 void setStringValue(unsigned short stringType, const DOM::DOMString &stringValue); 0509 0510 /** 0511 * This method is used to get the string value in a specified 0512 * unit. If the CSS value doesn't contain a string value, a 0513 * \c DOMException is raised. 0514 * 0515 * @return The string value in the current unit. The current 0516 * \c valueType can only be a string unit type (e.g. 0517 * \c CSS_URI , \c CSS_IDENT and 0518 * \c CSS_ATTR ). 0519 * 0520 * @exception DOMException 0521 * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a 0522 * string value. 0523 * 0524 */ 0525 DOM::DOMString getStringValue() const; 0526 0527 /** 0528 * This method is used to get the Counter value. If this CSS value 0529 * doesn't contain a counter value, a \c DOMException 0530 * is raised. Modification to the corresponding style property can 0531 * be achieved using the \c Counter interface. 0532 * 0533 * @return The Counter value. 0534 * 0535 * @exception DOMException 0536 * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a 0537 * Counter value. 0538 * 0539 */ 0540 Counter getCounterValue() const; 0541 0542 /** 0543 * This method is used to get the Rect value. If this CSS value 0544 * doesn't contain a rect value, a \c DOMException is 0545 * raised. Modification to the corresponding style property can be 0546 * achieved using the \c Rect interface. 0547 * 0548 * @return The Rect value. 0549 * 0550 * @exception DOMException 0551 * INVALID_ACCESS_ERR: Raises if the CSS value doesn't contain a 0552 * Rect value. 0553 * 0554 */ 0555 Rect getRectValue() const; 0556 0557 /** 0558 * This method is used to get the RGB color. If this CSS value 0559 * doesn't contain a RGB color value, a \c DOMException 0560 * is raised. Modification to the corresponding style 0561 * property can be achieved using the \c RGBColor 0562 * interface. 0563 * 0564 * @return the RGB color value. 0565 * 0566 * @exception DOMException 0567 * INVALID_ACCESS_ERR: Raises if the attached property can't 0568 * return a RGB color value. 0569 * 0570 */ 0571 RGBColor getRGBColorValue() const; 0572 }; 0573 0574 /** 0575 * The \c RGBColor interface is used to represent any <a 0576 * href="https://www.w3.org/TR/CSS2/syndata.html#value-def-color"> 0577 * RGB color </a> value. This interface reflects the values in the 0578 * underlying style property. Hence, modifications made through this 0579 * interface modify the style property. 0580 * 0581 */ 0582 class KHTML_EXPORT RGBColor 0583 { 0584 public: 0585 RGBColor(); 0586 /** 0587 * @deprecated 0588 */ 0589 RGBColor(const QColor &c) 0590 { 0591 m_color = c.rgb(); 0592 } 0593 RGBColor(QRgb color); 0594 0595 RGBColor(const RGBColor &other); 0596 RGBColor &operator = (const RGBColor &other); 0597 0598 ~RGBColor(); 0599 0600 /** 0601 * This attribute is used for the red value of the RGB color. 0602 * 0603 */ 0604 CSSPrimitiveValue red() const; 0605 0606 /** 0607 * This attribute is used for the green value of the RGB color. 0608 * 0609 */ 0610 CSSPrimitiveValue green() const; 0611 0612 /** 0613 * This attribute is used for the blue value of the RGB color. 0614 * 0615 */ 0616 CSSPrimitiveValue blue() const; 0617 0618 /** 0619 * @internal 0620 */ 0621 QRgb color() const 0622 { 0623 return m_color; 0624 } 0625 protected: 0626 QRgb m_color; 0627 }; 0628 0629 class RectImpl; 0630 0631 /** 0632 * The \c Rect interface is used to represent any <a 0633 * href="https://www.w3.org/TR/CSS2/visufx.html#value-def-shape"> 0634 * rect </a> value. This interface reflects the values in the 0635 * underlying style property. Hence, modifications made through this 0636 * interface modify the style property. 0637 * 0638 */ 0639 class KHTML_EXPORT Rect 0640 { 0641 friend class CSSPrimitiveValue; 0642 public: 0643 Rect(); 0644 Rect(const Rect &other); 0645 0646 Rect &operator = (const Rect &other); 0647 0648 ~Rect(); 0649 0650 /** 0651 * This attribute is used for the top of the rect. 0652 * 0653 */ 0654 CSSPrimitiveValue top() const; 0655 0656 /** 0657 * This attribute is used for the right of the rect. 0658 * 0659 */ 0660 CSSPrimitiveValue right() const; 0661 0662 /** 0663 * This attribute is used for the bottom of the rect. 0664 * 0665 */ 0666 CSSPrimitiveValue bottom() const; 0667 0668 /** 0669 * This attribute is used for the left of the rect. 0670 * 0671 */ 0672 CSSPrimitiveValue left() const; 0673 0674 /** 0675 * @internal 0676 * not part of the DOM 0677 */ 0678 RectImpl *handle() const; 0679 bool isNull() const; 0680 0681 protected: 0682 RectImpl *impl; 0683 Rect(RectImpl *i); 0684 }; 0685 0686 class CounterImpl; 0687 0688 /** 0689 * The \c Counter interface is used to represent any <a 0690 * href="https://www.w3.org/TR/CSS2/syndata.html#value-def-counter"> 0691 * counter or counters function </a> value. This interface reflects 0692 * the values in the underlying style property. Hence, modifications 0693 * made through this interface modify the style property. 0694 * 0695 */ 0696 class KHTML_EXPORT Counter 0697 { 0698 friend class CSSPrimitiveValue; 0699 public: 0700 Counter(); 0701 Counter(const Counter &other); 0702 public: 0703 0704 Counter &operator = (const Counter &other); 0705 0706 ~Counter(); 0707 0708 /** 0709 * This attribute is used for the identifier of the counter. 0710 * 0711 */ 0712 DOM::DOMString identifier() const; 0713 0714 /** 0715 * This attribute is used for the style of the list. 0716 * 0717 */ 0718 DOM::DOMString listStyle() const; 0719 0720 /** 0721 * This attribute is used for the separator of nested counters. 0722 * 0723 */ 0724 DOM::DOMString separator() const; 0725 0726 /** 0727 * @internal 0728 * not part of the DOM 0729 */ 0730 CounterImpl *handle() const; 0731 bool isNull() const; 0732 0733 protected: 0734 CounterImpl *impl; 0735 Counter(CounterImpl *i); 0736 }; 0737 0738 } // namespace 0739 0740 #endif