File indexing completed on 2024-04-28 11:37:41

0001 /**
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright 1999 Lars Knoll (knoll@kde.org)
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 
0023 #include "css/css_ruleimpl.h"
0024 
0025 using namespace DOM;
0026 
0027 CSSRule::CSSRule()
0028 {
0029     impl = nullptr;
0030 }
0031 
0032 CSSRule::CSSRule(const CSSRule &other)
0033 {
0034     impl = other.impl;
0035     if (impl) {
0036         impl->ref();
0037     }
0038 }
0039 
0040 CSSRule::CSSRule(CSSRuleImpl *i)
0041 {
0042     impl = i;
0043     if (impl) {
0044         impl->ref();
0045     }
0046 }
0047 
0048 CSSRule &CSSRule::operator = (const CSSRule &other)
0049 {
0050     if (impl != other.impl) {
0051         if (impl) {
0052             impl->deref();
0053         }
0054         impl = other.impl;
0055         if (impl) {
0056             impl->ref();
0057         }
0058     }
0059     return *this;
0060 }
0061 
0062 CSSRule::~CSSRule()
0063 {
0064     if (impl) {
0065         impl->deref();
0066     }
0067 }
0068 
0069 unsigned short CSSRule::type() const
0070 {
0071     if (!impl) {
0072         return 0;
0073     }
0074     return ((CSSRuleImpl *)impl)->type();
0075 }
0076 
0077 DOMString CSSRule::cssText() const
0078 {
0079     if (!impl) {
0080         return DOMString();
0081     }
0082     return impl->cssText();
0083 }
0084 
0085 void CSSRule::setCssText(const DOMString &value)
0086 {
0087     if (!impl) {
0088         return;
0089     }
0090     impl->setCssText(value);
0091 }
0092 
0093 CSSStyleSheet CSSRule::parentStyleSheet() const
0094 {
0095     if (!impl) {
0096         return CSSStyleSheet();
0097     }
0098     return ((CSSRuleImpl *)impl)->parentStyleSheet();
0099 }
0100 
0101 CSSRule CSSRule::parentRule() const
0102 {
0103     if (!impl) {
0104         return nullptr;
0105     }
0106     return ((CSSRuleImpl *)impl)->parentRule();
0107 }
0108 
0109 CSSRuleImpl *CSSRule::handle() const
0110 {
0111     return impl;
0112 }
0113 
0114 bool CSSRule::isNull() const
0115 {
0116     return (impl == nullptr);
0117 }
0118 
0119 void CSSRule::assignOther(const CSSRule &other, RuleType thisType)
0120 {
0121     if (other.type() != thisType) {
0122         if (impl) {
0123             impl->deref();
0124         }
0125         impl = nullptr;
0126     } else {
0127         CSSRule::operator = (other);
0128     }
0129 }
0130 
0131 // ----------------------------------------------------------
0132 
0133 CSSCharsetRule::CSSCharsetRule()
0134     : CSSRule()
0135 {
0136 }
0137 
0138 CSSCharsetRule::CSSCharsetRule(const CSSCharsetRule &other) : CSSRule(other)
0139 {
0140 }
0141 
0142 CSSCharsetRule::CSSCharsetRule(const CSSRule &other)
0143 {
0144     impl = nullptr;
0145     operator=(other);
0146 }
0147 
0148 CSSCharsetRule::CSSCharsetRule(CSSCharsetRuleImpl *impl) : CSSRule(impl)
0149 {
0150 }
0151 
0152 CSSCharsetRule &CSSCharsetRule::operator = (const CSSCharsetRule &other)
0153 {
0154     CSSRule::operator = (other);
0155     return *this;
0156 }
0157 
0158 CSSCharsetRule &CSSCharsetRule::operator = (const CSSRule &other)
0159 {
0160     assignOther(other, CSSRule::CHARSET_RULE);
0161     return *this;
0162 }
0163 
0164 CSSCharsetRule::~CSSCharsetRule()
0165 {
0166 }
0167 
0168 DOMString CSSCharsetRule::encoding() const
0169 {
0170     if (!impl) {
0171         return DOMString();
0172     }
0173     return ((CSSCharsetRuleImpl *)impl)->encoding();
0174 }
0175 
0176 void CSSCharsetRule::setEncoding(const DOMString &value)
0177 {
0178     ((CSSCharsetRuleImpl *)impl)->setEncoding(value);
0179 }
0180 
0181 // ----------------------------------------------------------
0182 
0183 CSSFontFaceRule::CSSFontFaceRule() : CSSRule()
0184 {
0185 }
0186 
0187 CSSFontFaceRule::CSSFontFaceRule(const CSSFontFaceRule &other) : CSSRule(other)
0188 {
0189 }
0190 
0191 CSSFontFaceRule::CSSFontFaceRule(const CSSRule &other)
0192 {
0193     impl = nullptr;
0194     operator=(other);
0195 }
0196 
0197 CSSFontFaceRule::CSSFontFaceRule(CSSFontFaceRuleImpl *impl) : CSSRule(impl)
0198 {
0199 }
0200 
0201 CSSFontFaceRule &CSSFontFaceRule::operator = (const CSSFontFaceRule &other)
0202 {
0203     CSSRule::operator = (other);
0204     return *this;
0205 }
0206 
0207 CSSFontFaceRule &CSSFontFaceRule::operator = (const CSSRule &other)
0208 {
0209     assignOther(other, CSSRule::FONT_FACE_RULE);
0210     return *this;
0211 }
0212 
0213 CSSFontFaceRule::~CSSFontFaceRule()
0214 {
0215 }
0216 
0217 CSSStyleDeclaration CSSFontFaceRule::style() const
0218 {
0219     if (!impl) {
0220         return CSSStyleDeclaration();
0221     }
0222     return ((CSSFontFaceRuleImpl *)impl)->style();
0223 }
0224 
0225 // ----------------------------------------------------------
0226 
0227 CSSImportRule::CSSImportRule() : CSSRule()
0228 {
0229 }
0230 
0231 CSSImportRule::CSSImportRule(const CSSImportRule &other) : CSSRule(other)
0232 {
0233 }
0234 
0235 CSSImportRule::CSSImportRule(const CSSRule &other)
0236 {
0237     impl = nullptr;
0238     operator=(other);
0239 }
0240 
0241 CSSImportRule::CSSImportRule(CSSImportRuleImpl *impl) : CSSRule(impl)
0242 {
0243 }
0244 
0245 CSSImportRule &CSSImportRule::operator = (const CSSImportRule &other)
0246 {
0247     CSSRule::operator = (other);
0248     return *this;
0249 }
0250 
0251 CSSImportRule &CSSImportRule::operator = (const CSSRule &other)
0252 {
0253     assignOther(other, CSSRule::IMPORT_RULE);
0254     return *this;
0255 }
0256 
0257 CSSImportRule::~CSSImportRule()
0258 {
0259 }
0260 
0261 DOMString CSSImportRule::href() const
0262 {
0263     if (!impl) {
0264         return DOMString();
0265     }
0266     return ((CSSImportRuleImpl *)impl)->href();
0267 }
0268 
0269 MediaList CSSImportRule::media() const
0270 {
0271     if (!impl) {
0272         return MediaList();
0273     }
0274     return ((CSSImportRuleImpl *)impl)->media();
0275 }
0276 
0277 CSSStyleSheet CSSImportRule::styleSheet() const
0278 {
0279     if (!impl) {
0280         return CSSStyleSheet();
0281     }
0282     return ((CSSImportRuleImpl *)impl)->styleSheet();
0283 }
0284 
0285 // ----------------------------------------------------------
0286 
0287 CSSMediaRule::CSSMediaRule() : CSSRule()
0288 {
0289 }
0290 
0291 CSSMediaRule::CSSMediaRule(const CSSMediaRule &other) : CSSRule(other)
0292 {
0293 }
0294 
0295 CSSMediaRule::CSSMediaRule(const CSSRule &other)
0296 {
0297     impl = nullptr;
0298     operator=(other);
0299 }
0300 
0301 CSSMediaRule::CSSMediaRule(CSSMediaRuleImpl *impl) : CSSRule(impl)
0302 {
0303 }
0304 
0305 CSSMediaRule &CSSMediaRule::operator = (const CSSMediaRule &other)
0306 {
0307     CSSRule::operator = (other);
0308     return *this;
0309 }
0310 
0311 CSSMediaRule &CSSMediaRule::operator = (const CSSRule &other)
0312 {
0313     assignOther(other, CSSRule::MEDIA_RULE);
0314     return *this;
0315 }
0316 
0317 CSSMediaRule::~CSSMediaRule()
0318 {
0319 }
0320 
0321 MediaList CSSMediaRule::media() const
0322 {
0323     if (!impl) {
0324         return MediaList();
0325     }
0326     return ((CSSMediaRuleImpl *)impl)->media();
0327 }
0328 
0329 CSSRuleList CSSMediaRule::cssRules() const
0330 {
0331     if (!impl) {
0332         return CSSRuleList();
0333     }
0334     return ((CSSMediaRuleImpl *)impl)->cssRules();
0335 }
0336 
0337 unsigned long CSSMediaRule::insertRule(const DOMString &rule, unsigned long index)
0338 {
0339     if (!impl) {
0340         return 0;
0341     }
0342     return ((CSSMediaRuleImpl *)impl)->insertRule(rule, index);
0343 }
0344 
0345 void CSSMediaRule::deleteRule(unsigned long index)
0346 {
0347     if (impl) {
0348         ((CSSMediaRuleImpl *)impl)->deleteRule(index);
0349     }
0350 }
0351 
0352 // ----------------------------------------------------------
0353 
0354 CSSPageRule::CSSPageRule() : CSSRule()
0355 {
0356 }
0357 
0358 CSSPageRule::CSSPageRule(const CSSPageRule &other) : CSSRule(other)
0359 {
0360 }
0361 
0362 CSSPageRule::CSSPageRule(const CSSRule &other)
0363 {
0364     impl = nullptr;
0365     operator=(other);
0366 }
0367 
0368 CSSPageRule::CSSPageRule(CSSPageRuleImpl *impl) : CSSRule(impl)
0369 {
0370 }
0371 
0372 CSSPageRule &CSSPageRule::operator = (const CSSPageRule &other)
0373 {
0374     CSSRule::operator = (other);
0375     return *this;
0376 }
0377 
0378 CSSPageRule &CSSPageRule::operator = (const CSSRule &other)
0379 {
0380     assignOther(other, CSSRule::PAGE_RULE);
0381     return *this;
0382 }
0383 
0384 CSSPageRule::~CSSPageRule()
0385 {
0386 }
0387 
0388 DOMString CSSPageRule::selectorText() const
0389 {
0390     if (!impl) {
0391         return DOMString();
0392     }
0393     return ((CSSPageRuleImpl *)impl)->selectorText();
0394 }
0395 
0396 void CSSPageRule::setSelectorText(const DOMString &value)
0397 {
0398     ((CSSPageRuleImpl *)impl)->setSelectorText(value);
0399 }
0400 
0401 CSSStyleDeclaration CSSPageRule::style() const
0402 {
0403     if (!impl) {
0404         return CSSStyleDeclaration();
0405     }
0406     return ((CSSPageRuleImpl *)impl)->style();
0407 }
0408 
0409 // ----------------------------------------------------------
0410 
0411 CSSStyleRule::CSSStyleRule() : CSSRule()
0412 {
0413 }
0414 
0415 CSSStyleRule::CSSStyleRule(const CSSStyleRule &other)
0416     : CSSRule(other)
0417 {
0418 }
0419 
0420 CSSStyleRule::CSSStyleRule(const CSSRule &other)
0421 {
0422     impl = nullptr;
0423     operator=(other);
0424 }
0425 
0426 CSSStyleRule::CSSStyleRule(CSSStyleRuleImpl *impl)
0427     : CSSRule(impl)
0428 {
0429 }
0430 
0431 CSSStyleRule &CSSStyleRule::operator = (const CSSStyleRule &other)
0432 {
0433     CSSRule::operator = (other);
0434     return *this;
0435 }
0436 
0437 CSSStyleRule &CSSStyleRule::operator = (const CSSRule &other)
0438 {
0439     assignOther(other, CSSRule::STYLE_RULE);
0440     return *this;
0441 }
0442 
0443 CSSStyleRule::~CSSStyleRule()
0444 {
0445 }
0446 
0447 DOMString CSSStyleRule::selectorText() const
0448 {
0449     if (!impl) {
0450         return DOMString();
0451     }
0452     return ((CSSStyleRuleImpl *)impl)->selectorText();
0453 }
0454 
0455 void CSSStyleRule::setSelectorText(const DOMString &value)
0456 {
0457     ((CSSStyleRuleImpl *)impl)->setSelectorText(value);
0458 }
0459 
0460 CSSStyleDeclaration CSSStyleRule::style() const
0461 {
0462     if (!impl) {
0463         return CSSStyleDeclaration();
0464     }
0465     return ((CSSStyleRuleImpl *)impl)->style();
0466 }
0467 
0468 // ----------------------------------------------------------
0469 
0470 CSSNamespaceRule::CSSNamespaceRule() : CSSRule()
0471 {
0472 }
0473 
0474 CSSNamespaceRule::CSSNamespaceRule(const CSSNamespaceRule &other)
0475     : CSSRule(other)
0476 {
0477 }
0478 
0479 CSSNamespaceRule::CSSNamespaceRule(const CSSRule &other)
0480 {
0481     impl = nullptr;
0482     operator=(other);
0483 }
0484 
0485 CSSNamespaceRule::CSSNamespaceRule(CSSNamespaceRuleImpl *impl)
0486     : CSSRule(impl)
0487 {
0488 }
0489 
0490 CSSNamespaceRule &CSSNamespaceRule::operator = (const CSSNamespaceRule &other)
0491 {
0492     CSSRule::operator = (other);
0493     return *this;
0494 }
0495 
0496 CSSNamespaceRule &CSSNamespaceRule::operator = (const CSSRule &other)
0497 {
0498     assignOther(other, CSSRule::NAMESPACE_RULE);
0499     return *this;
0500 }
0501 
0502 CSSNamespaceRule::~CSSNamespaceRule()
0503 {
0504 }
0505 
0506 DOMString CSSNamespaceRule::namespaceURI() const
0507 {
0508     if (!impl) {
0509         return DOMString();
0510     }
0511     return static_cast<CSSNamespaceRuleImpl *>(impl)->namespaceURI();
0512 }
0513 
0514 DOMString CSSNamespaceRule::prefix() const
0515 {
0516     if (!impl) {
0517         return DOMString();
0518     }
0519     return static_cast<CSSNamespaceRuleImpl *>(impl)->prefix();
0520 }
0521 
0522 // ----------------------------------------------------------
0523 
0524 CSSUnknownRule::CSSUnknownRule() : CSSRule()
0525 {
0526 }
0527 
0528 CSSUnknownRule::CSSUnknownRule(const CSSUnknownRule &other)
0529     : CSSRule(other)
0530 {
0531 }
0532 
0533 CSSUnknownRule::CSSUnknownRule(const CSSRule &other)
0534 {
0535     impl = nullptr;
0536     operator=(other);
0537 }
0538 
0539 CSSUnknownRule::CSSUnknownRule(CSSUnknownRuleImpl *impl)
0540     : CSSRule(impl)
0541 {
0542 }
0543 
0544 CSSUnknownRule &CSSUnknownRule::operator = (const CSSUnknownRule &other)
0545 {
0546     CSSRule::operator = (other);
0547     return *this;
0548 }
0549 
0550 CSSUnknownRule &CSSUnknownRule::operator = (const CSSRule &other)
0551 {
0552     assignOther(other, CSSRule::UNKNOWN_RULE);
0553     return *this;
0554 }
0555 
0556 CSSUnknownRule::~CSSUnknownRule()
0557 {
0558 }
0559 
0560 // ----------------------------------------------------------
0561 
0562 CSSRuleList::CSSRuleList()
0563 {
0564     impl = nullptr;
0565 }
0566 
0567 CSSRuleList::CSSRuleList(const CSSRuleList &other)
0568 {
0569     impl = other.impl;
0570     if (impl) {
0571         impl->ref();
0572     }
0573 }
0574 
0575 CSSRuleList::CSSRuleList(CSSRuleListImpl *i)
0576 {
0577     impl = i;
0578     if (impl) {
0579         impl->ref();
0580     }
0581 }
0582 
0583 CSSRuleList::CSSRuleList(StyleListImpl *lst)
0584 {
0585     impl = new CSSRuleListImpl;
0586     impl->ref();
0587     if (lst) {
0588         for (unsigned long i = 0; i < lst->length(); ++i) {
0589             StyleBaseImpl *style = lst->item(i);
0590             if (style->isRule()) {
0591                 impl->insertRule(static_cast<CSSRuleImpl *>(style), impl->length());
0592             }
0593         }
0594     }
0595 }
0596 
0597 CSSRuleList &CSSRuleList::operator = (const CSSRuleList &other)
0598 {
0599     if (impl != other.impl) {
0600         if (impl) {
0601             impl->deref();
0602         }
0603         impl = other.impl;
0604         if (impl) {
0605             impl->ref();
0606         }
0607     }
0608     return *this;
0609 }
0610 
0611 CSSRuleList::~CSSRuleList()
0612 {
0613     if (impl) {
0614         impl->deref();
0615     }
0616 }
0617 
0618 unsigned long CSSRuleList::length() const
0619 {
0620     if (!impl) {
0621         return 0;
0622     }
0623     return ((CSSRuleListImpl *)impl)->length();
0624     return 0;
0625 }
0626 
0627 CSSRule CSSRuleList::item(unsigned long index)
0628 {
0629     if (!impl) {
0630         return CSSRule();
0631     }
0632     return ((CSSRuleListImpl *)impl)->item(index);
0633 }
0634 
0635 CSSRuleListImpl *CSSRuleList::handle() const
0636 {
0637     return impl;
0638 }
0639 
0640 bool CSSRuleList::isNull() const
0641 {
0642     return (impl == nullptr);
0643 }
0644