File indexing completed on 2024-04-28 15:22:54

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_stylesheet_h_
0028 #define _CSS_css_stylesheet_h_
0029 
0030 #include <khtml_export.h>
0031 
0032 #include <dom/dom_string.h>
0033 #include <dom/dom_node.h>
0034 #include <dom/dom_misc.h>
0035 
0036 namespace DOM
0037 {
0038 
0039 class StyleSheetImpl;
0040 class MediaList;
0041 class NodeImpl;
0042 class DocumentImpl;
0043 
0044 /**
0045  * The \c StyleSheet interface is the abstract base
0046  * interface for any type of style sheet. It represents a single style
0047  * sheet associated with a structured document. In HTML, the
0048  * StyleSheet interface represents either an external style sheet,
0049  * included via the HTML <a
0050  * href="https://www.w3.org/TR/REC-html40/struct/links.html#h-12.3">
0051  * LINK </a> element, or an inline <a
0052  * href="https://www.w3.org/TR/REC-html40/present/styles.html#h-14.2.3">
0053  * STYLE </a> element. In XML, this interface represents an external
0054  * style sheet, included via a <a
0055  * href="https://www.w3.org/TR/xml-stylesheet"> style sheet processing
0056  * instruction </a> .
0057  *
0058  */
0059 class KHTML_EXPORT StyleSheet
0060 {
0061 public:
0062     StyleSheet();
0063     StyleSheet(const StyleSheet &other);
0064     StyleSheet(StyleSheetImpl *impl);
0065 public:
0066 
0067     StyleSheet &operator = (const StyleSheet &other);
0068 
0069     ~StyleSheet();
0070 
0071     /**
0072      * This specifies the style sheet language for this style sheet.
0073      * The style sheet language is specified as a content type (e.g.
0074      * "text/css"). The content type is often specified in the
0075      * \c ownerNode . A list of registered content types can be
0076      * found at <a
0077      * href="ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/">
0078      * ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/ </a> .
0079      * Also see the <a
0080      * href="https://www.w3.org/TR/REC-html40/struct/links.html#adef-type-A">
0081      * type attribute definition </a> for the \c LINK
0082      * element in HTML 4.0, and the type pseudo-attribute for the XML
0083      * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
0084      * processing instruction </a> .
0085      *
0086      */
0087     DOM::DOMString type() const;
0088 
0089     /**
0090      * \c false if the style sheet is applied to the
0091      * document. \c true if it is not. Modifying this
0092      * attribute may cause a reresolution of style for the document.
0093      *
0094      */
0095     bool disabled() const;
0096 
0097     /**
0098      * see disabled
0099      */
0100     void setDisabled(bool);
0101 
0102     /**
0103      * The node that associates this style sheet with the document.
0104      * For HTML, this may be the corresponding \c LINK or
0105      * \c STYLE element. For XML, it may be the linking
0106      * processing instruction. For style sheets that are included by
0107      * other style sheets, this attribute has a value of null.
0108      *
0109      */
0110     DOM::Node ownerNode() const;
0111 
0112     /**
0113      * For style sheet languages that support the concept of style
0114      * sheet inclusion, this attribute represents the including style
0115      * sheet, if one exists. If the style sheet is a top-level style
0116      * sheet, or the style sheet language does not support inclusion,
0117      * the value of the attribute is null.
0118      *
0119      */
0120     StyleSheet parentStyleSheet() const;
0121 
0122     /**
0123      * If the style sheet is a linked style sheet, the value of its
0124      * attribute is its location. For inline style sheets, the value
0125      * of this attribute is null. See the <a
0126      * href="https://www.w3.org/TR/REC-html40/struct/links.html#adef-href">
0127      * href attribute definition </a> for the \c LINK
0128      * element in HTML 4.0, and the href pseudo-attribute for the XML
0129      * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
0130      * processing instruction </a> .
0131      *
0132      */
0133     DOM::DOMString href() const;
0134 
0135     /**
0136      * The advisory title. The title is often specified in the
0137      * \c ownerNode . See the <a
0138      * href="https://www.w3.org/TR/REC-html40/struct/global.html#adef-title">
0139      * title attribute definition </a> for the \c LINK
0140      * element in HTML 4.0, and the title pseudo-attribute for the XML
0141      * <a href="https://www.w3.org/TR/xml-stylesheet"> style sheet
0142      * processing instruction </a> .
0143      *
0144      */
0145     DOM::DOMString title() const;
0146 
0147     /**
0148      * The intended destination media for style information. The media
0149      * is often specified in the \c ownerNode . See the <a
0150      * href="https://www.w3.org/TR/REC-html40/present/styles.html#adef-media">
0151      * media attribute definition </a> for the \c LINK
0152      * element in HTML 4.0, and the media pseudo-attribute for the XML
0153      * <a href="https://www.w3.org/TR/WD-xml-stylesheet"> style sheet
0154      * processing instruction </a> .
0155      *
0156      */
0157     MediaList media() const;
0158 
0159     /**
0160      * @internal
0161      */
0162     QUrl baseUrl();
0163     bool isCSSStyleSheet() const;
0164     StyleSheetImpl *handle() const
0165     {
0166         return impl;
0167     }
0168     bool isNull() const
0169     {
0170         return !impl;
0171     }
0172 protected:
0173     StyleSheetImpl *impl;
0174 };
0175 
0176 /**
0177  * This exception is raised when a specific CSS operation is impossible
0178  * to perform.
0179  */
0180 class KHTML_EXPORT CSSException
0181 {
0182 public:
0183     CSSException(unsigned short _code)
0184     {
0185         code = _code;
0186     }
0187     CSSException(const CSSException &other)
0188     {
0189         code = other.code;
0190     }
0191 
0192     CSSException &operator = (const CSSException &other)
0193     {
0194         code = other.code;
0195         return *this;
0196     }
0197 
0198     virtual ~CSSException() {}
0199     /**
0200      * An integer indicating the type of error generated.
0201      *
0202      */
0203     unsigned short   code;
0204 
0205     enum ExceptionCode {
0206         SYNTAX_ERR                     = 0,
0207         INVALID_MODIFICATION_ERR       = 1,
0208         _EXCEPTION_OFFSET              = 1000,
0209         _EXCEPTION_MAX                 = 1999
0210     };
0211 
0212     /// Returns the name of this error
0213     DOMString codeAsString() const;
0214 
0215     /// Returns the name of given error code
0216     static DOMString codeAsString(int cssCode);
0217 
0218     /** @internal - checks to see whether internal code is a CSS one */
0219     static bool isCSSExceptionCode(int exceptioncode);
0220 };
0221 
0222 class CSSStyleSheetImpl;
0223 class CSSRule;
0224 class CSSRuleList;
0225 
0226 /**
0227  * The \c CSSStyleSheet interface is a concrete interface
0228  * used to represent a CSS style sheet i.e. a style sheet whose
0229  * content type is "text/css".
0230  *
0231  */
0232 class KHTML_EXPORT CSSStyleSheet : public StyleSheet
0233 {
0234 public:
0235     CSSStyleSheet();
0236     CSSStyleSheet(const CSSStyleSheet &other);
0237     CSSStyleSheet(const StyleSheet &other);
0238     CSSStyleSheet(CSSStyleSheetImpl *impl);
0239 public:
0240 
0241     CSSStyleSheet &operator = (const CSSStyleSheet &other);
0242     CSSStyleSheet &operator = (const StyleSheet &other);
0243 
0244     ~CSSStyleSheet();
0245 
0246     /**
0247      * If this style sheet comes from an \c \@import rule,
0248      * the \c ownerRule attribute will contain the
0249      * \c CSSImportRule . In that case, the \c ownerNode
0250      * attribute in the \c StyleSheet interface
0251      * will be \c null . If the style sheet comes from an
0252      * element or a processing instruction, the \c ownerRule
0253      * attribute will be \c null and the
0254      * \c ownerNode attribute will contain the \c Node .
0255      *
0256      */
0257     CSSRule ownerRule() const;
0258 
0259     /**
0260      * The list of all CSS rules contained within the style sheet.
0261      * This includes both <a
0262      * href="https://www.w3.org/TR/CSS2/syndata.html#q8"> rule sets
0263      * </a> and <a
0264      * href="https://www.w3.org/TR/CSS2/syndata.html#at-rules">
0265      * at-rules </a> .
0266      *
0267      */
0268     CSSRuleList cssRules() const;
0269 
0270     /**
0271      * Used to insert a new rule into the style sheet. The new rule
0272      * now becomes part of the cascade.
0273      *
0274      * @param rule The parsable text representing the rule. For rule
0275      * sets this contains both the selector and the style declaration.
0276      * For at-rules, this specifies both the at-identifier and the
0277      * rule content.
0278      *
0279      * @param index The index within the style sheet's rule list of
0280      * the rule before which to insert the specified rule. If the
0281      * specified index is equal to the length of the style sheet's
0282      * rule collection, the rule will be added to the end of the style
0283      * sheet.
0284      *
0285      * @return The index within the style sheet's rule collection of
0286      * the newly inserted rule.
0287      *
0288      * @exception DOMException
0289      * HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at
0290      * the specified index e.g. if an \c \@import rule is
0291      * inserted after a standard rule set or other at-rule.
0292      *
0293      *  INDEX_SIZE_ERR: Raised if the specified index is not a valid
0294      * insertion point.
0295      *
0296      *  NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
0297      * readonly.
0298      *
0299      * @exception CSSException
0300      *  SYNTAX_ERR: Raised if the specified rule has a syntax error
0301      * and is unparsable.
0302      *
0303      */
0304     unsigned long insertRule(const DOM::DOMString &rule, unsigned long index);
0305 
0306     /**
0307      * Used to delete a rule from the style sheet.
0308      *
0309      * @param index The index within the style sheet's rule list of
0310      * the rule to remove.
0311      *
0312      * @return
0313      *
0314      * @exception DOMException
0315      * INDEX_SIZE_ERR: Raised if the specified index does not
0316      * correspond to a rule in the style sheet's rule list.
0317      *
0318      *  NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
0319      * readonly.
0320      *
0321      */
0322     void deleteRule(unsigned long index);
0323 
0324     /** @internal */
0325     DOM::DOMString charset() const;
0326 };
0327 
0328 class StyleSheetListImpl;
0329 class StyleSheet;
0330 
0331 /**
0332  * The \c StyleSheetList interface provides the
0333  * abstraction of an ordered collection of style sheets.
0334  *
0335  */
0336 class KHTML_EXPORT StyleSheetList
0337 {
0338 public:
0339     StyleSheetList();
0340     StyleSheetList(const StyleSheetList &other);
0341     StyleSheetList(StyleSheetListImpl *impl);
0342 public:
0343 
0344     StyleSheetList &operator = (const StyleSheetList &other);
0345 
0346     ~StyleSheetList();
0347 
0348     /**
0349      * The number of \c StyleSheet in the list. The range
0350      * of valid child stylesheet indices is \c 0 to
0351      * \c length-1 inclusive.
0352      *
0353      */
0354     unsigned long length() const;
0355 
0356     /**
0357      * Used to retrieve a style sheet by ordinal index.
0358      *
0359      * @param index Index into the collection
0360      *
0361      * @return The style sheet at the \c index position in
0362      * the \c StyleSheetList , or \c null if
0363      * that is not a valid index.
0364      *
0365      */
0366     StyleSheet item(unsigned long index);
0367 
0368     /**
0369      * @internal
0370      */
0371     StyleSheetListImpl *handle() const;
0372     bool isNull() const;
0373 
0374 protected:
0375     StyleSheetListImpl *impl;
0376 };
0377 
0378 class MediaListImpl;
0379 class CSSRule;
0380 class CSSStyleSheet;
0381 
0382 /**
0383  * The \c MediaList interface provides the abstraction of
0384  * an ordered collection of media, without defining or constraining
0385  * how this collection is implemented. All media are lowercase
0386  * strings.
0387  *
0388  */
0389 class KHTML_EXPORT MediaList
0390 {
0391 public:
0392     MediaList();
0393     MediaList(const MediaList &other);
0394     MediaList(MediaListImpl *impl);
0395 public:
0396 
0397     MediaList &operator = (const MediaList &other);
0398 
0399     ~MediaList();
0400 
0401     /**
0402      * The parsable textual representation of the media list. This is a
0403      * comma-separated list of media.
0404      *
0405      * @exception DOMException
0406      * SYNTAX_ERR: Raised if the specified string value has a syntax error and
0407      * is unparsable.
0408      *
0409      * NO_MODIFICATION_ALLOWED_ERR: Raised if this media list is readonly.
0410      */
0411     DOM::DOMString mediaText() const;
0412 
0413     /**
0414      * see mediaText
0415      */
0416     void setMediaText(const DOM::DOMString &value);
0417 
0418     /**
0419      * The number of media in the list. The range of valid media is 0 to length-1 inclusive.
0420      */
0421     unsigned long length() const;
0422 
0423     /**
0424      * Returns the indexth in the list. If index is greater than or equal to
0425      * the number of media in the list, this returns null.
0426      *
0427      * @param index Index into the collection.
0428      *
0429      * @return The medium at the indexth position in the MediaList, or null if
0430      * that is not a valid index.
0431      */
0432     DOM::DOMString item(unsigned long index) const;
0433 
0434     /**
0435      * Deletes the medium indicated by oldMedium from the list.
0436      *
0437      * @param oldMedium The medium to delete in the media list.
0438      *
0439      * @exception DOMException
0440      * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
0441      *
0442      * NOT_FOUND_ERR: Raised if oldMedium is not in the list.
0443      */
0444     void deleteMedium(const DOM::DOMString &oldMedium);
0445 
0446     /**
0447      * Adds the medium newMedium to the end of the list. If the newMedium is
0448      * already used, it is first removed.
0449      *
0450      * @param newMedium The new medium to add.
0451      *
0452      * @exception DOMException
0453      * INVALID_CHARACTER_ERR: If the medium contains characters that are
0454      * invalid in the underlying style language.
0455      *
0456      * NO_MODIFICATION_ALLOWED_ERR: Raised if this list is readonly.
0457      */
0458     void appendMedium(const DOM::DOMString &newMedium);
0459 
0460     /**
0461      * @internal
0462      */
0463     MediaListImpl *handle() const;
0464     bool isNull() const;
0465 
0466 protected:
0467     MediaListImpl *impl;
0468 };
0469 
0470 class LinkStyleImpl;
0471 
0472 class KHTML_EXPORT LinkStyle
0473 {
0474 public:
0475     LinkStyle();
0476     LinkStyle(const LinkStyle &other);
0477 
0478     LinkStyle &operator = (const LinkStyle &other);
0479     LinkStyle &operator = (const Node &other);
0480 
0481     ~LinkStyle();
0482 
0483     StyleSheet sheet();
0484 
0485     bool isNull() const;
0486 
0487 protected:
0488     DOM::NodeImpl *node;
0489     LinkStyleImpl *impl;
0490 };
0491 
0492 class DocumentStyleImpl;
0493 
0494 class KHTML_EXPORT DocumentStyle
0495 {
0496 public:
0497     DocumentStyle();
0498     DocumentStyle(const DocumentStyle &other);
0499 
0500     DocumentStyle &operator = (const DocumentStyle &other);
0501     DocumentStyle &operator = (const Document &other);
0502 
0503     ~DocumentStyle();
0504 
0505     StyleSheetList styleSheets() const;
0506 
0507     DOMString preferredStylesheetSet() const;
0508     DOMString selectedStylesheetSet() const;
0509     void setSelectedStylesheetSet(const DOMString &aString);
0510 
0511     bool isNull() const
0512     {
0513         return !impl;
0514     }
0515 
0516 protected:
0517     DOM::DocumentImpl *doc;
0518     DocumentStyleImpl *impl;
0519 };
0520 
0521 } // namespace
0522 
0523 #endif