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