• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • dom
dom_node.cpp
Go to the documentation of this file.
1 
23 #include "dom/dom_doc.h"
24 #include "dom/dom_exception.h"
25 #include "dom/dom2_events.h"
26 #include "xml/dom_docimpl.h"
27 #include "xml/dom_elementimpl.h"
28 #include "xml/dom2_eventsimpl.h"
29 
30 #include <QtCore/QRect>
31 
32 using namespace DOM;
33 
34 NamedNodeMap::NamedNodeMap()
35 {
36  impl = 0;
37 }
38 
39 NamedNodeMap::NamedNodeMap(const NamedNodeMap &other)
40 {
41  impl = other.impl;
42  if (impl) impl->ref();
43 }
44 
45 NamedNodeMap::NamedNodeMap(NamedNodeMapImpl *i)
46 {
47  impl = i;
48  if (impl) impl->ref();
49 }
50 
51 NamedNodeMap &NamedNodeMap::operator = (const NamedNodeMap &other)
52 {
53  if ( impl != other.impl ) {
54  if(impl) impl->deref();
55  impl = other.impl;
56  if(impl) impl->ref();
57  }
58  return *this;
59 }
60 
61 NamedNodeMap::~NamedNodeMap()
62 {
63  if(impl) impl->deref();
64 }
65 
66 Node NamedNodeMap::getNamedItem( const DOMString &name ) const
67 {
68  if (!impl) return 0;
69  return impl->getNamedItem(name);
70 }
71 
72 Node NamedNodeMap::setNamedItem( const Node &arg )
73 {
74  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
75 
76  int exceptioncode = 0;
77  Node r = impl->setNamedItem(arg, exceptioncode);
78  if (exceptioncode)
79  throw DOMException(exceptioncode);
80  return r;
81 }
82 
83 Node NamedNodeMap::removeNamedItem( const DOMString &name )
84 {
85  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
86  int exceptioncode = 0;
87  Node r = impl->removeNamedItem(name, exceptioncode);
88  if (exceptioncode)
89  throw DOMException(exceptioncode);
90  return r;
91 }
92 
93 Node NamedNodeMap::item( unsigned long index ) const
94 {
95  if (!impl) return 0;
96  return impl->item(index);
97 }
98 
99 Node NamedNodeMap::getNamedItemNS( const DOMString &namespaceURI, const DOMString &localName ) const
100 {
101  if (!impl) return 0;
102  return impl->getNamedItemNS(namespaceURI, localName);
103 }
104 
105 Node NamedNodeMap::setNamedItemNS( const Node &arg )
106 {
107  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
108  int exceptioncode = 0;
109  Node r = impl->setNamedItemNS(arg, exceptioncode);
110  if (exceptioncode)
111  throw DOMException(exceptioncode);
112  return r;
113 }
114 
115 Node NamedNodeMap::removeNamedItemNS( const DOMString &namespaceURI, const DOMString &localName )
116 {
117  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
118  int exceptioncode = 0;
119  Node r = impl->removeNamedItemNS(namespaceURI, localName, exceptioncode);
120  if (exceptioncode)
121  throw DOMException(exceptioncode);
122  return r;
123 }
124 
125 unsigned long NamedNodeMap::length() const
126 {
127  if (!impl) return 0;
128  return impl->length();
129 }
130 
131 // ---------------------------------------------------------------------------
132 
133 Node::Node(const Node &other)
134 {
135  impl = other.impl;
136  if(impl) impl->ref();
137 }
138 
139 Node::Node( NodeImpl *i )
140 {
141  impl = i;
142  if(impl) impl->ref();
143 }
144 
145 Node &Node::operator = (const Node &other)
146 {
147  if(impl != other.impl) {
148  if(impl) impl->deref();
149  impl = other.impl;
150  if(impl) impl->ref();
151  }
152  return *this;
153 }
154 
155 bool Node::operator == (const Node &other) const
156 {
157  return (impl == other.impl);
158 }
159 
160 bool Node::operator != (const Node &other) const
161 {
162  return !(impl == other.impl);
163 }
164 
165 Node::~Node()
166 {
167  if(impl) impl->deref();
168 }
169 
170 DOMString Node::nodeName() const
171 {
172  if(impl) return impl->nodeName();
173  return DOMString();
174 }
175 
176 DOMString Node::nodeValue() const
177 {
178  // ### should throw exception on plain node ?
179  if(impl) return impl->nodeValue();
180  return DOMString();
181 }
182 
183 void Node::setNodeValue( const DOMString &_str )
184 {
185  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
186 
187  int exceptioncode = 0;
188  if(impl) impl->setNodeValue( _str,exceptioncode );
189  if (exceptioncode)
190  throw DOMException(exceptioncode);
191 }
192 
193 unsigned short Node::nodeType() const
194 {
195  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
196  return impl->nodeType();
197 }
198 
199 Node Node::parentNode() const
200 {
201  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
202  return impl->parentNode();
203 }
204 
205 NodeList Node::childNodes() const
206 {
207  if (!impl) return 0;
208  return impl->childNodes();
209 }
210 
211 Node Node::firstChild() const
212 {
213  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
214  return impl->firstChild();
215 }
216 
217 Node Node::lastChild() const
218 {
219  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
220  return impl->lastChild();
221 }
222 
223 Node Node::previousSibling() const
224 {
225  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
226  return impl->previousSibling();
227 }
228 
229 Node Node::nextSibling() const
230 {
231  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
232  return impl->nextSibling();
233 }
234 
235 NamedNodeMap Node::attributes() const
236 {
237  if (!impl || !impl->isElementNode()) return 0;
238  return static_cast<ElementImpl*>(impl)->attributes();
239 }
240 
241 Document Node::ownerDocument() const
242 {
243  if (!impl || !impl->ownerDocument())
244  return Document(false);
245  return impl->ownerDocument();
246 }
247 
248 Node Node::insertBefore( const Node &newChild, const Node &refChild )
249 {
250  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
251  int exceptioncode = 0;
252  NodeImpl *r = impl->insertBefore( newChild.impl, refChild.impl, exceptioncode );
253  if (exceptioncode)
254  throw DOMException(exceptioncode);
255  return r;
256 }
257 
258 Node Node::replaceChild( const Node &newChild, const Node &oldChild )
259 {
260  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
261  int exceptioncode = 0;
262  impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode );
263  if (exceptioncode)
264  throw DOMException(exceptioncode);
265  return oldChild;
266 }
267 
268 Node Node::removeChild( const Node &oldChild )
269 {
270  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
271  int exceptioncode = 0;
272  impl->removeChild( oldChild.impl, exceptioncode );
273  if (exceptioncode)
274  throw DOMException(exceptioncode);
275 
276  return oldChild;
277 }
278 
279 Node Node::appendChild( const Node &newChild )
280 {
281  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
282  int exceptioncode = 0;
283  NodeImpl *r = impl->appendChild( newChild.impl, exceptioncode );
284  if (exceptioncode)
285  throw DOMException(exceptioncode);
286  return r;
287 }
288 
289 bool Node::hasAttributes()
290 {
291  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
292  return impl->hasAttributes();
293 }
294 
295 bool Node::hasChildNodes( )
296 {
297  if (!impl) return false;
298  return impl->hasChildNodes();
299 }
300 
301 Node Node::cloneNode( bool deep )
302 {
303  if (!impl) return 0;
304  return impl->cloneNode( deep ).get();
305 }
306 
307 void Node::normalize ( )
308 {
309  if (!impl) return;
310  impl->normalize();
311 }
312 
313 bool Node::isSupported( const DOMString &feature,
314  const DOMString &version ) const
315 {
316  return NodeImpl::isSupported(feature, version);
317 }
318 
319 DOMString Node::namespaceURI( ) const
320 {
321  if (!impl) return DOMString();
322  return impl->namespaceURI();
323 }
324 
325 DOMString Node::prefix( ) const
326 {
327  if (!impl) return DOMString();
328  return impl->prefix();
329 }
330 
331 void Node::setPrefix(const DOMString &prefix )
332 {
333  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
334  int exceptioncode = 0;
335  impl->setPrefix(prefix,exceptioncode);
336  if (exceptioncode)
337  throw DOMException(exceptioncode);
338 }
339 
340 DOMString Node::localName( ) const
341 {
342  if (!impl) return DOMString();
343  return impl->localName();
344 }
345 
346 void Node::addEventListener(const DOMString &type,
347  EventListener *listener,
348  const bool useCapture)
349 {
350  if (!impl) return;
351  if (listener)
352  impl->addEventListener(EventName::fromString(type),listener,useCapture);
353 }
354 
355 void Node::removeEventListener(const DOMString &type,
356  EventListener *listener,
357  bool useCapture)
358 {
359  if (!impl) return;
360  impl->removeEventListener(EventName::fromString(type),listener,useCapture);
361 }
362 
363 bool Node::dispatchEvent(const Event &evt)
364 {
365  if (!impl)
366  throw DOMException(DOMException::INVALID_STATE_ERR);
367 
368  if (!evt.handle())
369  throw DOMException(DOMException::NOT_FOUND_ERR);
370 
371  int exceptioncode = 0;
372  impl->dispatchEvent(evt.handle(),exceptioncode);
373  if (exceptioncode)
374  throw DOMException(exceptioncode);
375  return !evt.handle()->defaultPrevented();
376 }
377 
378 DOMString Node::textContent() const
379 {
380  if (!impl) return DOMString();
381  return impl->textContent();
382 }
383 
384 void Node::setTextContent(const DOMString& content)
385 {
386  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
387  int exceptioncode = 0;
388  impl->setTextContent(content, exceptioncode);
389  if (exceptioncode)
390  throw DOMException(exceptioncode);
391 }
392 
393 unsigned Node::compareDocumentPosition(const Node& other)
394 {
395  if (!impl || !other.impl)
396  throw DOMException(DOMException::NOT_FOUND_ERR);
397  return impl->compareDocumentPosition(other.impl);
398 }
399 
400 unsigned int Node::elementId() const
401 {
402  if (!impl) return 0;
403  return impl->id();
404 }
405 
406 unsigned long Node::index() const
407 {
408  if (!impl) return 0;
409  return impl->nodeIndex();
410 }
411 
412 #ifndef KDE_NO_DEPRECATED
413 QString Node::toHTML()
414 {
415  if (!impl) return QString();
416  return impl->toString().string();
417 }
418 #endif
419 
420 void Node::applyChanges()
421 {
422  if (!impl) return;
423  impl->recalcStyle( NodeImpl::Inherit );
424 }
425 
426 #ifndef KDE_NO_DEPRECATED
427 void Node::getCursor(int offset, int &_x, int &_y, int &height)
428 {
429  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
430  int dummy;
431  impl->getCaret(offset, false, _x, _y, dummy, height);
432 }
433 #endif
434 
435 QRect Node::getRect()
436 {
437  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
438  return impl->getRect();
439 }
440 
441 //-----------------------------------------------------------------------------
442 
443 NodeList::NodeList()
444 {
445  impl = 0;
446 }
447 
448 NodeList::NodeList(const NodeList &other)
449 {
450  impl = other.impl;
451  if(impl) impl->ref();
452 }
453 
454 NodeList::NodeList(const NodeListImpl *i)
455 {
456  impl = const_cast<NodeListImpl *>(i);
457  if(impl) impl->ref();
458 }
459 
460 NodeList &NodeList::operator = (const NodeList &other)
461 {
462  if ( impl != other.impl ) {
463  if(impl) impl->deref();
464  impl = other.impl;
465  if(impl) impl->ref();
466  }
467  return *this;
468 }
469 
470 NodeList::~NodeList()
471 {
472  if(impl) impl->deref();
473 }
474 
475 Node NodeList::item( unsigned long index ) const
476 {
477  if (!impl) return 0;
478  return impl->item(index);
479 }
480 
481 unsigned long NodeList::length() const
482 {
483  if (!impl) return 0;
484  return impl->length();
485 }
486 
487 //-----------------------------------------------------------------------------
488 
489 DOMString DOMException::codeAsString() const
490 {
491  return codeAsString(code);
492 }
493 
494 DOMString DOMException::codeAsString(int code)
495 {
496  switch ( code ) {
497  case INDEX_SIZE_ERR:
498  return DOMString( "INDEX_SIZE_ERR" );
499  case DOMSTRING_SIZE_ERR:
500  return DOMString( "DOMSTRING_SIZE_ERR" );
501  case HIERARCHY_REQUEST_ERR:
502  return DOMString( "HIERARCHY_REQUEST_ERR" );
503  case WRONG_DOCUMENT_ERR:
504  return DOMString( "WRONG_DOCUMENT_ERR" );
505  case INVALID_CHARACTER_ERR:
506  return DOMString( "INVALID_CHARACTER_ERR" );
507  case NO_DATA_ALLOWED_ERR:
508  return DOMString( "NO_DATA_ALLOWED_ERR" );
509  case NO_MODIFICATION_ALLOWED_ERR:
510  return DOMString( "NO_MODIFICATION_ALLOWED_ERR" );
511  case NOT_FOUND_ERR:
512  return DOMString( "NOT_FOUND_ERR" );
513  case NOT_SUPPORTED_ERR:
514  return DOMString( "NOT_SUPPORTED_ERR" );
515  case INUSE_ATTRIBUTE_ERR:
516  return DOMString( "INUSE_ATTRIBUTE_ERR" );
517  case INVALID_STATE_ERR:
518  return DOMString( "INVALID_STATE_ERR" );
519  case SYNTAX_ERR:
520  return DOMString( "SYNTAX_ERR" );
521  case INVALID_MODIFICATION_ERR:
522  return DOMString( "INVALID_MODIFICATION_ERR" );
523  case NAMESPACE_ERR:
524  return DOMString( "NAMESPACE_ERR" );
525  case INVALID_ACCESS_ERR:
526  return DOMString( "INVALID_ACCESS_ERR" );
527  case VALIDATION_ERR:
528  return DOMString( "VALIDATION_ERR" );
529  case TYPE_MISMATCH_ERR:
530  return DOMString( "TYPE_MISMATCH_ERR" );
531  case SECURITY_ERR:
532  return DOMString( "SECURITY_ERR" );
533  case NETWORK_ERR:
534  return DOMString( "NETWORK_ERR" );
535  case ABORT_ERR:
536  return DOMString( "ABORT_ERR" );
537  case URL_MISMATCH_ERR:
538  return DOMString( "URL_MISMATCH_ERR" );
539  case QUOTA_EXCEEDED_ERR:
540  return DOMString( "QUOTA_EXCEEDED_ERR" );
541  case TIMEOUT_ERR:
542  return DOMString( "TIMEOUT_ERR" );
543  case NOT_READABLE_ERR:
544  return DOMString( "NOT_READABLE_ERR" );
545  case DATA_CLONE_ERR:
546  return DOMString( "DATA_CLONE_ERR" );
547  case ENCODING_ERR:
548  return DOMString( "ENCODING_ERR" );
549  default:
550  return DOMString( "(unknown exception code)" );
551  }
552 }
553 
554 bool DOMException::isDOMExceptionCode(int exceptioncode)
555 {
556  return exceptioncode < 100;
557 }
558 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jun 1 2013 22:07:23 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal