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