File: css_stylesheetimpl.h

package info (click to toggle)
khtml 5.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,940 kB
  • sloc: cpp: 206,281; java: 4,060; ansic: 2,829; perl: 2,313; yacc: 1,497; python: 339; sh: 141; xml: 37; makefile: 7
file content (271 lines) | stat: -rw-r--r-- 7,658 bytes parent folder | download | duplicates (5)
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 DOM implementation for KDE.
 *
 * Copyright 1999-2003 Lars Knoll (knoll@kde.org)
 * Copyright 2004 Apple Computer, Inc.
 *
 * 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_css_stylesheetimpl_h_
#define _CSS_css_stylesheetimpl_h_

#include "dom/dom_string.h"
#include "css/css_base.h"
#include "misc/loader_client.h"
#include "xml/dom_docimpl.h"
#include <QPointer>

namespace khtml
{
class CachedCSSStyleSheet;
class DocLoader;
class MediaQuery;
}

namespace DOM
{

class StyleSheet;
class CSSStyleSheet;
class CSSParser;
class MediaListImpl;
class CSSRuleImpl;
class CSSNamespaceRuleImpl;
class CSSRuleListImpl;
class NodeImpl;
class DocumentImpl;

class StyleSheetImpl : public StyleListImpl
{
public:
    StyleSheetImpl(DOM::NodeImpl *ownerNode, DOM::DOMString href = DOMString());
    StyleSheetImpl(StyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
    StyleSheetImpl(StyleBaseImpl *owner, DOM::DOMString href  = DOMString());
    StyleSheetImpl(khtml::CachedCSSStyleSheet *cached, DOM::DOMString href  = DOMString());
    virtual ~StyleSheetImpl();

    bool isStyleSheet() const override
    {
        return true;
    }

    virtual DOM::DOMString type() const
    {
        return DOMString();
    }

    bool disabled() const
    {
        return m_disabled;
    }
    void setDisabled(bool disabled);
    DOM::NodeImpl *ownerNode() const
    {
        return m_parentNode;
    }
    StyleSheetImpl *parentStyleSheet() const;
    DOM::DOMString href() const
    {
        return m_strHref;
    }
    void setHref(const DOM::DOMString &href)
    {
        m_strHref = href;
    }
    DOM::DOMString title() const
    {
        return m_strTitle;
    }
    MediaListImpl *media() const
    {
        return m_media;
    }
    void setMedia(MediaListImpl *media);
    void setTitle(const DOM::DOMString &title)
    {
        m_strTitle = title;
    }

protected:
    DOM::NodeImpl *m_parentNode;
    DOM::DOMString m_strHref;
    DOM::DOMString m_strTitle;
    MediaListImpl *m_media;
    bool m_disabled;
};

class CSSStyleSheetImpl : public StyleSheetImpl
{
public:
    CSSStyleSheetImpl(DOM::NodeImpl *parentNode, DOM::DOMString href = DOMString(), bool _implicit = false);
    CSSStyleSheetImpl(CSSStyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
    CSSStyleSheetImpl(CSSRuleImpl *ownerRule, DOM::DOMString href = DOMString());
    // clone from a cached version of the sheet
    CSSStyleSheetImpl(DOM::NodeImpl *parentNode, CSSStyleSheetImpl *orig);
    CSSStyleSheetImpl(CSSRuleImpl *ownerRule, CSSStyleSheetImpl *orig);

    ~CSSStyleSheetImpl()
    {
        delete m_namespaces;
    }

    bool isCSSStyleSheet() const override
    {
        return true;
    }

    DOM::DOMString type() const override
    {
        return "text/css";
    }

    CSSRuleImpl *ownerRule() const;
    CSSRuleListImpl *cssRules(bool omitCharsetRule = false);
    unsigned long insertRule(const DOM::DOMString &rule, unsigned long index, int &exceptioncode);
    void deleteRule(unsigned long index, int &exceptioncode);

    void determineNamespace(NamespaceName &namespacename, const DOM::DOMString &prefix);
    quint32 defaultNamespace()
    {
        return m_defaultNamespace.id();
    }
    void appendNamespaceRule(CSSNamespaceRuleImpl *ns);

    void setCharset(const DOMString &charset)
    {
        m_charset = charset;
    }
    const DOMString &charset() const
    {
        return m_charset;
    }

    bool parseString(const DOMString &string, bool strict = true) override;

    bool isLoading() const;

    void checkLoaded() const override;
    void checkPending() const override;
    bool loadedHint() const
    {
        return m_loadedHint;
    }

    // ### remove? (clients should use sheet->doc()->docLoader())
    khtml::DocLoader *docLoader() const
    {
        return m_doc ? m_doc->docLoader() : nullptr;
    }

    DocumentImpl *doc() const
    {
        return m_doc;
    }
    bool implicit() const
    {
        return m_implicit;
    }
protected:
    void recomputeNamespaceInfo(); // updates m_defaultNamespace and m_namespaces
    // we update m_namespaces lazily, but
    // m_defaulNamespace eagerly.
    void dirtyNamespaceInfo()
    {
        delete m_namespaces;
        m_namespaces = nullptr;
    }

    DocumentImpl *m_doc;
    bool m_implicit;
    mutable bool m_loadedHint;
    NamespaceName m_defaultNamespace;
    QList<CSSNamespaceRuleImpl *> *m_namespaces;
    DOMString m_charset;
};

// ----------------------------------------------------------------------------

class StyleSheetListImpl : public khtml::Shared<StyleSheetListImpl>
{
public:
    // the manager argument should be passed only when this is
    // document.styleSheets.
    StyleSheetListImpl(DocumentImpl *manager = nullptr): managerDocument(manager) {}
    ~StyleSheetListImpl();

    // the following two ignore implicit stylesheets
    unsigned long length() const;
    StyleSheetImpl *item(unsigned long index);

    void add(StyleSheetImpl *s);
    void remove(StyleSheetImpl *s);

    QList<StyleSheetImpl *> styleSheets;

    // we need the document pointer to make it update the stylesheet list
    // if needed for the global list. Luckily, we don't care about that if the
    // document dies, so we use QPointer to break the cycle
    QPointer<DocumentImpl> managerDocument;
};

// ----------------------------------------------------------------------------

class MediaListImpl : public StyleBaseImpl
{
public:
    MediaListImpl(bool fallbackToDescription = false)
        : StyleBaseImpl(nullptr), m_fallback(fallbackToDescription) {}
    MediaListImpl(CSSStyleSheetImpl *parentSheet, bool fallbackToDescription = false)
        : StyleBaseImpl(parentSheet), m_fallback(fallbackToDescription) {}
    MediaListImpl(CSSStyleSheetImpl *parentSheet,
                  const DOM::DOMString &media, bool fallbackToDescription = false);
    MediaListImpl(CSSRuleImpl *parentRule, const DOM::DOMString &media, bool fallbackToDescription = false);
    ~MediaListImpl();

    bool isMediaList() const override
    {
        return true;
    }

    CSSStyleSheetImpl *parentStyleSheet() const;
    CSSRuleImpl *parentRule() const;
    unsigned long length() const
    {
        return  m_queries.size();
    }
    DOM::DOMString item(unsigned long index) const;
    void deleteMedium(const DOM::DOMString &oldMedium, int &ec);
    void appendMedium(const DOM::DOMString &newMedium, int &ec);

    DOM::DOMString mediaText() const;
    void setMediaText(const DOM::DOMString &value, int &ec);

    void appendMediaQuery(khtml::MediaQuery *mediaQuery);
    const QList<khtml::MediaQuery *> *mediaQueries() const
    {
        return &m_queries;
    }

protected:
    QList<khtml::MediaQuery *> m_queries;
    bool m_fallback; // true if failed media query parsing should fallback to media description parsing
};

} // namespace

#endif