summaryrefslogtreecommitdiffstats
path: root/tdehtml/css/css_base.h
blob: d2ab4f63facd01180a49002b6d50f6986344630a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
 * This file is part of the CSS implementation for KDE.
 *
 * Copyright (C) 1999-2003 Lars Knoll ([email protected])
 *               1999 Waldo Bastian ([email protected])
 *               2002 Apple Computer, Inc.
 *               2004 Allan Sandfeld Jensen ([email protected])
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */
#ifndef _CSS_BASE_H
#define _CSS_BASE_H

#include "dom/dom_string.h"
#include "dom/dom_misc.h"
#include "xml/dom_nodeimpl.h"
#include "misc/shared.h"
#include <kdemacros.h>
#include <tqdatetime.h>
#include <tqptrlist.h>

namespace DOM {

    class StyleSheetImpl;
    class MediaList;

    class CSSSelector;
    class CSSProperty;
    class CSSValueImpl;
    class CSSPrimitiveValueImpl;
    class CSSStyleDeclarationImpl;
    class CSSRuleImpl;
    class CSSStyleRuleImpl;

    class DocumentImpl;

    struct CSSNamespace {
        DOMString m_prefix;
        DOMString m_uri;
        CSSNamespace* m_parent;

        CSSNamespace(const DOMString& p, const DOMString& u, CSSNamespace* parent)
            :m_prefix(p), m_uri(u), m_parent(parent) {}
        ~CSSNamespace() { delete m_parent; }

        const DOMString& uri() { return m_uri; }
        const DOMString& prefix() { return m_prefix; }

        CSSNamespace* namespaceForPrefix(const DOMString& prefix) {
            if (prefix == m_prefix)
                return this;
            if (m_parent)
                return m_parent->namespaceForPrefix(prefix);
            return 0;
        }
    };

// this class represents a selector for a StyleRule
    class CSSSelector
    {
    public:
	CSSSelector()
	    : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName), relation( Descendant ),
	      match( None ), nonCSSHint( false ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
        {}

	~CSSSelector() {
	    delete tagHistory;
            delete simpleSelector;
	}

	/**
	 * Print debug output for this selector
	 */
	void print();

	/**
	 * Re-create selector text from selector's data
	 */
	DOMString selectorText() const;

	// checks if the 2 selectors (including sub selectors) agree.
	bool operator == ( const CSSSelector &other ) const;

	// tag == -1 means apply to all elements (Selector = *)

	unsigned int specificity() const;

	/* how the attribute value has to match.... Default is Exact */
	enum Match
	{
	    None = 0,
	    Id,
	    Exact,
	    Set,
	    Class,
	    List,
	    Hyphen,
	    PseudoClass,
	    PseudoElement,
	    Contain,   // css3: E[foo*="bar"]
	    Begin,     // css3: E[foo^="bar"]
	    End        // css3: E[foo$="bar"]
	};

	enum Relation
	{
	    Descendant = 0,
	    Child,
	    DirectAdjacent,
            IndirectAdjacent,
            SubSelector
	};

	enum PseudoType
	{
	    PseudoNotParsed = 0,
	    PseudoOther,
	    PseudoEmpty,
	    PseudoFirstChild,
            PseudoLastChild,
            PseudoNthChild,
            PseudoNthLastChild,
            PseudoOnlyChild,
            PseudoFirstOfType,
            PseudoLastOfType,
            PseudoNthOfType,
            PseudoNthLastOfType,
            PseudoOnlyOfType,
	    PseudoLink,
	    PseudoVisited,
	    PseudoHover,
	    PseudoFocus,
	    PseudoActive,
            PseudoTarget,
            PseudoLang,
            PseudoNot,
            PseudoContains,
            PseudoRoot,
            PseudoEnabled,
            PseudoDisabled,
            PseudoChecked,
            PseudoIndeterminate,
// pseudo-elements:
    // inherited:
            PseudoFirstLine,
            PseudoFirstLetter,
            PseudoSelection,
    // generated:
            PseudoBefore,
            PseudoAfter,
            PseudoMarker,
            PseudoReplaced
	};

	PseudoType pseudoType() const {
            if (_pseudoType == PseudoNotParsed)
                extractPseudoType();
            return _pseudoType;
        }

        mutable DOM::DOMString value;
	CSSSelector *tagHistory;
        CSSSelector* simpleSelector; // Used by :not
        DOM::DOMString string_arg; // Used by :contains, :lang and :nth-*
        DOM::NodeImpl::Id attr;
        DOM::NodeImpl::Id tag;

	Relation relation     : 3;
	mutable Match 	 match         : 4;
	bool	nonCSSHint : 1;
	unsigned int pseudoId : 4;
	mutable PseudoType _pseudoType : 6;

    private:
	void extractPseudoType() const;
    };

    // a style class which has a parent (almost all have)
    class StyleBaseImpl : public tdehtml::TreeShared<StyleBaseImpl>
    {
    public:
	StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
	StyleBaseImpl(StyleBaseImpl *p) {
	    m_parent = p; hasInlinedDecl = false;
	    strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
	    multiLength = false;
	}

	virtual ~StyleBaseImpl() {}

	// returns the url of the style sheet this object belongs to
        // not const
	KURL baseURL();

	virtual bool isStyleSheet() const { return false; }
	virtual bool isCSSStyleSheet() const { return false; }
	virtual bool isStyleSheetList() const { return false; }
	virtual bool isMediaList() const { return false; }
	virtual bool isRuleList() const { return false; }
	virtual bool isRule() const { return false; }
	virtual bool isStyleRule() const { return false; }
	virtual bool isCharetRule() const { return false; }
	virtual bool isImportRule() const { return false; }
	virtual bool isMediaRule() const { return false; }
	virtual bool isFontFaceRule() const { return false; }
	virtual bool isPageRule() const { return false; }
	virtual bool isUnknownRule() const { return false; }
	virtual bool isStyleDeclaration() const { return false; }
	virtual bool isValue() const { return false; }
	virtual bool isPrimitiveValue() const { return false; }
	virtual bool isValueList() const { return false; }
	virtual bool isValueCustom() const { return false; }

	void setParent(StyleBaseImpl *parent) { m_parent = parent; }

	static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
				   bool important, bool nonCSSHint, TQPtrList<CSSProperty> *propList);

	virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }

	virtual void checkLoaded() const;

	void setStrictParsing( bool b ) { strictParsing = b; }
	bool useStrictParsing() const { return strictParsing; }

        // not const
	StyleSheetImpl* stylesheet();

    protected:
	bool hasInlinedDecl : 1;
	bool strictParsing : 1;
	bool multiLength : 1;
    };

    // a style class which has a list of children (StyleSheets for example)
    class StyleListImpl : public StyleBaseImpl
    {
    public:
	StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
	StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
	virtual ~StyleListImpl();

	unsigned long length() const { return m_lstChildren->count(); }
	StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }

	void append(StyleBaseImpl *item) { m_lstChildren->append(item); }

    protected:
	TQPtrList<StyleBaseImpl> *m_lstChildren;
    };

    KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);

}

#endif