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.
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>
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
)
61 return m_parent
->namespaceForPrefix(prefix
);
66 // this class represents a selector for a StyleRule
71 : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName
), relation( Descendant
),
72 match( None
), pseudoId( 0 ), _pseudoType(PseudoNotParsed
)
77 delete simpleSelector
;
81 * Print debug output for this selector
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 */
109 Contain
, // css3: E[foo*="bar"]
110 Begin
, // css3: E[foo^="bar"]
111 End
// css3: E[foo$="bar"]
167 PseudoType
pseudoType() const {
168 if (_pseudoType
== PseudoNotParsed
)
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;
186 void extractPseudoType() const;
189 // a style class which has a parent (almost all have)
190 class StyleBaseImpl
: public khtml::TreeShared
<StyleBaseImpl
>
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);
200 virtual ~StyleBaseImpl() {}
202 // returns the url of the style sheet this object belongs to
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
; }
242 StyleSheetImpl
* stylesheet();
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
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
); }
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
);