fix logic
[personal-kdelibs.git] / khtml / dom / css_stylesheet.h
blobff082ef7955195ab457b5da8c643a7e7fe4027dd
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_stylesheet_h_
28 #define _CSS_css_stylesheet_h_
30 #include <khtml_export.h>
32 #include <dom/dom_string.h>
33 #include <dom/dom_node.h>
34 #include <dom/dom_misc.h>
36 namespace DOM {
38 class StyleSheetImpl;
39 class MediaList;
40 class NodeImpl;
41 class DocumentImpl;
43 /**
44 * The \c StyleSheet interface is the abstract base
45 * interface for any type of style sheet. It represents a single style
46 * sheet associated with a structured document. In HTML, the
47 * StyleSheet interface represents either an external style sheet,
48 * included via the HTML <a
49 * href="http://www.w3.org/TR/REC-html40/struct/links.html#h-12.3">
50 * LINK </a> element, or an inline <a
51 * href="http://www.w3.org/TR/REC-html40/present/styles.html#h-14.2.3">
52 * STYLE </a> element. In XML, this interface represents an external
53 * style sheet, included via a <a
54 * href="http://www.w3.org/TR/xml-stylesheet"> style sheet processing
55 * instruction </a> .
58 class KHTML_EXPORT StyleSheet
60 public:
61 StyleSheet();
62 StyleSheet(const StyleSheet &other);
63 StyleSheet(StyleSheetImpl *impl);
64 public:
66 StyleSheet & operator = (const StyleSheet &other);
68 ~StyleSheet();
70 /**
71 * This specifies the style sheet language for this style sheet.
72 * The style sheet language is specified as a content type (e.g.
73 * "text/css"). The content type is often specified in the
74 * \c ownerNode . A list of registered content types can be
75 * found at <a
76 * href="ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/">
77 * ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/ </a> .
78 * Also see the <a
79 * href="http://www.w3.org/TR/REC-html40/struct/links.html#adef-type-A">
80 * type attribute definition </a> for the \c LINK
81 * element in HTML 4.0, and the type pseudo-attribute for the XML
82 * <a href="http://www.w3.org/TR/xml-stylesheet"> style sheet
83 * processing instruction </a> .
86 DOM::DOMString type() const;
88 /**
89 * \c false if the style sheet is applied to the
90 * document. \c true if it is not. Modifying this
91 * attribute may cause a reresolution of style for the document.
94 bool disabled() const;
96 /**
97 * see disabled
99 void setDisabled( bool );
102 * The node that associates this style sheet with the document.
103 * For HTML, this may be the corresponding \c LINK or
104 * \c STYLE element. For XML, it may be the linking
105 * processing instruction. For style sheets that are included by
106 * other style sheets, this attribute has a value of null.
109 DOM::Node ownerNode() const;
112 * For style sheet languages that support the concept of style
113 * sheet inclusion, this attribute represents the including style
114 * sheet, if one exists. If the style sheet is a top-level style
115 * sheet, or the style sheet language does not support inclusion,
116 * the value of the attribute is null.
119 StyleSheet parentStyleSheet() const;
122 * If the style sheet is a linked style sheet, the value of its
123 * attribute is its location. For inline style sheets, the value
124 * of this attribute is null. See the <a
125 * href="http://www.w3.org/TR/REC-html40/struct/links.html#adef-href">
126 * href attribute definition </a> for the \c LINK
127 * element in HTML 4.0, and the href pseudo-attribute for the XML
128 * <a href="http://www.w3.org/TR/xml-stylesheet"> style sheet
129 * processing instruction </a> .
132 DOM::DOMString href() const;
135 * The advisory title. The title is often specified in the
136 * \c ownerNode . See the <a
137 * href="http://www.w3.org/TR/REC-html40/struct/global.html#adef-title">
138 * title attribute definition </a> for the \c LINK
139 * element in HTML 4.0, and the title pseudo-attribute for the XML
140 * <a href="http://www.w3.org/TR/xml-stylesheet"> style sheet
141 * processing instruction </a> .
144 DOM::DOMString title() const;
147 * The intended destination media for style information. The media
148 * is often specified in the \c ownerNode . See the <a
149 * href="http://www.w3.org/TR/REC-html40/present/styles.html#adef-media">
150 * media attribute definition </a> for the \c LINK
151 * element in HTML 4.0, and the media pseudo-attribute for the XML
152 * <a href="http://www.w3.org/TR/WD-xml-stylesheet"> style sheet
153 * processing instruction </a> .
156 MediaList media() const;
159 * @internal
161 KUrl baseUrl();
162 bool isCSSStyleSheet() const;
163 StyleSheetImpl *handle() const { return impl; }
164 bool isNull() const { return !impl; }
165 protected:
166 StyleSheetImpl *impl;
171 * This exception is raised when a specific CSS operation is impossible
172 * to perform.
174 class KHTML_EXPORT CSSException
176 public:
177 CSSException(unsigned short _code) { code = _code; }
178 CSSException(const CSSException &other) { code = other.code; }
180 CSSException & operator = (const CSSException &other)
181 { code = other.code; return *this; }
183 virtual ~CSSException() {}
185 * An integer indicating the type of error generated.
188 unsigned short code;
190 enum ExceptionCode
192 SYNTAX_ERR = 0,
193 INVALID_MODIFICATION_ERR = 1,
194 _EXCEPTION_OFFSET = 1000,
195 _EXCEPTION_MAX = 1999
199 class CSSStyleSheetImpl;
200 class CSSRule;
201 class CSSRuleList;
204 * The \c CSSStyleSheet interface is a concrete interface
205 * used to represent a CSS style sheet i.e. a style sheet whose
206 * content type is "text/css".
209 class KHTML_EXPORT CSSStyleSheet : public StyleSheet
211 public:
212 CSSStyleSheet();
213 CSSStyleSheet(const CSSStyleSheet &other);
214 CSSStyleSheet(const StyleSheet &other);
215 CSSStyleSheet(CSSStyleSheetImpl *impl);
216 public:
218 CSSStyleSheet & operator = (const CSSStyleSheet &other);
219 CSSStyleSheet & operator = (const StyleSheet &other);
221 ~CSSStyleSheet();
224 * If this style sheet comes from an \c \@import rule,
225 * the \c ownerRule attribute will contain the
226 * \c CSSImportRule . In that case, the \c ownerNode
227 * attribute in the \c StyleSheet interface
228 * will be \c null . If the style sheet comes from an
229 * element or a processing instruction, the \c ownerRule
230 * attribute will be \c null and the
231 * \c ownerNode attribute will contain the \c Node .
234 CSSRule ownerRule() const;
237 * The list of all CSS rules contained within the style sheet.
238 * This includes both <a
239 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#q8"> rule sets
240 * </a> and <a
241 * href="http://www.w3.org/TR/REC-CSS2/syndata.html#at-rules">
242 * at-rules </a> .
245 CSSRuleList cssRules() const;
248 * Used to insert a new rule into the style sheet. The new rule
249 * now becomes part of the cascade.
251 * @param rule The parsable text representing the rule. For rule
252 * sets this contains both the selector and the style declaration.
253 * For at-rules, this specifies both the at-identifier and the
254 * rule content.
256 * @param index The index within the style sheet's rule list of
257 * the rule before which to insert the specified rule. If the
258 * specified index is equal to the length of the style sheet's
259 * rule collection, the rule will be added to the end of the style
260 * sheet.
262 * @return The index within the style sheet's rule collection of
263 * the newly inserted rule.
265 * @exception DOMException
266 * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at
267 * the specified index e.g. if an \c \@import rule is
268 * inserted after a standard rule set or other at-rule.
270 * INDEX_SIZE_ERR: Raised if the specified index is not a valid
271 * insertion point.
273 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
274 * readonly.
276 * @exception CSSException
277 * SYNTAX_ERR: Raised if the specified rule has a syntax error
278 * and is unparsable.
281 unsigned long insertRule ( const DOM::DOMString &rule, unsigned long index );
284 * Used to delete a rule from the style sheet.
286 * @param index The index within the style sheet's rule list of
287 * the rule to remove.
289 * @return
291 * @exception DOMException
292 * INDEX_SIZE_ERR: Raised if the specified index does not
293 * correspond to a rule in the style sheet's rule list.
295 * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
296 * readonly.
299 void deleteRule ( unsigned long index );
301 /** @internal */
302 DOM::DOMString charset() const;
306 class StyleSheetListImpl;
307 class StyleSheet;
310 * The \c StyleSheetList interface provides the
311 * abstraction of an ordered collection of style sheets.
314 class KHTML_EXPORT StyleSheetList
316 public:
317 StyleSheetList();
318 StyleSheetList(const StyleSheetList &other);
319 StyleSheetList(StyleSheetListImpl *impl);
320 public:
322 StyleSheetList & operator = (const StyleSheetList &other);
324 ~StyleSheetList();
327 * The number of \c StyleSheet in the list. The range
328 * of valid child stylesheet indices is \c 0 to
329 * \c length-1 inclusive.
332 unsigned long length() const;
335 * Used to retrieve a style sheet by ordinal index.
337 * @param index Index into the collection
339 * @return The style sheet at the \c index position in
340 * the \c StyleSheetList , or \c null if
341 * that is not a valid index.
344 StyleSheet item ( unsigned long index );
347 * @internal
349 StyleSheetListImpl *handle() const;
350 bool isNull() const;
352 protected:
353 StyleSheetListImpl *impl;
357 class MediaListImpl;
358 class CSSRule;
359 class CSSStyleSheet;
362 * The \c MediaList interface provides the abstraction of
363 * an ordered collection of media, without defining or constraining
364 * how this collection is implemented. All media are lowercase
365 * strings.
368 class KHTML_EXPORT MediaList
370 public:
371 MediaList();
372 MediaList(const MediaList &other);
373 MediaList(MediaListImpl *impl);
374 public:
376 MediaList & operator = (const MediaList &other);
378 ~MediaList();
381 * The parsable textual representation of the media list. This is a
382 * comma-separated list of media.
384 * @exception DOMException
385 * SYNTAX_ERR: Raised if the specified string value has a syntax error and
386 * is unparsable.
388 * NO_MODIFICATION_ALLOWED_ERR: Raised if this media list is readonly.
390 DOM::DOMString mediaText() const;
393 * see mediaText
395 void setMediaText(const DOM::DOMString &value);
398 * The number of media in the list. The range of valid media is 0 to length-1 inclusive.
400 unsigned long length() const;
404 * Returns the indexth in the list. If index is greater than or equal to
405 * the number of media in the list, this returns null.
407 * @param index Index into the collection.
409 * @return The medium at the indexth position in the MediaList, or null if
410 * that is not a valid index.
412 DOM::DOMString item(unsigned long index) const;
415 * Deletes the medium indicated by oldMedium from the list.
417 * @param oldMedium The medium to delete in the media list.
419 * @exception DOMException
420 * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
422 * NOT_FOUND_ERR: Raised if oldMedium is not in the list.
424 void deleteMedium(const DOM::DOMString &oldMedium);
427 * Adds the medium newMedium to the end of the list. If the newMedium is
428 * already used, it is first removed.
430 * @param newMedium The new medium to add.
432 * @exception DOMException
433 * INVALID_CHARACTER_ERR: If the medium contains characters that are
434 * invalid in the underlying style language.
436 * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
438 void appendMedium(const DOM::DOMString &newMedium);
441 * @internal
443 MediaListImpl *handle() const;
444 bool isNull() const;
446 protected:
447 MediaListImpl *impl;
450 class LinkStyleImpl;
452 class KHTML_EXPORT LinkStyle
454 public:
455 LinkStyle();
456 LinkStyle(const LinkStyle &other);
458 LinkStyle & operator = (const LinkStyle &other);
459 LinkStyle & operator = (const Node &other);
461 ~LinkStyle();
463 StyleSheet sheet();
465 bool isNull() const;
467 protected:
468 DOM::NodeImpl *node;
469 LinkStyleImpl *impl;
472 class DocumentStyleImpl;
474 class KHTML_EXPORT DocumentStyle
476 public:
477 DocumentStyle();
478 DocumentStyle(const DocumentStyle &other);
480 DocumentStyle & operator = (const DocumentStyle &other);
481 DocumentStyle & operator = (const Document &other);
483 ~DocumentStyle();
485 StyleSheetList styleSheets() const ;
487 DOMString preferredStylesheetSet() const;
488 DOMString selectedStylesheetSet() const;
489 void setSelectedStylesheetSet( const DOMString& aString );
491 bool isNull() const { return !impl; }
493 protected:
494 DOM::DocumentImpl *doc;
495 DocumentStyleImpl *impl;
498 } // namespace
500 #endif