File indexing completed on 2024-04-28 11:37:45

0001 /**
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright 1999 Lars Knoll (knoll@kde.org)
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 #include "dom/dom_exception.h"
0023 #include "dom/html_misc.h"
0024 #include "css/css_base.h"
0025 #include "html/html_miscimpl.h" // HTMLCollectionImpl
0026 
0027 using namespace DOM;
0028 
0029 HTMLElement::HTMLElement() : Element()
0030 {
0031 }
0032 
0033 HTMLElement::HTMLElement(const HTMLElement &other) : Element(other)
0034 {
0035 }
0036 
0037 HTMLElement::HTMLElement(HTMLElementImpl *impl) : Element(impl)
0038 {
0039 }
0040 
0041 HTMLElement &HTMLElement::operator = (const HTMLElement &other)
0042 {
0043     Element::operator = (other);
0044     return *this;
0045 }
0046 
0047 HTMLElement &HTMLElement::operator = (const Node &other)
0048 {
0049     NodeImpl *ohandle = other.handle();
0050     if (!ohandle || !ohandle->isHTMLElement()) {
0051         if (impl) {
0052             impl->deref();
0053         }
0054         impl = nullptr;
0055         return *this;
0056     }
0057     Node::operator = (other);
0058     return *this;
0059 }
0060 
0061 HTMLElement::~HTMLElement()
0062 {
0063 }
0064 
0065 DOMString HTMLElement::id() const
0066 {
0067     if (!impl) {
0068         return DOMString();
0069     }
0070     return ((ElementImpl *)impl)->getAttribute(ATTR_ID);
0071 }
0072 
0073 void HTMLElement::setId(const DOMString &value)
0074 {
0075     if (impl) {
0076         ((ElementImpl *)impl)->setAttribute(ATTR_ID, value);
0077     }
0078 }
0079 
0080 DOMString HTMLElement::title() const
0081 {
0082     if (!impl) {
0083         return DOMString();
0084     }
0085     return ((ElementImpl *)impl)->getAttribute(ATTR_TITLE);
0086 }
0087 
0088 void HTMLElement::setTitle(const DOMString &value)
0089 {
0090     if (impl) {
0091         ((ElementImpl *)impl)->setAttribute(ATTR_TITLE, value);
0092     }
0093 }
0094 
0095 DOMString HTMLElement::lang() const
0096 {
0097     if (!impl) {
0098         return DOMString();
0099     }
0100     return ((ElementImpl *)impl)->getAttribute(ATTR_LANG);
0101 }
0102 
0103 void HTMLElement::setLang(const DOMString &value)
0104 {
0105     if (impl) {
0106         ((ElementImpl *)impl)->setAttribute(ATTR_LANG, value);
0107     }
0108 }
0109 
0110 DOMString HTMLElement::dir() const
0111 {
0112     if (!impl) {
0113         return DOMString();
0114     }
0115     return ((ElementImpl *)impl)->getAttribute(ATTR_DIR);
0116 }
0117 
0118 void HTMLElement::setDir(const DOMString &value)
0119 {
0120     if (impl) {
0121         ((ElementImpl *)impl)->setAttribute(ATTR_DIR, value);
0122     }
0123 }
0124 
0125 DOMString HTMLElement::className() const
0126 {
0127     if (!impl) {
0128         return DOMString();
0129     }
0130     return ((ElementImpl *)impl)->getAttribute(ATTR_CLASS);
0131 }
0132 
0133 void HTMLElement::setClassName(const DOMString &value)
0134 {
0135     if (impl) {
0136         ((ElementImpl *)impl)->setAttribute(ATTR_CLASS, value);
0137     }
0138 }
0139 
0140 void HTMLElement::removeCSSProperty(const DOMString &property)
0141 {
0142     int id = getPropertyID(property.string().toLower().toLatin1().constData(), property.length());
0143     if (id && impl) {
0144         static_cast<HTMLElementImpl *>(impl)->removeCSSProperty(id);
0145     }
0146 }
0147 
0148 void HTMLElement::addCSSProperty(const DOMString &property, const DOMString &value)
0149 {
0150     int id = getPropertyID(property.string().toLower().toLatin1().constData(), property.length());
0151     if (id && impl) {
0152         static_cast<HTMLElementImpl *>(impl)->addCSSProperty(id, value);
0153     }
0154 }
0155 
0156 DOMString HTMLElement::innerHTML() const
0157 {
0158     if (!impl) {
0159         return DOMString();
0160     }
0161     return ((HTMLElementImpl *)impl)->innerHTML();
0162 }
0163 
0164 void HTMLElement::setInnerHTML(const DOMString &html)
0165 {
0166     if (!impl) {
0167         return;
0168     }
0169     int exceptioncode = 0;
0170     ((HTMLElementImpl *)impl)->setInnerHTML(html, exceptioncode);
0171     if (exceptioncode) {
0172         throw DOMException(exceptioncode);
0173     }
0174 }
0175 
0176 DOMString HTMLElement::innerText() const
0177 {
0178     if (!impl) {
0179         return DOMString();
0180     }
0181     return ((HTMLElementImpl *)impl)->innerText();
0182 }
0183 
0184 void HTMLElement::setInnerText(const DOMString &text)
0185 {
0186     if (!impl) {
0187         return;
0188     }
0189     int exceptioncode = 0;
0190     ((HTMLElementImpl *)impl)->setInnerText(text, exceptioncode);
0191     if (exceptioncode) {
0192         throw DOMException(exceptioncode);
0193     }
0194 }
0195 
0196 HTMLCollection HTMLElement::children() const
0197 {
0198     if (!impl) {
0199         return HTMLCollection();
0200     }
0201     return HTMLCollection(impl, HTMLCollectionImpl::NODE_CHILDREN);
0202 }
0203 
0204 HTMLCollection HTMLElement::all() const
0205 {
0206     if (!impl) {
0207         return HTMLCollection();
0208     }
0209     return HTMLCollection(impl, HTMLCollectionImpl::DOC_ALL /*it's called "doc" but it works from any node */);
0210 }
0211 
0212 void HTMLElement::assignOther(const Node &other, int elementId)
0213 {
0214     if (other.elementId() != static_cast<quint32>(elementId)) {
0215         if (impl) {
0216             impl->deref();
0217         }
0218         impl = nullptr;
0219     } else {
0220         Node::operator = (other);
0221     }
0222 }
0223 
0224 bool HTMLElement::isContentEditable() const
0225 {
0226     if (!impl) {
0227         return false;
0228     }
0229     return static_cast<HTMLElementImpl *>(impl)->isContentEditable();
0230 }
0231 
0232 DOMString HTMLElement::contentEditable() const
0233 {
0234     if (!impl) {
0235         return "inherit";
0236     }
0237     return static_cast<HTMLElementImpl *>(impl)->contentEditable();
0238 }
0239 
0240 void HTMLElement::setContentEditable(const DOMString &enabled)
0241 {
0242     if (!impl) {
0243         throw DOMException(DOMException::INVALID_STATE_ERR);
0244     }
0245     static_cast<HTMLElementImpl *>(impl)->setContentEditable(enabled);
0246 }