fix logic
[personal-kdelibs.git] / khtml / css / css_stylesheetimpl.h
blob5fd18a56559d9e02175d5bedcd3595d2ac28203a
1 /*
2 * This file is part of the DOM implementation for KDE.
4 * Copyright 1999-2003 Lars Knoll (knoll@kde.org)
5 * Copyright 2004 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #ifndef _CSS_css_stylesheetimpl_h_
24 #define _CSS_css_stylesheetimpl_h_
26 #include "dom/dom_string.h"
27 #include "css/css_base.h"
28 #include "misc/loader_client.h"
29 #include "xml/dom_docimpl.h"
31 namespace khtml {
32 class CachedCSSStyleSheet;
33 class DocLoader;
34 class MediaQuery;
37 namespace DOM {
39 class StyleSheet;
40 class CSSStyleSheet;
41 class CSSParser;
42 class MediaListImpl;
43 class CSSRuleImpl;
44 class CSSRuleListImpl;
45 class NodeImpl;
46 class DocumentImpl;
48 class StyleSheetImpl : public StyleListImpl
50 public:
51 StyleSheetImpl(DOM::NodeImpl *ownerNode, DOM::DOMString href = DOMString());
52 StyleSheetImpl(StyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
53 StyleSheetImpl(StyleBaseImpl *owner, DOM::DOMString href = DOMString());
54 StyleSheetImpl(khtml::CachedCSSStyleSheet *cached, DOM::DOMString href = DOMString());
55 virtual ~StyleSheetImpl();
57 virtual bool isStyleSheet() const { return true; }
59 virtual DOM::DOMString type() const { return DOMString(); }
61 bool disabled() const { return m_disabled; }
62 void setDisabled( bool disabled );
63 DOM::NodeImpl *ownerNode() const { return m_parentNode; }
64 StyleSheetImpl *parentStyleSheet() const;
65 DOM::DOMString href() const { return m_strHref; }
66 void setHref(const DOM::DOMString& href) { m_strHref = href; }
67 DOM::DOMString title() const { return m_strTitle; }
68 MediaListImpl *media() const { return m_media; }
69 void setMedia( MediaListImpl *media );
70 void setTitle( const DOM::DOMString& title ) { m_strTitle = title; }
72 protected:
73 DOM::NodeImpl *m_parentNode;
74 DOM::DOMString m_strHref;
75 DOM::DOMString m_strTitle;
76 MediaListImpl *m_media;
77 bool m_disabled;
80 class CSSStyleSheetImpl : public StyleSheetImpl
82 public:
83 CSSStyleSheetImpl(DOM::NodeImpl *parentNode, DOM::DOMString href = DOMString(), bool _implicit = false);
84 CSSStyleSheetImpl(CSSStyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
85 CSSStyleSheetImpl(CSSRuleImpl *ownerRule, DOM::DOMString href = DOMString());
86 // clone from a cached version of the sheet
87 CSSStyleSheetImpl(DOM::NodeImpl *parentNode, CSSStyleSheetImpl *orig);
88 CSSStyleSheetImpl(CSSRuleImpl *ownerRule, CSSStyleSheetImpl *orig);
90 ~CSSStyleSheetImpl() { delete m_namespaces; }
92 virtual bool isCSSStyleSheet() const { return true; }
94 virtual DOM::DOMString type() const { return "text/css"; }
96 CSSRuleImpl *ownerRule() const;
97 CSSRuleListImpl *cssRules(bool omitCharsetRule = false);
98 unsigned long insertRule ( const DOM::DOMString &rule, unsigned long index, int &exceptioncode );
99 void deleteRule ( unsigned long index, int &exceptioncode );
101 void addNamespace(CSSParser* p, const DOM::DOMString& prefix, const DOM::DOMString& uri);
102 void determineNamespace(NamespaceName& namespacename, const DOM::DOMString& prefix);
103 quint32 defaultNamespace() { return m_defaultNamespace.id(); }
105 void setCharset(const DOMString &charset) { m_charset = charset; }
106 const DOMString& charset() const { return m_charset; }
108 virtual bool parseString( const DOMString &string, bool strict = true );
110 bool isLoading() const;
112 virtual void checkLoaded() const;
113 virtual void checkPending() const;
114 bool loadedHint() const { return m_loadedHint; }
116 // ### remove? (clients should use sheet->doc()->docLoader())
117 khtml::DocLoader *docLoader() const
118 { return m_doc ? m_doc->docLoader() : 0; }
120 DocumentImpl *doc() const { return m_doc; }
121 bool implicit() const { return m_implicit; }
122 protected:
123 DocumentImpl *m_doc;
124 bool m_implicit;
125 mutable bool m_loadedHint;
126 NamespaceName m_defaultNamespace;
127 CSSNamespace* m_namespaces;
128 DOMString m_charset;
131 // ----------------------------------------------------------------------------
133 class StyleSheetListImpl : public khtml::Shared<StyleSheetListImpl>
135 public:
136 StyleSheetListImpl() {}
137 ~StyleSheetListImpl();
139 // the following two ignore implicit stylesheets
140 unsigned long length() const;
141 StyleSheetImpl *item ( unsigned long index );
143 void add(StyleSheetImpl* s);
144 void remove(StyleSheetImpl* s);
146 QList<StyleSheetImpl*> styleSheets;
149 // ----------------------------------------------------------------------------
151 class MediaListImpl : public StyleBaseImpl
153 public:
154 MediaListImpl(bool fallbackToDescription = false)
155 : StyleBaseImpl( 0 ), m_fallback(fallbackToDescription) {}
156 MediaListImpl( CSSStyleSheetImpl *parentSheet, bool fallbackToDescription = false)
157 : StyleBaseImpl(parentSheet), m_fallback(fallbackToDescription) {}
158 MediaListImpl( CSSStyleSheetImpl *parentSheet,
159 const DOM::DOMString &media, bool fallbackToDescription = false);
160 MediaListImpl( CSSRuleImpl *parentRule, const DOM::DOMString &media, bool fallbackToDescription = false);
161 ~MediaListImpl();
163 virtual bool isMediaList() const { return true; }
165 CSSStyleSheetImpl *parentStyleSheet() const;
166 CSSRuleImpl *parentRule() const;
167 unsigned long length() const { return m_queries.size(); }
168 DOM::DOMString item ( unsigned long index ) const;
169 void deleteMedium ( const DOM::DOMString &oldMedium, int& ec);
170 void appendMedium ( const DOM::DOMString &newMedium, int& ec);
172 DOM::DOMString mediaText() const;
173 void setMediaText(const DOM::DOMString &value, int& ec);
175 void appendMediaQuery(khtml::MediaQuery* mediaQuery);
176 const QList<khtml::MediaQuery*>* mediaQueries() const { return &m_queries; }
178 protected:
179 QList<khtml::MediaQuery*> m_queries;
180 bool m_fallback; // true if failed media query parsing should fallback to media description parsing
184 } // namespace
186 #endif