File indexing completed on 2024-04-28 15:22:59
0001 /** 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 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 0024 #include "html_document.h" 0025 #include "dom/html_misc.h" 0026 #include "dom/dom_exception.h" 0027 #include "xml/dom_textimpl.h" 0028 #include "html/html_documentimpl.h" 0029 #include "html/html_miscimpl.h" 0030 0031 using namespace DOM; 0032 0033 HTMLDocument::HTMLDocument() : Document(false) // create the impl here 0034 { 0035 impl = DOMImplementationImpl::createHTMLDocument(); 0036 impl->ref(); 0037 0038 } 0039 0040 HTMLDocument::HTMLDocument(KHTMLView *parent) 0041 : Document(false) // create the impl here 0042 { 0043 impl = DOMImplementationImpl::createHTMLDocument(parent); 0044 impl->ref(); 0045 } 0046 0047 HTMLDocument::HTMLDocument(const HTMLDocument &other) : Document(other) 0048 { 0049 } 0050 0051 HTMLDocument::HTMLDocument(HTMLDocumentImpl *impl) : Document(impl) 0052 { 0053 } 0054 0055 HTMLDocument &HTMLDocument::operator = (const Node &other) 0056 { 0057 if (other.nodeType() != DOCUMENT_NODE) { 0058 if (impl) { 0059 impl->deref(); 0060 } 0061 impl = nullptr; 0062 } else { 0063 DocumentImpl *d = static_cast<DocumentImpl *>(other.handle()); 0064 if (!d->isHTMLDocument()) { 0065 if (impl) { 0066 impl->deref(); 0067 } 0068 impl = nullptr; 0069 } else { 0070 Node::operator =(other); 0071 } 0072 } 0073 return *this; 0074 } 0075 0076 HTMLDocument &HTMLDocument::operator = (const HTMLDocument &other) 0077 { 0078 Document::operator =(other); 0079 return *this; 0080 } 0081 0082 HTMLDocument::~HTMLDocument() 0083 { 0084 } 0085 0086 DOMString HTMLDocument::title() const 0087 { 0088 if (!impl) { 0089 return DOMString(); 0090 } 0091 return static_cast<HTMLDocumentImpl *>(impl)->title(); 0092 } 0093 0094 void HTMLDocument::setTitle(const DOMString &value) 0095 { 0096 if (impl) { 0097 static_cast<HTMLDocumentImpl *>(impl)->setTitle(value); 0098 } 0099 } 0100 0101 DOMString HTMLDocument::referrer() const 0102 { 0103 if (!impl) { 0104 return DOMString(); 0105 } 0106 return ((HTMLDocumentImpl *)impl)->referrer(); 0107 } 0108 0109 DOMString HTMLDocument::completeURL(const DOMString &str) const 0110 { 0111 if (!impl) { 0112 return str; 0113 } 0114 return ((HTMLDocumentImpl *)impl)->completeURL(str.trimSpaces().string()); 0115 } 0116 0117 DOMString HTMLDocument::domain() const 0118 { 0119 if (!impl) { 0120 return DOMString(); 0121 } 0122 return ((HTMLDocumentImpl *)impl)->domain(); 0123 } 0124 0125 DOMString HTMLDocument::lastModified() const 0126 { 0127 if (!impl) { 0128 return DOMString(); 0129 } 0130 return ((HTMLDocumentImpl *)impl)->lastModified(); 0131 } 0132 0133 DOMString HTMLDocument::URL() const 0134 { 0135 if (!impl) { 0136 return DOMString(); 0137 } 0138 return ((HTMLDocumentImpl *)impl)->URL().url(); 0139 } 0140 0141 HTMLElement HTMLDocument::body() const 0142 { 0143 if (!impl) { 0144 return nullptr; 0145 } 0146 return ((HTMLDocumentImpl *)impl)->body(); 0147 } 0148 0149 void HTMLDocument::setBody(const HTMLElement &_body) 0150 { 0151 if (!impl) { 0152 return; 0153 } 0154 int exceptioncode = 0; 0155 ((HTMLDocumentImpl *)impl)->setBody(static_cast<HTMLElementImpl *>(_body.handle()), exceptioncode); 0156 if (exceptioncode) { 0157 throw DOMException(exceptioncode); 0158 } 0159 return; 0160 } 0161 0162 HTMLCollection HTMLDocument::images() const 0163 { 0164 if (!impl) { 0165 return HTMLCollection(); 0166 } 0167 return ((HTMLDocumentImpl *)impl)->images(); 0168 } 0169 0170 HTMLCollection HTMLDocument::applets() const 0171 { 0172 if (!impl) { 0173 return HTMLCollection(); 0174 } 0175 return ((HTMLDocumentImpl *)impl)->applets(); 0176 } 0177 0178 HTMLCollection HTMLDocument::scripts() const 0179 { 0180 if (!impl) { 0181 return HTMLCollection(); 0182 } 0183 return ((HTMLDocumentImpl *)impl)->scripts(); 0184 } 0185 0186 HTMLCollection HTMLDocument::links() const 0187 { 0188 if (!impl) { 0189 return HTMLCollection(); 0190 } 0191 return ((HTMLDocumentImpl *)impl)->links(); 0192 } 0193 0194 HTMLCollection HTMLDocument::forms() const 0195 { 0196 if (!impl) { 0197 return HTMLCollection(); 0198 } 0199 return ((HTMLDocumentImpl *)impl)->forms(); 0200 } 0201 0202 HTMLCollection HTMLDocument::layers() const 0203 { 0204 if (!impl) { 0205 return HTMLCollection(); 0206 } 0207 return ((HTMLDocumentImpl *)impl)->layers(); 0208 } 0209 0210 HTMLCollection HTMLDocument::anchors() const 0211 { 0212 if (!impl) { 0213 return HTMLCollection(); 0214 } 0215 return ((HTMLDocumentImpl *)impl)->anchors(); 0216 } 0217 0218 HTMLCollection HTMLDocument::all() const 0219 { 0220 if (!impl) { 0221 return HTMLCollection(); 0222 } 0223 return ((HTMLDocumentImpl *)impl)->all(); 0224 } 0225 0226 DOMString HTMLDocument::cookie() const 0227 { 0228 if (!impl) { 0229 return DOMString(); 0230 } 0231 return ((HTMLDocumentImpl *)impl)->cookie(); 0232 } 0233 0234 void HTMLDocument::setCookie(const DOMString &value) 0235 { 0236 if (impl) { 0237 ((HTMLDocumentImpl *)impl)->setCookie(value); 0238 } 0239 0240 } 0241 0242 void HTMLDocument::open() 0243 { 0244 if (impl) { 0245 ((HTMLDocumentImpl *)impl)->open(); 0246 } 0247 } 0248 0249 void HTMLDocument::close() 0250 { 0251 if (impl) { 0252 ((HTMLDocumentImpl *)impl)->close(); 0253 } 0254 } 0255 0256 void HTMLDocument::write(const DOMString &text) 0257 { 0258 if (impl) { 0259 ((HTMLDocumentImpl *)impl)->write(text); 0260 } 0261 } 0262 0263 void HTMLDocument::writeln(const DOMString &text) 0264 { 0265 if (impl) { 0266 ((HTMLDocumentImpl *)impl)->writeln(text); 0267 } 0268 } 0269 0270 NodeList HTMLDocument::getElementsByName(const DOMString &elementName) 0271 { 0272 if (!impl) { 0273 return nullptr; 0274 } 0275 return ((HTMLDocumentImpl *)impl)->getElementsByName(elementName); 0276 } 0277