summaryrefslogtreecommitdiffstats
path: root/khtml/dom/css_rule.h
blob: 5f27e8f8ae9e34425500cc18467366e808433357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*
 * This file is part of the DOM implementation for KDE.
 *
 * (C) 1999 Lars Knoll ([email protected])
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * This file includes excerpts from the Document Object Model (DOM)
 * Level 2 Specification (Candidate Recommendation)
 * http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/
 * Copyright � 2000 W3C� (MIT, INRIA, Keio), All Rights Reserved.
 *
 */
#ifndef _CSS_css_rule_h_
#define _CSS_css_rule_h_

#include <dom/dom_string.h>
#include <dom/css_stylesheet.h>
#include <dom/css_value.h>

namespace DOM {

class CSSRuleImpl;

/**
 * The \c CSSRule interface is the abstract base interface
 * for any type of CSS <a
 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q5"> statement
 * </a> . This includes both <a
 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8"> rule sets
 * </a> and <a
 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#at-rules">
 * at-rules </a> . An implementation is expected to preserve all rules
 * specified in a CSS style sheet, even if it is not recognized.
 * Unrecognized rules are represented using the \c CSSUnknownRule
 * interface.
 *
 */
class KHTML_EXPORT CSSRule
{
public:
    CSSRule();
    CSSRule(const CSSRule &other);
    CSSRule(CSSRuleImpl *impl);
public:

    CSSRule & operator = (const CSSRule &other);

    ~CSSRule();
    /**
     * An integer indicating which type of rule this is.
     *
     */
    enum RuleType {
        UNKNOWN_RULE = 0,
        STYLE_RULE = 1,
        CHARSET_RULE = 2,
        IMPORT_RULE = 3,
        MEDIA_RULE = 4,
        FONT_FACE_RULE = 5,
        PAGE_RULE = 6,
	QUIRKS_RULE = 100 // KHTML CSS Extension
    };

    /**
     * The type of the rule, as defined above. The expectation is that
     * binding-specific casting methods can be used to cast down from
     * an instance of the \c CSSRule interface to the
     * specific derived interface implied by the \c type .
     *
     */
    unsigned short type() const;

    /**
     * The parsable textual representation of the rule. This reflects
     * the current state of the rule and not its initial value.
     *
     */
    DOM::DOMString cssText() const;

    /**
     * see cssText
     * @exception DOMException
     *
     *  HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted
     * at this point in the style sheet.
     *
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
     * readonly.
     *
     * @exception CSSException
     * SYNTAX_ERR: Raised if the specified CSS string value has a
     * syntax error and is unparsable.
     *
     * INVALID_MODIFICATION_ERR: Raised if the specified CSS string value
     * represents a different type of rule than the current one.
     */
    void setCssText( const DOM::DOMString & );

    /**
     * The style sheet that contains this rule.
     *
     */
    CSSStyleSheet parentStyleSheet() const;

    /**
     * If this rule is contained inside another rule (e.g. a style
     * rule inside an \@media block), this is the containing rule. If
     * this rule is not nested inside any other rules, this returns
     * \c null .
     *
     */
    CSSRule parentRule() const;

    /**
     * @internal
     * not part of the DOM
     */
    CSSRuleImpl *handle() const;
    bool isNull() const;

protected:
    CSSRuleImpl *impl;

    void assignOther( const CSSRule &other, RuleType thisType );
};

class CSSCharsetRuleImpl;

/**
 * The \c CSSCharsetRule interface a <a href=""> \@charset
 * rule </a> in a CSS style sheet. A \c \@charset rule can
 * be used to define the encoding of the style sheet.
 *
 */
class KHTML_EXPORT CSSCharsetRule : public CSSRule
{
public:
    CSSCharsetRule();
    CSSCharsetRule(const CSSCharsetRule &other);
    CSSCharsetRule(const CSSRule &other);
    CSSCharsetRule(CSSCharsetRuleImpl *impl);
public:

    CSSCharsetRule & operator = (const CSSCharsetRule &other);
    CSSCharsetRule & operator = (const CSSRule &other);

    ~CSSCharsetRule();

    /**
     * The encoding information used in this \c \@charset
     * rule.
     *
     */
    DOM::DOMString encoding() const;

    /**
     * see encoding
     * @exception CSSException
     * SYNTAX_ERR: Raised if the specified encoding value has a syntax
     * error and is unparsable.
     *
     * @exception DOMException
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this encoding rule is
     * readonly.
     *
     */
    void setEncoding( const DOM::DOMString & );
};


class CSSFontFaceRuleImpl;
/**
 * The \c CSSFontFaceRule interface represents a <a
 * href="http://www.w3.org/TR/REC-CSS2/fonts.html#font-descriptions">
 * \c \@font-face rule </a> in a CSS style sheet. The \c \@font-face
 * rule is used to hold a set of font descriptions.
 *
 */
class KHTML_EXPORT CSSFontFaceRule : public CSSRule
{
public:
    CSSFontFaceRule();
    CSSFontFaceRule(const CSSFontFaceRule &other);
    CSSFontFaceRule(const CSSRule &other);
    CSSFontFaceRule(CSSFontFaceRuleImpl *impl);
public:

    CSSFontFaceRule & operator = (const CSSFontFaceRule &other);
    CSSFontFaceRule & operator = (const CSSRule &other);

    ~CSSFontFaceRule();

    /**
     * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
     * declaration-block </a> of this rule.
     *
     */
    CSSStyleDeclaration style() const;
};

class CSSImportRuleImpl;
/**
 * The \c CSSImportRule interface represents a <a
 * href="http://www.w3.org/TR/REC-CSS2/cascade.html#at-import">
 * \c \@import rule </a> within a CSS style sheet. The \c \@import
 * rule is used to import style rules from other style sheets.
 *
 */
class KHTML_EXPORT CSSImportRule : public CSSRule
{
public:
    CSSImportRule();
    CSSImportRule(const CSSImportRule &other);
    CSSImportRule(const CSSRule &other);
    CSSImportRule(CSSImportRuleImpl *impl);
public:

    CSSImportRule & operator = (const CSSImportRule &other);
    CSSImportRule & operator = (const CSSRule &other);

    ~CSSImportRule();

    /**
     * The location of the style sheet to be imported. The attribute
     * will not contain the \c "url(...)" specifier around
     * the URI.
     *
     */
    DOM::DOMString href() const;

    /**
     * A list of media types for which this style sheet may be used.
     *
     */
    MediaList media() const;

    /**
     * The style sheet referred to by this rule, if it has been
     * loaded. The value of this attribute is null if the style sheet
     * has not yet been loaded or if it will not be loaded (e.g. if
     * the style sheet is for a media type not supported by the user
     * agent).
     *
     */
    CSSStyleSheet styleSheet() const;
};

class CSSMediaRuleImpl;
/**
 * The \c CSSMediaRule interface represents a <a
 * href="http://www.w3.org/TR/REC-CSS2/media.html#at-media-rule">
 * \@media rule </a> in a CSS style sheet. A \c \@media rule
 * can be used to delimit style rules for specific media types.
 *
 */
class KHTML_EXPORT CSSMediaRule : public CSSRule
{
public:
    CSSMediaRule();
    CSSMediaRule(const CSSMediaRule &other);
    CSSMediaRule(const CSSRule &other);
    CSSMediaRule(CSSMediaRuleImpl *impl);
public:

    CSSMediaRule & operator = (const CSSMediaRule &other);
    CSSMediaRule & operator = (const CSSRule &other);

    ~CSSMediaRule();

    /**
     * A list of <a
     * href="http://www.w3.org/TR/REC-CSS2/media.html#media-types">
     * media types </a> for this rule.
     *
     */
    MediaList media() const;

    /**
     * A list of all CSS rules contained within the media block.
     *
     */
    CSSRuleList cssRules() const;

    /**
     * Used to insert a new rule into the media block.
     *
     * @param rule The parsable text representing the rule. For rule
     * sets this contains both the selector and the style declaration.
     * For at-rules, this specifies both the at-identifier and the
     * rule content.
     *
     * @param index The index within the media block's rule collection
     * of the rule before which to insert the specified rule. If the
     * specified index is equal to the length of the media blocks's
     * rule collection, the rule will be added to the end of the media
     * block.
     *
     * @return The index within the media block's rule collection of
     * the newly inserted rule.
     *
     * \exception DOMException
     * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at
     * the specified index. e.g. if an \c \@import rule is
     * inserted after a standard rule set or other at-rule.
     *
     *  INDEX_SIZE_ERR: Raised if the specified index is not a valid
     * insertion point.
     *
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is
     * readonly.
     *
     * \exception CSSException
     *  SYNTAX_ERR: Raised if the specified rule has a syntax error
     * and is unparsable.
     *
     */
    unsigned long insertRule ( const DOM::DOMString &rule, unsigned long index );

    /**
     * Used to delete a rule from the media block.
     *
     * @param index The index within the media block's rule collection
     * of the rule to remove.
     *
     * @return
     *
     * \exception DOMException
     * INDEX_SIZE_ERR: Raised if the specified index does not
     * correspond to a rule in the media rule list.
     *
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is
     * readonly.
     *
     */
    void deleteRule ( unsigned long index );
};


class CSSPageRuleImpl;
/**
 * The \c CSSPageRule interface represents a <a
 * href="http://www.w3.org/TR/REC-CSS2/page.html#page-box"> page rule
 * </a> within a CSS style sheet. The \c @page rule is
 * used to specify the dimensions, orientation, margins, etc. of a
 * page box for paged media.
 *
 */
class KHTML_EXPORT CSSPageRule : public CSSRule
{
public:
    CSSPageRule();
    CSSPageRule(const CSSPageRule &other);
    CSSPageRule(const CSSRule &other);
    CSSPageRule(CSSPageRuleImpl *impl);
public:

    CSSPageRule & operator = (const CSSPageRule &other);
    CSSPageRule & operator = (const CSSRule &other);

    ~CSSPageRule();

    /**
     * The parsable textual representation of the page selector for
     * the rule.
     *
     */
    DOM::DOMString selectorText() const;

    /**
     * see selectorText
     * @exception CSSException
     * SYNTAX_ERR: Raised if the specified CSS string value has a
     * syntax error and is unparsable.
     *
     * @exception DOMException
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
     * readonly.
     *
     */
    void setSelectorText( const DOM::DOMString & );

    /**
     * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
     * declaration-block </a> of this rule.
     *
     */
    CSSStyleDeclaration style() const;
};

class CSSStyleRuleImpl;
/**
 * The \c CSSStyleRule interface represents a single <a
 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8"> rule set </a>
 * in a CSS style sheet.
 *
 */
class KHTML_EXPORT CSSStyleRule : public CSSRule
{
public:
    CSSStyleRule();
    CSSStyleRule(const CSSStyleRule &other);
    CSSStyleRule(const CSSRule &other);
    CSSStyleRule(CSSStyleRuleImpl *impl);
public:

    CSSStyleRule & operator = (const CSSStyleRule &other);
    CSSStyleRule & operator = (const CSSRule &other);

    ~CSSStyleRule();

    /**
     * The textual representation of the <a
     * href="http://www.w3.org/TR/REC-CSS2/selector.html"> selector
     * </a> for the rule set. The implementation may have stripped out
     * insignificant whitespace while parsing the selector.
     *
     */
    DOM::DOMString selectorText() const;

    /**
     * see selectorText
     * @exception CSSException
     * SYNTAX_ERR: Raised if the specified CSS string value has a
     * syntax error and is unparsable.
     *
     * @exception DOMException
     *  NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
     * readonly.
     *
     */
    void setSelectorText( const DOM::DOMString & );

    /**
     * The <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8">
     * declaration-block </a> of this rule set.
     *
     */
    CSSStyleDeclaration style() const;
};

class CSSUnknownRuleImpl;
/**
 * The \c CSSUnkownRule interface represents an at-rule
 * not supported by this user agent.
 *
 */
class KHTML_EXPORT CSSUnknownRule : public CSSRule
{
public:
    CSSUnknownRule();
    CSSUnknownRule(const CSSUnknownRule &other);
    CSSUnknownRule(const CSSRule &other);
    CSSUnknownRule(CSSUnknownRuleImpl *impl);
public:

    CSSUnknownRule & operator = (const CSSUnknownRule &other);
    CSSUnknownRule & operator = (const CSSRule &other);

    ~CSSUnknownRule();
};


class CSSRuleListImpl;
class StyleListImpl;
/**
 * The \c CSSRuleList interface provides the abstraction
 * of an ordered collection of CSS rules.
 *
 */
class KHTML_EXPORT CSSRuleList
{
public:
    CSSRuleList();
    CSSRuleList(const CSSRuleList &other);
    CSSRuleList(CSSRuleListImpl *i);
    CSSRuleList(StyleListImpl *i);
public:

    CSSRuleList & operator = (const CSSRuleList &other);

    ~CSSRuleList();

    /**
     * The number of \c CSSRule s in the list. The range
     * of valid child rule indices is \c 0 to
     * \c length-1 inclusive.
     *
     */
    unsigned long length() const;

    /**
     * Used to retrieve a CSS rule by ordinal index. The order in this
     * collection represents the order of the rules in the CSS style
     * sheet.
     *
     * @param index Index into the collection
     *
     * @return The style rule at the \c index position in
     * the \c CSSRuleList , or \c null if that
     * is not a valid index.
     *
     */
    CSSRule item ( unsigned long index );

    /**
     * @internal
     * not part of the DOM
     */
    CSSRuleListImpl *handle() const;
    bool isNull() const;

protected:
    // we just need a pointer to an implementation here.
    CSSRuleListImpl *impl;
};


} // namespace

#endif