add support for ':default', ':read-only' and ':read-write' pseudo classes
[kdelibs.git] / khtml / css / css_base.h
bloba623542933b7879b39db5c89ccb2b697dbaac36e
1 /*
2 * This file is part of the CSS implementation for KDE.
4 * Copyright 1999-2003 Lars Knoll (knoll@kde.org)
5 * Copyright 1999 Waldo Bastian (bastian@kde.org)
6 * Copyright 2002 Apple Computer, Inc.
7 * Copyright 2004 Allan Sandfeld Jensen (kde@carewolf.com)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #ifndef _CSS_BASE_H
26 #define _CSS_BASE_H
28 #include "dom/dom_string.h"
29 #include "dom/dom_misc.h"
30 #include "xml/dom_nodeimpl.h"
31 #include "misc/shared.h"
32 #include <kdemacros.h>
33 #include <QtCore/QDate>
35 namespace DOM {
37 class StyleSheetImpl;
38 class MediaList;
40 class CSSSelector;
41 class CSSProperty;
42 class CSSValueImpl;
45 struct CSSNamespace {
46 DOMString m_prefix;
47 DOMString m_uri;
48 CSSNamespace* m_parent;
50 CSSNamespace(const DOMString& p, const DOMString& u, CSSNamespace* parent)
51 :m_prefix(p), m_uri(u), m_parent(parent) {}
52 ~CSSNamespace() { delete m_parent; }
54 const DOMString& uri() { return m_uri; }
55 const DOMString& prefix() { return m_prefix; }
57 CSSNamespace* namespaceForPrefix(const DOMString& prefix) {
58 if (prefix == m_prefix)
59 return this;
60 if (m_parent)
61 return m_parent->namespaceForPrefix(prefix);
62 return 0;
66 // this class represents a selector for a StyleRule
67 class CSSSelector
69 public:
70 CSSSelector()
71 : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName), relation( Descendant ),
72 match( None ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
75 ~CSSSelector() {
76 delete tagHistory;
77 delete simpleSelector;
80 /**
81 * Print debug output for this selector
83 void print();
85 /**
86 * Re-create selector text from selector's data
88 DOMString selectorText() const;
90 // checks if the 2 selectors (including sub selectors) agree.
91 bool operator == ( const CSSSelector &other ) const;
93 // tag == -1 means apply to all elements (Selector = *)
95 unsigned int specificity() const;
97 /* how the attribute value has to match.... Default is Exact */
98 enum Match
100 None = 0,
102 Exact,
103 Set,
104 Class,
105 List,
106 Hyphen,
107 PseudoClass,
108 PseudoElement,
109 Contain, // css3: E[foo*="bar"]
110 Begin, // css3: E[foo^="bar"]
111 End // css3: E[foo$="bar"]
114 enum Relation
116 Descendant = 0,
117 Child,
118 DirectAdjacent,
119 IndirectAdjacent,
120 SubSelector
123 enum PseudoType
125 PseudoNotParsed = 0,
126 PseudoOther,
127 PseudoEmpty,
128 PseudoFirstChild,
129 PseudoLastChild,
130 PseudoNthChild,
131 PseudoNthLastChild,
132 PseudoOnlyChild,
133 PseudoFirstOfType,
134 PseudoLastOfType,
135 PseudoNthOfType,
136 PseudoNthLastOfType,
137 PseudoOnlyOfType,
138 PseudoLink,
139 PseudoVisited,
140 PseudoHover,
141 PseudoFocus,
142 PseudoActive,
143 PseudoTarget,
144 PseudoLang,
145 PseudoNot,
146 PseudoContains,
147 PseudoRoot,
148 PseudoEnabled,
149 PseudoDisabled,
150 PseudoDefault,
151 PseudoReadOnly,
152 PseudoReadWrite,
153 PseudoChecked,
154 PseudoIndeterminate,
155 // pseudo-elements:
156 // inherited:
157 PseudoFirstLine,
158 PseudoFirstLetter,
159 PseudoSelection,
160 // generated:
161 PseudoBefore,
162 PseudoAfter,
163 PseudoMarker,
164 PseudoReplaced
167 PseudoType pseudoType() const {
168 if (_pseudoType == PseudoNotParsed)
169 extractPseudoType();
170 return KDE_CAST_BF_ENUM(PseudoType, _pseudoType);
173 mutable DOM::DOMString value;
174 CSSSelector *tagHistory;
175 CSSSelector* simpleSelector; // Used by :not
176 DOM::DOMString string_arg; // Used by :contains, :lang and :nth-*
177 DOM::NodeImpl::Id attr;
178 DOM::NodeImpl::Id tag;
180 KDE_BF_ENUM(Relation) relation : 3;
181 mutable KDE_BF_ENUM(Match) match : 4;
182 unsigned int pseudoId : 4;
183 mutable KDE_BF_ENUM(PseudoType) _pseudoType : 6;
185 private:
186 void extractPseudoType() const;
189 // a style class which has a parent (almost all have)
190 class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
192 public:
193 StyleBaseImpl() { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
194 StyleBaseImpl(StyleBaseImpl *p) {
195 m_parent = p; hasInlinedDecl = false;
196 strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
197 multiLength = false;
200 virtual ~StyleBaseImpl() {}
202 // returns the url of the style sheet this object belongs to
203 // not const
204 KUrl baseURL();
206 virtual bool isStyleSheet() const { return false; }
207 virtual bool isCSSStyleSheet() const { return false; }
208 virtual bool isStyleSheetList() const { return false; }
209 virtual bool isMediaList() const { return false; }
210 virtual bool isRuleList() const { return false; }
211 virtual bool isRule() const { return false; }
212 virtual bool isStyleRule() const { return false; }
213 virtual bool isCharsetRule() const { return false; }
214 virtual bool isImportRule() const { return false; }
215 virtual bool isMediaRule() const { return false; }
216 virtual bool isFontFaceRule() const { return false; }
217 virtual bool isPageRule() const { return false; }
218 virtual bool isUnknownRule() const { return false; }
219 virtual bool isStyleDeclaration() const { return false; }
220 virtual bool isValue() const { return false; }
221 virtual bool isPrimitiveValue() const { return false; }
222 virtual bool isValueList() const { return false; }
223 virtual bool isValueCustom() const { return false; }
225 void setParent(StyleBaseImpl *parent) { m_parent = parent; }
227 static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
228 bool important, QList<CSSProperty*> *propList);
230 virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
232 // verifies if the resource chain is fully loaded,
233 // and in the affirmative, notifies the owner document
234 virtual void checkLoaded() const;
235 // makes sure the resource chain is considered 'Pending' by the owner document
236 virtual void checkPending() const;
238 void setStrictParsing( bool b ) { strictParsing = b; }
239 bool useStrictParsing() const { return strictParsing; }
241 // not const
242 StyleSheetImpl* stylesheet();
244 protected:
245 bool hasInlinedDecl : 1;
246 bool strictParsing : 1;
247 bool multiLength : 1;
250 // a style class which has a list of children (StyleSheets for example)
251 class StyleListImpl : public StyleBaseImpl
253 public:
254 StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
255 StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
256 virtual ~StyleListImpl();
258 unsigned long length() const { return m_lstChildren->count(); }
259 StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
261 void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
263 protected:
264 QList<StyleBaseImpl*> *m_lstChildren;
267 KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
268 KDE_NO_EXPORT int getValueID(const char *tagStr, int len);
271 #endif