KHtml

html_element.cpp
1 
22 #include "dom/dom_exception.h"
23 #include "dom/html_misc.h"
24 #include "css/css_base.h"
25 #include "html/html_miscimpl.h" // HTMLCollectionImpl
26 
27 using namespace DOM;
28 
29 HTMLElement::HTMLElement() : Element()
30 {
31 }
32 
33 HTMLElement::HTMLElement(const HTMLElement &other) : Element(other)
34 {
35 }
36 
37 HTMLElement::HTMLElement(HTMLElementImpl *impl) : Element(impl)
38 {
39 }
40 
41 HTMLElement &HTMLElement::operator = (const HTMLElement &other)
42 {
43  Element::operator = (other);
44  return *this;
45 }
46 
47 HTMLElement &HTMLElement::operator = (const Node &other)
48 {
49  NodeImpl *ohandle = other.handle();
50  if (!ohandle || !ohandle->isHTMLElement()) {
51  if (impl) {
52  impl->deref();
53  }
54  impl = nullptr;
55  return *this;
56  }
57  Node::operator = (other);
58  return *this;
59 }
60 
61 HTMLElement::~HTMLElement()
62 {
63 }
64 
66 {
67  if (!impl) {
68  return DOMString();
69  }
70  return ((ElementImpl *)impl)->getAttribute(ATTR_ID);
71 }
72 
73 void HTMLElement::setId(const DOMString &value)
74 {
75  if (impl) {
76  ((ElementImpl *)impl)->setAttribute(ATTR_ID, value);
77  }
78 }
79 
81 {
82  if (!impl) {
83  return DOMString();
84  }
85  return ((ElementImpl *)impl)->getAttribute(ATTR_TITLE);
86 }
87 
88 void HTMLElement::setTitle(const DOMString &value)
89 {
90  if (impl) {
91  ((ElementImpl *)impl)->setAttribute(ATTR_TITLE, value);
92  }
93 }
94 
96 {
97  if (!impl) {
98  return DOMString();
99  }
100  return ((ElementImpl *)impl)->getAttribute(ATTR_LANG);
101 }
102 
103 void HTMLElement::setLang(const DOMString &value)
104 {
105  if (impl) {
106  ((ElementImpl *)impl)->setAttribute(ATTR_LANG, value);
107  }
108 }
109 
111 {
112  if (!impl) {
113  return DOMString();
114  }
115  return ((ElementImpl *)impl)->getAttribute(ATTR_DIR);
116 }
117 
118 void HTMLElement::setDir(const DOMString &value)
119 {
120  if (impl) {
121  ((ElementImpl *)impl)->setAttribute(ATTR_DIR, value);
122  }
123 }
124 
126 {
127  if (!impl) {
128  return DOMString();
129  }
130  return ((ElementImpl *)impl)->getAttribute(ATTR_CLASS);
131 }
132 
134 {
135  if (impl) {
136  ((ElementImpl *)impl)->setAttribute(ATTR_CLASS, value);
137  }
138 }
139 
140 void HTMLElement::removeCSSProperty(const DOMString &property)
141 {
142  int id = getPropertyID(property.string().toLower().toLatin1().constData(), property.length());
143  if (id && impl) {
144  static_cast<HTMLElementImpl *>(impl)->removeCSSProperty(id);
145  }
146 }
147 
148 void HTMLElement::addCSSProperty(const DOMString &property, const DOMString &value)
149 {
150  int id = getPropertyID(property.string().toLower().toLatin1().constData(), property.length());
151  if (id && impl) {
152  static_cast<HTMLElementImpl *>(impl)->addCSSProperty(id, value);
153  }
154 }
155 
157 {
158  if (!impl) {
159  return DOMString();
160  }
161  return ((HTMLElementImpl *)impl)->innerHTML();
162 }
163 
165 {
166  if (!impl) {
167  return;
168  }
169  int exceptioncode = 0;
170  ((HTMLElementImpl *)impl)->setInnerHTML(html, exceptioncode);
171  if (exceptioncode) {
172  throw DOMException(exceptioncode);
173  }
174 }
175 
177 {
178  if (!impl) {
179  return DOMString();
180  }
181  return ((HTMLElementImpl *)impl)->innerText();
182 }
183 
185 {
186  if (!impl) {
187  return;
188  }
189  int exceptioncode = 0;
190  ((HTMLElementImpl *)impl)->setInnerText(text, exceptioncode);
191  if (exceptioncode) {
192  throw DOMException(exceptioncode);
193  }
194 }
195 
197 {
198  if (!impl) {
199  return HTMLCollection();
200  }
201  return HTMLCollection(impl, HTMLCollectionImpl::NODE_CHILDREN);
202 }
203 
205 {
206  if (!impl) {
207  return HTMLCollection();
208  }
209  return HTMLCollection(impl, HTMLCollectionImpl::DOC_ALL /*it's called "doc" but it works from any node */);
210 }
211 
212 void HTMLElement::assignOther(const Node &other, int elementId)
213 {
214  if (other.elementId() != static_cast<quint32>(elementId)) {
215  if (impl) {
216  impl->deref();
217  }
218  impl = nullptr;
219  } else {
220  Node::operator = (other);
221  }
222 }
223 
225 {
226  if (!impl) {
227  return false;
228  }
229  return static_cast<HTMLElementImpl *>(impl)->isContentEditable();
230 }
231 
233 {
234  if (!impl) {
235  return "inherit";
236  }
237  return static_cast<HTMLElementImpl *>(impl)->contentEditable();
238 }
239 
241 {
242  if (!impl) {
243  throw DOMException(DOMException::INVALID_STATE_ERR);
244  }
245  static_cast<HTMLElementImpl *>(impl)->setContentEditable(enabled);
246 }
void setContentEditable(const DOMString &enabled)
Sets the editability of this element.
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:278
DOMString lang() const
Language code defined in RFC 1766.
void setTitle(const DOMString &)
see title
void setClassName(const DOMString &)
see className
DOMString dir() const
Specifies the base direction of directionally neutral text and the directionality of tables...
DOMString innerText() const
The text contained in this element.
void setInnerText(const DOMString &text)
Set the text content of this node.
DOMString innerHTML() const
The HTML code contained in this element.
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
void setId(const DOMString &)
see id
void setDir(const DOMString &)
see dir
An HTMLCollection is a list of nodes.
Definition: html_misc.h:133
By far the vast majority of objects (apart from text) that authors encounter when traversing a docume...
Definition: dom_element.h:212
const char * constData() const const
void setInnerHTML(const DOMString &html)
Set the HTML content of this node.
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
HTMLCollection all() const
Retrieves a collection of all nodes that descend from this node.
DOMString id() const
The element&#39;s identifier.
QString toLower() const const
This library provides a full-featured HTML parser and widget.
QByteArray toLatin1() const const
DOMString contentEditable() const
Returns the kind of editability that applies to this element.
quint32 elementId() const
Definition: dom_node.cpp:509
NodeImpl * handle() const
Definition: dom_node.h:936
void setLang(const DOMString &)
see lang
DOMString className() const
The class attribute of the element.
All HTML element interfaces derive from this class.
Definition: html_element.h:70
DOMString title() const
The element&#39;s advisory title.
bool isContentEditable() const
Returns whether this element is editable.
HTMLCollection children() const
Retrieves a collection of nodes that are direct descendants of this node.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:48:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.