khtml Library API Documentation

dom_node.cpp

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 <qrect.h>
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     NodeImpl::Id nid = impl->mapId(0, name.implementation(), true);
00070     if (!nid) return 0;
00071     return impl->getNamedItem(nid, false, name.implementation());
00072 }
00073 
00074 Node NamedNodeMap::setNamedItem( const Node &arg )
00075 {
00076     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00077     if (!arg.impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00078     int exceptioncode = 0;
00079     Node r = impl->setNamedItem(arg.impl, false,
00080                        arg.impl->nodeName().implementation(), exceptioncode);
00081     if (exceptioncode)
00082         throw DOMException(exceptioncode);
00083     return r;
00084 }
00085 
00086 Node NamedNodeMap::removeNamedItem( const DOMString &name )
00087 {
00088     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00089     int exceptioncode = 0;
00090     Node r = impl->removeNamedItem(impl->mapId(0, name.implementation(), false),
00091                                    false, name.implementation(), exceptioncode);
00092     if (exceptioncode)
00093         throw DOMException(exceptioncode);
00094     return r;
00095 }
00096 
00097 Node NamedNodeMap::item( unsigned long index ) const
00098 {
00099     if (!impl) return 0;
00100     return impl->item(index);
00101 }
00102 
00103 Node NamedNodeMap::getNamedItemNS( const DOMString &namespaceURI, const DOMString &localName ) const
00104 {
00105     if (!impl) return 0;
00106     NodeImpl::Id nid = impl->mapId( namespaceURI.implementation(), localName.implementation(), true );
00107     return impl->getNamedItem(nid, true);
00108 }
00109 
00110 Node NamedNodeMap::setNamedItemNS( const Node &arg )
00111 {
00112     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00113     int exceptioncode = 0;
00114     Node r = impl->setNamedItem(arg.impl, true, 0, exceptioncode);
00115     if (exceptioncode)
00116         throw DOMException(exceptioncode);
00117     return r;
00118 }
00119 
00120 Node NamedNodeMap::removeNamedItemNS( const DOMString &namespaceURI, const DOMString &localName )
00121 {
00122     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00123     int exceptioncode = 0;
00124     NodeImpl::Id nid = impl->mapId( namespaceURI.implementation(), localName.implementation(), false );
00125     Node r = impl->removeNamedItem(nid, true, 0, exceptioncode);
00126     if (exceptioncode)
00127         throw DOMException(exceptioncode);
00128     return r;
00129 }
00130 
00131 unsigned long NamedNodeMap::length() const
00132 {
00133     if (!impl) return 0;
00134     return impl->length();
00135 }
00136 
00137 // ---------------------------------------------------------------------------
00138 
00139 Node::Node(const Node &other)
00140 {
00141     impl = other.impl;
00142     if(impl) impl->ref();
00143 }
00144 
00145 Node::Node( NodeImpl *i )
00146 {
00147     impl = i;
00148     if(impl) impl->ref();
00149 }
00150 
00151 Node &Node::operator = (const Node &other)
00152 {
00153     if(impl != other.impl) {
00154         if(impl) impl->deref();
00155         impl = other.impl;
00156         if(impl) impl->ref();
00157     }
00158     return *this;
00159 }
00160 
00161 bool Node::operator == (const Node &other) const
00162 {
00163     return (impl == other.impl);
00164 }
00165 
00166 bool Node::operator != (const Node &other) const
00167 {
00168     return !(impl == other.impl);
00169 }
00170 
00171 Node::~Node()
00172 {
00173     if(impl) impl->deref();
00174 }
00175 
00176 DOMString Node::nodeName() const
00177 {
00178     if(impl) return impl->nodeName();
00179     return DOMString();
00180 }
00181 
00182 DOMString Node::nodeValue() const
00183 {
00184     // ### should throw exception on plain node ?
00185     if(impl) return impl->nodeValue();
00186     return DOMString();
00187 }
00188 
00189 void Node::setNodeValue( const DOMString &_str )
00190 {
00191     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00192 
00193     int exceptioncode = 0;
00194     if(impl) impl->setNodeValue( _str,exceptioncode );
00195     if (exceptioncode)
00196     throw DOMException(exceptioncode);
00197 }
00198 
00199 unsigned short Node::nodeType() const
00200 {
00201     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00202     return impl->nodeType();
00203 }
00204 
00205 Node Node::parentNode() const
00206 {
00207     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00208     return impl->parentNode();
00209 }
00210 
00211 NodeList Node::childNodes() const
00212 {
00213     if (!impl) return 0;
00214     return impl->childNodes();
00215 }
00216 
00217 Node Node::firstChild() const
00218 {
00219     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00220     return impl->firstChild();
00221 }
00222 
00223 Node Node::lastChild() const
00224 {
00225     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00226     return impl->lastChild();
00227 }
00228 
00229 Node Node::previousSibling() const
00230 {
00231     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00232     return impl->previousSibling();
00233 }
00234 
00235 Node Node::nextSibling() const
00236 {
00237     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00238     return impl->nextSibling();
00239 }
00240 
00241 NamedNodeMap Node::attributes() const
00242 {
00243     if (!impl || !impl->isElementNode()) return 0;
00244     return static_cast<ElementImpl*>(impl)->attributes();
00245 }
00246 
00247 Document Node::ownerDocument() const
00248 {
00249     // braindead DOM spec says that ownerDocument
00250     // should return null if called on the document node
00251     // we don't do that in the *impl tree to avoid excessive if()'s
00252     // so we simply hack it here in one central place.
00253     if (!impl || impl->getDocument() == impl) return Document(false);
00254 
00255     return impl->getDocument();
00256 }
00257 
00258 Node Node::insertBefore( const Node &newChild, const Node &refChild )
00259 {
00260     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00261     int exceptioncode = 0;
00262     NodeImpl *r = impl->insertBefore( newChild.impl, refChild.impl, exceptioncode );
00263     if (exceptioncode)
00264     throw DOMException(exceptioncode);
00265     return r;
00266 }
00267 
00268 Node Node::replaceChild( const Node &newChild, const Node &oldChild )
00269 {
00270     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00271     int exceptioncode = 0;
00272     NodeImpl *r = impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode );
00273     if (exceptioncode)
00274     throw DOMException(exceptioncode);
00275     return r;
00276 }
00277 
00278 Node Node::removeChild( const Node &oldChild )
00279 {
00280     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00281     int exceptioncode = 0;
00282     NodeImpl *r = impl->removeChild( oldChild.impl, exceptioncode );
00283     if (exceptioncode)
00284     throw DOMException(exceptioncode);
00285     return r;
00286 }
00287 
00288 Node Node::appendChild( const Node &newChild )
00289 {
00290     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00291     int exceptioncode = 0;
00292     NodeImpl *r = impl->appendChild( newChild.impl, exceptioncode );
00293     if (exceptioncode)
00294     throw DOMException(exceptioncode);
00295     return r;
00296 }
00297 
00298 bool Node::hasAttributes()
00299 {
00300     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00301     if (!impl->isElementNode()) return false;
00302     ElementImpl* e = static_cast<ElementImpl*>(impl);
00303     return e->attributes(true) && e->attributes(true)->length();
00304 }
00305 
00306 bool Node::hasChildNodes(  )
00307 {
00308     if (!impl) return false;
00309     return impl->hasChildNodes();
00310 }
00311 
00312 Node Node::cloneNode( bool deep )
00313 {
00314     if (!impl) return 0;
00315     return impl->cloneNode( deep  );
00316 }
00317 
00318 void Node::normalize (  )
00319 {
00320     if (!impl) return;
00321     impl->normalize();
00322 }
00323 
00324 bool Node::isSupported( const DOMString &feature,
00325                         const DOMString & /*version*/ ) const
00326 {
00327     DOMString upFeature = feature.upper();
00328     return (upFeature == "HTML" ||
00329             upFeature == "XML" ||
00330             upFeature == "CORE");
00331 }
00332 
00333 DOMString Node::namespaceURI(  ) const
00334 {
00335     if (!impl) return DOMString();
00336     return impl->namespaceURI();
00337 }
00338 
00339 DOMString Node::prefix(  ) const
00340 {
00341     if (!impl) return DOMString();
00342     return impl->prefix();
00343 }
00344 
00345 void Node::setPrefix(const DOMString &prefix )
00346 {
00347     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00348     int exceptioncode = 0;
00349     impl->setPrefix(prefix,exceptioncode);
00350     if (exceptioncode)
00351         throw DOMException(exceptioncode);
00352 }
00353 
00354 DOMString Node::localName(  ) const
00355 {
00356     if (!impl) return DOMString();
00357     return impl->localName();
00358 }
00359 
00360 void Node::addEventListener(const DOMString &type,
00361               EventListener *listener,
00362               const bool useCapture)
00363 {
00364     if (!impl) return;
00365     if (listener)
00366         impl->addEventListener(EventImpl::typeToId(type),listener,useCapture);
00367 }
00368 
00369 void Node::removeEventListener(const DOMString &type,
00370                  EventListener *listener,
00371                  bool useCapture)
00372 {
00373     if (!impl) return;
00374     impl->removeEventListener(EventImpl::typeToId(type),listener,useCapture);
00375 }
00376 
00377 bool Node::dispatchEvent(const Event &evt)
00378 {
00379     if (!impl)
00380     throw DOMException(DOMException::INVALID_STATE_ERR);
00381 
00382     if (!evt.handle())
00383         throw DOMException(DOMException::NOT_FOUND_ERR);
00384 
00385     int exceptioncode = 0;
00386     impl->dispatchEvent(evt.handle(),exceptioncode);
00387     if (exceptioncode)
00388     throw DOMException(exceptioncode);
00389     return !evt.handle()->defaultPrevented();
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     int dummy;
00421     impl->getCaret(offset, false, _x, _y, dummy, height);
00422 }
00423 
00424 QRect Node::getRect()
00425 {
00426     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00427     return impl->getRect();
00428 }
00429 
00430 //-----------------------------------------------------------------------------
00431 
00432 NodeList::NodeList()
00433 {
00434     impl = 0;
00435 }
00436 
00437 NodeList::NodeList(const NodeList &other)
00438 {
00439     impl = other.impl;
00440     if(impl) impl->ref();
00441 }
00442 
00443 NodeList::NodeList(const NodeListImpl *i)
00444 {
00445     impl = const_cast<NodeListImpl *>(i);
00446     if(impl) impl->ref();
00447 }
00448 
00449 NodeList &NodeList::operator = (const NodeList &other)
00450 {
00451     if ( impl != other.impl ) {
00452         if(impl) impl->deref();
00453         impl = other.impl;
00454         if(impl) impl->ref();
00455     }
00456     return *this;
00457 }
00458 
00459 NodeList::~NodeList()
00460 {
00461     if(impl) impl->deref();
00462 }
00463 
00464 Node NodeList::item( unsigned long index ) const
00465 {
00466     if (!impl) return 0;
00467     return impl->item(index);
00468 }
00469 
00470 unsigned long NodeList::length() const
00471 {
00472     if (!impl) return 0;
00473     return impl->length();
00474 }
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 5 07:18:23 2004 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003