File indexing completed on 2024-04-28 15:22:56

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 "dom/dom_exception.h"
0024 #include "dom/dom_xml.h"
0025 #include "dom/dom2_range.h"
0026 #include "dom/dom2_events.h"
0027 #include "dom/dom2_views.h"
0028 #include "dom/dom2_traversal.h"
0029 #include "dom/html_document.h"
0030 #include "html/html_documentimpl.h"
0031 
0032 #include "xml/dom_docimpl.h"
0033 #include "xml/dom_elementimpl.h"
0034 
0035 #include "khtml_debug.h"
0036 
0037 namespace DOM
0038 {
0039 
0040 DOMImplementation::DOMImplementation()
0041 {
0042     impl = nullptr;
0043 }
0044 
0045 DOMImplementation::DOMImplementation(const DOMImplementation &other)
0046 {
0047     impl = other.impl;
0048     if (impl) {
0049         impl->ref();
0050     }
0051 }
0052 
0053 DOMImplementation::DOMImplementation(DOMImplementationImpl *i)
0054 {
0055     impl = i;
0056     if (impl) {
0057         impl->ref();
0058     }
0059 }
0060 
0061 DOMImplementation &DOMImplementation::operator = (const DOMImplementation &other)
0062 {
0063     if (impl != other.impl) {
0064         if (impl) {
0065             impl->deref();
0066         }
0067         impl = other.impl;
0068         if (impl) {
0069             impl->ref();
0070         }
0071     }
0072     return *this;
0073 }
0074 
0075 DOMImplementation::~DOMImplementation()
0076 {
0077     if (impl) {
0078         impl->deref();
0079     }
0080 }
0081 
0082 bool DOMImplementation::hasFeature(const DOMString &feature, const DOMString &version)
0083 {
0084     if (!impl) {
0085         return false;    // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
0086     }
0087 
0088     return impl->hasFeature(feature, version);
0089 }
0090 
0091 DocumentType DOMImplementation::createDocumentType(const DOMString &qualifiedName,
0092         const DOMString &publicId,
0093         const DOMString &systemId)
0094 {
0095     if (!impl) {
0096         throw DOMException(DOMException::NOT_FOUND_ERR);
0097     }
0098 
0099     int exceptioncode = 0;
0100     DocumentTypeImpl *r = impl->createDocumentType(qualifiedName, publicId, systemId, exceptioncode);
0101     if (exceptioncode) {
0102         throw DOMException(exceptioncode);
0103     }
0104     return r;
0105 }
0106 
0107 Document DOMImplementation::createDocument(const DOMString &namespaceURI,
0108         const DOMString &qualifiedName,
0109         const DocumentType &doctype)
0110 {
0111     if (!impl) {
0112         throw DOMException(DOMException::NOT_FOUND_ERR);
0113     }
0114 
0115     int exceptioncode = 0;
0116     DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName,
0117                                            (DocumentTypeImpl *)doctype.handle(),
0118                                            nullptr, exceptioncode);
0119     if (exceptioncode) {
0120         throw DOMException(exceptioncode);
0121     }
0122     return r;
0123 }
0124 
0125 HTMLDocument DOMImplementation::createHTMLDocument(const DOMString &title)
0126 {
0127     if (!impl) {
0128         throw DOMException(DOMException::NOT_FOUND_ERR);
0129     }
0130     return static_cast<DOMImplementationImpl *>(impl)->createHTMLDocument(title);
0131 }
0132 
0133 DOMImplementation DOMImplementation::getInterface(const DOMString &/*feature*/) const
0134 {
0135     if (!impl) {
0136         throw DOMException(DOMException::NOT_FOUND_ERR);
0137     }
0138 
0139     // This method is a no-op for us.
0140     return impl;
0141 }
0142 
0143 CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media)
0144 {
0145     if (!impl) {
0146         throw DOMException(DOMException::NOT_FOUND_ERR);
0147     }
0148 
0149     int exceptioncode = 0;
0150     CSSStyleSheetImpl *r = impl->createCSSStyleSheet(title.implementation(), media.implementation(),
0151                            exceptioncode);
0152     if (exceptioncode) {
0153         throw DOMException(exceptioncode);
0154     }
0155     return r;
0156 }
0157 
0158 DOMImplementationImpl *DOMImplementation::handle() const
0159 {
0160     return impl;
0161 }
0162 
0163 bool DOMImplementation::isNull() const
0164 {
0165     return (impl == nullptr);
0166 }
0167 
0168 // ----------------------------------------------------------------------------
0169 
0170 Document::Document()
0171     : Node()
0172 {
0173     // we always want an implementation
0174     impl = DOMImplementationImpl::createDocument();
0175     impl->ref();
0176 }
0177 
0178 Document::Document(bool create)
0179     : Node()
0180 {
0181     if (create) {
0182         impl = DOMImplementationImpl::createDocument();
0183         impl->ref();
0184     } else {
0185         impl = nullptr;
0186     }
0187 //    qCDebug(KHTML_LOG) << "Document::Document(bool)";
0188 }
0189 
0190 Document::Document(const Document &other) : Node(other)
0191 {
0192 //    qCDebug(KHTML_LOG) << "Document::Document(Document &)";
0193 }
0194 
0195 Document::Document(DocumentImpl *i) : Node(i)
0196 {
0197 //    qCDebug(KHTML_LOG) << "Document::Document(DocumentImpl)";
0198 }
0199 
0200 Document &Document::operator = (const Node &other)
0201 {
0202     NodeImpl *ohandle = other.handle();
0203     if (impl != ohandle) {
0204         if (!ohandle || ohandle->nodeType() != DOCUMENT_NODE) {
0205             if (impl) {
0206                 impl->deref();
0207             }
0208             impl = nullptr;
0209         } else {
0210             Node::operator =(other);
0211         }
0212     }
0213     return *this;
0214 }
0215 
0216 Document &Document::operator = (const Document &other)
0217 {
0218     Node::operator =(other);
0219     return *this;
0220 }
0221 
0222 Document::~Document()
0223 {
0224 //    qCDebug(KHTML_LOG) << "Document::~Document\n";
0225 }
0226 
0227 DocumentType Document::doctype() const
0228 {
0229     if (impl) {
0230         return ((DocumentImpl *)impl)->doctype();
0231     }
0232     return nullptr;
0233 }
0234 
0235 DOMImplementation Document::implementation() const
0236 {
0237     if (impl) {
0238         return ((DocumentImpl *)impl)->implementation();
0239     }
0240     return nullptr;
0241 }
0242 
0243 Element Document::documentElement() const
0244 {
0245     if (impl) {
0246         return ((DocumentImpl *)impl)->documentElement();
0247     }
0248     return nullptr;
0249 }
0250 
0251 Element Document::createElement(const DOMString &tagName)
0252 {
0253     if (!impl) {
0254         throw DOMException(DOMException::NOT_FOUND_ERR);
0255     }
0256 
0257     int exceptioncode = 0;
0258     ElementImpl *r = ((DocumentImpl *)impl)->createElement(tagName, &exceptioncode);
0259     if (exceptioncode) {
0260         throw DOMException(exceptioncode);
0261     }
0262     return r;
0263 }
0264 
0265 Element Document::createElementNS(const DOMString &namespaceURI, const DOMString &qualifiedName)
0266 {
0267     if (!impl) {
0268         throw DOMException(DOMException::NOT_FOUND_ERR);
0269     }
0270 
0271     int exceptioncode = 0;
0272     ElementImpl *r = ((DocumentImpl *)impl)->createElementNS(namespaceURI, qualifiedName, &exceptioncode);
0273     if (exceptioncode) {
0274         throw DOMException(exceptioncode);
0275     }
0276     return r;
0277 }
0278 
0279 DocumentFragment Document::createDocumentFragment()
0280 {
0281     if (impl) {
0282         return ((DocumentImpl *)impl)->createDocumentFragment();
0283     }
0284     return nullptr;
0285 }
0286 
0287 Text Document::createTextNode(const DOMString &data)
0288 {
0289     if (impl) {
0290         return ((DocumentImpl *)impl)->createTextNode(data.implementation());
0291     }
0292     return nullptr;
0293 }
0294 
0295 Comment Document::createComment(const DOMString &data)
0296 {
0297     if (impl) {
0298         return ((DocumentImpl *)impl)->createComment(data.implementation());
0299     }
0300     return nullptr;
0301 }
0302 
0303 CDATASection Document::createCDATASection(const DOMString &data)
0304 {
0305     if (!impl) {
0306         return nullptr;
0307     }
0308     int exceptioncode = 0;
0309     CDATASectionImpl *d = ((DocumentImpl *)impl)->createCDATASection(data.implementation(), exceptioncode);
0310     if (exceptioncode) {
0311         throw DOMException(exceptioncode);
0312     }
0313     return d;
0314 }
0315 
0316 ProcessingInstruction Document::createProcessingInstruction(const DOMString &target, const DOMString &data)
0317 {
0318     if (impl) {
0319         return ((DocumentImpl *)impl)->createProcessingInstruction(target, data.implementation());
0320     }
0321     return nullptr;
0322 }
0323 
0324 Attr Document::createAttribute(const DOMString &name)
0325 {
0326     if (!impl) {
0327         throw DOMException(DOMException::NOT_FOUND_ERR);
0328     }
0329     if (name.isNull()) {
0330         throw DOMException(DOMException::NOT_FOUND_ERR);
0331     }
0332     int exceptioncode = 0;
0333     AttrImpl *a = impl->document()->createAttribute(name, &exceptioncode);
0334     if (exceptioncode) {
0335         throw DOMException(exceptioncode);
0336     }
0337     return a;
0338 }
0339 
0340 Attr Document::createAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName)
0341 {
0342     if (!impl) {
0343         throw DOMException(DOMException::NOT_FOUND_ERR);
0344     }
0345     if (qualifiedName.isNull()) {
0346         throw DOMException(DOMException::NAMESPACE_ERR);
0347     }
0348     int exceptioncode = 0;
0349     AttrImpl *a = impl->document()->createAttributeNS(namespaceURI, qualifiedName, &exceptioncode);
0350     if (exceptioncode) {
0351         throw DOMException(exceptioncode);
0352     }
0353     return a;
0354 }
0355 
0356 EntityReference Document::createEntityReference(const DOMString &name)
0357 {
0358     if (!impl) {
0359         return nullptr;
0360     }
0361     int exceptioncode = 0;
0362     EntityReferenceImpl *er = ((DocumentImpl *)impl)->createEntityReference(name, exceptioncode);
0363     if (exceptioncode) {
0364         throw DOMException(exceptioncode);
0365     }
0366     return er;
0367 }
0368 
0369 Element Document::getElementById(const DOMString &elementId) const
0370 {
0371     if (impl) {
0372         return ((DocumentImpl *)impl)->getElementById(elementId);
0373     }
0374     return nullptr;
0375 }
0376 
0377 NodeList Document::getElementsByTagName(const DOMString &tagName)
0378 {
0379     if (!impl) {
0380         return nullptr;
0381     }
0382     return impl->getElementsByTagName(tagName);
0383 }
0384 
0385 NodeList Document::getElementsByTagNameNS(const DOMString &namespaceURI, const DOMString &localName)
0386 {
0387     if (!impl) {
0388         return nullptr;
0389     }
0390     return impl->getElementsByTagNameNS(namespaceURI, localName);
0391 }
0392 
0393 NodeList Document::getElementsByClassName(const DOMString &className)
0394 {
0395     if (!impl) {
0396         return nullptr;
0397     }
0398     return impl->getElementsByClassName(className);
0399 }
0400 
0401 Node Document::importNode(const Node &importedNode, bool deep)
0402 {
0403     if (!impl) {
0404         throw DOMException(DOMException::INVALID_STATE_ERR);
0405     }
0406 
0407     int exceptioncode = 0;
0408     NodeImpl *r = static_cast<DocumentImpl *>(impl)->importNode(importedNode.handle(), deep, exceptioncode);
0409     if (exceptioncode) {
0410         throw DOMException(exceptioncode);
0411     }
0412     return r;
0413 }
0414 
0415 bool Document::isHTMLDocument() const
0416 {
0417     if (impl) {
0418         return ((DocumentImpl *)impl)->isHTMLDocument();
0419     }
0420     return 0;
0421 }
0422 
0423 Range Document::createRange()
0424 {
0425     if (impl) {
0426         return ((DocumentImpl *)impl)->createRange();
0427     }
0428     return nullptr;
0429 }
0430 
0431 NodeIterator Document::createNodeIterator(Node root, unsigned long whatToShow,
0432         NodeFilter filter, bool entityReferenceExpansion)
0433 {
0434     if (!impl) {
0435         throw DOMException(DOMException::INVALID_STATE_ERR);
0436     }
0437 
0438     int exceptioncode = 0;
0439     NodeIteratorImpl *r = static_cast<DocumentImpl *>(impl)->createNodeIterator(root.handle(),
0440                           whatToShow, filter.handle(), entityReferenceExpansion, exceptioncode);
0441     if (exceptioncode) {
0442         throw DOMException(exceptioncode);
0443     }
0444     return r;
0445 }
0446 
0447 TreeWalker Document::createTreeWalker(Node root, unsigned long whatToShow, NodeFilter filter,
0448                                       bool entityReferenceExpansion)
0449 {
0450     if (!impl) {
0451         throw DOMException(DOMException::INVALID_STATE_ERR);
0452     }
0453 
0454     int exceptioncode = 0;
0455 
0456     TreeWalkerImpl *tw = static_cast<DocumentImpl *>(impl)->createTreeWalker(
0457                              root.handle(), whatToShow, filter.handle(), entityReferenceExpansion, exceptioncode);
0458     if (exceptioncode) {
0459         throw DOMException(exceptioncode);
0460     }
0461 
0462     return tw;
0463 }
0464 
0465 Event Document::createEvent(const DOMString &eventType)
0466 {
0467     if (!impl) {
0468         throw DOMException(DOMException::INVALID_STATE_ERR);
0469     }
0470 
0471     int exceptioncode = 0;
0472     EventImpl *r = ((DocumentImpl *)impl)->createEvent(eventType, exceptioncode);
0473     if (exceptioncode) {
0474         throw DOMException(exceptioncode);
0475     }
0476     return r;
0477 }
0478 
0479 AbstractView Document::defaultView() const
0480 {
0481     if (!impl) {
0482         throw DOMException(DOMException::INVALID_STATE_ERR);
0483     }
0484 
0485     return static_cast<DocumentImpl *>(impl)->defaultView();
0486 }
0487 
0488 StyleSheetList Document::styleSheets() const
0489 {
0490     if (!impl) {
0491         throw DOMException(DOMException::INVALID_STATE_ERR);
0492     }
0493 
0494     return static_cast<DocumentImpl *>(impl)->styleSheets();
0495 }
0496 
0497 DOMString Document::preferredStylesheetSet()
0498 {
0499     if (!impl) {
0500         throw DOMException(DOMException::INVALID_STATE_ERR);
0501     }
0502 
0503     return static_cast<DocumentImpl *>(impl)->preferredStylesheetSet();
0504 }
0505 
0506 DOMString Document::selectedStylesheetSet()
0507 {
0508     if (!impl) {
0509         throw DOMException(DOMException::INVALID_STATE_ERR);
0510     }
0511 
0512     return static_cast<DocumentImpl *>(impl)->selectedStylesheetSet();
0513 }
0514 
0515 void Document::setSelectedStylesheetSet(const DOMString &s)
0516 {
0517     if (!impl) {
0518         throw DOMException(DOMException::INVALID_STATE_ERR);
0519     }
0520 
0521     static_cast<DocumentImpl *>(impl)->setSelectedStylesheetSet(s);
0522 }
0523 
0524 KHTMLView *Document::view() const
0525 {
0526     if (!impl) {
0527         return nullptr;
0528     }
0529 
0530     return static_cast<DocumentImpl *>(impl)->view();
0531 }
0532 
0533 CSSStyleDeclaration Document::getOverrideStyle(const Element &elt, const DOMString &pseudoElt)
0534 {
0535     if (!impl) {
0536         throw DOMException(DOMException::INVALID_STATE_ERR);
0537     }
0538 
0539     CSSStyleDeclarationImpl *r = ((DocumentImpl *)impl)->getOverrideStyle(static_cast<ElementImpl *>(elt.handle()), pseudoElt.implementation());
0540     return r;
0541 }
0542 
0543 bool Document::execCommand(const DOMString &command, bool userInterface, const DOMString &value)
0544 {
0545     if (!impl) {
0546         throw DOMException(DOMException::NOT_FOUND_ERR);
0547     }
0548 
0549     return static_cast<DocumentImpl *>(impl)->execCommand(command, userInterface, value);
0550 }
0551 
0552 bool Document::queryCommandEnabled(const DOMString &command)
0553 {
0554     if (!impl) {
0555         throw DOMException(DOMException::NOT_FOUND_ERR);
0556     }
0557 
0558     return static_cast<DocumentImpl *>(impl)->queryCommandEnabled(command);
0559 }
0560 
0561 bool Document::queryCommandIndeterm(const DOMString &command)
0562 {
0563     if (!impl) {
0564         throw DOMException(DOMException::NOT_FOUND_ERR);
0565     }
0566 
0567     return static_cast<DocumentImpl *>(impl)->queryCommandIndeterm(command);
0568 }
0569 
0570 bool Document::queryCommandState(const DOMString &command)
0571 {
0572     if (!impl) {
0573         throw DOMException(DOMException::NOT_FOUND_ERR);
0574     }
0575 
0576     return static_cast<DocumentImpl *>(impl)->queryCommandState(command);
0577 }
0578 
0579 bool Document::queryCommandSupported(const DOMString &command)
0580 {
0581     if (!impl) {
0582         throw DOMException(DOMException::NOT_FOUND_ERR);
0583     }
0584 
0585     return static_cast<DocumentImpl *>(impl)->queryCommandSupported(command);
0586 }
0587 
0588 DOMString Document::queryCommandValue(const DOMString &command)
0589 {
0590     if (!impl) {
0591         throw DOMException(DOMException::NOT_FOUND_ERR);
0592     }
0593 
0594     return static_cast<DocumentImpl *>(impl)->queryCommandValue(command);
0595 }
0596 
0597 bool Document::async() const
0598 {
0599     if (!impl) {
0600         throw DOMException(DOMException::INVALID_STATE_ERR);
0601     }
0602 
0603     return static_cast<DocumentImpl *>(impl)->async();
0604 }
0605 
0606 void Document::setAsync(bool b)
0607 {
0608     if (!impl) {
0609         throw DOMException(DOMException::INVALID_STATE_ERR);
0610     }
0611 
0612     static_cast<DocumentImpl *>(impl)->setAsync(b);
0613 }
0614 
0615 void Document::abort()
0616 {
0617     if (!impl) {
0618         throw DOMException(DOMException::INVALID_STATE_ERR);
0619     }
0620 
0621     static_cast<DocumentImpl *>(impl)->abort();
0622 }
0623 
0624 void Document::load(const DOMString &uri)
0625 {
0626     if (!impl) {
0627         throw DOMException(DOMException::INVALID_STATE_ERR);
0628     }
0629 
0630     static_cast<DocumentImpl *>(impl)->load(uri);
0631 }
0632 
0633 void Document::loadXML(const DOMString &source)
0634 {
0635     if (!impl) {
0636         throw DOMException(DOMException::INVALID_STATE_ERR);
0637     }
0638 
0639     static_cast<DocumentImpl *>(impl)->loadXML(source);
0640 }
0641 
0642 Element Document::querySelector(const DOMString &query) const
0643 {
0644     int ec = 0;
0645     if (!impl) {
0646         throw DOMException(DOMException::NOT_FOUND_ERR);
0647     }
0648     Element res = impl->querySelector(query, ec).get();
0649     if (ec) {
0650         throw DOMException(ec);
0651     }
0652     return res;
0653 }
0654 
0655 NodeList Document::querySelectorAll(const DOMString &query) const
0656 {
0657     int ec = 0;
0658     if (!impl) {
0659         throw DOMException(DOMException::NOT_FOUND_ERR);
0660     }
0661     NodeList res = impl->querySelectorAll(query, ec).get();
0662     if (ec) {
0663         throw DOMException(ec);
0664     }
0665     return res;
0666 }
0667 
0668 bool Document::designMode() const
0669 {
0670     if (!impl) {
0671         throw DOMException(DOMException::INVALID_STATE_ERR);
0672     }
0673 
0674     return static_cast<DocumentImpl *>(impl)->designMode();
0675 }
0676 
0677 void Document::setDesignMode(bool enable)
0678 {
0679     if (!impl) {
0680         throw DOMException(DOMException::INVALID_STATE_ERR);
0681     }
0682 
0683     static_cast<DocumentImpl *>(impl)->setDesignMode(enable);
0684 }
0685 
0686 DOMString Document::completeURL(const DOMString &url)
0687 {
0688     if (!impl) {
0689         return url;
0690     }
0691     return static_cast<DocumentImpl *>(impl)->completeURL(url.string());
0692 }
0693 
0694 DOMString Document::toString() const
0695 {
0696     if (!impl) {
0697         throw DOMException(DOMException::NOT_FOUND_ERR);
0698     }
0699 
0700     return static_cast<DocumentImpl *>(impl)->toString();
0701 }
0702 
0703 void Document::updateRendering()
0704 {
0705     if (!impl) {
0706         return;
0707     }
0708     static_cast<DocumentImpl *>(impl)->updateRendering();
0709 }
0710 
0711 void Document::addStyleSheet(const StyleSheet &sheet)
0712 {
0713     if (!impl || sheet.isNull()) {
0714         throw DOMException(DOMException::INVALID_STATE_ERR);
0715     }
0716 
0717     int exceptioncode;
0718     static_cast<DocumentImpl *>(impl)->addStyleSheet(sheet.handle(), &exceptioncode);
0719     if (exceptioncode) {
0720         throw DOMException(exceptioncode);
0721     }
0722 }
0723 
0724 void Document::removeStyleSheet(const StyleSheet &sheet)
0725 {
0726     if (!impl || sheet.isNull()) {
0727         throw DOMException(DOMException::INVALID_STATE_ERR);
0728     }
0729 
0730     int exceptioncode;
0731     static_cast<DocumentImpl *>(impl)->removeStyleSheet(sheet.handle(), &exceptioncode);
0732     if (exceptioncode) {
0733         throw DOMException(exceptioncode);
0734     }
0735 }
0736 
0737 // ----------------------------------------------------------------------------
0738 
0739 DocumentFragment::DocumentFragment() : Node()
0740 {
0741 }
0742 
0743 DocumentFragment::DocumentFragment(const DocumentFragment &other) : Node(other)
0744 {
0745 }
0746 
0747 DocumentFragment &DocumentFragment::operator = (const Node &other)
0748 {
0749     NodeImpl *ohandle = other.handle();
0750     if (impl != ohandle) {
0751         if (!ohandle || ohandle->nodeType() != DOCUMENT_FRAGMENT_NODE) {
0752             if (impl) {
0753                 impl->deref();
0754             }
0755             impl = nullptr;
0756         } else {
0757             Node::operator =(other);
0758         }
0759     }
0760     return *this;
0761 }
0762 
0763 DocumentFragment &DocumentFragment::operator = (const DocumentFragment &other)
0764 {
0765     Node::operator =(other);
0766     return *this;
0767 }
0768 
0769 DocumentFragment::~DocumentFragment()
0770 {
0771 }
0772 
0773 Element DocumentFragment::querySelector(const DOMString &query) const
0774 {
0775     int ec = 0;
0776     if (!impl) {
0777         throw DOMException(DOMException::NOT_FOUND_ERR);
0778     }
0779     Element res = impl->querySelector(query, ec).get();
0780     if (ec) {
0781         throw DOMException(ec);
0782     }
0783     return res;
0784 }
0785 
0786 NodeList DocumentFragment::querySelectorAll(const DOMString &query) const
0787 {
0788     int ec = 0;
0789     if (!impl) {
0790         throw DOMException(DOMException::NOT_FOUND_ERR);
0791     }
0792     NodeList res = impl->querySelectorAll(query, ec).get();
0793     if (ec) {
0794         throw DOMException(ec);
0795     }
0796     return res;
0797 }
0798 
0799 DocumentFragment::DocumentFragment(DocumentFragmentImpl *i) : Node(i)
0800 {
0801 }
0802 
0803 // ----------------------------------------------------------------------------
0804 
0805 DocumentType::DocumentType()
0806     : Node()
0807 {
0808 }
0809 
0810 DocumentType::DocumentType(const DocumentType &other)
0811     : Node(other)
0812 {
0813 }
0814 
0815 DocumentType::DocumentType(DocumentTypeImpl *impl) : Node(impl)
0816 {
0817 }
0818 
0819 DocumentType &DocumentType::operator = (const Node &other)
0820 {
0821     NodeImpl *ohandle = other.handle();
0822     if (impl != ohandle) {
0823         if (!ohandle || ohandle->nodeType() != DOCUMENT_TYPE_NODE) {
0824             if (impl) {
0825                 impl->deref();
0826             }
0827             impl = nullptr;
0828         } else {
0829             Node::operator =(other);
0830         }
0831     }
0832     return *this;
0833 }
0834 
0835 DocumentType &DocumentType::operator = (const DocumentType &other)
0836 {
0837     Node::operator =(other);
0838     return *this;
0839 }
0840 
0841 DocumentType::~DocumentType()
0842 {
0843 }
0844 
0845 DOMString DocumentType::name() const
0846 {
0847     if (!impl) {
0848         return DOMString();    // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
0849     }
0850 
0851     return static_cast<DocumentTypeImpl *>(impl)->name();
0852 }
0853 
0854 NamedNodeMap DocumentType::entities() const
0855 {
0856     if (!impl) {
0857         return nullptr;    // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
0858     }
0859 
0860     return static_cast<DocumentTypeImpl *>(impl)->entities();
0861 }
0862 
0863 NamedNodeMap DocumentType::notations() const
0864 {
0865     if (!impl) {
0866         return nullptr;    // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
0867     }
0868 
0869     return static_cast<DocumentTypeImpl *>(impl)->notations();
0870 }
0871 
0872 DOMString DocumentType::publicId() const
0873 {
0874     if (!impl) {
0875         throw DOMException(DOMException::NOT_FOUND_ERR);
0876     }
0877 
0878     return static_cast<DocumentTypeImpl *>(impl)->publicId();
0879 }
0880 
0881 DOMString DocumentType::systemId() const
0882 {
0883     if (!impl) {
0884         throw DOMException(DOMException::NOT_FOUND_ERR);
0885     }
0886 
0887     return static_cast<DocumentTypeImpl *>(impl)->systemId();
0888 }
0889 
0890 DOMString DocumentType::internalSubset() const
0891 {
0892     if (!impl) {
0893         throw DOMException(DOMException::NOT_FOUND_ERR);
0894     }
0895 
0896     return static_cast<DocumentTypeImpl *>(impl)->internalSubset();
0897 }
0898 
0899 } // namespace