• 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
32using namespace DOM;
33
34NamedNodeMap::NamedNodeMap()
35{
36 impl = 0;
37}
38
39NamedNodeMap::NamedNodeMap(const NamedNodeMap &other)
40{
41 impl = other.impl;
42 if (impl) impl->ref();
43}
44
45NamedNodeMap::NamedNodeMap(NamedNodeMapImpl *i)
46{
47 impl = i;
48 if (impl) impl->ref();
49}
50
51NamedNodeMap &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
61NamedNodeMap::~NamedNodeMap()
62{
63 if(impl) impl->deref();
64}
65
66Node 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
74Node 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
86Node 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
97Node NamedNodeMap::item( unsigned long index ) const
98{
99 if (!impl) return 0;
100 return impl->item(index);
101}
102
103Node 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
110Node 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
120Node 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
131unsigned long NamedNodeMap::length() const
132{
133 if (!impl) return 0;
134 return impl->length();
135}
136
137// ---------------------------------------------------------------------------
138
139Node::Node(const Node &other)
140{
141 impl = other.impl;
142 if(impl) impl->ref();
143}
144
145Node::Node( NodeImpl *i )
146{
147 impl = i;
148 if(impl) impl->ref();
149}
150
151Node &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
161bool Node::operator == (const Node &other) const
162{
163 return (impl == other.impl);
164}
165
166bool Node::operator != (const Node &other) const
167{
168 return !(impl == other.impl);
169}
170
171Node::~Node()
172{
173 if(impl) impl->deref();
174}
175
176DOMString Node::nodeName() const
177{
178 if(impl) return impl->nodeName();
179 return DOMString();
180}
181
182DOMString Node::nodeValue() const
183{
184 // ### should throw exception on plain node ?
185 if(impl) return impl->nodeValue();
186 return DOMString();
187}
188
189void 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
199unsigned short Node::nodeType() const
200{
201 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
202 return impl->nodeType();
203}
204
205Node Node::parentNode() const
206{
207 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
208 return impl->parentNode();
209}
210
211NodeList Node::childNodes() const
212{
213 if (!impl) return 0;
214 return impl->childNodes();
215}
216
217Node Node::firstChild() const
218{
219 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
220 return impl->firstChild();
221}
222
223Node Node::lastChild() const
224{
225 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
226 return impl->lastChild();
227}
228
229Node Node::previousSibling() const
230{
231 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
232 return impl->previousSibling();
233}
234
235Node Node::nextSibling() const
236{
237 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
238 return impl->nextSibling();
239}
240
241NamedNodeMap Node::attributes() const
242{
243 if (!impl || !impl->isElementNode()) return 0;
244 return static_cast<ElementImpl*>(impl)->attributes();
245}
246
247Document 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
258Node 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
269Node 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
281Node 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
292Node 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
303bool 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
311bool Node::hasChildNodes( )
312{
313 if (!impl) return false;
314 return impl->hasChildNodes();
315}
316
317Node Node::cloneNode( bool deep )
318{
319 if (!impl) return 0;
320 return impl->cloneNode( deep );
321}
322
323void Node::normalize ( )
324{
325 if (!impl) return;
326 impl->normalize();
327}
328
329bool 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
338DOMString Node::namespaceURI( ) const
339{
340 if (!impl) return DOMString();
341 return impl->namespaceURI();
342}
343
344DOMString Node::prefix( ) const
345{
346 if (!impl) return DOMString();
347 return impl->prefix();
348}
349
350void 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
359DOMString Node::localName( ) const
360{
361 if (!impl) return DOMString();
362 return impl->localName();
363}
364
365void 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
374void 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
382bool 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
398unsigned int Node::elementId() const
399{
400 if (!impl) return 0;
401 return impl->id();
402}
403
404unsigned long Node::index() const
405{
406 if (!impl) return 0;
407 return impl->nodeIndex();
408}
409
410TQString Node::toHTML()
411{
412 if (!impl) return TQString::null;
413 return impl->toString().string();
414}
415
416void Node::applyChanges()
417{
418 if (!impl) return;
419 impl->recalcStyle( NodeImpl::Inherit );
420}
421
422void 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
429TQRect Node::getRect()
430{
431 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
432 return impl->getRect();
433}
434
435DOMString Node::textContent( ) const
436{
437 if(impl) return impl->textContent();
438 return DOMString();
439}
440
441void 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
453NodeList::NodeList()
454{
455 impl = 0;
456}
457
458NodeList::NodeList(const NodeList &other)
459{
460 impl = other.impl;
461 if(impl) impl->ref();
462}
463
464NodeList::NodeList(const NodeListImpl *i)
465{
466 impl = const_cast<NodeListImpl *>(i);
467 if(impl) impl->ref();
468}
469
470NodeList &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
480NodeList::~NodeList()
481{
482 if(impl) impl->deref();
483}
484
485Node NodeList::item( unsigned long index ) const
486{
487 if (!impl) return 0;
488 return impl->item(index);
489}
490
491unsigned long NodeList::length() const
492{
493 if (!impl) return 0;
494 return impl->length();
495}
DOM::DOMException
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
DOM::DOMString::upper
DOMString upper() const
Returns an uppercase version of the string.
Definition: dom_string.cpp:179
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
DOM::EventListener
Introduced in DOM Level 2.
Definition: dom2_events.h:64
DOM::Event
Introduced in DOM Level 2.
Definition: dom2_events.h:111
DOM::NamedNodeMap
Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can b...
Definition: dom_node.h:67
DOM::NamedNodeMap::setNamedItem
Node setNamedItem(const Node &arg)
Adds a node using its nodeName attribute.
Definition: dom_node.cpp:74
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::NamedNodeMap::getNamedItemNS
Node getNamedItemNS(const DOMString &namespaceURI, const DOMString &localName) const
Introduced in DOM Level 2.
Definition: dom_node.cpp:103
DOM::NamedNodeMap::setNamedItemNS
Node setNamedItemNS(const Node &arg)
Introduced in DOM Level 2.
Definition: dom_node.cpp:110
DOM::NamedNodeMap::removeNamedItemNS
Node removeNamedItemNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_node.cpp:120
DOM::NamedNodeMap::item
Node item(unsigned long index) const
Returns the index th item in the map.
Definition: dom_node.cpp:97
DOM::NamedNodeMap::removeNamedItem
Node removeNamedItem(const DOMString &name)
Removes a node specified by name.
Definition: dom_node.cpp:86
DOM::NodeList
The NodeList interface provides the abstraction of an ordered collection of nodes,...
Definition: dom_node.h:932
DOM::NodeList::length
unsigned long length() const
The number of nodes in the list.
Definition: dom_node.cpp:491
DOM::NodeList::item
Node item(unsigned long index) const
Returns the index th item in the collection.
Definition: dom_node.cpp:485
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:275
DOM::Node::nextSibling
Node nextSibling() const
The node immediately following this node.
Definition: dom_node.cpp:235
DOM::Node::isSupported
bool isSupported(const DOMString &feature, const DOMString &version) const
Introduced in DOM Level 2.
Definition: dom_node.cpp:329
DOM::Node::previousSibling
Node previousSibling() const
The node immediately preceding this node.
Definition: dom_node.cpp:229
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::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::localName
DOMString localName() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:359
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::Node::childNodes
NodeList childNodes() const
A NodeList that contains all children of this node.
Definition: dom_node.cpp:211
DOM::Node::setPrefix
void setPrefix(const DOMString &prefix)
see prefix
Definition: dom_node.cpp:350
DOM::Node::setTextContent
void setTextContent(const DOMString &content) const
Introduced in DOM Level 3.
Definition: dom_node.cpp:441
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::Node::namespaceURI
DOMString namespaceURI() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:338
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::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::parentNode
Node parentNode() const
The parent of this node.
Definition: dom_node.cpp:205
DOM::Node::lastChild
Node lastChild() const
The last child of this node.
Definition: dom_node.cpp:223
DOM::Node::firstChild
Node firstChild() const
The first child of this node.
Definition: dom_node.cpp:217
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::ownerDocument
Document ownerDocument() const
The Document object associated with this node.
Definition: dom_node.cpp:247
DOM::Node::hasAttributes
bool hasAttributes()
Returns whether this node (if it is an element) has any attributes.
Definition: dom_node.cpp:303
DOM::Node::textContent
DOMString textContent() const
Introduced in DOM Level 3.
Definition: dom_node.cpp:435
DOM::Node::normalize
void normalize()
Modified in DOM Level 2.
Definition: dom_node.cpp:323
DOM::Node::getRect
TQRect getRect()
not part of the DOM.
Definition: dom_node.cpp:429
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::getCursor
void getCursor(int offset, int &_x, int &_y, int &height) TDE_DEPRECATED
Definition: dom_node.cpp:422
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::Node::setNodeValue
void setNodeValue(const DOMString &)
see nodeValue
Definition: dom_node.cpp:189
DOM::Node::nodeType
unsigned short nodeType() const
A code representing the type of the underlying object, as defined above.
Definition: dom_node.cpp:199
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::Node::nodeName
DOMString nodeName() const
The name of this node, depending on its type; see the table above.
Definition: dom_node.cpp:176
DOM::Node::prefix
DOMString prefix() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:344
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
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
Definition: design.h:57

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.9.4
This website is maintained by Timothy Pearson.