KHtml

css_rule.cpp
1 /**
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "css/css_ruleimpl.h"
24 
25 using namespace DOM;
26 
27 CSSRule::CSSRule()
28 {
29  impl = nullptr;
30 }
31 
32 CSSRule::CSSRule(const CSSRule &other)
33 {
34  impl = other.impl;
35  if (impl) {
36  impl->ref();
37  }
38 }
39 
40 CSSRule::CSSRule(CSSRuleImpl *i)
41 {
42  impl = i;
43  if (impl) {
44  impl->ref();
45  }
46 }
47 
48 CSSRule &CSSRule::operator = (const CSSRule &other)
49 {
50  if (impl != other.impl) {
51  if (impl) {
52  impl->deref();
53  }
54  impl = other.impl;
55  if (impl) {
56  impl->ref();
57  }
58  }
59  return *this;
60 }
61 
62 CSSRule::~CSSRule()
63 {
64  if (impl) {
65  impl->deref();
66  }
67 }
68 
69 unsigned short CSSRule::type() const
70 {
71  if (!impl) {
72  return 0;
73  }
74  return ((CSSRuleImpl *)impl)->type();
75 }
76 
78 {
79  if (!impl) {
80  return DOMString();
81  }
82  return impl->cssText();
83 }
84 
85 void CSSRule::setCssText(const DOMString &value)
86 {
87  if (!impl) {
88  return;
89  }
90  impl->setCssText(value);
91 }
92 
94 {
95  if (!impl) {
96  return CSSStyleSheet();
97  }
98  return ((CSSRuleImpl *)impl)->parentStyleSheet();
99 }
100 
102 {
103  if (!impl) {
104  return nullptr;
105  }
106  return ((CSSRuleImpl *)impl)->parentRule();
107 }
108 
109 CSSRuleImpl *CSSRule::handle() const
110 {
111  return impl;
112 }
113 
114 bool CSSRule::isNull() const
115 {
116  return (impl == nullptr);
117 }
118 
119 void CSSRule::assignOther(const CSSRule &other, RuleType thisType)
120 {
121  if (other.type() != thisType) {
122  if (impl) {
123  impl->deref();
124  }
125  impl = nullptr;
126  } else {
127  CSSRule::operator = (other);
128  }
129 }
130 
131 // ----------------------------------------------------------
132 
133 CSSCharsetRule::CSSCharsetRule()
134  : CSSRule()
135 {
136 }
137 
138 CSSCharsetRule::CSSCharsetRule(const CSSCharsetRule &other) : CSSRule(other)
139 {
140 }
141 
142 CSSCharsetRule::CSSCharsetRule(const CSSRule &other)
143 {
144  impl = nullptr;
145  operator=(other);
146 }
147 
148 CSSCharsetRule::CSSCharsetRule(CSSCharsetRuleImpl *impl) : CSSRule(impl)
149 {
150 }
151 
152 CSSCharsetRule &CSSCharsetRule::operator = (const CSSCharsetRule &other)
153 {
154  CSSRule::operator = (other);
155  return *this;
156 }
157 
158 CSSCharsetRule &CSSCharsetRule::operator = (const CSSRule &other)
159 {
160  assignOther(other, CSSRule::CHARSET_RULE);
161  return *this;
162 }
163 
164 CSSCharsetRule::~CSSCharsetRule()
165 {
166 }
167 
169 {
170  if (!impl) {
171  return DOMString();
172  }
173  return ((CSSCharsetRuleImpl *)impl)->encoding();
174 }
175 
177 {
178  ((CSSCharsetRuleImpl *)impl)->setEncoding(value);
179 }
180 
181 // ----------------------------------------------------------
182 
183 CSSFontFaceRule::CSSFontFaceRule() : CSSRule()
184 {
185 }
186 
187 CSSFontFaceRule::CSSFontFaceRule(const CSSFontFaceRule &other) : CSSRule(other)
188 {
189 }
190 
191 CSSFontFaceRule::CSSFontFaceRule(const CSSRule &other)
192 {
193  impl = nullptr;
194  operator=(other);
195 }
196 
197 CSSFontFaceRule::CSSFontFaceRule(CSSFontFaceRuleImpl *impl) : CSSRule(impl)
198 {
199 }
200 
201 CSSFontFaceRule &CSSFontFaceRule::operator = (const CSSFontFaceRule &other)
202 {
203  CSSRule::operator = (other);
204  return *this;
205 }
206 
207 CSSFontFaceRule &CSSFontFaceRule::operator = (const CSSRule &other)
208 {
209  assignOther(other, CSSRule::FONT_FACE_RULE);
210  return *this;
211 }
212 
213 CSSFontFaceRule::~CSSFontFaceRule()
214 {
215 }
216 
218 {
219  if (!impl) {
220  return CSSStyleDeclaration();
221  }
222  return ((CSSFontFaceRuleImpl *)impl)->style();
223 }
224 
225 // ----------------------------------------------------------
226 
227 CSSImportRule::CSSImportRule() : CSSRule()
228 {
229 }
230 
231 CSSImportRule::CSSImportRule(const CSSImportRule &other) : CSSRule(other)
232 {
233 }
234 
235 CSSImportRule::CSSImportRule(const CSSRule &other)
236 {
237  impl = nullptr;
238  operator=(other);
239 }
240 
241 CSSImportRule::CSSImportRule(CSSImportRuleImpl *impl) : CSSRule(impl)
242 {
243 }
244 
245 CSSImportRule &CSSImportRule::operator = (const CSSImportRule &other)
246 {
247  CSSRule::operator = (other);
248  return *this;
249 }
250 
251 CSSImportRule &CSSImportRule::operator = (const CSSRule &other)
252 {
253  assignOther(other, CSSRule::IMPORT_RULE);
254  return *this;
255 }
256 
257 CSSImportRule::~CSSImportRule()
258 {
259 }
260 
262 {
263  if (!impl) {
264  return DOMString();
265  }
266  return ((CSSImportRuleImpl *)impl)->href();
267 }
268 
270 {
271  if (!impl) {
272  return MediaList();
273  }
274  return ((CSSImportRuleImpl *)impl)->media();
275 }
276 
278 {
279  if (!impl) {
280  return CSSStyleSheet();
281  }
282  return ((CSSImportRuleImpl *)impl)->styleSheet();
283 }
284 
285 // ----------------------------------------------------------
286 
287 CSSMediaRule::CSSMediaRule() : CSSRule()
288 {
289 }
290 
291 CSSMediaRule::CSSMediaRule(const CSSMediaRule &other) : CSSRule(other)
292 {
293 }
294 
295 CSSMediaRule::CSSMediaRule(const CSSRule &other)
296 {
297  impl = nullptr;
298  operator=(other);
299 }
300 
301 CSSMediaRule::CSSMediaRule(CSSMediaRuleImpl *impl) : CSSRule(impl)
302 {
303 }
304 
305 CSSMediaRule &CSSMediaRule::operator = (const CSSMediaRule &other)
306 {
307  CSSRule::operator = (other);
308  return *this;
309 }
310 
311 CSSMediaRule &CSSMediaRule::operator = (const CSSRule &other)
312 {
313  assignOther(other, CSSRule::MEDIA_RULE);
314  return *this;
315 }
316 
317 CSSMediaRule::~CSSMediaRule()
318 {
319 }
320 
322 {
323  if (!impl) {
324  return MediaList();
325  }
326  return ((CSSMediaRuleImpl *)impl)->media();
327 }
328 
330 {
331  if (!impl) {
332  return CSSRuleList();
333  }
334  return ((CSSMediaRuleImpl *)impl)->cssRules();
335 }
336 
337 unsigned long CSSMediaRule::insertRule(const DOMString &rule, unsigned long index)
338 {
339  if (!impl) {
340  return 0;
341  }
342  return ((CSSMediaRuleImpl *)impl)->insertRule(rule, index);
343 }
344 
345 void CSSMediaRule::deleteRule(unsigned long index)
346 {
347  if (impl) {
348  ((CSSMediaRuleImpl *)impl)->deleteRule(index);
349  }
350 }
351 
352 // ----------------------------------------------------------
353 
354 CSSPageRule::CSSPageRule() : CSSRule()
355 {
356 }
357 
358 CSSPageRule::CSSPageRule(const CSSPageRule &other) : CSSRule(other)
359 {
360 }
361 
362 CSSPageRule::CSSPageRule(const CSSRule &other)
363 {
364  impl = nullptr;
365  operator=(other);
366 }
367 
368 CSSPageRule::CSSPageRule(CSSPageRuleImpl *impl) : CSSRule(impl)
369 {
370 }
371 
372 CSSPageRule &CSSPageRule::operator = (const CSSPageRule &other)
373 {
374  CSSRule::operator = (other);
375  return *this;
376 }
377 
378 CSSPageRule &CSSPageRule::operator = (const CSSRule &other)
379 {
380  assignOther(other, CSSRule::PAGE_RULE);
381  return *this;
382 }
383 
384 CSSPageRule::~CSSPageRule()
385 {
386 }
387 
388 DOMString CSSPageRule::selectorText() const
389 {
390  if (!impl) {
391  return DOMString();
392  }
393  return ((CSSPageRuleImpl *)impl)->selectorText();
394 }
395 
396 void CSSPageRule::setSelectorText(const DOMString &value)
397 {
398  ((CSSPageRuleImpl *)impl)->setSelectorText(value);
399 }
400 
401 CSSStyleDeclaration CSSPageRule::style() const
402 {
403  if (!impl) {
404  return CSSStyleDeclaration();
405  }
406  return ((CSSPageRuleImpl *)impl)->style();
407 }
408 
409 // ----------------------------------------------------------
410 
411 CSSStyleRule::CSSStyleRule() : CSSRule()
412 {
413 }
414 
415 CSSStyleRule::CSSStyleRule(const CSSStyleRule &other)
416  : CSSRule(other)
417 {
418 }
419 
420 CSSStyleRule::CSSStyleRule(const CSSRule &other)
421 {
422  impl = nullptr;
423  operator=(other);
424 }
425 
426 CSSStyleRule::CSSStyleRule(CSSStyleRuleImpl *impl)
427  : CSSRule(impl)
428 {
429 }
430 
431 CSSStyleRule &CSSStyleRule::operator = (const CSSStyleRule &other)
432 {
433  CSSRule::operator = (other);
434  return *this;
435 }
436 
437 CSSStyleRule &CSSStyleRule::operator = (const CSSRule &other)
438 {
439  assignOther(other, CSSRule::STYLE_RULE);
440  return *this;
441 }
442 
443 CSSStyleRule::~CSSStyleRule()
444 {
445 }
446 
448 {
449  if (!impl) {
450  return DOMString();
451  }
452  return ((CSSStyleRuleImpl *)impl)->selectorText();
453 }
454 
456 {
457  ((CSSStyleRuleImpl *)impl)->setSelectorText(value);
458 }
459 
461 {
462  if (!impl) {
463  return CSSStyleDeclaration();
464  }
465  return ((CSSStyleRuleImpl *)impl)->style();
466 }
467 
468 // ----------------------------------------------------------
469 
470 CSSNamespaceRule::CSSNamespaceRule() : CSSRule()
471 {
472 }
473 
474 CSSNamespaceRule::CSSNamespaceRule(const CSSNamespaceRule &other)
475  : CSSRule(other)
476 {
477 }
478 
479 CSSNamespaceRule::CSSNamespaceRule(const CSSRule &other)
480 {
481  impl = nullptr;
482  operator=(other);
483 }
484 
485 CSSNamespaceRule::CSSNamespaceRule(CSSNamespaceRuleImpl *impl)
486  : CSSRule(impl)
487 {
488 }
489 
490 CSSNamespaceRule &CSSNamespaceRule::operator = (const CSSNamespaceRule &other)
491 {
492  CSSRule::operator = (other);
493  return *this;
494 }
495 
496 CSSNamespaceRule &CSSNamespaceRule::operator = (const CSSRule &other)
497 {
498  assignOther(other, CSSRule::NAMESPACE_RULE);
499  return *this;
500 }
501 
502 CSSNamespaceRule::~CSSNamespaceRule()
503 {
504 }
505 
506 DOMString CSSNamespaceRule::namespaceURI() const
507 {
508  if (!impl) {
509  return DOMString();
510  }
511  return static_cast<CSSNamespaceRuleImpl *>(impl)->namespaceURI();
512 }
513 
514 DOMString CSSNamespaceRule::prefix() const
515 {
516  if (!impl) {
517  return DOMString();
518  }
519  return static_cast<CSSNamespaceRuleImpl *>(impl)->prefix();
520 }
521 
522 // ----------------------------------------------------------
523 
524 CSSUnknownRule::CSSUnknownRule() : CSSRule()
525 {
526 }
527 
528 CSSUnknownRule::CSSUnknownRule(const CSSUnknownRule &other)
529  : CSSRule(other)
530 {
531 }
532 
533 CSSUnknownRule::CSSUnknownRule(const CSSRule &other)
534 {
535  impl = nullptr;
536  operator=(other);
537 }
538 
539 CSSUnknownRule::CSSUnknownRule(CSSUnknownRuleImpl *impl)
540  : CSSRule(impl)
541 {
542 }
543 
544 CSSUnknownRule &CSSUnknownRule::operator = (const CSSUnknownRule &other)
545 {
546  CSSRule::operator = (other);
547  return *this;
548 }
549 
550 CSSUnknownRule &CSSUnknownRule::operator = (const CSSRule &other)
551 {
552  assignOther(other, CSSRule::UNKNOWN_RULE);
553  return *this;
554 }
555 
556 CSSUnknownRule::~CSSUnknownRule()
557 {
558 }
559 
560 // ----------------------------------------------------------
561 
562 CSSRuleList::CSSRuleList()
563 {
564  impl = nullptr;
565 }
566 
567 CSSRuleList::CSSRuleList(const CSSRuleList &other)
568 {
569  impl = other.impl;
570  if (impl) {
571  impl->ref();
572  }
573 }
574 
575 CSSRuleList::CSSRuleList(CSSRuleListImpl *i)
576 {
577  impl = i;
578  if (impl) {
579  impl->ref();
580  }
581 }
582 
583 CSSRuleList::CSSRuleList(StyleListImpl *lst)
584 {
585  impl = new CSSRuleListImpl;
586  impl->ref();
587  if (lst) {
588  for (unsigned long i = 0; i < lst->length(); ++i) {
589  StyleBaseImpl *style = lst->item(i);
590  if (style->isRule()) {
591  impl->insertRule(static_cast<CSSRuleImpl *>(style), impl->length());
592  }
593  }
594  }
595 }
596 
597 CSSRuleList &CSSRuleList::operator = (const CSSRuleList &other)
598 {
599  if (impl != other.impl) {
600  if (impl) {
601  impl->deref();
602  }
603  impl = other.impl;
604  if (impl) {
605  impl->ref();
606  }
607  }
608  return *this;
609 }
610 
611 CSSRuleList::~CSSRuleList()
612 {
613  if (impl) {
614  impl->deref();
615  }
616 }
617 
618 unsigned long CSSRuleList::length() const
619 {
620  if (!impl) {
621  return 0;
622  }
623  return ((CSSRuleListImpl *)impl)->length();
624  return 0;
625 }
626 
627 CSSRule CSSRuleList::item(unsigned long index)
628 {
629  if (!impl) {
630  return CSSRule();
631  }
632  return ((CSSRuleListImpl *)impl)->item(index);
633 }
634 
635 CSSRuleListImpl *CSSRuleList::handle() const
636 {
637  return impl;
638 }
639 
640 bool CSSRuleList::isNull() const
641 {
642  return (impl == nullptr);
643 }
644 
CSSStyleDeclaration style() const
The declaration-block of this rule.
Definition: css_rule.cpp:217
The CSSNamespaceRule interface represents an.
Definition: css_rule.h:455
The CSSStyleDeclaration interface represents a single CSS declaration block .
Definition: css_value.h:59
DOM::DOMString encoding() const
The encoding information used in this @charset rule.
Definition: css_rule.cpp:168
The CSSRule interface is the abstract base interface for any type of CSS statement .
Definition: css_rule.h:53
The CSSStyleRule interface represents a single rule set in a CSS style sheet.
Definition: css_rule.h:411
void setCssText(const DOM::DOMString &)
see cssText
Definition: css_rule.cpp:85
This library provides a full-featured HTML parser and widget.
DOM::DOMString cssText() const
The parsable textual representation of the rule.
Definition: css_rule.cpp:77
The CSSImportRule interface represents a @import rule within a CSS style sheet.
Definition: css_rule.h:224
The CSSMediaRule interface represents a @media rule in a CSS style sheet.
Definition: css_rule.h:271
unsigned long length() const
The number of CSSRule s in the list.
Definition: css_rule.cpp:618
DOM::DOMString selectorText() const
The textual representation of the selector for the rule set.
Definition: css_rule.cpp:447
void deleteRule(unsigned long index)
Used to delete a rule from the media block.
Definition: css_rule.cpp:345
DOM::DOMString href() const
The location of the style sheet to be imported.
Definition: css_rule.cpp:261
The CSSUnkownRule interface represents an at-rule not supported by this user agent.
Definition: css_rule.h:485
CSSStyleSheet parentStyleSheet() const
The style sheet that contains this rule.
Definition: css_rule.cpp:93
The CSSFontFaceRule interface represents a @font-face rule in a CSS style sheet.
Definition: css_rule.h:194
MediaList media() const
A list of media types for this rule.
Definition: css_rule.cpp:321
@ NAMESPACE_RULE
CSSOM,.
Definition: css_rule.h:76
CSSStyleDeclaration style() const
The declaration-block of this rule set.
Definition: css_rule.cpp:460
CSSStyleSheet styleSheet() const
The style sheet referred to by this rule, if it has been loaded.
Definition: css_rule.cpp:277
The CSSStyleSheet interface is a concrete interface used to represent a CSS style sheet i....
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
CSSRuleImpl * handle() const
Definition: css_rule.cpp:109
CSSRule parentRule() const
If this rule is contained inside another rule (e.g.
Definition: css_rule.cpp:101
The MediaList interface provides the abstraction of an ordered collection of media,...
void setSelectorText(const DOM::DOMString &)
see selectorText
Definition: css_rule.cpp:455
MediaList media() const
A list of media types for which this style sheet may be used.
Definition: css_rule.cpp:269
unsigned long insertRule(const DOM::DOMString &rule, unsigned long index)
Used to insert a new rule into the media block.
Definition: css_rule.cpp:337
The CSSRuleList interface provides the abstraction of an ordered collection of CSS rules.
Definition: css_rule.h:507
CSSRuleListImpl * handle() const
Definition: css_rule.cpp:635
unsigned short type() const
The type of the rule, as defined above.
Definition: css_rule.cpp:69
CSSRuleList cssRules() const
A list of all CSS rules contained within the media block.
Definition: css_rule.cpp:329
The CSSCharsetRule interface a @charset rule in a CSS style sheet.
Definition: css_rule.h:151
void setEncoding(const DOM::DOMString &)
see encoding
Definition: css_rule.cpp:176
CSSRule item(unsigned long index)
Used to retrieve a CSS rule by ordinal index.
Definition: css_rule.cpp:627
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:01:28 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.