23 #include "dom/dom_exception.h"
24 #include "xml/dom_docimpl.h"
25 #include "xml/dom_elementimpl.h"
26 #include "html/html_formimpl.h"
34 Attr::Attr(
const Attr &other) :
Node(other)
38 Attr::Attr( AttrImpl *_impl )
41 if (impl) impl->ref();
44 Attr &Attr::operator = (
const Node &other)
46 NodeImpl* ohandle = other.handle();
47 if ( impl != ohandle ) {
48 if (!ohandle || !ohandle->isAttributeNode()) {
49 if (impl) impl->deref();
52 Node::operator =(other);
58 Attr &Attr::operator = (
const Attr &other)
60 Node::operator =(other);
70 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
71 return ((AttrImpl *)impl)->name();
76 if (impl)
return ((AttrImpl *)impl)->specified();
88 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
89 return impl->nodeValue();
97 int exceptioncode = 0;
98 ((AttrImpl *)impl)->setValue(newValue,exceptioncode);
105 Element::Element() :
Node()
109 Element::Element(
const Element &other) :
Node(other)
113 Element::Element(ElementImpl *impl) :
Node(impl)
119 NodeImpl* ohandle = other.handle();
120 if ( impl != ohandle ) {
121 if (!ohandle || !ohandle->isElementNode()) {
122 if (impl) impl->deref();
125 Node::operator =(other);
133 Node::operator =(other);
143 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
144 return static_cast<ElementImpl*
>(impl)->
tagName();
152 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
153 if (!name.implementation())
throw DOMException(DOMException::NOT_FOUND_ERR);
155 NodeImpl::Id
id = impl->getDocument()->getId(NodeImpl::AttributeId,name.implementation(),
true,
true);
158 ElementImpl* e =
static_cast<ElementImpl*
>(impl);
159 return e->getAttribute(
id,
false, name);
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 ,
167 true, &exceptioncode);
169 static_cast<ElementImpl*
>(impl)->
setAttribute(
id, value, name, exceptioncode);
176 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
177 NodeImpl::Id
id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(),
true,
true);
180 int exceptioncode = 0;
182 attributes->
removeNamedItem(
id,
false, name.implementation(), exceptioncode);
184 if ( exceptioncode && exceptioncode != DOMException::NOT_FOUND_ERR )
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);
195 ElementImpl* e =
static_cast<ElementImpl*
>(impl);
196 if (!e->attributes())
return 0;
198 return static_cast<AttrImpl*
>(e->attributes()->getNamedItem(
id,
false, name.implementation()));
203 if (!impl || newAttr.
isNull())
207 int exceptioncode = 0;
209 newAttr.handle()->nodeName().implementation(), exceptioncode);
212 static_cast<AttrImpl *
>(newAttr.handle())->setOwnerElement( static_cast<ElementImpl*>(impl) );
221 if (impl->isReadOnly())
222 throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
224 if (!static_cast<ElementImpl*>(impl)->attributes(
true))
228 return attributes->removeAttr(static_cast<AttrImpl*>(static_cast<AttrImpl*>(oldAttr.handle())));
235 if ( tagName ==
"*" )
238 id = impl->getDocument()->getId(NodeImpl::ElementId, tagName.implementation(),
false,
true);
239 return new TagNodeListImpl( impl,
id );
246 return new TagNodeListImpl( impl, namespaceURI, localName );
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, localName.implementation(),
true,
true);
255 ElementImpl* e =
static_cast<ElementImpl*
>(impl);
256 return e->getAttribute(
id,
true);
263 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
265 int exceptioncode = 0;
266 static_cast<ElementImpl*
>(impl)->
setAttributeNS(namespaceURI, qualifiedName, value, exceptioncode);
274 if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
276 int exceptioncode = 0;
278 NodeImpl::Id
id = impl->getDocument()->getId(NodeImpl::AttributeId, namespaceURI.implementation(), 0, localName.implementation(),
false,
true);
279 attributes->removeNamedItem(
id,
true, 0, exceptioncode);
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, localName.implementation(),
true,
true);
291 ElementImpl* e =
static_cast<ElementImpl*
>(impl);
292 if (!e->attributes())
return 0;
294 return static_cast<AttrImpl*
>(e->attributes()->getNamedItem(
id,
true));
299 if (!impl || newAttr.
isNull())
303 int exceptioncode = 0;
307 static_cast<AttrImpl *
>(newAttr.handle())->setOwnerElement( static_cast<ElementImpl*>(impl) );
314 if (!impl || !static_cast<ElementImpl*>(impl)->
attributes())
return false;
315 NodeImpl::Id
id = impl->getDocument()->getId(NodeImpl::AttributeId, name.implementation(),
true,
true);
316 if (!
id)
return false;
318 if (!static_cast<ElementImpl*>(impl)->attributes(
true ))
return false;
319 return static_cast<ElementImpl*
>(impl)->
attributes(
true)->getValue(
id,
false, name.implementation()) != 0;
325 if (!impl || !static_cast<ElementImpl*>(impl)->
attributes())
return false;
326 if (!static_cast<ElementImpl*>(impl)->
attributes(
true ))
return false;
327 NodeImpl::Id
id = impl->getDocument()->getId(NodeImpl::AttributeId,namespaceURI.implementation(),
328 0, localName.implementation(),
true,
true);
329 return static_cast<ElementImpl*
>(impl)->
attributes(
true)->getValue(
id,
true) != 0;
332 bool Element::isHTMLElement()
const
334 if(!impl)
return false;
335 return ((ElementImpl *)impl)->isHTMLElement();
340 if (!impl || !impl->isGenericFormElement())
return 0;
341 return static_cast<HTMLGenericFormElementImpl*
>(impl)->
form();
342 ElementImpl* f =
static_cast<HTMLGenericFormElementImpl*
>( impl )->
form();
344 if( f && f->implicitNode() )
351 if (impl)
return ((ElementImpl *)impl)->styleRules();
356 if(!impl)
return false;
367 bool Element::khtmlValidAttrName(
const DOMString &name)
371 DOMStringImpl* _name = name.implementation();
372 TQChar ch = _name->s[0];
373 if ( !ch.isLetter() && ch !=
'_' && ch !=
':' )
375 for ( uint i = 0; i < _name->l; ++i )
378 if ( !ch.isLetter() && !ch.isDigit() && ch !=
'.'
379 && ch !=
'-' && ch !=
'_' && ch !=
':'
380 && ch.category() != TQChar::Mark_SpacingCombining
387 bool Element::khtmlValidPrefix(
const DOMString &name)
390 return !name.implementation() || khtmlValidAttrName(name);
393 bool Element::khtmlValidQualifiedName(
const DOMString &name)
395 return khtmlValidAttrName(name);
398 bool Element::khtmlMalformedQualifiedName(
const DOMString &name)
402 return name.isNull();
405 bool Element::khtmlMalformedPrefix(
const DOMString &)