dom_elementimpl.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _DOM_ELEMENTImpl_h_
00027 #define _DOM_ELEMENTImpl_h_
00028
00029 #include "dom_nodeimpl.h"
00030 #include "dom/dom_element.h"
00031 #include "xml/dom_stringimpl.h"
00032 #include "misc/shared.h"
00033
00034 namespace khtml {
00035 class CSSStyleSelector;
00036 }
00037
00038 namespace DOM {
00039
00040 class ElementImpl;
00041 class DocumentImpl;
00042 class NamedAttrMapImpl;
00043
00044
00045
00046
00047
00048
00049 class AttributeImpl : public khtml::Shared<AttributeImpl>
00050 {
00051 friend class NamedAttrMapImpl;
00052 friend class ElementImpl;
00053 friend class AttrImpl;
00054
00055 public:
00056
00057 AttributeImpl(NodeImpl::Id id, DOMStringImpl* value)
00058 : m_id(id), _prefix(0), _value(value), _impl(0)
00059 { _value->ref(); };
00060 ~AttributeImpl() {
00061 if (_prefix) _prefix->deref();
00062 if (_value) _value->deref();
00063
00064 }
00065
00066 DOMString value() const { return _value; }
00067 DOMStringImpl* val() const { return _value; }
00068 DOMStringImpl* prefix() const { return _prefix; }
00069 NodeImpl::Id id() const { return m_id; }
00070 AttrImpl* attrImpl() const { return _impl; }
00071
00072 private:
00073
00074 void setValue(DOMStringImpl* value) {
00075 _value->deref();
00076 _value = value;
00077 _value->ref();
00078 }
00079 void setPrefix(DOMStringImpl* prefix) {
00080 if (_prefix) _prefix->deref();
00081 _prefix = prefix;
00082 if (_prefix) _prefix->ref();
00083 }
00084 void allocateImpl(ElementImpl* e);
00085 void detachImpl();
00086
00087 protected:
00088 NodeImpl::Id m_id;
00089 DOMStringImpl *_prefix;
00090 DOMStringImpl *_value;
00091 AttrImpl* _impl;
00092 };
00093
00094
00095
00096
00097
00098
00099 class AttrImpl : public NodeBaseImpl
00100 {
00101 friend class ElementImpl;
00102 friend class NamedAttrMapImpl;
00103
00104 public:
00105 AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a);
00106 ~AttrImpl();
00107
00108 private:
00109 AttrImpl(const AttrImpl &other);
00110 AttrImpl &operator = (const AttrImpl &other);
00111 public:
00112
00113
00114 bool specified() const { return m_specified; }
00115 ElementImpl* ownerElement() const { return m_element; }
00116 void setOwnerElement( ElementImpl* impl ) { m_element = impl; }
00117 AttributeImpl* attrImpl() const { return m_attribute; }
00118
00119
00120 void setValue( const DOMString &v, int &exceptioncode );
00121
00122
00123 virtual DOMString nodeName() const;
00124 virtual unsigned short nodeType() const;
00125 virtual DOMString prefix() const;
00126 virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );
00127
00128 virtual DOMString nodeValue() const;
00129 virtual void setNodeValue( const DOMString &, int &exceptioncode );
00130 virtual NodeImpl *cloneNode ( bool deep );
00131
00132
00133 virtual bool isAttributeNode() const { return true; }
00134 virtual bool childAllowed( NodeImpl *newChild );
00135 virtual bool childTypeAllowed( unsigned short type );
00136
00137 protected:
00138 ElementImpl* m_element;
00139 AttributeImpl* m_attribute;
00140 };
00141
00142
00143 class ElementImpl : public NodeBaseImpl
00144 {
00145 friend class DocumentImpl;
00146 friend class NamedAttrMapImpl;
00147 friend class AttrImpl;
00148 friend class NodeImpl;
00149 friend class khtml::CSSStyleSelector;
00150 public:
00151 ElementImpl(DocumentPtr *doc);
00152 ~ElementImpl();
00153
00154 DOMString getAttribute( NodeImpl::Id id ) const;
00155 void setAttribute( NodeImpl::Id id, DOMStringImpl* value, int &exceptioncode );
00156 void removeAttribute( NodeImpl::Id id, int &exceptioncode );
00157
00158 DOMString prefix() const { return m_prefix; }
00159 void setPrefix(const DOMString &_prefix, int &exceptioncode );
00160
00161
00162 virtual DOMString tagName() const;
00163 virtual unsigned short nodeType() const;
00164 virtual NodeImpl *cloneNode ( bool deep );
00165 virtual DOMString nodeName() const;
00166 virtual bool isElementNode() const { return true; }
00167
00168
00169 void setAttribute (NodeImpl::Id id, const DOMString &value);
00170
00171 NamedAttrMapImpl* attributes(bool readonly = false) const
00172 {
00173 if (!readonly && !namedAttrMap) createAttributeMap();
00174 return namedAttrMap;
00175 }
00176
00177
00178 virtual void parseAttribute(AttributeImpl *) {}
00179
00180
00181 void setAttributeMap ( NamedAttrMapImpl* list );
00182
00183
00184 virtual QString state() { return QString::null; }
00185
00186 virtual void attach();
00187 virtual void recalcStyle( StyleChange = NoChange );
00188
00189 virtual void mouseEventHandler( MouseEvent *, bool ) {};
00190 virtual bool isSelectable() const;
00191 virtual bool childAllowed( NodeImpl *newChild );
00192 virtual bool childTypeAllowed( unsigned short type );
00193
00194 DOM::CSSStyleDeclarationImpl *styleRules() {
00195 if (!m_styleDecls) createDecl();
00196 return m_styleDecls;
00197 }
00198
00199 void dispatchAttrRemovalEvent(AttributeImpl *attr);
00200 void dispatchAttrAdditionEvent(AttributeImpl *attr);
00201
00202 #ifndef NDEBUG
00203 virtual void dump(QTextStream *stream, QString ind = "") const;
00204 #endif
00205
00206 protected:
00207 void createAttributeMap() const;
00208 void createDecl();
00209
00210 private:
00211
00212
00213
00214 virtual NamedAttrMapImpl* defaultMap() const;
00215
00216 protected:
00217 mutable NamedAttrMapImpl *namedAttrMap;
00218
00219 DOM::CSSStyleDeclarationImpl *m_styleDecls;
00220 DOMStringImpl *m_prefix;
00221 };
00222
00223
00224 class XMLElementImpl : public ElementImpl
00225 {
00226
00227 public:
00228 XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_tagName);
00229 XMLElementImpl(DocumentPtr *doc, Id id);
00230 XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_qualifiedName, DOMStringImpl *_namespaceURI);
00231 ~XMLElementImpl();
00232
00233
00234
00235 virtual DOMString localName() const;
00236 virtual NodeImpl *cloneNode ( bool deep );
00237
00238
00239 virtual bool isXMLElementNode() const { return true; }
00240 virtual Id id() const { return m_id; }
00241
00242 protected:
00243 Id m_id;
00244 };
00245
00246
00247 class NamedAttrMapImpl : public NamedNodeMapImpl
00248 {
00249 friend class ElementImpl;
00250 public:
00251 NamedAttrMapImpl(ElementImpl *e);
00252 virtual ~NamedAttrMapImpl();
00253 NamedAttrMapImpl(const NamedAttrMapImpl&);
00254 NamedAttrMapImpl &operator =(const NamedAttrMapImpl &other);
00255
00256
00257 virtual AttrImpl *getNamedItem ( NodeImpl::Id id ) const;
00258 virtual Node removeNamedItem ( NodeImpl::Id id, int &exceptioncode );
00259 virtual Node setNamedItem ( NodeImpl* arg, int &exceptioncode );
00260
00261 virtual AttrImpl *item ( unsigned long index ) const;
00262 virtual unsigned long length( ) const;
00263
00264
00265 virtual NodeImpl::Id mapId(const DOMString& namespaceURI, const DOMString& localName, bool readonly);
00266 AttributeImpl* attributeItem(unsigned long index) const { return m_attrs ? m_attrs[index] : 0; }
00267 AttributeImpl* getAttributeItem(NodeImpl::Id id) const;
00268 virtual bool isReadOnly() { return m_element ? m_element->isReadOnly() : false; }
00269
00270
00271
00272 void insertAttribute(AttributeImpl* newAttribute) {
00273 if (!getAttributeItem(newAttribute->id()))
00274 addAttribute(newAttribute);
00275 else
00276 newAttribute->deref();
00277 }
00278
00279 private:
00280
00281 void addAttribute(AttributeImpl* newAttribute);
00282
00283 void removeAttribute(NodeImpl::Id id);
00284 void clearAttributes();
00285 void detachFromElement();
00286
00287 protected:
00288 ElementImpl *m_element;
00289 AttributeImpl **m_attrs;
00290 uint m_len;
00291 };
00292
00293 }
00294
00295 #endif
This file is part of the documentation for kdelibs Version 3.1.5.