fix logic
[personal-kdelibs.git] / khtml / dom / css_rule.h
blob9f5f02722f10c37d6568777d7ffa9c222f15d704
1 /*
2 * This file is part of the DOM implementation for KDE.
4 * Copyright 1999 Lars Knoll (knoll@kde.org)
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.
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.
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.
21 * This file includes excerpts from the Document Object Model (DOM)
22 * Level 2 Specification (Candidate Recommendation)
23 * http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/
24 * Copyright © 2000 W3C® (MIT, INRIA, Keio), All Rights Reserved.
27 #ifndef _CSS_css_rule_h_
28 #define _CSS_css_rule_h_
30 #include <dom/dom_string.h>
31 #include <dom/css_stylesheet.h>
32 #include <dom/css_value.h>
34 namespace DOM {
36 class CSSRuleImpl;
38 /**
39 * The \c CSSRule interface is the abstract base interface
40 * for any type of CSS <a
41 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q5"> statement
42 * </a> . This includes both <a
43 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8"> rule sets
44 * </a> and <a
45 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#at-rules">
46 * at-rules </a> . An implementation is expected to preserve all rules
47 * specified in a CSS style sheet, even if it is not recognized.
48 * Unrecognized rules are represented using the \c CSSUnknownRule
49 * interface.
52 class KHTML_EXPORT CSSRule
54 public:
55 CSSRule();
56 CSSRule(const CSSRule &other);
57 CSSRule(CSSRuleImpl *impl);
58 public:
60 CSSRule & operator = (const CSSRule &other);
62 ~CSSRule();
63 /**
64 * An integer indicating which type of rule this is.
67 enum RuleType {
68 UNKNOWN_RULE = 0,
69 STYLE_RULE = 1,
70 CHARSET_RULE = 2,
71 IMPORT_RULE = 3,
72 MEDIA_RULE = 4,
73 FONT_FACE_RULE = 5,
74 PAGE_RULE = 6,
75 QUIRKS_RULE = 100 // KHTML CSS Extension
78 /**
79 * The type of the rule, as defined above. The expectation is that
80 * binding-specific casting methods can be used to cast down from
81 * an instance of the \c CSSRule interface to the
82 * specific derived interface implied by the \c type .
85 unsigned short type() const;
87 /**
88 * The parsable textual representation of the rule. This reflects
89 * the current state of the rule and not its initial value.
92 DOM::DOMString cssText() const;
94 /**
95 * see cssText
96 * @exception DOMException
98 * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted
99 * at this point in the style sheet.
101 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
102 * readonly.
104 * @exception CSSException
105 * SYNTAX_ERR: Raised if the specified CSS string value has a
106 * syntax error and is unparsable.
108 * INVALID_MODIFICATION_ERR: Raised if the specified CSS string value
109 * represents a different type of rule than the current one.
111 void setCssText( const DOM::DOMString & );
114 * The style sheet that contains this rule.
117 CSSStyleSheet parentStyleSheet() const;
120 * If this rule is contained inside another rule (e.g. a style
121 * rule inside an \@media block), this is the containing rule. If
122 * this rule is not nested inside any other rules, this returns
123 * \c null .
126 CSSRule parentRule() const;
129 * @internal
130 * not part of the DOM
132 CSSRuleImpl *handle() const;
133 bool isNull() const;
135 protected:
136 CSSRuleImpl *impl;
138 void assignOther( const CSSRule &other, RuleType thisType );
141 class CSSCharsetRuleImpl;
144 * The \c CSSCharsetRule interface a <a href=""> \@charset
145 * rule </a> in a CSS style sheet. A \c \@charset rule can
146 * be used to define the encoding of the style sheet.
149 class KHTML_EXPORT CSSCharsetRule : public CSSRule
151 public:
152 CSSCharsetRule();
153 CSSCharsetRule(const CSSCharsetRule &other);
154 CSSCharsetRule(const CSSRule &other);
155 CSSCharsetRule(CSSCharsetRuleImpl *impl);
156 public:
158 CSSCharsetRule & operator = (const CSSCharsetRule &other);
159 CSSCharsetRule & operator = (const CSSRule &other);
161 ~CSSCharsetRule();
164 * The encoding information used in this \c \@charset
165 * rule.
168 DOM::DOMString encoding() const;
171 * see encoding
172 * @exception CSSException
173 * SYNTAX_ERR: Raised if the specified encoding value has a syntax
174 * error and is unparsable.
176 * @exception DOMException
177 * NO_MODIFICATION_ALLOWED_ERR: Raised if this encoding rule is
178 * readonly.
181 void setEncoding( const DOM::DOMString & );
185 class CSSFontFaceRuleImpl;
187 * The \c CSSFontFaceRule interface represents a <a
188 * href="http://www.w3.org/TR/REC-CSS2/fonts.html#font-descriptions">
189 * \c \@font-face rule </a> in a CSS style sheet. The \c \@font-face
190 * rule is used to hold a set of font descriptions.
193 class KHTML_EXPORT CSSFontFaceRule : public CSSRule
195 public:
196 CSSFontFaceRule();
197 CSSFontFaceRule(const CSSFontFaceRule &other);
198 CSSFontFaceRule(const CSSRule &other);
199 CSSFontFaceRule(CSSFontFaceRuleImpl *impl);
200 public:
202 CSSFontFaceRule & operator = (const CSSFontFaceRule &other);
203 CSSFontFaceRule & operator = (const CSSRule &other);
205 ~CSSFontFaceRule();
208 * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
209 * declaration-block </a> of this rule.
212 CSSStyleDeclaration style() const;
215 class CSSImportRuleImpl;
217 * The \c CSSImportRule interface represents a <a
218 * href="http://www.w3.org/TR/REC-CSS2/cascade.html#at-import">
219 * \c \@import rule </a> within a CSS style sheet. The \c \@import
220 * rule is used to import style rules from other style sheets.
223 class KHTML_EXPORT CSSImportRule : public CSSRule
225 public:
226 CSSImportRule();
227 CSSImportRule(const CSSImportRule &other);
228 CSSImportRule(const CSSRule &other);
229 CSSImportRule(CSSImportRuleImpl *impl);
230 public:
232 CSSImportRule & operator = (const CSSImportRule &other);
233 CSSImportRule & operator = (const CSSRule &other);
235 ~CSSImportRule();
238 * The location of the style sheet to be imported. The attribute
239 * will not contain the \c "url(...)" specifier around
240 * the URI.
243 DOM::DOMString href() const;
246 * A list of media types for which this style sheet may be used.
249 MediaList media() const;
252 * The style sheet referred to by this rule, if it has been
253 * loaded. The value of this attribute is null if the style sheet
254 * has not yet been loaded or if it will not be loaded (e.g. if
255 * the style sheet is for a media type not supported by the user
256 * agent).
259 CSSStyleSheet styleSheet() const;
262 class CSSMediaRuleImpl;
264 * The \c CSSMediaRule interface represents a <a
265 * href="http://www.w3.org/TR/REC-CSS2/media.html#at-media-rule">
266 * \@media rule </a> in a CSS style sheet. A \c \@media rule
267 * can be used to delimit style rules for specific media types.
270 class KHTML_EXPORT CSSMediaRule : public CSSRule
272 public:
273 CSSMediaRule();
274 CSSMediaRule(const CSSMediaRule &other);
275 CSSMediaRule(const CSSRule &other);
276 CSSMediaRule(CSSMediaRuleImpl *impl);
277 public:
279 CSSMediaRule & operator = (const CSSMediaRule &other);
280 CSSMediaRule & operator = (const CSSRule &other);
282 ~CSSMediaRule();
285 * A list of <a
286 * href="http://www.w3.org/TR/REC-CSS2/media.html#media-types">
287 * media types </a> for this rule.
290 MediaList media() const;
293 * A list of all CSS rules contained within the media block.
296 CSSRuleList cssRules() const;
299 * Used to insert a new rule into the media block.
301 * @param rule The parsable text representing the rule. For rule
302 * sets this contains both the selector and the style declaration.
303 * For at-rules, this specifies both the at-identifier and the
304 * rule content.
306 * @param index The index within the media block's rule collection
307 * of the rule before which to insert the specified rule. If the
308 * specified index is equal to the length of the media blocks's
309 * rule collection, the rule will be added to the end of the media
310 * block.
312 * @return The index within the media block's rule collection of
313 * the newly inserted rule.
315 * \exception DOMException
316 * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at
317 * the specified index. e.g. if an \c \@import rule is
318 * inserted after a standard rule set or other at-rule.
320 * INDEX_SIZE_ERR: Raised if the specified index is not a valid
321 * insertion point.
323 * NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is
324 * readonly.
326 * \exception CSSException
327 * SYNTAX_ERR: Raised if the specified rule has a syntax error
328 * and is unparsable.
331 unsigned long insertRule ( const DOM::DOMString &rule, unsigned long index );
334 * Used to delete a rule from the media block.
336 * @param index The index within the media block's rule collection
337 * of the rule to remove.
339 * @return
341 * \exception DOMException
342 * INDEX_SIZE_ERR: Raised if the specified index does not
343 * correspond to a rule in the media rule list.
345 * NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is
346 * readonly.
349 void deleteRule ( unsigned long index );
353 class CSSPageRuleImpl;
355 * The \c CSSPageRule interface represents a <a
356 * href="http://www.w3.org/TR/REC-CSS2/page.html#page-box"> page rule
357 * </a> within a CSS style sheet. The \c @page rule is
358 * used to specify the dimensions, orientation, margins, etc. of a
359 * page box for paged media.
362 class KHTML_EXPORT CSSPageRule : public CSSRule
364 public:
365 CSSPageRule();
366 CSSPageRule(const CSSPageRule &other);
367 CSSPageRule(const CSSRule &other);
368 CSSPageRule(CSSPageRuleImpl *impl);
369 public:
371 CSSPageRule & operator = (const CSSPageRule &other);
372 CSSPageRule & operator = (const CSSRule &other);
374 ~CSSPageRule();
377 * The parsable textual representation of the page selector for
378 * the rule.
381 DOM::DOMString selectorText() const;
384 * see selectorText
385 * @exception CSSException
386 * SYNTAX_ERR: Raised if the specified CSS string value has a
387 * syntax error and is unparsable.
389 * @exception DOMException
390 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
391 * readonly.
394 void setSelectorText( const DOM::DOMString & );
397 * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
398 * declaration-block </a> of this rule.
401 CSSStyleDeclaration style() const;
404 class CSSStyleRuleImpl;
406 * The \c CSSStyleRule interface represents a single <a
407 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8"> rule set </a>
408 * in a CSS style sheet.
411 class KHTML_EXPORT CSSStyleRule : public CSSRule
413 public:
414 CSSStyleRule();
415 CSSStyleRule(const CSSStyleRule &other);
416 CSSStyleRule(const CSSRule &other);
417 CSSStyleRule(CSSStyleRuleImpl *impl);
418 public:
420 CSSStyleRule & operator = (const CSSStyleRule &other);
421 CSSStyleRule & operator = (const CSSRule &other);
423 ~CSSStyleRule();
426 * The textual representation of the <a
427 * href="http://www.w3.org/TR/REC-CSS2/selector.html"> selector
428 * </a> for the rule set. The implementation may have stripped out
429 * insignificant whitespace while parsing the selector.
432 DOM::DOMString selectorText() const;
435 * see selectorText
436 * @exception CSSException
437 * SYNTAX_ERR: Raised if the specified CSS string value has a
438 * syntax error and is unparsable.
440 * @exception DOMException
441 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
442 * readonly.
445 void setSelectorText( const DOM::DOMString & );
448 * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
449 * declaration-block </a> of this rule set.
452 CSSStyleDeclaration style() const;
455 class CSSUnknownRuleImpl;
457 * The \c CSSUnkownRule interface represents an at-rule
458 * not supported by this user agent.
461 class KHTML_EXPORT CSSUnknownRule : public CSSRule
463 public:
464 CSSUnknownRule();
465 CSSUnknownRule(const CSSUnknownRule &other);
466 CSSUnknownRule(const CSSRule &other);
467 CSSUnknownRule(CSSUnknownRuleImpl *impl);
468 public:
470 CSSUnknownRule & operator = (const CSSUnknownRule &other);
471 CSSUnknownRule & operator = (const CSSRule &other);
473 ~CSSUnknownRule();
477 class CSSRuleListImpl;
478 class StyleListImpl;
480 * The \c CSSRuleList interface provides the abstraction
481 * of an ordered collection of CSS rules.
484 class KHTML_EXPORT CSSRuleList
486 public:
487 CSSRuleList();
488 CSSRuleList(const CSSRuleList &other);
489 CSSRuleList(CSSRuleListImpl *i);
490 CSSRuleList(StyleListImpl *i);
491 public:
493 CSSRuleList & operator = (const CSSRuleList &other);
495 ~CSSRuleList();
498 * The number of \c CSSRule s in the list. The range
499 * of valid child rule indices is \c 0 to
500 * \c length-1 inclusive.
503 unsigned long length() const;
506 * Used to retrieve a CSS rule by ordinal index. The order in this
507 * collection represents the order of the rules in the CSS style
508 * sheet.
510 * @param index Index into the collection
512 * @return The style rule at the \c index position in
513 * the \c CSSRuleList , or \c null if that
514 * is not a valid index.
517 CSSRule item ( unsigned long index );
520 * @internal
521 * not part of the DOM
523 CSSRuleListImpl *handle() const;
524 bool isNull() const;
526 protected:
527 // we just need a pointer to an implementation here.
528 CSSRuleListImpl *impl;
532 } // namespace
534 #endif