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

tdehtml

  • tdehtml
  • dom
dom_element.cpp
1
23#include "dom/dom_exception.h"
24#include "xml/dom_docimpl.h"
25#include "xml/dom_elementimpl.h"
26#include "html/html_formimpl.h"
27
28using namespace DOM;
29
30Attr::Attr() : Node()
31{
32}
33
34Attr::Attr(const Attr &other) : Node(other)
35{
36}
37
38Attr::Attr( AttrImpl *_impl )
39{
40 impl= _impl;
41 if (impl) impl->ref();
42}
43
44Attr &Attr::operator = (const Node &other)
45{
46 NodeImpl* ohandle = other.handle();
47 if ( impl != ohandle ) {
48 if (!ohandle || !ohandle->isAttributeNode()) {
49 if (impl) impl->deref();
50 impl = 0;
51 } else {
52 Node::operator =(other);
53 }
54 }
55 return *this;
56}
57
58Attr &Attr::operator = (const Attr &other)
59{
60 Node::operator =(other);
61 return *this;
62}
63
64Attr::~Attr()
65{
66}
67
68DOMString Attr::name() const
69{
70 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
71 return ((AttrImpl *)impl)->name();
72}
73
74bool Attr::specified() const
75{
76 if (impl) return ((AttrImpl *)impl)->specified();
77 return 0;
78}
79
80Element Attr::ownerElement() const
81{
82 if (!impl) return 0;
83 return static_cast<AttrImpl*>(impl)->ownerElement();
84}
85
86DOMString Attr::value() const
87{
88 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
89 return impl->nodeValue();
90}
91
92void Attr::setValue( const DOMString &newValue )
93{
94 if (!impl)
95 return;
96
97 int exceptioncode = 0;
98 ((AttrImpl *)impl)->setValue(newValue,exceptioncode);
99 if (exceptioncode)
100 throw DOMException(exceptioncode);
101}
102
103// ---------------------------------------------------------------------------
104
105Element::Element() : Node()
106{
107}
108
109Element::Element(const Element &other) : Node(other)
110{
111}
112
113Element::Element(ElementImpl *impl) : Node(impl)
114{
115}
116
117Element &Element::operator = (const Node &other)
118{
119 NodeImpl* ohandle = other.handle();
120 if ( impl != ohandle ) {
121 if (!ohandle || !ohandle->isElementNode()) {
122 if (impl) impl->deref();
123 impl = 0;
124 } else {
125 Node::operator =(other);
126 }
127 }
128 return *this;
129}
130
131Element &Element::operator = (const Element &other)
132{
133 Node::operator =(other);
134 return *this;
135}
136
137Element::~Element()
138{
139}
140
141DOMString Element::tagName() const
142{
143 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
144 return static_cast<ElementImpl*>(impl)->tagName();
145}
146
147DOMString Element::getAttribute( const DOMString &name )
148{
149 // ### getAttribute() and getAttributeNS() are supposed to return the empty string if the attribute
150 // does not exist. However, there are a number of places around tdehtml that expect a null string
151 // for nonexistent attributes. These need to be changed to use hasAttribute() instead.
152 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
153 if (!name.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
154
155 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId,name.implementation(),true,true);
156 if (!id) return DOMString();
157
158 ElementImpl* e = static_cast<ElementImpl*>(impl);
159 return e->getAttribute(id, false, name);
160}
161
162void Element::setAttribute( const DOMString &name, const DOMString &value )
163{
164 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
165 int exceptioncode = 0;
166 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(), false /* allocate */,
167 true, &exceptioncode);
168
169 static_cast<ElementImpl*>(impl)->setAttribute(id, value, name, exceptioncode);
170 if ( exceptioncode )
171 throw DOMException( exceptioncode );
172}
173
174void Element::removeAttribute( const DOMString &name )
175{
176 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
177 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(), true, true);
178 if (!id) return;
179
180 int exceptioncode = 0;
181 NamedNodeMapImpl *attributes = static_cast<ElementImpl*>(impl)->attributes(false);
182 attributes->removeNamedItem(id, false, name.implementation(), exceptioncode);
183 // it's allowed to remove attributes that don't exist.
184 if ( exceptioncode && exceptioncode != DOMException::NOT_FOUND_ERR )
185 throw DOMException( exceptioncode );
186}
187
188Attr Element::getAttributeNode( const DOMString &name )
189{
190 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
191 if (!name.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
192 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(), true, true);
193 if (!id) return 0;
194
195 ElementImpl* e = static_cast<ElementImpl*>(impl);
196 if (!e->attributes()) return 0;
197
198 return static_cast<AttrImpl*>(e->attributes()->getNamedItem(id, false, name.implementation()));
199}
200
201Attr Element::setAttributeNode( const Attr &newAttr )
202{
203 if (!impl || newAttr.isNull())
204 throw DOMException(DOMException::NOT_FOUND_ERR);
205 // WRONG_DOCUMENT_ERR and INUSE_ATTRIBUTE_ERR are already tested & thrown by setNamedItem
206
207 int exceptioncode = 0;
208 Attr r = static_cast<ElementImpl*>(impl)->attributes(false)->setNamedItem(newAttr.handle(), false,
209 newAttr.handle()->nodeName().implementation(), exceptioncode);
210 if ( exceptioncode )
211 throw DOMException( exceptioncode );
212 static_cast<AttrImpl *>(newAttr.handle())->setOwnerElement( static_cast<ElementImpl*>(impl) );
213 return r;
214}
215
216Attr Element::removeAttributeNode( const Attr &oldAttr )
217{
218 if (!impl || oldAttr.isNull() || oldAttr.ownerElement().handle() != impl)
219 throw DOMException(DOMException::NOT_FOUND_ERR);
220
221 if (impl->isReadOnly())
222 throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
223
224 if (!static_cast<ElementImpl*>(impl)->attributes(true))
225 throw DOMException(DOMException::NOT_FOUND_ERR);
226
227 NamedAttrMapImpl *attributes = static_cast<ElementImpl*>(impl)->attributes(false);
228 return attributes->removeAttr(static_cast<AttrImpl*>(static_cast<AttrImpl*>(oldAttr.handle())));
229}
230
231NodeList Element::getElementsByTagName( const DOMString &tagName )
232{
233 if (!impl) return 0;
234 NodeImpl::Id id;
235 if ( tagName == "*" )
236 id = 0;
237 else
238 id = impl->getDocument()->getId(NodeImpl::ElementId, tagName.implementation(), false, true);
239 return new TagNodeListImpl( impl, id );
240}
241
242NodeList Element::getElementsByTagNameNS( const DOMString &namespaceURI,
243 const DOMString &localName )
244{
245 if (!impl) return 0;
246 return new TagNodeListImpl( impl, namespaceURI, localName );
247}
248
249DOMString Element::getAttributeNS( const DOMString &namespaceURI,
250 const DOMString &localName)
251{
252 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
253 if (!localName.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
254 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, namespaceURI.implementation(), 0/*prefix*/, localName.implementation(), true, true);
255 ElementImpl* e = static_cast<ElementImpl*>(impl);
256 return e->getAttribute(id, true);
257}
258
259void Element::setAttributeNS( const DOMString &namespaceURI,
260 const DOMString &qualifiedName,
261 const DOMString &value)
262{
263 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
264
265 int exceptioncode = 0;
266 static_cast<ElementImpl*>(impl)->setAttributeNS(namespaceURI, qualifiedName, value, exceptioncode);
267 if ( exceptioncode )
268 throw DOMException( exceptioncode );
269}
270
271void Element::removeAttributeNS( const DOMString &namespaceURI,
272 const DOMString &localName )
273{
274 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
275
276 int exceptioncode = 0;
277 NamedNodeMapImpl *attributes = static_cast<ElementImpl*>(impl)->attributes(false);
278 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, namespaceURI.implementation(), 0/*prefix*/, localName.implementation(), false, true);
279 attributes->removeNamedItem(id, true, 0, exceptioncode);
280 if ( exceptioncode )
281 throw DOMException( exceptioncode );
282}
283
284Attr Element::getAttributeNodeNS( const DOMString &namespaceURI,
285 const DOMString &localName )
286{
287 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
288 if (!localName.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
289 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, namespaceURI.implementation(),
290 0/*prefix*/, localName.implementation(), true, true);
291 ElementImpl* e = static_cast<ElementImpl*>(impl);
292 if (!e->attributes()) return 0;
293
294 return static_cast<AttrImpl*>(e->attributes()->getNamedItem(id, true));
295}
296
297Attr Element::setAttributeNodeNS( const Attr &newAttr )
298{
299 if (!impl || newAttr.isNull())
300 throw DOMException(DOMException::NOT_FOUND_ERR);
301 // WRONG_DOCUMENT_ERR and INUSE_ATTRIBUTE_ERR are already tested & thrown by setNamedItem
302
303 int exceptioncode = 0;
304 Attr r = static_cast<ElementImpl*>(impl)->attributes(false)->setNamedItem(newAttr.handle(), true, 0, exceptioncode);
305 if ( exceptioncode )
306 throw DOMException( exceptioncode );
307 static_cast<AttrImpl *>(newAttr.handle())->setOwnerElement( static_cast<ElementImpl*>(impl) );
308 return r;
309}
310
311
312bool Element::hasAttribute( const DOMString& name )
313{
314 if (!impl || !static_cast<ElementImpl*>(impl)->attributes()) return false; // ### throw ?
315 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(), true, true);
316 if (!id) return false;
317
318 if (!static_cast<ElementImpl*>(impl)->attributes(true /*readonly*/)) return false;
319 return static_cast<ElementImpl*>(impl)->attributes(true)->getValue(id, false, name.implementation()) != 0;
320}
321
322bool Element::hasAttributeNS( const DOMString &namespaceURI,
323 const DOMString &localName )
324{
325 if (!impl || !static_cast<ElementImpl*>(impl)->attributes()) return false; // ### throw ?
326 if (!static_cast<ElementImpl*>(impl)->attributes(true /*readonly*/)) return false;
327 NodeImpl::Id id = impl->getDocument()->getId(NodeImpl::AttributeId,namespaceURI.implementation(),
328 0/*prefix*/, localName.implementation(), true, true);
329 return static_cast<ElementImpl*>(impl)->attributes(true)->getValue(id, true) != 0;
330}
331
332bool Element::isHTMLElement() const
333{
334 if(!impl) return false;
335 return ((ElementImpl *)impl)->isHTMLElement();
336}
337
338Element Element::form() const
339{
340 if (!impl || !impl->isGenericFormElement()) return 0;
341 return static_cast<HTMLGenericFormElementImpl*>(impl)->form();
342 ElementImpl* f = static_cast<HTMLGenericFormElementImpl*>( impl )->form();
343
344 if( f && f->implicitNode() )
345 return 0;
346 return f;
347}
348
349CSSStyleDeclaration Element::style()
350{
351 if (impl) return ((ElementImpl *)impl)->styleRules();
352 return 0;
353}
354
355bool Element::contentEditable() const {
356 if(!impl) return false;
357 return static_cast<ElementImpl *>(impl)->contentEditable();
358}
359
360void Element::setContentEditable(bool enabled) {
361 if(!impl)
362 throw DOMException(DOMException::INVALID_STATE_ERR);
363
364 static_cast<ElementImpl *>(impl)->setContentEditable(enabled);
365}
366
367bool Element::tdehtmlValidAttrName(const DOMString &name)
368{
369 // Check if name is valid
370 // http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name
371 DOMStringImpl* _name = name.implementation();
372 TQChar ch = _name->s[0];
373 if ( !ch.isLetter() && ch != '_' && ch != ':' )
374 return false; // first char isn't valid
375 for ( uint i = 0; i < _name->l; ++i )
376 {
377 ch = _name->s[i];
378 if ( !ch.isLetter() && !ch.isDigit() && ch != '.'
379 && ch != '-' && ch != '_' && ch != ':'
380 && ch.category() != TQChar::Mark_SpacingCombining
381 /* no idea what "extender is" */ )
382 return false;
383 }
384 return true;
385}
386
387bool Element::tdehtmlValidPrefix(const DOMString &name)
388{
389 // Null prefix is ok. If not null, reuse code from tdehtmlValidAttrName
390 return !name.implementation() || tdehtmlValidAttrName(name);
391}
392
393bool Element::tdehtmlValidQualifiedName(const DOMString &name)
394{
395 return tdehtmlValidAttrName(name);
396}
397
398bool Element::tdehtmlMalformedQualifiedName(const DOMString &name)
399{
400 // #### Not clearly defined in the DOM spec...
401 // But we know for sure that a null qualified name is malformed
402 return name.isNull();
403}
404
405bool Element::tdehtmlMalformedPrefix(const DOMString &/*name*/)
406{
407 // ####
408 return false;
409}
DOM::Attr
The Attr interface represents an attribute in an Element object.
Definition: dom_element.h:90
DOM::Attr::name
DOMString name() const
Returns the name of this attribute.
Definition: dom_element.cpp:68
DOM::Attr::ownerElement
Element ownerElement() const
Introduced in DOM Level 2.
Definition: dom_element.cpp:80
DOM::Attr::specified
bool specified() const
If this attribute was explicitly given a value in the original document, this is true ; otherwise,...
Definition: dom_element.cpp:74
DOM::Attr::value
DOMString value() const
On retrieval, the value of the attribute is returned as a string.
Definition: dom_element.cpp:86
DOM::Attr::setValue
void setValue(const DOMString &)
see value
Definition: dom_element.cpp:92
DOM::CSSStyleDeclaration
The CSSStyleDeclaration interface represents a single CSS declaration block .
Definition: css_value.h:61
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::Element
By far the vast majority of objects (apart from text) that authors encounter when traversing a docume...
Definition: dom_element.h:211
DOM::Element::tagName
DOMString tagName() const
The name of the element.
Definition: dom_element.cpp:141
DOM::Element::getAttributeNS
DOMString getAttributeNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_element.cpp:249
DOM::Element::setAttributeNode
Attr setAttributeNode(const Attr &newAttr)
Adds a new attribute.
Definition: dom_element.cpp:201
DOM::Element::hasAttribute
bool hasAttribute(const DOMString &name)
Returns true when an attribute with a given name is specified on this element or has a default value,...
Definition: dom_element.cpp:312
DOM::Element::getAttribute
DOMString getAttribute(const DOMString &name)
Retrieves an attribute value by name.
Definition: dom_element.cpp:147
DOM::Element::removeAttribute
void removeAttribute(const DOMString &name)
Removes an attribute by name.
Definition: dom_element.cpp:174
DOM::Element::setAttributeNodeNS
Attr setAttributeNodeNS(const Attr &newAttr)
Introduced in DOM Level 2.
Definition: dom_element.cpp:297
DOM::Element::getElementsByTagName
NodeList getElementsByTagName(const DOMString &name)
Returns a NodeList of all descendant elements with a given tag name, in the order in which they would...
Definition: dom_element.cpp:231
DOM::Element::getAttributeNode
Attr getAttributeNode(const DOMString &name)
Retrieves an Attr node by name.
Definition: dom_element.cpp:188
DOM::Element::style
CSSStyleDeclaration style()
Introduced in DOM Level 2 This method is from the CSSStyleDeclaration interface.
Definition: dom_element.cpp:349
DOM::Element::hasAttributeNS
bool hasAttributeNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_element.cpp:322
DOM::Element::contentEditable
bool contentEditable() const
not part of the official DOM
Definition: dom_element.cpp:355
DOM::Element::setAttribute
void setAttribute(const DOMString &name, const DOMString &value)
Adds a new attribute.
Definition: dom_element.cpp:162
DOM::Element::getAttributeNodeNS
Attr getAttributeNodeNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_element.cpp:284
DOM::Element::getElementsByTagNameNS
NodeList getElementsByTagNameNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2 Returns a NodeList of all the descendant Elements with a given local name a...
Definition: dom_element.cpp:242
DOM::Element::removeAttributeNS
void removeAttributeNS(const DOMString &namespaceURI, const DOMString &localName)
Introduced in DOM Level 2.
Definition: dom_element.cpp:271
DOM::Element::setAttributeNS
void setAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value)
Introduced in DOM Level 2.
Definition: dom_element.cpp:259
DOM::Element::setContentEditable
void setContentEditable(bool enabled)
not part of the official DOM
Definition: dom_element.cpp:360
DOM::Element::removeAttributeNode
Attr removeAttributeNode(const Attr &oldAttr)
Removes the specified attribute.
Definition: dom_element.cpp:216
DOM::Element::form
Element form() const
TDEHTML extension to DOM This method returns the associated form element.
Definition: dom_element.cpp:338
DOM::NamedNodeMap::setNamedItem
Node setNamedItem(const Node &arg)
Adds a node using its nodeName attribute.
Definition: dom_node.cpp:74
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::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:275
DOM::Node::localName
DOMString localName() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:359
DOM::Node::isNull
bool isNull() const
tests if this Node is 0.
Definition: dom_node.h:892
DOM::Node::namespaceURI
DOMString namespaceURI() const
Introduced in DOM Level 2.
Definition: dom_node.cpp:338
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
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
Definition: design.h:57
TDEStdAccel::name
TQString name(StdAccel id)

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.