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

tdehtml

  • tdehtml
  • 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 }
DOM::NamedNodeMap::getNamedItemNS
Node getNamedItemNS(const DOMString &namespaceURI, const DOMString &localName) const
Introduced in DOM Level 2.
Definition: dom_node.cpp:103
DOM::Node::lastChild
Node lastChild() const
The last child of this node.
Definition: dom_node.cpp:223
DOM::Node::textContent
DOMString textContent() const
Introduced in DOM Level 3.
Definition: dom_node.cpp:435
DOM::Node::insertBefore
Node insertBefore(const Node &newChild, const Node &refChild)
Inserts the node newChild before the existing child node refChild .
Definition: dom_node.cpp:258
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:274
DOM::Node::dispatchEvent
bool dispatchEvent(const Event &evt)
Introduced in DOM Level 2 This method is from the EventTarget interface.
Definition: dom_node.cpp:382
DOM::Node::nodeName
DOMString nodeName() const
The name of this node, depending on its type; see the table above.
Definition: dom_node.cpp:176
DOM::NamedNodeMap::removeNamedItem
Node removeNamedItem(const DOMString &name)
Removes a node specified by name.
Definition: dom_node.cpp:86
DOM::Node::prefix
DOMString prefix() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:344
DOM::Node::previousSibling
Node previousSibling() const
The node immediately preceding this node.
Definition: dom_node.cpp:229
DOM::Node::setNodeValue
void setNodeValue(const DOMString &)
see nodeValue NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
Definition: dom_node.cpp:189
DOM::Node::appendChild
Node appendChild(const Node &newChild)
Adds the node newChild to the end of the list of children of this node.
Definition: dom_node.cpp:292
DOM::Node::removeEventListener
void removeEventListener(const DOMString &type, EventListener *listener, bool useCapture)
Introduced in DOM Level 2 This method is from the EventTarget interface.
Definition: dom_node.cpp:374
DOM::Node::attributes
NamedNodeMap attributes() const
A NamedNodeMap containing the attributes of this node (if it is an Element ) or null otherwise...
Definition: dom_node.cpp:241
DOM::Node::hasChildNodes
bool hasChildNodes()
This is a convenience method to allow easy determination of whether a node has any children...
Definition: dom_node.cpp:311
DOM::DOMException
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:57
DOM::Node::replaceChild
Node replaceChild(const Node &newChild, const Node &oldChild)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node...
Definition: dom_node.cpp:269
DOM::Node::childNodes
NodeList childNodes() const
A NodeList that contains all children of this node.
Definition: dom_node.cpp:211
DOM::NamedNodeMap
Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can b...
Definition: dom_node.h:66
DOM::Node::isSupported
bool isSupported(const DOMString &feature, const DOMString &version) const
Introduced in DOM Level 2.
Definition: dom_node.cpp:329
DOM::Node::parentNode
Node parentNode() const
The parent of this node.
Definition: dom_node.cpp:205
DOM::NodeList::item
Node item(unsigned long index) const
Returns the index th item in the collection.
Definition: dom_node.cpp:485
DOM::Node::localName
DOMString localName() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:359
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:43
DOM::Node::nodeValue
DOMString nodeValue() const
The value of this node, depending on its type; see the table above.
Definition: dom_node.cpp:182
DOM::Node::removeChild
Node removeChild(const Node &oldChild)
Removes the child node indicated by oldChild from the list of children, and returns it...
Definition: dom_node.cpp:281
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:245
DOM::Node::ownerDocument
Document ownerDocument() const
The Document object associated with this node.
Definition: dom_node.cpp:247
DOM::Node::addEventListener
void addEventListener(const DOMString &type, EventListener *listener, const bool useCapture)
Introduced in DOM Level 2 This method is from the EventTarget interface.
Definition: dom_node.cpp:365
DOM::NamedNodeMap::setNamedItemNS
Node setNamedItemNS(const Node &arg)
Introduced in DOM Level 2.
Definition: dom_node.cpp:110
DOM::Node::cloneNode
Node cloneNode(bool deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
Definition: dom_node.cpp:317
DOM::NamedNodeMap::item
Node item(unsigned long index) const
Returns the index th item in the map.
Definition: dom_node.cpp:97
DOM::Node::getRect
TQRect getRect()
not part of the DOM.
Definition: dom_node.cpp:429
DOM::Node::normalize
void normalize()
Modified in DOM Level 2.
Definition: dom_node.cpp:323
DOM::Node::firstChild
Node firstChild() const
The first child of this node.
Definition: dom_node.cpp:217
DOM::NodeList
The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented.
Definition: dom_node.h:931
DOM::EventListener
Introduced in DOM Level 2.
Definition: dom2_events.h:64
DOM
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
Definition: design.h:56
DOM::Event
Introduced in DOM Level 2.
Definition: dom2_events.h:111
DOM::Node::getCursor
void getCursor(int offset, int &_x, int &_y, int &height) KDE_DEPRECATED
Definition: dom_node.cpp:422
DOM::NamedNodeMap::getNamedItem
Node getNamedItem(const DOMString &name) const
Retrieves a node specified by name.
Definition: dom_node.cpp:66
DOM::NamedNodeMap::length
unsigned long length() const
The number of nodes in the map.
Definition: dom_node.cpp:131
DOM::Node::namespaceURI
DOMString namespaceURI() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:338
DOM::Node::hasAttributes
bool hasAttributes()
Returns whether this node (if it is an element) has any attributes.
Definition: dom_node.cpp:303
DOM::Node::setTextContent
void setTextContent(const DOMString &content) const
Introduced in DOM Level 3.
Definition: dom_node.cpp:441
DOM::Node::setPrefix
void setPrefix(const DOMString &prefix)
see prefix
Definition: dom_node.cpp:350
DOM::NamedNodeMap::removeNamedItemNS
Node removeNamedItemNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_node.cpp:120
DOM::Node::nextSibling
Node nextSibling() const
The node immediately following this node.
Definition: dom_node.cpp:235
DOM::NamedNodeMap::setNamedItem
Node setNamedItem(const Node &arg)
Adds a node using its nodeName attribute.
Definition: dom_node.cpp:74
DOM::NodeList::length
unsigned long length() const
The number of nodes in the list.
Definition: dom_node.cpp:491
DOM::DOMString::upper
DOMString upper() const
Returns an uppercase version of the string.
Definition: dom_string.cpp:179
DOM::Node::nodeType
unsigned short nodeType() const
A code representing the type of the underlying object, as defined above.
Definition: dom_node.cpp:199

tdehtml

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

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.8.8
This website is maintained by Timothy Pearson.