khtml Library API Documentation

dom_element.cpp

00001 
00024 #include "dom/dom_exception.h"
00025 #include "xml/dom_docimpl.h"
00026 #include "xml/dom_elementimpl.h"
00027 #include "html/html_formimpl.h"
00028 
00029 using namespace DOM;
00030 
00031 Attr::Attr() : Node()
00032 {
00033 }
00034 
00035 Attr::Attr(const Attr &other) : Node(other)
00036 {
00037 }
00038 
00039 Attr::Attr( AttrImpl *_impl )
00040 {
00041     impl= _impl;
00042     if (impl) impl->ref();
00043 }
00044 
00045 Attr &Attr::operator = (const Node &other)
00046 {
00047     NodeImpl* ohandle = other.handle();
00048     if ( impl != ohandle ) {
00049         if (!ohandle || !ohandle->isAttributeNode()) {
00050             if (impl) impl->deref();
00051             impl = 0;
00052         } else {
00053             Node::operator =(other);
00054         }
00055     }
00056     return *this;
00057 }
00058 
00059 Attr &Attr::operator = (const Attr &other)
00060 {
00061     Node::operator =(other);
00062     return *this;
00063 }
00064 
00065 Attr::~Attr()
00066 {
00067 }
00068 
00069 DOMString Attr::name() const
00070 {
00071     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00072     return impl->getDocument()->attrName(
00073         static_cast<AttrImpl*>(impl)->attrImpl()->id());
00074 }
00075 
00076 
00077 bool Attr::specified() const
00078 {
00079   if (impl) return ((AttrImpl *)impl)->specified();
00080   return 0;
00081 }
00082 
00083 Element Attr::ownerElement() const
00084 {
00085   if (!impl) return 0;
00086   return static_cast<AttrImpl*>(impl)->ownerElement();
00087 }
00088 
00089 DOMString Attr::value() const
00090 {
00091     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00092     return impl->nodeValue();
00093 }
00094 
00095 void Attr::setValue( const DOMString &newValue )
00096 {
00097   if (!impl)
00098     return;
00099 
00100   int exceptioncode = 0;
00101   ((AttrImpl *)impl)->setValue(newValue,exceptioncode);
00102   if (exceptioncode)
00103     throw DOMException(exceptioncode);
00104 }
00105 
00106 // ---------------------------------------------------------------------------
00107 
00108 Element::Element() : Node()
00109 {
00110 }
00111 
00112 Element::Element(const Element &other) : Node(other)
00113 {
00114 }
00115 
00116 Element::Element(ElementImpl *impl) : Node(impl)
00117 {
00118 }
00119 
00120 Element &Element::operator = (const Node &other)
00121 {
00122     NodeImpl* ohandle = other.handle();
00123     if ( impl != ohandle ) {
00124         if (!ohandle || !ohandle->isElementNode()) {
00125             if (impl) impl->deref();
00126             impl = 0;
00127     } else {
00128             Node::operator =(other);
00129     }
00130     }
00131     return *this;
00132 }
00133 
00134 Element &Element::operator = (const Element &other)
00135 {
00136     Node::operator =(other);
00137     return *this;
00138 }
00139 
00140 Element::~Element()
00141 {
00142 }
00143 
00144 DOMString Element::tagName() const
00145 {
00146     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00147     return static_cast<ElementImpl*>(impl)->tagName();
00148 }
00149 
00150 DOMString Element::getAttribute( const DOMString &name )
00151 {
00152     return getAttributeNS(DOMString(), name);
00153 }
00154 
00155 void Element::setAttribute( const DOMString &name, const DOMString &value )
00156 {
00157     setAttributeNS(DOMString(), name, value);
00158 }
00159 
00160 void Element::removeAttribute( const DOMString &name )
00161 {
00162     removeAttributeNS(DOMString(), name);
00163 }
00164 
00165 Attr Element::getAttributeNode( const DOMString &name )
00166 {
00167     return getAttributeNodeNS(DOMString(), name);
00168 }
00169 
00170 Attr Element::setAttributeNode( const Attr &newAttr )
00171 {
00172     return setAttributeNodeNS(newAttr);
00173 }
00174 
00175 Attr Element::removeAttributeNode( const Attr &oldAttr )
00176 {
00177     if (!impl || oldAttr.isNull() || oldAttr.ownerElement() != *this)
00178         throw DOMException(DOMException::NOT_FOUND_ERR);
00179     if (impl->getDocument() != oldAttr.handle()->getDocument())
00180         throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
00181 
00182     int exceptioncode = 0;
00183     Attr r = static_cast<ElementImpl*>(impl)->attributes(true)->removeNamedItem(oldAttr.handle()->id(), exceptioncode);
00184     if ( exceptioncode )
00185         throw DOMException( exceptioncode );
00186     return r;
00187 }
00188 
00189 NodeList Element::getElementsByTagName( const DOMString &name )
00190 {
00191     if (!impl) return 0;
00192     return static_cast<ElementImpl*>(impl)->
00193         getElementsByTagNameNS(0, name.implementation());
00194 }
00195 
00196 NodeList Element::getElementsByTagNameNS( const DOMString &namespaceURI,
00197                                           const DOMString &localName )
00198 {
00199     if (!impl) return 0;
00200     return static_cast<ElementImpl*>(impl)->
00201         getElementsByTagNameNS(namespaceURI.implementation(), localName.implementation());
00202 }
00203 
00204 DOMString Element::getAttributeNS( const DOMString &namespaceURI,
00205                                    const DOMString &localName)
00206 {
00207     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00208     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
00209                                                  localName.implementation(), true);
00210     if (!id) return DOMString();
00211     return static_cast<ElementImpl*>(impl)->getAttribute(id);
00212 }
00213 
00214 void Element::setAttributeNS( const DOMString &namespaceURI,
00215                               const DOMString &qualifiedName,
00216                               const DOMString &value)
00217 {
00218     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00219 
00220     int colonpos = qualifiedName.find(':');
00221     DOMString localName = qualifiedName;
00222     if (colonpos >= 0) {
00223         localName.remove(0, colonpos+1);
00224         // ### extract and set new prefix
00225     }
00226     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
00227                                                     localName.implementation(), false /* allocate */);
00228     int exceptioncode = 0;
00229     static_cast<ElementImpl*>(impl)->setAttribute(id, value.implementation(), exceptioncode);
00230     if (exceptioncode)
00231         throw DOMException(exceptioncode);
00232 }
00233 
00234 void Element::removeAttributeNS( const DOMString &namespaceURI,
00235                                  const DOMString &localName )
00236 {
00237     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00238     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
00239                                                     localName.implementation(), true);
00240     if (!id) return;
00241 
00242     int exceptioncode = 0;
00243     ((ElementImpl *)impl)->removeAttribute(id, exceptioncode);
00244     if ( exceptioncode )
00245         throw DOMException( exceptioncode );
00246 }
00247 
00248 Attr Element::getAttributeNodeNS( const DOMString &namespaceURI,
00249                                   const DOMString &localName )
00250 {
00251     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00252     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
00253                                                     localName.implementation(), true);
00254     if (!id) return 0;
00255 
00256     ElementImpl* e = static_cast<ElementImpl*>(impl);
00257     if (!e->attributes()) return 0; // exception ?
00258 
00259     return e->attributes()->getNamedItem(id);
00260 }
00261 
00262 Attr Element::setAttributeNodeNS( const Attr &newAttr )
00263 {
00264     if (!impl || newAttr.isNull())
00265         throw DOMException(DOMException::NOT_FOUND_ERR);
00266     if (impl->getDocument() != newAttr.handle()->getDocument())
00267         throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
00268     if (!newAttr.ownerElement().isNull())
00269         throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR);
00270 
00271     int exceptioncode = 0;
00272     Attr r = static_cast<ElementImpl*>(impl)->attributes(false)->setNamedItem(newAttr.handle(), exceptioncode);
00273     if ( exceptioncode )
00274         throw DOMException( exceptioncode );
00275     return r;
00276 }
00277 
00278 
00279 bool Element::hasAttribute( const DOMString& name )
00280 {
00281     return hasAttributeNS(DOMString(), name);
00282 }
00283 
00284 bool Element::hasAttributeNS( const DOMString &namespaceURI,
00285                               const DOMString &localName )
00286 {
00287     if (!impl || !static_cast<ElementImpl*>(impl)->attributes()) return false; // ### throw ?
00288     NodeImpl::Id id = impl->getDocument()->attrId(namespaceURI.implementation(),
00289                                                     localName.implementation(), true);
00290     if (!id) return false;
00291 
00292     if (!static_cast<ElementImpl*>(impl)->attributes(true /*readonly*/)) return false;
00293     return static_cast<ElementImpl*>(impl)->attributes(true)->getAttributeItem(id) != 0;
00294 }
00295 
00296 bool Element::isHTMLElement() const
00297 {
00298     if(!impl) return false;
00299     return ((ElementImpl *)impl)->isHTMLElement();
00300 }
00301 
00302 Element Element::form() const
00303 {
00304     if (!impl || !impl->isGenericFormElement()) return 0;
00305     return static_cast<HTMLGenericFormElementImpl*>(impl)->form();
00306 }
00307 
00308 CSSStyleDeclaration Element::style()
00309 {
00310     if (impl) return ((ElementImpl *)impl)->styleRules();
00311     return 0;
00312 }
00313 
00314 bool Element::khtmlValidAttrName(const DOMString &/*name*/)
00315 {
00316     // ###
00317     return true;
00318 }
00319 
00320 bool Element::khtmlValidPrefix(const DOMString &/*name*/)
00321 {
00322     // ###
00323     return true;
00324 }
00325 
00326 bool Element::khtmlValidQualifiedName(const DOMString &/*name*/)
00327 {
00328     // ###
00329     return true;
00330 }
00331 
00332 bool Element::khtmlMalformedQualifiedName(const DOMString &/*name*/)
00333 {
00334     // ###
00335     return false;
00336 }
00337 
00338 bool Element::khtmlMalformedPrefix(const DOMString &/*name*/)
00339 {
00340     // ###
00341     return false;
00342 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:35 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001