File indexing completed on 2024-05-05 12:14:46
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 (Candidate Recommendation) 0023 * https://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/ 0024 * Copyright © 2000 W3C® (MIT, INRIA, Keio), All Rights Reserved. 0025 * 0026 */ 0027 #ifndef _CSS_css_rule_h_ 0028 #define _CSS_css_rule_h_ 0029 0030 #include <dom/dom_string.h> 0031 #include <dom/css_stylesheet.h> 0032 #include <dom/css_value.h> 0033 0034 namespace DOM 0035 { 0036 0037 class CSSRuleImpl; 0038 0039 /** 0040 * The \c CSSRule interface is the abstract base interface 0041 * for any type of CSS <a 0042 * href="https://www.w3.org/TR/CSS2/syndata.html#q5"> statement 0043 * </a> . This includes both <a 0044 * href="https://www.w3.org/TR/CSS2/syndata.html#q8"> rule sets 0045 * </a> and <a 0046 * href="https://www.w3.org/TR/CSS2/syndata.html#at-rules"> 0047 * at-rules </a> . An implementation is expected to preserve all rules 0048 * specified in a CSS style sheet, even if it is not recognized. 0049 * Unrecognized rules are represented using the \c CSSUnknownRule 0050 * interface. 0051 * 0052 */ 0053 class KHTML_EXPORT CSSRule 0054 { 0055 public: 0056 CSSRule(); 0057 CSSRule(const CSSRule &other); 0058 CSSRule(CSSRuleImpl *impl); 0059 public: 0060 0061 CSSRule &operator = (const CSSRule &other); 0062 0063 ~CSSRule(); 0064 /** 0065 * An integer indicating which type of rule this is. 0066 * 0067 */ 0068 enum RuleType { 0069 UNKNOWN_RULE = 0, 0070 STYLE_RULE = 1, 0071 CHARSET_RULE = 2, 0072 IMPORT_RULE = 3, 0073 MEDIA_RULE = 4, 0074 FONT_FACE_RULE = 5, 0075 PAGE_RULE = 6, 0076 NAMESPACE_RULE = 10, ///< CSSOM, @since 4.6.0 0077 QUIRKS_RULE = 100 // KHTML CSS Extension 0078 }; 0079 0080 /** 0081 * The type of the rule, as defined above. The expectation is that 0082 * binding-specific casting methods can be used to cast down from 0083 * an instance of the \c CSSRule interface to the 0084 * specific derived interface implied by the \c type . 0085 * 0086 */ 0087 unsigned short type() const; 0088 0089 /** 0090 * The parsable textual representation of the rule. This reflects 0091 * the current state of the rule and not its initial value. 0092 * 0093 */ 0094 DOM::DOMString cssText() const; 0095 0096 /** 0097 * see cssText 0098 * @exception DOMException 0099 * 0100 * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted 0101 * at this point in the style sheet. 0102 * 0103 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is 0104 * readonly. 0105 * 0106 * @exception CSSException 0107 * SYNTAX_ERR: Raised if the specified CSS string value has a 0108 * syntax error and is unparsable. 0109 * 0110 * INVALID_MODIFICATION_ERR: Raised if the specified CSS string value 0111 * represents a different type of rule than the current one. 0112 */ 0113 void setCssText(const DOM::DOMString &); 0114 0115 /** 0116 * The style sheet that contains this rule. 0117 * 0118 */ 0119 CSSStyleSheet parentStyleSheet() const; 0120 0121 /** 0122 * If this rule is contained inside another rule (e.g. a style 0123 * rule inside an \@media block), this is the containing rule. If 0124 * this rule is not nested inside any other rules, this returns 0125 * \c null . 0126 * 0127 */ 0128 CSSRule parentRule() const; 0129 0130 /** 0131 * @internal 0132 * not part of the DOM 0133 */ 0134 CSSRuleImpl *handle() const; 0135 bool isNull() const; 0136 0137 protected: 0138 CSSRuleImpl *impl; 0139 0140 void assignOther(const CSSRule &other, RuleType thisType); 0141 }; 0142 0143 class CSSCharsetRuleImpl; 0144 0145 /** 0146 * The \c CSSCharsetRule interface a <a href=""> \@charset 0147 * rule </a> in a CSS style sheet. A \c \@charset rule can 0148 * be used to define the encoding of the style sheet. 0149 * 0150 */ 0151 class KHTML_EXPORT CSSCharsetRule : public CSSRule 0152 { 0153 public: 0154 CSSCharsetRule(); 0155 CSSCharsetRule(const CSSCharsetRule &other); 0156 CSSCharsetRule(const CSSRule &other); 0157 CSSCharsetRule(CSSCharsetRuleImpl *impl); 0158 public: 0159 0160 CSSCharsetRule &operator = (const CSSCharsetRule &other); 0161 CSSCharsetRule &operator = (const CSSRule &other); 0162 0163 ~CSSCharsetRule(); 0164 0165 /** 0166 * The encoding information used in this \c \@charset 0167 * rule. 0168 * 0169 */ 0170 DOM::DOMString encoding() const; 0171 0172 /** 0173 * see encoding 0174 * @exception CSSException 0175 * SYNTAX_ERR: Raised if the specified encoding value has a syntax 0176 * error and is unparsable. 0177 * 0178 * @exception DOMException 0179 * NO_MODIFICATION_ALLOWED_ERR: Raised if this encoding rule is 0180 * readonly. 0181 * 0182 */ 0183 void setEncoding(const DOM::DOMString &); 0184 }; 0185 0186 class CSSFontFaceRuleImpl; 0187 /** 0188 * The \c CSSFontFaceRule interface represents a <a 0189 * href="https://www.w3.org/TR/CSS2/fonts.html#font-descriptions"> 0190 * \c \@font-face rule </a> in a CSS style sheet. The \c \@font-face 0191 * rule is used to hold a set of font descriptions. 0192 * 0193 */ 0194 class KHTML_EXPORT CSSFontFaceRule : public CSSRule 0195 { 0196 public: 0197 CSSFontFaceRule(); 0198 CSSFontFaceRule(const CSSFontFaceRule &other); 0199 CSSFontFaceRule(const CSSRule &other); 0200 CSSFontFaceRule(CSSFontFaceRuleImpl *impl); 0201 public: 0202 0203 CSSFontFaceRule &operator = (const CSSFontFaceRule &other); 0204 CSSFontFaceRule &operator = (const CSSRule &other); 0205 0206 ~CSSFontFaceRule(); 0207 0208 /** 0209 * The <a href="https://www.w3.org/TR/CSS2/syndata.html#q8"> 0210 * declaration-block </a> of this rule. 0211 * 0212 */ 0213 CSSStyleDeclaration style() const; 0214 }; 0215 0216 class CSSImportRuleImpl; 0217 /** 0218 * The \c CSSImportRule interface represents a <a 0219 * href="https://www.w3.org/TR/CSS2/cascade.html#at-import"> 0220 * \c \@import rule </a> within a CSS style sheet. The \c \@import 0221 * rule is used to import style rules from other style sheets. 0222 * 0223 */ 0224 class KHTML_EXPORT CSSImportRule : public CSSRule 0225 { 0226 public: 0227 CSSImportRule(); 0228 CSSImportRule(const CSSImportRule &other); 0229 CSSImportRule(const CSSRule &other); 0230 CSSImportRule(CSSImportRuleImpl *impl); 0231 public: 0232 0233 CSSImportRule &operator = (const CSSImportRule &other); 0234 CSSImportRule &operator = (const CSSRule &other); 0235 0236 ~CSSImportRule(); 0237 0238 /** 0239 * The location of the style sheet to be imported. The attribute 0240 * will not contain the \c "url(...)" specifier around 0241 * the URI. 0242 * 0243 */ 0244 DOM::DOMString href() const; 0245 0246 /** 0247 * A list of media types for which this style sheet may be used. 0248 * 0249 */ 0250 MediaList media() const; 0251 0252 /** 0253 * The style sheet referred to by this rule, if it has been 0254 * loaded. The value of this attribute is null if the style sheet 0255 * has not yet been loaded or if it will not be loaded (e.g. if 0256 * the style sheet is for a media type not supported by the user 0257 * agent). 0258 * 0259 */ 0260 CSSStyleSheet styleSheet() const; 0261 }; 0262 0263 class CSSMediaRuleImpl; 0264 /** 0265 * The \c CSSMediaRule interface represents a <a 0266 * href="https://www.w3.org/TR/CSS2/media.html#at-media-rule"> 0267 * \@media rule </a> in a CSS style sheet. A \c \@media rule 0268 * can be used to delimit style rules for specific media types. 0269 * 0270 */ 0271 class KHTML_EXPORT CSSMediaRule : public CSSRule 0272 { 0273 public: 0274 CSSMediaRule(); 0275 CSSMediaRule(const CSSMediaRule &other); 0276 CSSMediaRule(const CSSRule &other); 0277 CSSMediaRule(CSSMediaRuleImpl *impl); 0278 public: 0279 0280 CSSMediaRule &operator = (const CSSMediaRule &other); 0281 CSSMediaRule &operator = (const CSSRule &other); 0282 0283 ~CSSMediaRule(); 0284 0285 /** 0286 * A list of <a 0287 * href="https://www.w3.org/TR/CSS2/media.html#media-types"> 0288 * media types </a> for this rule. 0289 * 0290 */ 0291 MediaList media() const; 0292 0293 /** 0294 * A list of all CSS rules contained within the media block. 0295 * 0296 */ 0297 CSSRuleList cssRules() const; 0298 0299 /** 0300 * Used to insert a new rule into the media block. 0301 * 0302 * @param rule The parsable text representing the rule. For rule 0303 * sets this contains both the selector and the style declaration. 0304 * For at-rules, this specifies both the at-identifier and the 0305 * rule content. 0306 * 0307 * @param index The index within the media block's rule collection 0308 * of the rule before which to insert the specified rule. If the 0309 * specified index is equal to the length of the media blocks's 0310 * rule collection, the rule will be added to the end of the media 0311 * block. 0312 * 0313 * @return The index within the media block's rule collection of 0314 * the newly inserted rule. 0315 * 0316 * \exception DOMException 0317 * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at 0318 * the specified index. e.g. if an \c \@import rule is 0319 * inserted after a standard rule set or other at-rule. 0320 * 0321 * INDEX_SIZE_ERR: Raised if the specified index is not a valid 0322 * insertion point. 0323 * 0324 * NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is 0325 * readonly. 0326 * 0327 * \exception CSSException 0328 * SYNTAX_ERR: Raised if the specified rule has a syntax error 0329 * and is unparsable. 0330 * 0331 */ 0332 unsigned long insertRule(const DOM::DOMString &rule, unsigned long index); 0333 0334 /** 0335 * Used to delete a rule from the media block. 0336 * 0337 * @param index The index within the media block's rule collection 0338 * of the rule to remove. 0339 * 0340 * @return 0341 * 0342 * \exception DOMException 0343 * INDEX_SIZE_ERR: Raised if the specified index does not 0344 * correspond to a rule in the media rule list. 0345 * 0346 * NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is 0347 * readonly. 0348 * 0349 */ 0350 void deleteRule(unsigned long index); 0351 }; 0352 0353 class CSSPageRuleImpl; 0354 /** 0355 * The \c CSSPageRule interface represents a <a 0356 * href="https://www.w3.org/TR/CSS2/page.html#page-box"> page rule 0357 * </a> within a CSS style sheet. The \c @page rule is 0358 * used to specify the dimensions, orientation, margins, etc. of a 0359 * page box for paged media. 0360 * 0361 */ 0362 class KHTML_EXPORT CSSPageRule : public CSSRule 0363 { 0364 public: 0365 CSSPageRule(); 0366 CSSPageRule(const CSSPageRule &other); 0367 CSSPageRule(const CSSRule &other); 0368 CSSPageRule(CSSPageRuleImpl *impl); 0369 public: 0370 0371 CSSPageRule &operator = (const CSSPageRule &other); 0372 CSSPageRule &operator = (const CSSRule &other); 0373 0374 ~CSSPageRule(); 0375 0376 /** 0377 * The parsable textual representation of the page selector for 0378 * the rule. 0379 * 0380 */ 0381 DOM::DOMString selectorText() const; 0382 0383 /** 0384 * see selectorText 0385 * @exception CSSException 0386 * SYNTAX_ERR: Raised if the specified CSS string value has a 0387 * syntax error and is unparsable. 0388 * 0389 * @exception DOMException 0390 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is 0391 * readonly. 0392 * 0393 */ 0394 void setSelectorText(const DOM::DOMString &); 0395 0396 /** 0397 * The <a href="https://www.w3.org/TR/CSS2/syndata.html#q8"> 0398 * declaration-block </a> of this rule. 0399 * 0400 */ 0401 CSSStyleDeclaration style() const; 0402 }; 0403 0404 class CSSStyleRuleImpl; 0405 /** 0406 * The \c CSSStyleRule interface represents a single <a 0407 * href="https://www.w3.org/TR/CSS2/syndata.html#q8"> rule set </a> 0408 * in a CSS style sheet. 0409 * 0410 */ 0411 class KHTML_EXPORT CSSStyleRule : public CSSRule 0412 { 0413 public: 0414 CSSStyleRule(); 0415 CSSStyleRule(const CSSStyleRule &other); 0416 CSSStyleRule(const CSSRule &other); 0417 CSSStyleRule(CSSStyleRuleImpl *impl); 0418 public: 0419 0420 CSSStyleRule &operator = (const CSSStyleRule &other); 0421 CSSStyleRule &operator = (const CSSRule &other); 0422 0423 ~CSSStyleRule(); 0424 0425 /** 0426 * The textual representation of the <a 0427 * href="https://www.w3.org/TR/CSS2/selector.html"> selector 0428 * </a> for the rule set. The implementation may have stripped out 0429 * insignificant whitespace while parsing the selector. 0430 * 0431 */ 0432 DOM::DOMString selectorText() const; 0433 0434 /** 0435 * see selectorText 0436 * @exception CSSException 0437 * SYNTAX_ERR: Raised if the specified CSS string value has a 0438 * syntax error and is unparsable. 0439 * 0440 * @exception DOMException 0441 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is 0442 * readonly. 0443 * 0444 */ 0445 void setSelectorText(const DOM::DOMString &); 0446 0447 /** 0448 * The <a href="https://www.w3.org/TR/CSS2/syndata.html#q8"> 0449 * declaration-block </a> of this rule set. 0450 * 0451 */ 0452 CSSStyleDeclaration style() const; 0453 }; 0454 0455 class CSSNamespaceRuleImpl; 0456 /** 0457 * The \c CSSNamespaceRule interface represents an @namespace rule 0458 * @since 4.6.0 0459 * 0460 */ 0461 class KHTML_EXPORT CSSNamespaceRule : public CSSRule 0462 { 0463 public: 0464 CSSNamespaceRule(); 0465 CSSNamespaceRule(const CSSNamespaceRule &other); 0466 CSSNamespaceRule(const CSSRule &other); 0467 CSSNamespaceRule(CSSNamespaceRuleImpl *impl); 0468 0469 DOMString namespaceURI() const; 0470 DOMString prefix() const; 0471 public: 0472 0473 CSSNamespaceRule &operator = (const CSSNamespaceRule &other); 0474 CSSNamespaceRule &operator = (const CSSRule &other); 0475 0476 ~CSSNamespaceRule(); 0477 }; 0478 0479 class CSSUnknownRuleImpl; 0480 /** 0481 * The \c CSSUnkownRule interface represents an at-rule 0482 * not supported by this user agent. 0483 * 0484 */ 0485 class KHTML_EXPORT CSSUnknownRule : public CSSRule 0486 { 0487 public: 0488 CSSUnknownRule(); 0489 CSSUnknownRule(const CSSUnknownRule &other); 0490 CSSUnknownRule(const CSSRule &other); 0491 CSSUnknownRule(CSSUnknownRuleImpl *impl); 0492 public: 0493 0494 CSSUnknownRule &operator = (const CSSUnknownRule &other); 0495 CSSUnknownRule &operator = (const CSSRule &other); 0496 0497 ~CSSUnknownRule(); 0498 }; 0499 0500 class CSSRuleListImpl; 0501 class StyleListImpl; 0502 /** 0503 * The \c CSSRuleList interface provides the abstraction 0504 * of an ordered collection of CSS rules. 0505 * 0506 */ 0507 class KHTML_EXPORT CSSRuleList 0508 { 0509 public: 0510 CSSRuleList(); 0511 CSSRuleList(const CSSRuleList &other); 0512 CSSRuleList(CSSRuleListImpl *i); 0513 CSSRuleList(StyleListImpl *i); 0514 public: 0515 0516 CSSRuleList &operator = (const CSSRuleList &other); 0517 0518 ~CSSRuleList(); 0519 0520 /** 0521 * The number of \c CSSRule s in the list. The range 0522 * of valid child rule indices is \c 0 to 0523 * \c length-1 inclusive. 0524 * 0525 */ 0526 unsigned long length() const; 0527 0528 /** 0529 * Used to retrieve a CSS rule by ordinal index. The order in this 0530 * collection represents the order of the rules in the CSS style 0531 * sheet. 0532 * 0533 * @param index Index into the collection 0534 * 0535 * @return The style rule at the \c index position in 0536 * the \c CSSRuleList , or \c null if that 0537 * is not a valid index. 0538 * 0539 */ 0540 CSSRule item(unsigned long index); 0541 0542 /** 0543 * @internal 0544 * not part of the DOM 0545 */ 0546 CSSRuleListImpl *handle() const; 0547 bool isNull() const; 0548 0549 protected: 0550 // we just need a pointer to an implementation here. 0551 CSSRuleListImpl *impl; 0552 }; 0553 0554 } // namespace 0555 0556 #endif