• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • khtml
 

khtml

  • khtml
  • dom
dom_node.cpp
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 <tqrect.h>
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  NodeImpl::Id nid = impl->mapId(0, name.implementation(), true);
70  if (!nid) return 0;
71  return impl->getNamedItem(nid, false, name.implementation());
72 }
73 
74 Node NamedNodeMap::setNamedItem( const Node &arg )
75 {
76  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
77  if (!arg.impl) throw DOMException(DOMException::NOT_FOUND_ERR);
78  int exceptioncode = 0;
79  Node r = impl->setNamedItem(arg.impl, false,
80  arg.impl->nodeName().implementation(), exceptioncode);
81  if (exceptioncode)
82  throw DOMException(exceptioncode);
83  return r;
84 }
85 
86 Node NamedNodeMap::removeNamedItem( const DOMString &name )
87 {
88  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
89  int exceptioncode = 0;
90  Node r = impl->removeNamedItem(impl->mapId(0, name.implementation(), false),
91  false, name.implementation(), exceptioncode);
92  if (exceptioncode)
93  throw DOMException(exceptioncode);
94  return r;
95 }
96 
97 Node NamedNodeMap::item( unsigned long index ) const
98 {
99  if (!impl) return 0;
100  return impl->item(index);
101 }
102 
103 Node NamedNodeMap::getNamedItemNS( const DOMString &namespaceURI, const DOMString &localName ) const
104 {
105  if (!impl) return 0;
106  NodeImpl::Id nid = impl->mapId( namespaceURI.implementation(), localName.implementation(), true );
107  return impl->getNamedItem(nid, true);
108 }
109 
110 Node NamedNodeMap::setNamedItemNS( const Node &arg )
111 {
112  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
113  int exceptioncode = 0;
114  Node r = impl->setNamedItem(arg.impl, true, 0, exceptioncode);
115  if (exceptioncode)
116  throw DOMException(exceptioncode);
117  return r;
118 }
119 
120 Node NamedNodeMap::removeNamedItemNS( const DOMString &namespaceURI, const DOMString &localName )
121 {
122  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
123  int exceptioncode = 0;
124  NodeImpl::Id nid = impl->mapId( namespaceURI.implementation(), localName.implementation(), false );
125  Node r = impl->removeNamedItem(nid, true, 0, exceptioncode);
126  if (exceptioncode)
127  throw DOMException(exceptioncode);
128  return r;
129 }
130 
131 unsigned long NamedNodeMap::length() const
132 {
133  if (!impl) return 0;
134  return impl->length();
135 }
136 
137 // ---------------------------------------------------------------------------
138 
139 Node::Node(const Node &other)
140 {
141  impl = other.impl;
142  if(impl) impl->ref();
143 }
144 
145 Node::Node( NodeImpl *i )
146 {
147  impl = i;
148  if(impl) impl->ref();
149 }
150 
151 Node &Node::operator = (const Node &other)
152 {
153  if(impl != other.impl) {
154  if(impl) impl->deref();
155  impl = other.impl;
156  if(impl) impl->ref();
157  }
158  return *this;
159 }
160 
161 bool Node::operator == (const Node &other) const
162 {
163  return (impl == other.impl);
164 }
165 
166 bool Node::operator != (const Node &other) const
167 {
168  return !(impl == other.impl);
169 }
170 
171 Node::~Node()
172 {
173  if(impl) impl->deref();
174 }
175 
176 DOMString Node::nodeName() const
177 {
178  if(impl) return impl->nodeName();
179  return DOMString();
180 }
181 
182 DOMString Node::nodeValue() const
183 {
184  // ### should throw exception on plain node ?
185  if(impl) return impl->nodeValue();
186  return DOMString();
187 }
188 
189 void Node::setNodeValue( const DOMString &_str )
190 {
191  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
192 
193  int exceptioncode = 0;
194  if(impl) impl->setNodeValue( _str,exceptioncode );
195  if (exceptioncode)
196  throw DOMException(exceptioncode);
197 }
198 
199 unsigned short Node::nodeType() const
200 {
201  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
202  return impl->nodeType();
203 }
204 
205 Node Node::parentNode() const
206 {
207  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
208  return impl->parentNode();
209 }
210 
211 NodeList Node::childNodes() const
212 {
213  if (!impl) return 0;
214  return impl->childNodes();
215 }
216 
217 Node Node::firstChild() const
218 {
219  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
220  return impl->firstChild();
221 }
222 
223 Node Node::lastChild() const
224 {
225  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
226  return impl->lastChild();
227 }
228 
229 Node Node::previousSibling() const
230 {
231  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
232  return impl->previousSibling();
233 }
234 
235 Node Node::nextSibling() const
236 {
237  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
238  return impl->nextSibling();
239 }
240 
241 NamedNodeMap Node::attributes() const
242 {
243  if (!impl || !impl->isElementNode()) return 0;
244  return static_cast<ElementImpl*>(impl)->attributes();
245 }
246 
247 Document Node::ownerDocument() const
248 {
249  // braindead DOM spec says that ownerDocument
250  // should return null if called on the document node
251  // we don't do that in the *impl tree to avoid excessive if()'s
252  // so we simply hack it here in one central place.
253  if (!impl || impl->getDocument() == impl) return Document(false);
254 
255  return impl->getDocument();
256 }
257 
258 Node Node::insertBefore( const Node &newChild, const Node &refChild )
259 {
260  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
261  int exceptioncode = 0;
262  NodeImpl *r = impl->insertBefore( newChild.impl, refChild.impl, exceptioncode );
263  if (exceptioncode)
264  throw DOMException(exceptioncode);
265  if (!newChild.impl->closed()) newChild.impl->close();
266  return r;
267 }
268 
269 Node Node::replaceChild( const Node &newChild, const Node &oldChild )
270 {
271  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
272  int exceptioncode = 0;
273  impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode );
274  if (exceptioncode)
275  throw DOMException(exceptioncode);
276  if (newChild.impl && !newChild.impl->closed()) newChild.impl->close();
277 
278  return oldChild;
279 }
280 
281 Node Node::removeChild( const Node &oldChild )
282 {
283  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
284  int exceptioncode = 0;
285  impl->removeChild( oldChild.impl, exceptioncode );
286  if (exceptioncode)
287  throw DOMException(exceptioncode);
288 
289  return oldChild;
290 }
291 
292 Node Node::appendChild( const Node &newChild )
293 {
294  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
295  int exceptioncode = 0;
296  NodeImpl *r = impl->appendChild( newChild.impl, exceptioncode );
297  if (exceptioncode)
298  throw DOMException(exceptioncode);
299  if (!newChild.impl->closed()) newChild.impl->close();
300  return r;
301 }
302 
303 bool Node::hasAttributes()
304 {
305  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
306  if (!impl->isElementNode()) return false;
307  ElementImpl* e = static_cast<ElementImpl*>(impl);
308  return e->attributes(true) && e->attributes(true)->length();
309 }
310 
311 bool Node::hasChildNodes( )
312 {
313  if (!impl) return false;
314  return impl->hasChildNodes();
315 }
316 
317 Node Node::cloneNode( bool deep )
318 {
319  if (!impl) return 0;
320  return impl->cloneNode( deep );
321 }
322 
323 void Node::normalize ( )
324 {
325  if (!impl) return;
326  impl->normalize();
327 }
328 
329 bool Node::isSupported( const DOMString &feature,
330  const DOMString & /*version*/ ) const
331 {
332  DOMString upFeature = feature.upper();
333  return (upFeature == "HTML" ||
334  upFeature == "XML" ||
335  upFeature == "CORE");
336 }
337 
338 DOMString Node::namespaceURI( ) const
339 {
340  if (!impl) return DOMString();
341  return impl->namespaceURI();
342 }
343 
344 DOMString Node::prefix( ) const
345 {
346  if (!impl) return DOMString();
347  return impl->prefix();
348 }
349 
350 void Node::setPrefix(const DOMString &prefix )
351 {
352  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
353  int exceptioncode = 0;
354  impl->setPrefix(prefix,exceptioncode);
355  if (exceptioncode)
356  throw DOMException(exceptioncode);
357 }
358 
359 DOMString Node::localName( ) const
360 {
361  if (!impl) return DOMString();
362  return impl->localName();
363 }
364 
365 void Node::addEventListener(const DOMString &type,
366  EventListener *listener,
367  const bool useCapture)
368 {
369  if (!impl) return;
370  if (listener)
371  impl->addEventListener(EventImpl::typeToId(type),listener,useCapture);
372 }
373 
374 void Node::removeEventListener(const DOMString &type,
375  EventListener *listener,
376  bool useCapture)
377 {
378  if (!impl) return;
379  impl->removeEventListener(EventImpl::typeToId(type),listener,useCapture);
380 }
381 
382 bool Node::dispatchEvent(const Event &evt)
383 {
384  if (!impl)
385  throw DOMException(DOMException::INVALID_STATE_ERR);
386 
387  if (!evt.handle())
388  throw DOMException(DOMException::NOT_FOUND_ERR);
389 
390  int exceptioncode = 0;
391  impl->dispatchEvent(evt.handle(),exceptioncode);
392  if (exceptioncode)
393  throw DOMException(exceptioncode);
394  return !evt.handle()->defaultPrevented();
395 }
396 
397 
398 unsigned int Node::elementId() const
399 {
400  if (!impl) return 0;
401  return impl->id();
402 }
403 
404 unsigned long Node::index() const
405 {
406  if (!impl) return 0;
407  return impl->nodeIndex();
408 }
409 
410 TQString Node::toHTML()
411 {
412  if (!impl) return TQString::null;
413  return impl->toString().string();
414 }
415 
416 void Node::applyChanges()
417 {
418  if (!impl) return;
419  impl->recalcStyle( NodeImpl::Inherit );
420 }
421 
422 void Node::getCursor(int offset, int &_x, int &_y, int &height)
423 {
424  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
425  int dummy;
426  impl->getCaret(offset, false, _x, _y, dummy, height);
427 }
428 
429 TQRect Node::getRect()
430 {
431  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
432  return impl->getRect();
433 }
434 
435 DOMString Node::textContent( ) const
436 {
437  if(impl) return impl->textContent();
438  return DOMString();
439 }
440 
441 void Node::setTextContent(const DOMString &content) const
442 {
443  if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
444 
445  int exceptioncode = 0;
446  impl->setTextContent( content, exceptioncode );
447  if (exceptioncode)
448  throw DOMException(exceptioncode);
449 }
450 
451 //-----------------------------------------------------------------------------
452 
453 NodeList::NodeList()
454 {
455  impl = 0;
456 }
457 
458 NodeList::NodeList(const NodeList &other)
459 {
460  impl = other.impl;
461  if(impl) impl->ref();
462 }
463 
464 NodeList::NodeList(const NodeListImpl *i)
465 {
466  impl = const_cast<NodeListImpl *>(i);
467  if(impl) impl->ref();
468 }
469 
470 NodeList &NodeList::operator = (const NodeList &other)
471 {
472  if ( impl != other.impl ) {
473  if(impl) impl->deref();
474  impl = other.impl;
475  if(impl) impl->ref();
476  }
477  return *this;
478 }
479 
480 NodeList::~NodeList()
481 {
482  if(impl) impl->deref();
483 }
484 
485 Node NodeList::item( unsigned long index ) const
486 {
487  if (!impl) return 0;
488  return impl->item(index);
489 }
490 
491 unsigned long NodeList::length() const
492 {
493  if (!impl) return 0;
494  return impl->length();
495 }

khtml

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

khtml

Skip menu "khtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for khtml by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |