khtml Library API Documentation

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     Node r = impl->removeNamedItem(impl->mapId(namespaceURI, localName, true), exceptioncode);
00109     if (exceptioncode)
00110         throw DOMException(exceptioncode);
00111     return r;
00112 }
00113 
00114 unsigned long NamedNodeMap::length() const
00115 {
00116     if (!impl) return 0;
00117     return impl->length();
00118 }
00119 
00120 NamedNodeMapImpl *NamedNodeMap::handle() const throw()
00121 {
00122     return impl;
00123 }
00124 
00125 bool NamedNodeMap::isNull() const throw()
00126 {
00127     return (impl == 0);
00128 }
00129 
00130 // ---------------------------------------------------------------------------
00131 
00132 Node::Node()
00133 {
00134     impl = 0;
00135 }
00136 
00137 Node::Node(const Node &other)
00138 {
00139     impl = other.impl;
00140     if(impl) impl->ref();
00141 }
00142 
00143 Node::Node( NodeImpl *i )
00144 {
00145     impl = i;
00146     if(impl) impl->ref();
00147 }
00148 
00149 Node &Node::operator = (const Node &other)
00150 {
00151     if(impl != other.impl) {
00152         if(impl) impl->deref();
00153         impl = other.impl;
00154         if(impl) impl->ref();
00155     }
00156     return *this;
00157 }
00158 
00159 bool Node::operator == (const Node &other)
00160 {
00161     return (impl == other.impl);
00162 }
00163 
00164 bool Node::operator != (const Node &other)
00165 {
00166     return !(impl == other.impl);
00167 }
00168 
00169 Node::~Node()
00170 {
00171     if(impl) impl->deref();
00172 }
00173 
00174 DOMString Node::nodeName() const
00175 {
00176     if(impl) return impl->nodeName();
00177     return DOMString();
00178 }
00179 
00180 DOMString Node::nodeValue() const
00181 {
00182     // ### should throw exception on plain node ?
00183     if(impl) return impl->nodeValue();
00184     return DOMString();
00185 }
00186 
00187 void Node::setNodeValue( const DOMString &_str )
00188 {
00189     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00190 
00191     int exceptioncode = 0;
00192     if(impl) impl->setNodeValue( _str,exceptioncode );
00193     if (exceptioncode)
00194     throw DOMException(exceptioncode);
00195 }
00196 
00197 unsigned short Node::nodeType() const
00198 {
00199     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00200     return impl->nodeType();
00201 }
00202 
00203 Node Node::parentNode() const
00204 {
00205     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00206     return impl->parentNode();
00207 }
00208 
00209 NodeList Node::childNodes() const
00210 {
00211     if (!impl) return 0;
00212     return impl->childNodes();
00213 }
00214 
00215 Node Node::firstChild() const
00216 {
00217     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00218     return impl->firstChild();
00219 }
00220 
00221 Node Node::lastChild() const
00222 {
00223     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00224     return impl->lastChild();
00225 }
00226 
00227 Node Node::previousSibling() const
00228 {
00229     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00230     return impl->previousSibling();
00231 }
00232 
00233 Node Node::nextSibling() const
00234 {
00235     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00236     return impl->nextSibling();
00237 }
00238 
00239 NamedNodeMap Node::attributes() const
00240 {
00241     if (!impl || !impl->isElementNode()) return 0;
00242     return static_cast<ElementImpl*>(impl)->attributes();
00243 }
00244 
00245 Document Node::ownerDocument() const
00246 {
00247     // braindead DOM spec says that ownerDocument
00248     // should return null if called on the document node
00249     // we don't do that in the *impl tree to avoid excessive if()'s
00250     // so we simply hack it here in one central place.
00251     if (!impl || impl->getDocument() == impl) return Document(false);
00252 
00253     return impl->getDocument();
00254 }
00255 
00256 Node Node::insertBefore( const Node &newChild, const Node &refChild )
00257 {
00258     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00259     int exceptioncode = 0;
00260     NodeImpl *r = impl->insertBefore( newChild.impl, refChild.impl, exceptioncode );
00261     if (exceptioncode)
00262     throw DOMException(exceptioncode);
00263     return r;
00264 }
00265 
00266 Node Node::replaceChild( const Node &newChild, const Node &oldChild )
00267 {
00268     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00269     int exceptioncode = 0;
00270     NodeImpl *r = impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode );
00271     if (exceptioncode)
00272     throw DOMException(exceptioncode);
00273     return r;
00274 }
00275 
00276 Node Node::removeChild( const Node &oldChild )
00277 {
00278     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00279     int exceptioncode = 0;
00280     NodeImpl *r = impl->removeChild( oldChild.impl, exceptioncode );
00281     if (exceptioncode)
00282     throw DOMException(exceptioncode);
00283     return r;
00284 }
00285 
00286 Node Node::appendChild( const Node &newChild )
00287 {
00288     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00289     int exceptioncode = 0;
00290     NodeImpl *r = impl->appendChild( newChild.impl, exceptioncode );
00291     if (exceptioncode)
00292     throw DOMException(exceptioncode);
00293     return r;
00294 }
00295 
00296 bool Node::hasAttributes()
00297 {
00298     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00299     if (!impl->isElementNode()) return false;
00300     ElementImpl* e = static_cast<ElementImpl*>(impl);
00301     return e->attributes(true) && e->attributes(true)->length();
00302 }
00303 
00304 bool Node::hasChildNodes(  )
00305 {
00306     if (!impl) return false;
00307     return impl->hasChildNodes();
00308 }
00309 
00310 Node Node::cloneNode( bool deep )
00311 {
00312     if (!impl) return 0;
00313     return impl->cloneNode( deep  );
00314 }
00315 
00316 void Node::normalize (  )
00317 {
00318     if (!impl) return;
00319     impl->normalize();
00320 }
00321 
00322 bool Node::isSupported( const DOMString &feature,
00323                         const DOMString & /*version*/ ) const
00324 {
00325     DOMString upFeature = feature.upper();
00326     return (upFeature == "HTML" ||
00327             upFeature == "XML" ||
00328             upFeature == "CORE");
00329 }
00330 
00331 DOMString Node::namespaceURI(  ) const
00332 {
00333     if (!impl) return DOMString();
00334     return impl->getDocument()->namespaceURI(impl->id());
00335 }
00336 
00337 DOMString Node::prefix(  ) const
00338 {
00339     if (!impl) return DOMString();
00340     return impl->prefix();
00341 }
00342 
00343 void Node::setPrefix(const DOMString &prefix )
00344 {
00345     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00346     int exceptioncode = 0;
00347     impl->setPrefix(prefix,exceptioncode);
00348     if (exceptioncode)
00349         throw DOMException(exceptioncode);
00350 }
00351 
00352 DOMString Node::localName(  ) const
00353 {
00354     if (!impl) return DOMString();
00355     return impl->localName();
00356 }
00357 
00358 void Node::addEventListener(const DOMString &type,
00359               EventListener *listener,
00360               const bool useCapture)
00361 {
00362     if (!impl) return;
00363     if (listener)
00364         impl->addEventListener(EventImpl::typeToId(type),listener,useCapture);
00365 }
00366 
00367 void Node::removeEventListener(const DOMString &type,
00368                  EventListener *listener,
00369                  bool useCapture)
00370 {
00371     if (!impl) return;
00372     impl->removeEventListener(EventImpl::typeToId(type),listener,useCapture);
00373 }
00374 
00375 bool Node::dispatchEvent(const Event &evt)
00376 {
00377     if (!impl)
00378     throw DOMException(DOMException::INVALID_STATE_ERR);
00379 
00380     int exceptioncode = 0;
00381     bool r = impl->dispatchEvent(evt.handle(),exceptioncode);
00382     if (exceptioncode)
00383     throw DOMException(exceptioncode);
00384     return r;
00385 }
00386 
00387 
00388 unsigned int Node::elementId() const
00389 {
00390     if (!impl) return 0;
00391     return impl->id();
00392 }
00393 
00394 unsigned long Node::index() const
00395 {
00396     if (!impl) return 0;
00397     return impl->nodeIndex();
00398 }
00399 
00400 QString Node::toHTML()
00401 {
00402     if (!impl) return QString::null;
00403     return impl->toHTML();
00404 }
00405 
00406 void Node::applyChanges()
00407 {
00408     if (!impl) return;
00409     impl->recalcStyle( NodeImpl::Inherit );
00410 }
00411 
00412 void Node::getCursor(int offset, int &_x, int &_y, int &height)
00413 {
00414     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00415     impl->getCursor(offset, _x, _y, height);
00416 }
00417 
00418 QRect Node::getRect()
00419 {
00420     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00421     return impl->getRect();
00422 }
00423 
00424 bool Node::isNull() const
00425 {
00426     return (impl == 0);
00427 }
00428 
00429 NodeImpl *Node::handle() const
00430 {
00431     return impl;
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 }
00479 
00480 NodeListImpl *NodeList::handle() const
00481 {
00482     return impl;
00483 }
00484 
00485 bool NodeList::isNull() const
00486 {
00487     return (impl == 0);
00488 }
00489 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:35 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001