KHtml

css_ruleimpl.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999-2003 Lars Knoll ([email protected])
5  * Copyright 2002-2003 Dirk Mueller ([email protected])
6  * Copyright 2002 Apple Computer, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 #ifndef _CSS_css_ruleimpl_h_
25 #define _CSS_css_ruleimpl_h_
26 
27 #include "dom/dom_string.h"
28 #include "dom/css_rule.h"
29 #include "css/css_base.h"
30 #include "misc/loader_client.h"
31 #include "misc/shared.h"
32 
33 namespace khtml
34 {
35 class CachedCSSStyleSheet;
36 }
37 
38 namespace DOM
39 {
40 
41 class CSSRule;
42 class CSSStyleSheet;
43 class CSSStyleSheetImpl;
44 class CSSStyleDeclarationImpl;
45 class CSSStyleListImpl;
46 class MediaListImpl;
47 
48 class CSSRuleImpl : public StyleBaseImpl
49 {
50 public:
51  CSSRuleImpl(StyleBaseImpl *parent)
52  : StyleBaseImpl(parent), m_type(CSSRule::UNKNOWN_RULE) {}
53 
54  bool isRule() const override
55  {
56  return true;
57  }
58  unsigned short type() const
59  {
60  return m_type;
61  }
62 
63  CSSStyleSheetImpl *parentStyleSheet() const;
64  CSSRuleImpl *parentRule() const;
65 
66  virtual DOM::DOMString cssText() const;
67  void setCssText(DOM::DOMString str);
68  virtual void init() {}
69 
70 protected:
71  CSSRule::RuleType m_type;
72 };
73 
74 class CSSCharsetRuleImpl : public CSSRuleImpl
75 {
76 public:
77  CSSCharsetRuleImpl(StyleBaseImpl *parent)
78  : CSSRuleImpl(parent)
79  {
80  m_type = CSSRule::CHARSET_RULE;
81  }
82  CSSCharsetRuleImpl(StyleBaseImpl *parent, const DOM::DOMString &encoding)
83  : CSSRuleImpl(parent), m_encoding(encoding)
84  {
85  m_type = CSSRule::CHARSET_RULE;
86  }
87 
88  bool isCharsetRule() const override
89  {
90  return true;
91  }
92 
93  DOMString encoding() const
94  {
95  return m_encoding;
96  }
97  void setEncoding(DOMString _encoding)
98  {
99  m_encoding = _encoding;
100  }
101  DOM::DOMString cssText() const override
102  {
103  return DOMString("@charset \"") + m_encoding + DOMString("\";");
104  }
105 protected:
106  DOMString m_encoding;
107 };
108 
109 class CSSFontFaceRuleImpl : public CSSRuleImpl
110 {
111 public:
112  CSSFontFaceRuleImpl(StyleBaseImpl *parent);
113 
114  virtual ~CSSFontFaceRuleImpl();
115 
116  bool isFontFaceRule() const override
117  {
118  return true;
119  }
120 
121  CSSStyleDeclarationImpl *style() const
122  {
123  return m_style;
124  }
125  void setDeclaration(CSSStyleDeclarationImpl *decl);
126  DOMString cssText() const override;
127 protected:
128  CSSStyleDeclarationImpl *m_style;
129 };
130 
131 class CSSImportRuleImpl : public khtml::CachedObjectClient, public CSSRuleImpl
132 {
133 public:
134  CSSImportRuleImpl(StyleBaseImpl *parent, const DOM::DOMString &href,
135  const DOM::DOMString &media);
136  CSSImportRuleImpl(StyleBaseImpl *parent, const DOM::DOMString &href,
137  MediaListImpl *media);
138 
139  virtual ~CSSImportRuleImpl();
140 
141  DOM::DOMString href() const
142  {
143  return m_strHref;
144  }
145  MediaListImpl *media() const
146  {
147  return m_lstMedia;
148  }
149  CSSStyleSheetImpl *styleSheet() const
150  {
151  return m_styleSheet;
152  }
153 
154  bool isImportRule() const override
155  {
156  return true;
157  }
158  DOM::DOMString cssText() const override;
159  void checkLoaded() const override;
160 
161  // from CachedObjectClient
162  void setStyleSheet(const DOM::DOMString &url, const DOM::DOMString &sheet, const DOM::DOMString &charset, const DOM::DOMString &mimetype) override;
163  void error(int err, const QString &text) override;
164 
165  bool isLoading() const;
166  void init() override;
167 
168 protected:
169  DOMString m_strHref;
170  MediaListImpl *m_lstMedia;
171  CSSStyleSheetImpl *m_styleSheet;
172  khtml::CachedCSSStyleSheet *m_cachedSheet;
173  bool m_loading;
174  bool m_done;
175 };
176 
177 class MediaList;
178 
179 class CSSRuleListImpl : public khtml::Shared<CSSRuleListImpl>
180 {
181 public:
182  CSSRuleListImpl() : m_list(nullptr) {}
183  CSSRuleListImpl(StyleListImpl *const lst, bool omitCharsetRules = false);
184 
185  ~CSSRuleListImpl();
186 
187  unsigned long length() const;
188  CSSRuleImpl *item(unsigned long index);
189 
190  // FIXME: Not part of the DOM. Only used by CSSMediaRuleImpl. We should be able to remove them if we changed media rules to work
191  // as StyleLists instead.
192  unsigned long insertRule(CSSRuleImpl *rule, unsigned long index);
193  void deleteRule(unsigned long index);
194 
195  void append(CSSRuleImpl *rule);
196 protected:
197  StyleListImpl *m_list;
198  QList<CSSRuleImpl *> m_lstCSSRules;
199 };
200 
201 class CSSMediaRuleImpl : public CSSRuleImpl
202 {
203 public:
204  CSSMediaRuleImpl(StyleBaseImpl *parent);
205  CSSMediaRuleImpl(StyleBaseImpl *parent, const DOM::DOMString &media);
206  CSSMediaRuleImpl(StyleBaseImpl *parent, MediaListImpl *mediaList, CSSRuleListImpl *ruleList);
207 
208  virtual ~CSSMediaRuleImpl();
209 
210  MediaListImpl *media() const
211  {
212  return m_lstMedia;
213  }
214  CSSRuleListImpl *cssRules()
215  {
216  return m_lstCSSRules;
217  }
218 
219  unsigned long insertRule(const DOM::DOMString &rule, unsigned long index);
220  void deleteRule(unsigned long index)
221  {
222  m_lstCSSRules->deleteRule(index);
223  }
224 
225  bool isMediaRule() const override
226  {
227  return true;
228  }
229  DOM::DOMString cssText() const override;
230 
231  /* Not part of the DOM */
232  unsigned long append(CSSRuleImpl *rule);
233 protected:
234  MediaListImpl *m_lstMedia;
235  CSSRuleListImpl *m_lstCSSRules;
236 };
237 
238 class CSSPageRuleImpl : public CSSRuleImpl
239 {
240 public:
241  CSSPageRuleImpl(StyleBaseImpl *parent);
242 
243  virtual ~CSSPageRuleImpl();
244 
245  CSSStyleDeclarationImpl *style() const
246  {
247  return m_style;
248  }
249 
250  bool isPageRule() const override
251  {
252  return true;
253  }
254 
255  DOM::DOMString selectorText() const;
256  void setSelectorText(DOM::DOMString str);
257 
258 protected:
259  CSSStyleDeclarationImpl *m_style;
260 };
261 
262 class CSSStyleRuleImpl : public CSSRuleImpl
263 {
264 public:
265  CSSStyleRuleImpl(StyleBaseImpl *parent);
266 
267  virtual ~CSSStyleRuleImpl();
268 
269  CSSStyleDeclarationImpl *style() const
270  {
271  return m_style;
272  }
273 
274  bool isStyleRule() const override
275  {
276  return true;
277  }
278  DOM::DOMString cssText() const override;
279 
280  DOM::DOMString selectorText() const;
281  void setSelectorText(DOM::DOMString str);
282 
283  bool parseString(const DOMString &string, bool = false) override;
284 
285  void setSelector(QList<CSSSelector *> *selector)
286  {
287  m_selector = selector;
288  }
289  void setDeclaration(CSSStyleDeclarationImpl *style);
290 
291  QList<CSSSelector *> *selector()
292  {
293  return m_selector;
294  }
295  CSSStyleDeclarationImpl *declaration()
296  {
297  return m_style;
298  }
299 
300 protected:
301  CSSStyleDeclarationImpl *m_style;
302  QList<CSSSelector *> *m_selector;
303 };
304 
305 class CSSNamespaceRuleImpl : public CSSRuleImpl
306 {
307 public:
308  CSSNamespaceRuleImpl(StyleBaseImpl *parent, const DOMString &prefix, const DOMString &ns);
309  DOMString namespaceURI() const
310  {
311  return m_namespace;
312  }
313  DOMString prefix() const
314  {
315  return m_prefix;
316  }
317 
318  bool isDefault() const
319  {
320  return m_prefix.isEmpty();
321  }
322 private:
323  DOMString m_prefix;
324  DOMString m_namespace;
325 };
326 
327 class CSSUnknownRuleImpl : public CSSRuleImpl
328 {
329 public:
330  CSSUnknownRuleImpl(StyleBaseImpl *parent) : CSSRuleImpl(parent) {}
331 
332  bool isUnknownRule() const override
333  {
334  return true;
335  }
336 };
337 
338 } // namespace
339 
340 #endif
The CSSNamespaceRule interface represents an.
Definition: css_rule.h:455
This file is part of the HTML rendering engine for KDE.
RuleType
An integer indicating which type of rule this is.
Definition: css_rule.h:68
a cached style sheet.
Definition: loader.h:282
Type type(const QSqlDatabase &db)
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
QCA_EXPORT void init()
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.