KHtml

css_stylesheet.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
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.
10  *
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.
15  *
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.
20  *
21  * This file includes excerpts from the Document Object Model (DOM)
22  * Level 2 Specification (Candidate Recommendation)
23  * https://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/
24  * Copyright © 2000 W3C® (MIT, INRIA, Keio), All Rights Reserved.
25  *
26  */
27 #ifndef _CSS_css_stylesheet_h_
28 #define _CSS_css_stylesheet_h_
29 
30 #include <khtml_export.h>
31 
32 #include <dom/dom_string.h>
33 #include <dom/dom_node.h>
34 #include <dom/dom_misc.h>
35 
36 namespace DOM
37 {
38 
39 class StyleSheetImpl;
40 class MediaList;
41 class NodeImpl;
42 class DocumentImpl;
43 
44 /**
45  * The \c StyleSheet interface is the abstract base
46  * interface for any type of style sheet. It represents a single style
47  * sheet associated with a structured document. In HTML, the
48  * StyleSheet interface represents either an external style sheet,
49  * included via the HTML <a
50  * href="https://www.w3.org/TR/REC-html40/struct/links.html#h-12.3">
51  * LINK </a> element, or an inline <a
52  * href="https://www.w3.org/TR/REC-html40/present/styles.html#h-14.2.3">
53  * STYLE </a> element. In XML, this interface represents an external
54  * style sheet, included via a <a
55  * href="https://www.w3.org/TR/xml-stylesheet"> style sheet processing
56  * instruction </a> .
57  *
58  */
59 class KHTML_EXPORT StyleSheet
60 {
61 public:
62  StyleSheet();
63  StyleSheet(const StyleSheet &other);
64  StyleSheet(StyleSheetImpl *impl);
65 public:
66 
67  StyleSheet &operator = (const StyleSheet &other);
68 
69  ~StyleSheet();
70 
71  /**
72  * This specifies the style sheet language for this style sheet.
73  * The style sheet language is specified as a content type (e.g.
74  * "text/css"). The content type is often specified in the
75  * \c ownerNode . A list of registered content types can be
76  * found at <a
77  * href="ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/">
78  * ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/ </a> .
79  * Also see the <a
80  * href="https://www.w3.org/TR/REC-html40/struct/links.html#adef-type-A">
81  * type attribute definition </a> for the \c LINK
82  * element in HTML 4.0, and the type pseudo-attribute for the XML
83  * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
84  * processing instruction </a> .
85  *
86  */
87  DOM::DOMString type() const;
88 
89  /**
90  * \c false if the style sheet is applied to the
91  * document. \c true if it is not. Modifying this
92  * attribute may cause a reresolution of style for the document.
93  *
94  */
95  bool disabled() const;
96 
97  /**
98  * see disabled
99  */
100  void setDisabled(bool);
101 
102  /**
103  * The node that associates this style sheet with the document.
104  * For HTML, this may be the corresponding \c LINK or
105  * \c STYLE element. For XML, it may be the linking
106  * processing instruction. For style sheets that are included by
107  * other style sheets, this attribute has a value of null.
108  *
109  */
110  DOM::Node ownerNode() const;
111 
112  /**
113  * For style sheet languages that support the concept of style
114  * sheet inclusion, this attribute represents the including style
115  * sheet, if one exists. If the style sheet is a top-level style
116  * sheet, or the style sheet language does not support inclusion,
117  * the value of the attribute is null.
118  *
119  */
120  StyleSheet parentStyleSheet() const;
121 
122  /**
123  * If the style sheet is a linked style sheet, the value of its
124  * attribute is its location. For inline style sheets, the value
125  * of this attribute is null. See the <a
126  * href="https://www.w3.org/TR/REC-html40/struct/links.html#adef-href">
127  * href attribute definition </a> for the \c LINK
128  * element in HTML 4.0, and the href pseudo-attribute for the XML
129  * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
130  * processing instruction </a> .
131  *
132  */
133  DOM::DOMString href() const;
134 
135  /**
136  * The advisory title. The title is often specified in the
137  * \c ownerNode . See the <a
138  * href="https://www.w3.org/TR/REC-html40/struct/global.html#adef-title">
139  * title attribute definition </a> for the \c LINK
140  * element in HTML 4.0, and the title pseudo-attribute for the XML
141  * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
142  * processing instruction </a> .
143  *
144  */
145  DOM::DOMString title() const;
146 
147  /**
148  * The intended destination media for style information. The media
149  * is often specified in the \c ownerNode . See the <a
150  * href="https://www.w3.org/TR/REC-html40/present/styles.html#adef-media">
151  * media attribute definition </a> for the \c LINK
152  * element in HTML 4.0, and the media pseudo-attribute for the XML
153  * <a href="https://www.w3.org/TR/WD-xml-stylesheet"> style sheet
154  * processing instruction </a> .
155  *
156  */
157  MediaList media() const;
158 
159  /**
160  * @internal
161  */
162  QUrl baseUrl();
163  bool isCSSStyleSheet() const;
164  StyleSheetImpl *handle() const
165  {
166  return impl;
167  }
168  bool isNull() const
169  {
170  return !impl;
171  }
172 protected:
173  StyleSheetImpl *impl;
174 };
175 
176 /**
177  * This exception is raised when a specific CSS operation is impossible
178  * to perform.
179  */
180 class KHTML_EXPORT CSSException
181 {
182 public:
183  CSSException(unsigned short _code)
184  {
185  code = _code;
186  }
187  CSSException(const CSSException &other)
188  {
189  code = other.code;
190  }
191 
192  CSSException &operator = (const CSSException &other)
193  {
194  code = other.code;
195  return *this;
196  }
197 
198  virtual ~CSSException() {}
199  /**
200  * An integer indicating the type of error generated.
201  *
202  */
203  unsigned short code;
204 
205  enum ExceptionCode {
206  SYNTAX_ERR = 0,
207  INVALID_MODIFICATION_ERR = 1,
208  _EXCEPTION_OFFSET = 1000,
209  _EXCEPTION_MAX = 1999
210  };
211 
212  /// Returns the name of this error
213  DOMString codeAsString() const;
214 
215  /// Returns the name of given error code
216  static DOMString codeAsString(int cssCode);
217 
218  /** @internal - checks to see whether internal code is a CSS one */
219  static bool isCSSExceptionCode(int exceptioncode);
220 };
221 
222 class CSSStyleSheetImpl;
223 class CSSRule;
224 class CSSRuleList;
225 
226 /**
227  * The \c CSSStyleSheet interface is a concrete interface
228  * used to represent a CSS style sheet i.e. a style sheet whose
229  * content type is "text/css".
230  *
231  */
232 class KHTML_EXPORT CSSStyleSheet : public StyleSheet
233 {
234 public:
235  CSSStyleSheet();
236  CSSStyleSheet(const CSSStyleSheet &other);
237  CSSStyleSheet(const StyleSheet &other);
238  CSSStyleSheet(CSSStyleSheetImpl *impl);
239 public:
240 
241  CSSStyleSheet &operator = (const CSSStyleSheet &other);
242  CSSStyleSheet &operator = (const StyleSheet &other);
243 
244  ~CSSStyleSheet();
245 
246  /**
247  * If this style sheet comes from an \c \@import rule,
248  * the \c ownerRule attribute will contain the
249  * \c CSSImportRule . In that case, the \c ownerNode
250  * attribute in the \c StyleSheet interface
251  * will be \c null . If the style sheet comes from an
252  * element or a processing instruction, the \c ownerRule
253  * attribute will be \c null and the
254  * \c ownerNode attribute will contain the \c Node .
255  *
256  */
257  CSSRule ownerRule() const;
258 
259  /**
260  * The list of all CSS rules contained within the style sheet.
261  * This includes both <a
262  * href="https://www.w3.org/TR/CSS2/syndata.html#q8"> rule sets
263  * </a> and <a
264  * href="https://www.w3.org/TR/CSS2/syndata.html#at-rules">
265  * at-rules </a> .
266  *
267  */
268  CSSRuleList cssRules() const;
269 
270  /**
271  * Used to insert a new rule into the style sheet. The new rule
272  * now becomes part of the cascade.
273  *
274  * @param rule The parsable text representing the rule. For rule
275  * sets this contains both the selector and the style declaration.
276  * For at-rules, this specifies both the at-identifier and the
277  * rule content.
278  *
279  * @param index The index within the style sheet's rule list of
280  * the rule before which to insert the specified rule. If the
281  * specified index is equal to the length of the style sheet's
282  * rule collection, the rule will be added to the end of the style
283  * sheet.
284  *
285  * @return The index within the style sheet's rule collection of
286  * the newly inserted rule.
287  *
288  * @exception DOMException
289  * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at
290  * the specified index e.g. if an \c \@import rule is
291  * inserted after a standard rule set or other at-rule.
292  *
293  * INDEX_SIZE_ERR: Raised if the specified index is not a valid
294  * insertion point.
295  *
296  * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
297  * readonly.
298  *
299  * @exception CSSException
300  * SYNTAX_ERR: Raised if the specified rule has a syntax error
301  * and is unparsable.
302  *
303  */
304  unsigned long insertRule(const DOM::DOMString &rule, unsigned long index);
305 
306  /**
307  * Used to delete a rule from the style sheet.
308  *
309  * @param index The index within the style sheet's rule list of
310  * the rule to remove.
311  *
312  * @return
313  *
314  * @exception DOMException
315  * INDEX_SIZE_ERR: Raised if the specified index does not
316  * correspond to a rule in the style sheet's rule list.
317  *
318  * NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
319  * readonly.
320  *
321  */
322  void deleteRule(unsigned long index);
323 
324  /** @internal */
325  DOM::DOMString charset() const;
326 };
327 
328 class StyleSheetListImpl;
329 class StyleSheet;
330 
331 /**
332  * The \c StyleSheetList interface provides the
333  * abstraction of an ordered collection of style sheets.
334  *
335  */
336 class KHTML_EXPORT StyleSheetList
337 {
338 public:
339  StyleSheetList();
340  StyleSheetList(const StyleSheetList &other);
341  StyleSheetList(StyleSheetListImpl *impl);
342 public:
343 
344  StyleSheetList &operator = (const StyleSheetList &other);
345 
346  ~StyleSheetList();
347 
348  /**
349  * The number of \c StyleSheet in the list. The range
350  * of valid child stylesheet indices is \c 0 to
351  * \c length-1 inclusive.
352  *
353  */
354  unsigned long length() const;
355 
356  /**
357  * Used to retrieve a style sheet by ordinal index.
358  *
359  * @param index Index into the collection
360  *
361  * @return The style sheet at the \c index position in
362  * the \c StyleSheetList , or \c null if
363  * that is not a valid index.
364  *
365  */
366  StyleSheet item(unsigned long index);
367 
368  /**
369  * @internal
370  */
371  StyleSheetListImpl *handle() const;
372  bool isNull() const;
373 
374 protected:
375  StyleSheetListImpl *impl;
376 };
377 
378 class MediaListImpl;
379 class CSSRule;
380 class CSSStyleSheet;
381 
382 /**
383  * The \c MediaList interface provides the abstraction of
384  * an ordered collection of media, without defining or constraining
385  * how this collection is implemented. All media are lowercase
386  * strings.
387  *
388  */
389 class KHTML_EXPORT MediaList
390 {
391 public:
392  MediaList();
393  MediaList(const MediaList &other);
394  MediaList(MediaListImpl *impl);
395 public:
396 
397  MediaList &operator = (const MediaList &other);
398 
399  ~MediaList();
400 
401  /**
402  * The parsable textual representation of the media list. This is a
403  * comma-separated list of media.
404  *
405  * @exception DOMException
406  * SYNTAX_ERR: Raised if the specified string value has a syntax error and
407  * is unparsable.
408  *
409  * NO_MODIFICATION_ALLOWED_ERR: Raised if this media list is readonly.
410  */
411  DOM::DOMString mediaText() const;
412 
413  /**
414  * see mediaText
415  */
416  void setMediaText(const DOM::DOMString &value);
417 
418  /**
419  * The number of media in the list. The range of valid media is 0 to length-1 inclusive.
420  */
421  unsigned long length() const;
422 
423  /**
424  * Returns the indexth in the list. If index is greater than or equal to
425  * the number of media in the list, this returns null.
426  *
427  * @param index Index into the collection.
428  *
429  * @return The medium at the indexth position in the MediaList, or null if
430  * that is not a valid index.
431  */
432  DOM::DOMString item(unsigned long index) const;
433 
434  /**
435  * Deletes the medium indicated by oldMedium from the list.
436  *
437  * @param oldMedium The medium to delete in the media list.
438  *
439  * @exception DOMException
440  * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
441  *
442  * NOT_FOUND_ERR: Raised if oldMedium is not in the list.
443  */
444  void deleteMedium(const DOM::DOMString &oldMedium);
445 
446  /**
447  * Adds the medium newMedium to the end of the list. If the newMedium is
448  * already used, it is first removed.
449  *
450  * @param newMedium The new medium to add.
451  *
452  * @exception DOMException
453  * INVALID_CHARACTER_ERR: If the medium contains characters that are
454  * invalid in the underlying style language.
455  *
456  * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
457  */
458  void appendMedium(const DOM::DOMString &newMedium);
459 
460  /**
461  * @internal
462  */
463  MediaListImpl *handle() const;
464  bool isNull() const;
465 
466 protected:
467  MediaListImpl *impl;
468 };
469 
470 class LinkStyleImpl;
471 
472 class KHTML_EXPORT LinkStyle
473 {
474 public:
475  LinkStyle();
476  LinkStyle(const LinkStyle &other);
477 
478  LinkStyle &operator = (const LinkStyle &other);
479  LinkStyle &operator = (const Node &other);
480 
481  ~LinkStyle();
482 
483  StyleSheet sheet();
484 
485  bool isNull() const;
486 
487 protected:
488  DOM::NodeImpl *node;
489  LinkStyleImpl *impl;
490 };
491 
492 class DocumentStyleImpl;
493 
494 class KHTML_EXPORT DocumentStyle
495 {
496 public:
497  DocumentStyle();
498  DocumentStyle(const DocumentStyle &other);
499 
500  DocumentStyle &operator = (const DocumentStyle &other);
501  DocumentStyle &operator = (const Document &other);
502 
503  ~DocumentStyle();
504 
505  StyleSheetList styleSheets() const;
506 
507  DOMString preferredStylesheetSet() const;
508  DOMString selectedStylesheetSet() const;
509  void setSelectedStylesheetSet(const DOMString &aString);
510 
511  bool isNull() const
512  {
513  return !impl;
514  }
515 
516 protected:
517  DOM::DocumentImpl *doc;
518  DocumentStyleImpl *impl;
519 };
520 
521 } // namespace
522 
523 #endif
The CSSNamespaceRule interface represents an.
Definition: css_rule.h:455
The CSSRule interface is the abstract base interface for any type of CSS statement .
Definition: css_rule.h:53
This library provides a full-featured HTML parser and widget.
The StyleSheet interface is the abstract base interface for any type of style sheet.
unsigned short code
An integer indicating the type of error generated.
The StyleSheetList interface provides the abstraction of an ordered collection of style sheets.
The CSSStyleSheet interface is a concrete interface used to represent a CSS style sheet i....
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
The MediaList interface provides the abstraction of an ordered collection of media,...
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:278
The CSSRuleList interface provides the abstraction of an ordered collection of CSS rules.
Definition: css_rule.h:507
This exception is raised when a specific CSS operation is impossible to perform.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:05:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.