KHTML
dom_element.cpp
Go to the documentation of this file.00001
00023 #include "dom/dom_exception.h"
00024 #include "xml/dom_docimpl.h"
00025 #include "xml/dom_elementimpl.h"
00026 #include "html/html_formimpl.h"
00027
00028 using namespace DOM;
00029
00030 Attr::Attr() : Node()
00031 {
00032 }
00033
00034 Attr::Attr(const Attr &other) : Node(other)
00035 {
00036 }
00037
00038 Attr::Attr( AttrImpl *_impl )
00039 {
00040 impl= _impl;
00041 if (impl) impl->ref();
00042 }
00043
00044 Attr &Attr::operator = (const Node &other)
00045 {
00046 NodeImpl* ohandle = other.handle();
00047 if ( impl != ohandle ) {
00048 if (!ohandle || !ohandle->isAttributeNode()) {
00049 if (impl) impl->deref();
00050 impl = 0;
00051 } else {
00052 Node::operator =(other);
00053 }
00054 }
00055 return *this;
00056 }
00057
00058 Attr &Attr::operator = (const Attr &other)
00059 {
00060 Node::operator =(other);
00061 return *this;
00062 }
00063
00064 Attr::~Attr()
00065 {
00066 }
00067
00068 DOMString Attr::name() const
00069 {
00070 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00071 return ((AttrImpl *)impl)->name();
00072 }
00073
00074 bool Attr::specified() const
00075 {
00076 if (impl) return ((AttrImpl *)impl)->specified();
00077 return 0;
00078 }
00079
00080 Element Attr::ownerElement() const
00081 {
00082 if (!impl) return 0;
00083 return static_cast<AttrImpl*>(impl)->ownerElement();
00084 }
00085
00086 DOMString Attr::value() const
00087 {
00088 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00089 return impl->nodeValue();
00090 }
00091
00092 void Attr::setValue( const DOMString &newValue )
00093 {
00094 if (!impl)
00095 return;
00096
00097 int exceptioncode = 0;
00098 ((AttrImpl *)impl)->setValue(newValue,exceptioncode);
00099 if (exceptioncode)
00100 throw DOMException(exceptioncode);
00101 }
00102
00103
00104
00105 Element::Element() : Node()
00106 {
00107 }
00108
00109 Element::Element(const Element &other) : Node(other)
00110 {
00111 }
00112
00113 Element::Element(ElementImpl *impl) : Node(impl)
00114 {
00115 }
00116
00117 Element &Element::operator = (const Node &other)
00118 {
00119 NodeImpl* ohandle = other.handle();
00120 if ( impl != ohandle ) {
00121 if (!ohandle || !ohandle->isElementNode()) {
00122 if (impl) impl->deref();
00123 impl = 0;
00124 } else {
00125 Node::operator =(other);
00126 }
00127 }
00128 return *this;
00129 }
00130
00131 Element &Element::operator = (const Element &other)
00132 {
00133 Node::operator =(other);
00134 return *this;
00135 }
00136
00137 Element::~Element()
00138 {
00139 }
00140
00141 DOMString Element::tagName() const
00142 {
00143 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00144 return static_cast<ElementImpl*>(impl)->tagName();
00145 }
00146
00147 DOMString Element::getAttribute( const DOMString &name )
00148 {
00149
00150
00151
00152 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00153 if (!name.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
00154
00155 return static_cast<ElementImpl*>(impl)->getAttribute(name);
00156 }
00157
00158 void Element::setAttribute( const DOMString &name, const DOMString &value )
00159 {
00160 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00161 int exceptioncode = 0;
00162 static_cast<ElementImpl*>(impl)->setAttribute(name, value, exceptioncode);
00163 if ( exceptioncode )
00164 throw DOMException( exceptioncode );
00165 }
00166
00167 void Element::removeAttribute( const DOMString &name )
00168 {
00169 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00170
00171 int exceptioncode = 0;
00172 static_cast<ElementImpl*>(impl)->removeAttribute(name, exceptioncode);
00173
00174 if ( exceptioncode && exceptioncode != DOMException::NOT_FOUND_ERR )
00175 throw DOMException( exceptioncode );
00176 }
00177
00178 Attr Element::getAttributeNode( const DOMString &name )
00179 {
00180 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00181 if (!name.implementation()) throw DOMException(DOMException::NOT_FOUND_ERR);
00182
00183 return static_cast<ElementImpl*>(impl)->getAttributeNode(name);
00184 }
00185
00186 Attr Element::setAttributeNode( const Attr &newAttr )
00187 {
00188 if (!impl || newAttr.isNull())
00189 throw DOMException(DOMException::NOT_FOUND_ERR);
00190
00191
00192 int exceptioncode = 0;
00193 Attr r = static_cast<ElementImpl*>(impl)->setAttributeNode(
00194 static_cast<AttrImpl*>(newAttr.handle()), exceptioncode);
00195 if ( exceptioncode )
00196 throw DOMException( exceptioncode );
00197 return r;
00198 }
00199
00200 Attr Element::removeAttributeNode( const Attr &oldAttr )
00201 {
00202 int exceptioncode = 0;
00203 if (!impl)
00204 throw DOMException(DOMException::NOT_FOUND_ERR);
00205
00206 Attr ret = static_cast<ElementImpl*>(impl)->removeAttributeNode(
00207 static_cast<AttrImpl*>(oldAttr.handle()), exceptioncode);
00208 if (exceptioncode)
00209 throw DOMException(exceptioncode);
00210
00211 return ret;
00212 }
00213
00214 NodeList Element::getElementsByTagName( const DOMString &tagName )
00215 {
00216 if (!impl) return 0;
00217 return static_cast<ElementImpl*>(impl)->getElementsByTagName( tagName );
00218 }
00219
00220 NodeList Element::getElementsByTagNameNS( const DOMString &namespaceURI,
00221 const DOMString &localName )
00222 {
00223 if (!impl) return 0;
00224 return static_cast<ElementImpl*>(impl)->getElementsByTagNameNS( namespaceURI, localName );
00225 }
00226
00227 DOMString Element::getAttributeNS( const DOMString &namespaceURI,
00228 const DOMString &localName)
00229 {
00230 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00231 ElementImpl* e = static_cast<ElementImpl*>(impl);
00232 int exceptioncode = 0;
00233 DOMString ret = e->getAttributeNS(namespaceURI, localName, exceptioncode);
00234 if (exceptioncode)
00235 throw DOMException(exceptioncode);
00236 return ret;
00237 }
00238
00239 void Element::setAttributeNS( const DOMString &namespaceURI,
00240 const DOMString &qualifiedName,
00241 const DOMString &value)
00242 {
00243 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00244
00245 int exceptioncode = 0;
00246 static_cast<ElementImpl*>(impl)->setAttributeNS(namespaceURI, qualifiedName, value, exceptioncode);
00247 if ( exceptioncode )
00248 throw DOMException( exceptioncode );
00249 }
00250
00251 void Element::removeAttributeNS( const DOMString &namespaceURI,
00252 const DOMString &localName )
00253 {
00254 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00255
00256 int exceptioncode = 0;
00257 static_cast<ElementImpl*>(impl)->removeAttributeNS(namespaceURI, localName, exceptioncode);
00258 if ( exceptioncode )
00259 throw DOMException( exceptioncode );
00260 }
00261
00262 Attr Element::getAttributeNodeNS( const DOMString &namespaceURI,
00263 const DOMString &localName )
00264 {
00265 if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
00266
00267 int exceptioncode = 0;
00268 Attr r = static_cast<ElementImpl*>(impl)->getAttributeNodeNS(namespaceURI, localName, exceptioncode);
00269 if (exceptioncode)
00270 throw DOMException( exceptioncode );
00271 return r;
00272 }
00273
00274 Attr Element::setAttributeNodeNS( const Attr &newAttr )
00275 {
00276 if (!impl)
00277 throw DOMException(DOMException::NOT_FOUND_ERR);
00278
00279 int exceptioncode = 0;
00280 Attr r = static_cast<ElementImpl*>(impl)->setAttributeNodeNS(
00281 static_cast<AttrImpl*>(newAttr.handle()), exceptioncode);
00282 return r;
00283 }
00284
00285 bool Element::hasAttribute( const DOMString& name )
00286 {
00287 if (!impl) return false;
00288 return static_cast<ElementImpl*>(impl)->hasAttribute(name);
00289 }
00290
00291 bool Element::hasAttributeNS( const DOMString &namespaceURI,
00292 const DOMString &localName )
00293 {
00294 if (!impl) return false;
00295 return static_cast<ElementImpl*>(impl)->hasAttributeNS(namespaceURI, localName);
00296 }
00297
00298 bool Element::isHTMLElement() const
00299 {
00300 if(!impl) return false;
00301 return ((ElementImpl *)impl)->isHTMLElement();
00302 }
00303
00304 Element Element::form() const
00305 {
00306 if (!impl || !impl->isGenericFormElement()) return 0;
00307 return static_cast<HTMLGenericFormElementImpl*>(impl)->form();
00308 ElementImpl* f = static_cast<HTMLGenericFormElementImpl*>( impl )->form();
00309
00310 if( f && f->implicitNode() )
00311 return 0;
00312 return f;
00313 }
00314
00315 CSSStyleDeclaration Element::style()
00316 {
00317 if (impl) return ((ElementImpl *)impl)->getInlineStyleDecls();
00318 return 0;
00319 }
00320
00321 bool Element::contentEditable() const {
00322 if(!impl) return false;
00323 return static_cast<ElementImpl *>(impl)->contentEditable();
00324 }
00325
00326 void Element::setContentEditable(bool enabled) {
00327 if(!impl)
00328 throw DOMException(DOMException::INVALID_STATE_ERR);
00329
00330 static_cast<ElementImpl *>(impl)->setContentEditable(enabled);
00331 }
00332
00333 bool Element::khtmlValidAttrName(const DOMString &name)
00334 {
00335
00336
00337 DOMStringImpl* _name = name.implementation();
00338 QChar ch = _name->s[0];
00339 if ( !ch.isLetter() && ch != '_' && ch != ':' )
00340 return false;
00341 for ( uint i = 0; i < _name->l; ++i )
00342 {
00343 ch = _name->s[i];
00344 if ( !ch.isLetter() && !ch.isDigit() && ch != '.'
00345 && ch != '-' && ch != '_' && ch != ':'
00346 && ch.category() != QChar::Mark_SpacingCombining
00347 )
00348 return false;
00349 }
00350 return true;
00351 }
00352
00353 bool Element::khtmlValidPrefix(const DOMString &name)
00354 {
00355
00356 return !name.implementation() || khtmlValidAttrName(name);
00357 }
00358
00359 bool Element::khtmlValidQualifiedName(const DOMString &name)
00360 {
00361 return khtmlValidAttrName(name);
00362 }
00363
00364 bool Element::khtmlMalformedQualifiedName(const DOMString &name)
00365 {
00366
00367
00368
00369 if (name.isNull())
00370 return true;
00371 if (name.isEmpty())
00372 return false;
00373
00374
00375
00376 int colonpos = name.find(':');
00377 if (colonpos == 0 || colonpos == name.length() - 1)
00378 return true;
00379
00380 return false;
00381 }
00382
00383 bool Element::khtmlMalformedPrefix(const DOMString &)
00384 {
00385
00386 return false;
00387 }