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