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
00086 protected:
00087 NodeImpl::Id m_id;
00088 DOMStringImpl *_prefix;
00089 DOMStringImpl *_value;
00090 AttrImpl* _impl;
00091 };
00092
00093
00094
00095
00096
00097
00098 class AttrImpl : public NodeBaseImpl
00099 {
00100 friend class ElementImpl;
00101 friend class NamedAttrMapImpl;
00102
00103 public:
00104 AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a);
00105 ~AttrImpl();
00106
00107 private:
00108 AttrImpl(const AttrImpl &other);
00109 AttrImpl &operator = (const AttrImpl &other);
00110 public:
00111
00112
00113 bool specified() const { return m_specified; }
00114 ElementImpl* ownerElement() const { return m_element; }
00115 AttributeImpl* attrImpl() const { return m_attribute; }
00116
00117
00118 void setValue( const DOMString &v, int &exceptioncode );
00119
00120
00121 virtual DOMString nodeName() const;
00122 virtual unsigned short nodeType() const;
00123 virtual DOMString prefix() const;
00124 virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );
00125
00126 virtual DOMString nodeValue() const;
00127 virtual void setNodeValue( const DOMString &, int &exceptioncode );
00128 virtual NodeImpl *cloneNode ( bool deep );
00129
00130
00131 virtual bool isAttributeNode() const { return true; }
00132 virtual bool childAllowed( NodeImpl *newChild );
00133 virtual bool childTypeAllowed( unsigned short type );
00134
00135 protected:
00136 ElementImpl* m_element;
00137 AttributeImpl* m_attribute;
00138 };
00139
00140
00141 class ElementImpl : public NodeBaseImpl
00142 {
00143 friend class DocumentImpl;
00144 friend class NamedAttrMapImpl;
00145 friend class AttrImpl;
00146 friend class NodeImpl;
00147 friend class khtml::CSSStyleSelector;
00148 public:
00149 ElementImpl(DocumentPtr *doc);
00150 ~ElementImpl();
00151
00152 DOMString getAttribute( NodeImpl::Id id ) const;
00153 void setAttribute( NodeImpl::Id id, DOMStringImpl* value, int &exceptioncode );
00154 void removeAttribute( NodeImpl::Id id, int &exceptioncode );
00155
00156 DOMString prefix() const { return m_prefix; }
00157 void setPrefix(const DOMString &_prefix, int &exceptioncode );
00158
00159
00160 virtual DOMString tagName() const;
00161 virtual unsigned short nodeType() const;
00162 virtual NodeImpl *cloneNode ( bool deep );
00163 virtual DOMString nodeName() const;
00164 virtual bool isElementNode() const { return true; }
00165
00166
00167 void setAttribute (NodeImpl::Id id, const DOMString &value);
00168
00169 NamedAttrMapImpl* attributes(bool readonly = false) const
00170 {
00171 if (!readonly && !namedAttrMap) createAttributeMap();
00172 return namedAttrMap;
00173 }
00174
00175
00176 virtual void parseAttribute(AttributeImpl *) {}
00177
00178
00179 void setAttributeMap ( NamedAttrMapImpl* list );
00180
00181
00182 virtual QString state() { return QString::null; }
00183
00184 virtual void attach();
00185 virtual void recalcStyle( StyleChange = NoChange );
00186
00187 virtual void mouseEventHandler( MouseEvent *, bool ) {};
00188 virtual bool isSelectable() const;
00189 virtual bool childAllowed( NodeImpl *newChild );
00190 virtual bool childTypeAllowed( unsigned short type );
00191
00192 DOM::CSSStyleDeclarationImpl *styleRules() {
00193 if (!m_styleDecls) createDecl();
00194 return m_styleDecls;
00195 }
00196
00197 void dispatchAttrRemovalEvent(AttributeImpl *attr);
00198 void dispatchAttrAdditionEvent(AttributeImpl *attr);
00199
00200 #ifndef NDEBUG
00201 virtual void dump(QTextStream *stream, QString ind = "") const;
00202 #endif
00203
00204 protected:
00205 void createAttributeMap() const;
00206 void createDecl();
00207
00208 private:
00209
00210
00211
00212 virtual NamedAttrMapImpl* defaultMap() const;
00213
00214 protected:
00215 mutable NamedAttrMapImpl *namedAttrMap;
00216
00217 DOM::CSSStyleDeclarationImpl *m_styleDecls;
00218 DOMStringImpl *m_prefix;
00219 };
00220
00221
00222 class XMLElementImpl : public ElementImpl
00223 {
00224
00225 public:
00226 XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_tagName);
00227 XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_qualifiedName, DOMStringImpl *_namespaceURI);
00228 ~XMLElementImpl();
00229
00230
00231
00232 virtual DOMString localName() const;
00233 virtual NodeImpl *cloneNode ( bool deep );
00234
00235
00236 virtual bool isXMLElementNode() const { return true; }
00237 virtual Id id() const { return m_id; }
00238
00239 protected:
00240 Id m_id;
00241 };
00242
00243
00244 class NamedAttrMapImpl : public NamedNodeMapImpl
00245 {
00246 friend class ElementImpl;
00247 public:
00248 NamedAttrMapImpl(ElementImpl *e);
00249 virtual ~NamedAttrMapImpl();
00250 NamedAttrMapImpl(const NamedAttrMapImpl&);
00251 NamedAttrMapImpl &operator =(const NamedAttrMapImpl &other);
00252
00253
00254 virtual AttrImpl *getNamedItem ( NodeImpl::Id id ) const;
00255 virtual Node removeNamedItem ( NodeImpl::Id id, int &exceptioncode );
00256 virtual Node setNamedItem ( NodeImpl* arg, int &exceptioncode );
00257
00258 virtual AttrImpl *item ( unsigned long index ) const;
00259 virtual unsigned long length( ) const;
00260
00261
00262 virtual NodeImpl::Id mapId(const DOMString& namespaceURI, const DOMString& localName, bool readonly);
00263 AttributeImpl* attributeItem(unsigned long index) const { return attrs ? attrs[index] : 0; }
00264 AttributeImpl* getAttributeItem(NodeImpl::Id id) const;
00265 virtual bool isReadOnly() { return element ? element->isReadOnly() : false; }
00266
00267
00268
00269 void insertAttribute(AttributeImpl* newAttribute) {
00270 if (!getAttributeItem(newAttribute->id()))
00271 addAttribute(newAttribute);
00272 else
00273 newAttribute->deref();
00274 }
00275
00276 private:
00277
00278 void addAttribute(AttributeImpl* newAttribute);
00279
00280 void removeAttribute(NodeImpl::Id id);
00281 void clearAttributes();
00282 void detachFromElement();
00283
00284 protected:
00285 ElementImpl *element;
00286 AttributeImpl **attrs;
00287 uint len;
00288 };
00289
00290 };
00291
00292 #endif
This file is part of the documentation for kdelibs Version 3.1.0.