KHTML
html_element.cpp
Go to the documentation of this file.
00001 00022 #include "dom/dom_exception.h" 00023 #include "dom/html_misc.h" 00024 #include "css/css_base.h" 00025 #include "html/html_miscimpl.h" // HTMLCollectionImpl 00026 00027 using namespace DOM; 00028 00029 HTMLElement::HTMLElement() : Element() 00030 { 00031 } 00032 00033 HTMLElement::HTMLElement(const HTMLElement &other) : Element(other) 00034 { 00035 } 00036 00037 HTMLElement::HTMLElement(HTMLElementImpl *impl) : Element(impl) 00038 { 00039 } 00040 00041 HTMLElement &HTMLElement::operator = (const HTMLElement &other) 00042 { 00043 Element::operator = (other); 00044 return *this; 00045 } 00046 00047 HTMLElement &HTMLElement::operator = (const Node &other) 00048 { 00049 NodeImpl* ohandle = other.handle(); 00050 if (!ohandle || !ohandle->isHTMLElement()) { 00051 if (impl) impl->deref(); 00052 impl = 0; 00053 return *this; 00054 } 00055 Node::operator = (other); 00056 return *this; 00057 } 00058 00059 HTMLElement::~HTMLElement() 00060 { 00061 } 00062 00063 DOMString HTMLElement::id() const 00064 { 00065 if(!impl) return DOMString(); 00066 return ((ElementImpl *)impl)->getAttribute(ATTR_ID); 00067 } 00068 00069 void HTMLElement::setId( const DOMString &value ) 00070 { 00071 if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_ID, value); 00072 } 00073 00074 DOMString HTMLElement::title() const 00075 { 00076 if(!impl) return DOMString(); 00077 return ((ElementImpl *)impl)->getAttribute(ATTR_TITLE); 00078 } 00079 00080 void HTMLElement::setTitle( const DOMString &value ) 00081 { 00082 if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_TITLE, value); 00083 } 00084 00085 DOMString HTMLElement::lang() const 00086 { 00087 if(!impl) return DOMString(); 00088 return ((ElementImpl *)impl)->getAttribute(ATTR_LANG); 00089 } 00090 00091 void HTMLElement::setLang( const DOMString &value ) 00092 { 00093 if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_LANG, value); 00094 } 00095 00096 DOMString HTMLElement::dir() const 00097 { 00098 if(!impl) return DOMString(); 00099 return ((ElementImpl *)impl)->getAttribute(ATTR_DIR); 00100 } 00101 00102 void HTMLElement::setDir( const DOMString &value ) 00103 { 00104 if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_DIR, value); 00105 } 00106 00107 DOMString HTMLElement::className() const 00108 { 00109 if(!impl) return DOMString(); 00110 return ((ElementImpl *)impl)->getAttribute(ATTR_CLASS); 00111 } 00112 00113 void HTMLElement::setClassName( const DOMString &value ) 00114 { 00115 if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_CLASS, value); 00116 } 00117 00118 void HTMLElement::removeCSSProperty( const DOMString &property ) 00119 { 00120 int id = getPropertyID(property.string().toLower().toAscii().constData(), property.length()); 00121 if(id && impl) 00122 static_cast<HTMLElementImpl*>(impl)->removeCSSProperty(id); 00123 } 00124 00125 void HTMLElement::addCSSProperty( const DOMString &property, const DOMString &value ) 00126 { 00127 int id = getPropertyID(property.string().toLower().toAscii().constData(), property.length()); 00128 if(id && impl) 00129 static_cast<HTMLElementImpl*>(impl)->addCSSProperty(id, value); 00130 } 00131 00132 DOMString HTMLElement::innerHTML() const 00133 { 00134 if ( !impl ) return DOMString(); 00135 return ((HTMLElementImpl *)impl)->innerHTML(); 00136 } 00137 00138 void HTMLElement::setInnerHTML( const DOMString &html ) 00139 { 00140 if( !impl ) 00141 return; 00142 int exceptioncode = 0; 00143 ((HTMLElementImpl *)impl)->setInnerHTML( html, exceptioncode ); 00144 if ( exceptioncode ) 00145 throw DOMException( exceptioncode ); 00146 } 00147 00148 DOMString HTMLElement::innerText() const 00149 { 00150 if ( !impl ) return DOMString(); 00151 return ((HTMLElementImpl *)impl)->innerText(); 00152 } 00153 00154 void HTMLElement::setInnerText( const DOMString &text ) 00155 { 00156 if( !impl ) 00157 return; 00158 int exceptioncode = 0; 00159 ((HTMLElementImpl *)impl)->setInnerText( text, exceptioncode ); 00160 if ( exceptioncode ) 00161 throw DOMException( exceptioncode ); 00162 } 00163 00164 HTMLCollection HTMLElement::children() const 00165 { 00166 if(!impl) return HTMLCollection(); 00167 return HTMLCollection(impl, HTMLCollectionImpl::NODE_CHILDREN); 00168 } 00169 00170 HTMLCollection HTMLElement::all() const 00171 { 00172 if(!impl) return HTMLCollection(); 00173 return HTMLCollection(impl, HTMLCollectionImpl::DOC_ALL /*it's called "doc" but it works from any node */); 00174 } 00175 00176 void HTMLElement::assignOther( const Node &other, int elementId ) 00177 { 00178 if (other.elementId() != static_cast<quint32>(elementId)) { 00179 if ( impl ) impl->deref(); 00180 impl = 0; 00181 } else { 00182 Node::operator = (other); 00183 } 00184 } 00185 00186 bool HTMLElement::isContentEditable() const 00187 { 00188 if(!impl) return false; 00189 return static_cast<HTMLElementImpl *>(impl)->isContentEditable(); 00190 } 00191 00192 DOMString HTMLElement::contentEditable() const { 00193 if(!impl) return "inherit"; 00194 return static_cast<HTMLElementImpl *>(impl)->contentEditable(); 00195 } 00196 00197 void HTMLElement::setContentEditable(const DOMString &enabled) { 00198 if(!impl) 00199 throw DOMException(DOMException::INVALID_STATE_ERR); 00200 static_cast<HTMLElementImpl *>(impl)->setContentEditable(enabled); 00201 }
KDE 4.6 API Reference