KHTML
dom_node.cpp
Go to the documentation of this file.00001
00023 #include "dom/dom_doc.h"
00024 #include "dom/dom_exception.h"
00025 #include "dom/dom2_events.h"
00026 #include "xml/dom_docimpl.h"
00027 #include "xml/dom_elementimpl.h"
00028 #include "xml/dom2_eventsimpl.h"
00029
00030 #include <QtCore/QRect>
00031
00032 using namespace DOM;
00033
00034 NamedNodeMap::NamedNodeMap()
00035 {
00036 impl = 0;
00037 }
00038
00039 NamedNodeMap::NamedNodeMap(const NamedNodeMap &other)
00040 {
00041 impl = other.impl;
00042 if (impl) impl->ref();
00043 }
00044
00045 NamedNodeMap::NamedNodeMap(NamedNodeMapImpl *i)
00046 {
00047 impl = i;
00048 if (impl) impl->ref();
00049 }
00050
00051 NamedNodeMap &NamedNodeMap::operator = (const NamedNodeMap &other)
00052 {
00053 if ( impl != other.impl ) {
00054 if(impl) impl->deref();
00055 impl = other.impl;
00056 if(impl) impl->ref();
00057 }
00058 return *this;
00059 }
00060
00061 NamedNodeMap::~NamedNodeMap()
00062 {
00063 if(impl) impl->deref();
00064 }
00065
00066 Node NamedNodeMap::getNamedItem( const DOMString &name ) const
00067 {
00068 if (!impl) return 0;
00069 return impl->getNamedItem(name);
00070 }
00071
00072 Node NamedNodeMap::setNamedItem( const Node &arg )
00073 {
00074 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00075
00076 int exceptioncode = 0;
00077 Node r = impl->setNamedItem(arg, exceptioncode);
00078 if (exceptioncode)
00079 throw DOMException(exceptioncode);
00080 return r;
00081 }
00082
00083 Node NamedNodeMap::removeNamedItem( const DOMString &name )
00084 {
00085 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00086 int exceptioncode = 0;
00087 Node r = impl->removeNamedItem(name, exceptioncode);
00088 if (exceptioncode)
00089 throw DOMException(exceptioncode);
00090 return r;
00091 }
00092
00093 Node NamedNodeMap::item( unsigned long index ) const
00094 {
00095 if (!impl) return 0;
00096 return impl->item(index);
00097 }
00098
00099 Node NamedNodeMap::getNamedItemNS( const DOMString &namespaceURI, const DOMString &localName ) const
00100 {
00101 if (!impl) return 0;
00102 return impl->getNamedItemNS(namespaceURI, localName);
00103 }
00104
00105 Node NamedNodeMap::setNamedItemNS( const Node &arg )
00106 {
00107 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00108 int exceptioncode = 0;
00109 Node r = impl->setNamedItemNS(arg, exceptioncode);
00110 if (exceptioncode)
00111 throw DOMException(exceptioncode);
00112 return r;
00113 }
00114
00115 Node NamedNodeMap::removeNamedItemNS( const DOMString &namespaceURI, const DOMString &localName )
00116 {
00117 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00118 int exceptioncode = 0;
00119 Node r = impl->removeNamedItemNS(namespaceURI, localName, exceptioncode);
00120 if (exceptioncode)
00121 throw DOMException(exceptioncode);
00122 return r;
00123 }
00124
00125 unsigned long NamedNodeMap::length() const
00126 {
00127 if (!impl) return 0;
00128 return impl->length();
00129 }
00130
00131
00132
00133 Node::Node(const Node &other)
00134 {
00135 impl = other.impl;
00136 if(impl) impl->ref();
00137 }
00138
00139 Node::Node( NodeImpl *i )
00140 {
00141 impl = i;
00142 if(impl) impl->ref();
00143 }
00144
00145 Node &Node::operator = (const Node &other)
00146 {
00147 if(impl != other.impl) {
00148 if(impl) impl->deref();
00149 impl = other.impl;
00150 if(impl) impl->ref();
00151 }
00152 return *this;
00153 }
00154
00155 bool Node::operator == (const Node &other) const
00156 {
00157 return (impl == other.impl);
00158 }
00159
00160 bool Node::operator != (const Node &other) const
00161 {
00162 return !(impl == other.impl);
00163 }
00164
00165 Node::~Node()
00166 {
00167 if(impl) impl->deref();
00168 }
00169
00170 DOMString Node::nodeName() const
00171 {
00172 if(impl) return impl->nodeName();
00173 return DOMString();
00174 }
00175
00176 DOMString Node::nodeValue() const
00177 {
00178
00179 if(impl) return impl->nodeValue();
00180 return DOMString();
00181 }
00182
00183 void Node::setNodeValue( const DOMString &_str )
00184 {
00185 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00186
00187 int exceptioncode = 0;
00188 if(impl) impl->setNodeValue( _str,exceptioncode );
00189 if (exceptioncode)
00190 throw DOMException(exceptioncode);
00191 }
00192
00193 unsigned short Node::nodeType() const
00194 {
00195 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00196 return impl->nodeType();
00197 }
00198
00199 Node Node::parentNode() const
00200 {
00201 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00202 return impl->parentNode();
00203 }
00204
00205 NodeList Node::childNodes() const
00206 {
00207 if (!impl) return 0;
00208 return impl->childNodes();
00209 }
00210
00211 Node Node::firstChild() const
00212 {
00213 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00214 return impl->firstChild();
00215 }
00216
00217 Node Node::lastChild() const
00218 {
00219 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00220 return impl->lastChild();
00221 }
00222
00223 Node Node::previousSibling() const
00224 {
00225 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00226 return impl->previousSibling();
00227 }
00228
00229 Node Node::nextSibling() const
00230 {
00231 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00232 return impl->nextSibling();
00233 }
00234
00235 NamedNodeMap Node::attributes() const
00236 {
00237 if (!impl || !impl->isElementNode()) return 0;
00238 return static_cast<ElementImpl*>(impl)->attributes();
00239 }
00240
00241 Document Node::ownerDocument() const
00242 {
00243 if (!impl || !impl->ownerDocument())
00244 return Document(false);
00245 return impl->ownerDocument();
00246 }
00247
00248 Node Node::insertBefore( const Node &newChild, const Node &refChild )
00249 {
00250 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00251 int exceptioncode = 0;
00252 NodeImpl *r = impl->insertBefore( newChild.impl, refChild.impl, exceptioncode );
00253 if (exceptioncode)
00254 throw DOMException(exceptioncode);
00255 if (!newChild.impl->closed()) newChild.impl->close();
00256 return r;
00257 }
00258
00259 Node Node::replaceChild( const Node &newChild, const Node &oldChild )
00260 {
00261 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00262 int exceptioncode = 0;
00263 impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode );
00264 if (exceptioncode)
00265 throw DOMException(exceptioncode);
00266 if (newChild.impl && !newChild.impl->closed()) newChild.impl->close();
00267
00268 return oldChild;
00269 }
00270
00271 Node Node::removeChild( const Node &oldChild )
00272 {
00273 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00274 int exceptioncode = 0;
00275 impl->removeChild( oldChild.impl, exceptioncode );
00276 if (exceptioncode)
00277 throw DOMException(exceptioncode);
00278
00279 return oldChild;
00280 }
00281
00282 Node Node::appendChild( const Node &newChild )
00283 {
00284 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00285 int exceptioncode = 0;
00286 NodeImpl *r = impl->appendChild( newChild.impl, exceptioncode );
00287 if (exceptioncode)
00288 throw DOMException(exceptioncode);
00289 if (!newChild.impl->closed()) newChild.impl->close();
00290 return r;
00291 }
00292
00293 bool Node::hasAttributes()
00294 {
00295 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00296 return impl->hasAttributes();
00297 }
00298
00299 bool Node::hasChildNodes( )
00300 {
00301 if (!impl) return false;
00302 return impl->hasChildNodes();
00303 }
00304
00305 Node Node::cloneNode( bool deep )
00306 {
00307 if (!impl) return 0;
00308 return impl->cloneNode( deep );
00309 }
00310
00311 void Node::normalize ( )
00312 {
00313 if (!impl) return;
00314 impl->normalize();
00315 }
00316
00317 bool Node::isSupported( const DOMString &feature,
00318 const DOMString &version ) const
00319 {
00320 return NodeImpl::isSupported(feature, version);
00321 }
00322
00323 DOMString Node::namespaceURI( ) const
00324 {
00325 if (!impl) return DOMString();
00326 return impl->namespaceURI();
00327 }
00328
00329 DOMString Node::prefix( ) const
00330 {
00331 if (!impl) return DOMString();
00332 return impl->prefix();
00333 }
00334
00335 void Node::setPrefix(const DOMString &prefix )
00336 {
00337 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00338 int exceptioncode = 0;
00339 impl->setPrefix(prefix,exceptioncode);
00340 if (exceptioncode)
00341 throw DOMException(exceptioncode);
00342 }
00343
00344 DOMString Node::localName( ) const
00345 {
00346 if (!impl) return DOMString();
00347 return impl->localName();
00348 }
00349
00350 void Node::addEventListener(const DOMString &type,
00351 EventListener *listener,
00352 const bool useCapture)
00353 {
00354 if (!impl) return;
00355 if (listener)
00356 impl->addEventListener(EventImpl::typeToId(type),listener,useCapture);
00357 }
00358
00359 void Node::removeEventListener(const DOMString &type,
00360 EventListener *listener,
00361 bool useCapture)
00362 {
00363 if (!impl) return;
00364 impl->removeEventListener(EventImpl::typeToId(type),listener,useCapture);
00365 }
00366
00367 bool Node::dispatchEvent(const Event &evt)
00368 {
00369 if (!impl)
00370 throw DOMException(DOMException::INVALID_STATE_ERR);
00371
00372 if (!evt.handle())
00373 throw DOMException(DOMException::NOT_FOUND_ERR);
00374
00375 int exceptioncode = 0;
00376 impl->dispatchEvent(evt.handle(),exceptioncode);
00377 if (exceptioncode)
00378 throw DOMException(exceptioncode);
00379 return !evt.handle()->defaultPrevented();
00380 }
00381
00382 DOMString Node::textContent() const
00383 {
00384 if (!impl) return DOMString();
00385 return impl->textContent();
00386 }
00387
00388 void Node::setTextContent(const DOMString& content)
00389 {
00390 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00391 int exceptioncode = 0;
00392 impl->setTextContent(content, exceptioncode);
00393 if (exceptioncode)
00394 throw DOMException(exceptioncode);
00395 }
00396
00397 unsigned int Node::elementId() const
00398 {
00399 if (!impl) return 0;
00400 return impl->id();
00401 }
00402
00403 unsigned long Node::index() const
00404 {
00405 if (!impl) return 0;
00406 return impl->nodeIndex();
00407 }
00408
00409 QString Node::toHTML()
00410 {
00411 if (!impl) return QString();
00412 return impl->toString().string();
00413 }
00414
00415 void Node::applyChanges()
00416 {
00417 if (!impl) return;
00418 impl->recalcStyle( NodeImpl::Inherit );
00419 }
00420
00421 void Node::getCursor(int offset, int &_x, int &_y, int &height)
00422 {
00423 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00424 int dummy;
00425 impl->getCaret(offset, false, _x, _y, dummy, height);
00426 }
00427
00428 QRect Node::getRect()
00429 {
00430 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00431 return impl->getRect();
00432 }
00433
00434
00435
00436 NodeList::NodeList()
00437 {
00438 impl = 0;
00439 }
00440
00441 NodeList::NodeList(const NodeList &other)
00442 {
00443 impl = other.impl;
00444 if(impl) impl->ref();
00445 }
00446
00447 NodeList::NodeList(const NodeListImpl *i)
00448 {
00449 impl = const_cast<NodeListImpl *>(i);
00450 if(impl) impl->ref();
00451 }
00452
00453 NodeList &NodeList::operator = (const NodeList &other)
00454 {
00455 if ( impl != other.impl ) {
00456 if(impl) impl->deref();
00457 impl = other.impl;
00458 if(impl) impl->ref();
00459 }
00460 return *this;
00461 }
00462
00463 NodeList::~NodeList()
00464 {
00465 if(impl) impl->deref();
00466 }
00467
00468 Node NodeList::item( unsigned long index ) const
00469 {
00470 if (!impl) return 0;
00471 return impl->item(index);
00472 }
00473
00474 unsigned long NodeList::length() const
00475 {
00476 if (!impl) return 0;
00477 return impl->length();
00478 }