dom_elementimpl.h Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# dom_elementimpl.h

    00001 /*
    00002  * This file is part of the DOM implementation for KDE.
    00003  *
    00004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    00005  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    00006  *           (C) 2001 Peter Kelly (pmk@post.com)
    00007  *           (C) 2001 Dirk Mueller (mueller@kde.org)
    00008  *
    00009  * This library is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU Library General Public
    00011  * License as published by the Free Software Foundation; either
    00012  * version 2 of the License, or (at your option) any later version.
    00013  *
    00014  * This library is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00017  * Library General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU Library General Public License
    00020  * along with this library; see the file COPYING.LIB.  If not, write to
    00021  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00022  * Boston, MA 02111-1307, USA.
    00023  *
    00024  * $Id: dom_elementimpl.h,v 1.101.2.7 2003/06/30 11:30:26 faure Exp $
    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 // this has no counterpart in DOM, purely internal
    00045 // representation of the nodevalue of an Attr.
    00046 // the actual Attr (AttrImpl) with its value as textchild
    00047 // is only allocated on demand by the DOM bindings.
    00048 // Any use of AttrImpl inside khtml should be avoided.
    00049 class AttributeImpl : public khtml::Shared<AttributeImpl>
    00050 {
    00051     friend class NamedAttrMapImpl;
    00052     friend class ElementImpl;
    00053     friend class AttrImpl;
    00054
    00055 public:
    00056     // null value is forbidden !
    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         // assert : _impl == 0
    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     // null pointers can never happen here
    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 // Attr can have Text and EntityReference children
    00095 // therefore it has to be a fullblown Node. The plan
    00096 // is to dynamically allocate a textchild and store the
    00097 // resulting nodevalue in the AttributeImpl upon
    00098 // destruction. however, this is not yet implemented.
    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     // DOM methods & attributes for Attr
    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     //DOMString value() const;
    00120     void setValue( const DOMString &v, int &exceptioncode );
    00121
    00122     // DOM methods overridden from  parent classes
    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     // Other methods (not part of DOM)
    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     // DOM methods overridden from  parent classes
    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     // convenience methods which ignore exceptions
    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     //This is always called, whenever an attribute changed
    00178     virtual void parseAttribute(AttributeImpl *) {}
    00179
    00180     // not part of the DOM
    00181     void setAttributeMap ( NamedAttrMapImpl* list );
    00182
    00183     // State of the element.
    00184     virtual QString state() { return QString::null; }
    00185
    00186     virtual void attach();
    00187     virtual void recalcStyle( StyleChange = NoChange );
    00188
    00189     virtual void mouseEventHandler( MouseEvent */*ev*/, bool /*inside*/ ) {};
    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     // map of default attributes. derived element classes are responsible
    00212     // for setting this according to the corresponding element description
    00213     // in the DTD
    00214     virtual NamedAttrMapImpl* defaultMap() const;
    00215
    00216 protected: // member variables
    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     // DOM methods overridden from  parent classes
    00234
    00235     virtual DOMString localName() const;
    00236     virtual NodeImpl *cloneNode ( bool deep );
    00237
    00238     // Other methods (not part of DOM)
    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 // the map of attributes of an element
    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     // DOM methods & attributes for NamedNodeMap
    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     // Other methods (not part of DOM)
    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     // used during parsing: only inserts if not already there
    00271     // no error checking!
    00272     void insertAttribute(AttributeImpl* newAttribute) {
    00273         if (!getAttributeItem(newAttribute->id()))
    00274             addAttribute(newAttribute);
    00275         else
    00276             newAttribute->deref();
    00277     }
    00278
    00279 private:
    00280     // this method is internal, does no error checking at all
    00281     void addAttribute(AttributeImpl* newAttribute);
    00282     // this method is internal, does no error checking at all
    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 } //namespace
    00294
    00295 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:43 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001