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 #ifndef _DOM_DocumentImpl_h_
00026 #define _DOM_DocumentImpl_h_
00027
00028 #include "xml/dom_elementimpl.h"
00029 #include "xml/dom_textimpl.h"
00030 #include "xml/dom2_traversalimpl.h"
00031 #include "misc/shared.h"
00032
00033 #include <qstringlist.h>
00034 #include <qptrlist.h>
00035 #include <qobject.h>
00036 #include <qdict.h>
00037 #include <qmap.h>
00038
00039 #include <kurl.h>
00040
00041 class QPaintDevice;
00042 class QTextCodec;
00043 class QPaintDeviceMetrics;
00044 class KHTMLView;
00045 class Tokenizer;
00046
00047 namespace khtml {
00048 class CSSStyleSelector;
00049 class DocLoader;
00050 class CSSStyleSelectorList;
00051 }
00052
00053 namespace DOM {
00054
00055 class AbstractViewImpl;
00056 class AttrImpl;
00057 class CDATASectionImpl;
00058 class CSSStyleSheetImpl;
00059 class CommentImpl;
00060 class DocumentFragmentImpl;
00061 class DocumentImpl;
00062 class DocumentType;
00063 class DocumentTypeImpl;
00064 class ElementImpl;
00065 class EntityReferenceImpl;
00066 class EventImpl;
00067 class EventListener;
00068 class GenericRONamedNodeMapImpl;
00069 class HTMLDocumentImpl;
00070 class HTMLElementImpl;
00071 class NodeFilter;
00072 class NodeFilterImpl;
00073 class NodeIteratorImpl;
00074 class NodeListImpl;
00075 class ProcessingInstructionImpl;
00076 class RangeImpl;
00077 class RegisteredEventListener;
00078 class StyleSheetImpl;
00079 class StyleSheetListImpl;
00080 class TextImpl;
00081 class TreeWalkerImpl;
00082
00083 class DOMImplementationImpl : public khtml::Shared<DOMImplementationImpl>
00084 {
00085 public:
00086 DOMImplementationImpl();
00087 ~DOMImplementationImpl();
00088
00089
00090 bool hasFeature ( const DOMString &feature, const DOMString &version );
00091 DocumentTypeImpl *createDocumentType( const DOMString &qualifiedName, const DOMString &publicId,
00092 const DOMString &systemId, int &exceptioncode );
00093 DocumentImpl *createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
00094 const DocumentType &doctype, int &exceptioncode );
00095
00096 DOMImplementationImpl* getInterface(const DOMString& feature) const;
00097
00098
00099 CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media, int &exceptioncode);
00100
00101
00102 HTMLDocumentImpl* createHTMLDocument( const DOMString& title);
00103
00104
00105 DocumentImpl *createDocument( KHTMLView *v = 0 );
00106 HTMLDocumentImpl *createHTMLDocument( KHTMLView *v = 0 );
00107
00108
00109
00110 static DOMImplementationImpl *instance();
00111
00112 protected:
00113 static DOMImplementationImpl *m_instance;
00114 };
00115
00116
00120 class DocumentImpl : public QObject, public NodeBaseImpl
00121 {
00122 Q_OBJECT
00123 public:
00124 DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v);
00125 ~DocumentImpl();
00126
00127
00128
00129 DocumentTypeImpl *doctype() const;
00130
00131 DOMImplementationImpl *implementation() const;
00132 ElementImpl *documentElement() const;
00133 virtual ElementImpl *createElement ( const DOMString &tagName );
00134 DocumentFragmentImpl *createDocumentFragment ();
00135 TextImpl *createTextNode ( DOMStringImpl* data ) { return new TextImpl( docPtr(), data); }
00136 TextImpl *createTextNode ( const QString& data )
00137 { return createTextNode(new DOMStringImpl(data.unicode(), data.length())); }
00138 CommentImpl *createComment ( DOMStringImpl* data );
00139 CDATASectionImpl *createCDATASection ( DOMStringImpl* data );
00140 ProcessingInstructionImpl *createProcessingInstruction ( const DOMString &target, DOMStringImpl* data );
00141 Attr createAttribute(NodeImpl::Id id);
00142 EntityReferenceImpl *createEntityReference ( const DOMString &name );
00143 NodeImpl *importNode( NodeImpl *importedNode, bool deep, int &exceptioncode );
00144 virtual ElementImpl *createElementNS ( const DOMString &_namespaceURI, const DOMString &_qualifiedName );
00145 ElementImpl *getElementById ( const DOMString &elementId ) const;
00146
00147
00148 DOMString title() const { return m_title; }
00149 void setTitle(DOMString _title);
00150
00151
00152
00153 virtual DOMString nodeName() const;
00154 virtual unsigned short nodeType() const;
00155
00156
00157 virtual bool isDocumentNode() const { return true; }
00158 virtual bool isHTMLDocument() const { return false; }
00159
00160 virtual ElementImpl *createHTMLElement ( const DOMString &tagName );
00161
00162 khtml::CSSStyleSelector *styleSelector() { return m_styleSelector; }
00163
00173 void updateStyleSelector();
00174
00175 void recalcStyleSelector();
00176
00177 QString nextState();
00178
00179
00180 QStringList docState();
00181 void registerMaintainsState(NodeImpl* e) { m_maintainsState.append(e); }
00182 void deregisterMaintainsState(NodeImpl* e) { m_maintainsState.removeRef(e); }
00183
00184
00185 void setRestoreState( const QStringList &s) { m_state = s; }
00186
00187 KHTMLView *view() const { return m_view; }
00188
00189 RangeImpl *createRange();
00190
00191 NodeIteratorImpl *createNodeIterator(NodeImpl *root, unsigned long whatToShow,
00192 NodeFilter &filter, bool entityReferenceExpansion, int &exceptioncode);
00193
00194 TreeWalkerImpl *createTreeWalker(Node root, unsigned long whatToShow, NodeFilter &filter,
00195 bool entityReferenceExpansion);
00196
00197 virtual void recalcStyle( StyleChange = NoChange );
00198 static QPtrList<DocumentImpl> * changedDocuments;
00199 virtual void updateRendering();
00200 static void updateDocumentsRendering();
00201 khtml::DocLoader *docLoader() { return m_docLoader; }
00202
00203 virtual void attach();
00204 virtual void detach();
00205
00206
00207 void setVisuallyOrdered();
00208
00209 void setDecoderCodec(const QTextCodec *codec);
00210
00211 void setSelection(NodeImpl* s, int sp, NodeImpl* e, int ep);
00212 void clearSelection();
00213
00214 void open ( );
00215 virtual void close ( );
00216 void write ( const DOMString &text );
00217 void write ( const QString &text );
00218 void writeln ( const DOMString &text );
00219 void finishParsing ( );
00220
00221 QString URL() const { return m_url; }
00222 void setURL(QString url) { m_url = url; }
00223
00224 QString baseURL() const { return m_baseURL.isEmpty() ? m_url : m_baseURL; }
00225 void setBaseURL(const QString& baseURL) { m_baseURL = baseURL; }
00226
00227 QString baseTarget() const { return m_baseTarget; }
00228 void setBaseTarget(const QString& baseTarget) { m_baseTarget = baseTarget; }
00229
00230 QString completeURL(const QString& url) const { return KURL(baseURL(),url,m_decoderMibEnum).url(); };
00231
00232
00233 virtual void setStyleSheet(const DOM::DOMString &url, const DOM::DOMString &sheetStr);
00234 void setUserStyleSheet(const QString& sheet);
00235 QString userStyleSheet() const { return m_usersheet; }
00236 void setPrintStyleSheet(const QString& sheet) { m_printSheet = sheet; }
00237 QString printStyleSheet() const { return m_printSheet; }
00238
00239 CSSStyleSheetImpl* elementSheet();
00240 virtual Tokenizer *createTokenizer();
00241 Tokenizer *tokenizer() { return m_tokenizer; }
00242
00243 QPaintDeviceMetrics *paintDeviceMetrics() { return m_paintDeviceMetrics; }
00244 QPaintDevice *paintDevice() const { return m_paintDevice; }
00245 void setPaintDevice( QPaintDevice *dev );
00246
00247 enum HTMLMode {
00248 Html3 = 0,
00249 Html4 = 1,
00250 XHtml = 2
00251 };
00252
00253 enum ParseMode {
00254 Unknown,
00255 Compat,
00256 Transitional,
00257 Strict
00258 };
00259 virtual void determineParseMode( const QString &str );
00260 void setParseMode( ParseMode m ) { pMode = m; }
00261 ParseMode parseMode() const { return pMode; }
00262
00263 void setHTMLMode( HTMLMode m ) { hMode = m; }
00264 HTMLMode htmlMode() const { return hMode; }
00265
00266 void setParsing(bool b) { m_bParsing = b; }
00267 bool parsing() const { return m_bParsing; }
00268
00269 void setTextColor( QColor color ) { m_textColor = color; }
00270 QColor textColor() const { return m_textColor; }
00271
00272
00273 NodeImpl *findElement( Id id );
00274
00275 bool prepareMouseEvent( bool readonly, int x, int y, MouseEvent *ev );
00276
00277 virtual bool childAllowed( NodeImpl *newChild );
00278 virtual bool childTypeAllowed( unsigned short nodeType );
00279 virtual NodeImpl *cloneNode ( bool deep );
00280
00281
00282
00283
00284 NodeImpl::Id tagId(DOMStringImpl* _namespaceURI, DOMStringImpl *_name, bool readonly);
00285 DOMString tagName(NodeImpl::Id _id) const;
00286
00287 NodeImpl::Id attrId(DOMStringImpl* _namespaceURI, DOMStringImpl *_name, bool readonly);
00288 DOMString attrName(NodeImpl::Id _id) const;
00289
00290
00291
00292 DOMStringImpl* namespaceURI(NodeImpl::Id _id) const;
00293
00294 StyleSheetListImpl* styleSheets();
00295
00296 QStringList availableStyleSheets() const;
00297 NodeImpl *focusNode() const { return m_focusNode; }
00298 void setFocusNode(NodeImpl *newFocusNode);
00299
00300 bool isDocumentChanged() { return m_docChanged; }
00301 virtual void setDocumentChanged(bool = true);
00302 void attachNodeIterator(NodeIteratorImpl *ni);
00303 void detachNodeIterator(NodeIteratorImpl *ni);
00304 void notifyBeforeNodeRemoval(NodeImpl *n);
00305 AbstractViewImpl *defaultView() const;
00306 EventImpl *createEvent(const DOMString &eventType, int &exceptioncode);
00307
00308
00309
00310 enum ListenerType {
00311 DOMSUBTREEMODIFIED_LISTENER = 0x01,
00312 DOMNODEINSERTED_LISTENER = 0x02,
00313 DOMNODEREMOVED_LISTENER = 0x04,
00314 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 0x08,
00315 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
00316 DOMATTRMODIFIED_LISTENER = 0x20,
00317 DOMCHARACTERDATAMODIFIED_LISTENER = 0x40
00318 };
00319
00320 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
00321 void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
00322
00323 CSSStyleDeclarationImpl *getOverrideStyle(ElementImpl *elt, DOMStringImpl *pseudoElt);
00324
00325 typedef QMap<QString, ProcessingInstructionImpl*> LocalStyleRefs;
00326 LocalStyleRefs* localStyleRefs() { return &m_localStyleRefs; }
00327
00328 virtual void defaultEventHandler(EventImpl *evt);
00329 virtual void setWindowEventListener(int id, EventListener *listener);
00330 EventListener *getWindowEventListener(int id);
00331 virtual void removeWindowEventListener(int id);
00332 EventListener *createHTMLEventListener(QString code);
00333
00345 NodeImpl *nextFocusNode(NodeImpl *fromNode);
00346
00358 NodeImpl *previousFocusNode(NodeImpl *fromNode);
00359
00360 int nodeAbsIndex(NodeImpl *node);
00361 NodeImpl *nodeWithAbsIndex(int absIndex);
00362
00372 void processHttpEquiv(const DOMString &equiv, const DOMString &content);
00373 bool isURLAllowed(const QString& url) const;
00374
00375 signals:
00376 void finishedParsing();
00377
00378 protected:
00379 khtml::CSSStyleSelector *m_styleSelector;
00380 KHTMLView *m_view;
00381 QStringList m_state;
00382
00383 khtml::DocLoader *m_docLoader;
00384 Tokenizer *m_tokenizer;
00385 QString m_url;
00386 QString m_baseURL;
00387 QString m_baseTarget;
00388
00389 DocumentTypeImpl *m_doctype;
00390 DOMImplementationImpl *m_implementation;
00391
00392 StyleSheetImpl *m_sheet;
00393 QString m_usersheet;
00394 QString m_printSheet;
00395 QStringList m_availableSheets;
00396
00397 CSSStyleSheetImpl *m_elemSheet;
00398
00399 QPaintDevice *m_paintDevice;
00400 QPaintDeviceMetrics *m_paintDeviceMetrics;
00401 ParseMode pMode;
00402 HTMLMode hMode;
00403
00404 QColor m_textColor;
00405 NodeImpl *m_focusNode;
00406
00407
00408
00409 DOMStringImpl **m_elementNames;
00410 unsigned short m_elementNameAlloc;
00411 unsigned short m_elementNameCount;
00412
00413 DOMStringImpl **m_attrNames;
00414 unsigned short m_attrNameAlloc;
00415 unsigned short m_attrNameCount;
00416
00417 DOMStringImpl** m_namespaceURIs;
00418 unsigned short m_namespaceURIAlloc;
00419 unsigned short m_namespaceURICount;
00420
00421 QPtrList<NodeIteratorImpl> m_nodeIterators;
00422 AbstractViewImpl *m_defaultView;
00423
00424 unsigned short m_listenerTypes;
00425 StyleSheetListImpl* m_styleSheets;
00426 LocalStyleRefs m_localStyleRefs;
00427 QPtrList<RegisteredEventListener> m_windowEventListeners;
00428 QPtrList<NodeImpl> m_maintainsState;
00429
00430 bool m_loadingSheet;
00431 bool visuallyOrdered;
00432 bool m_bParsing;
00433 bool m_docChanged;
00434 bool m_styleSelectorDirty;
00435 bool m_inStyleRecalc;
00436
00437 DOMString m_title;
00438 int m_decoderMibEnum;
00439 };
00440
00441 class DocumentFragmentImpl : public NodeBaseImpl
00442 {
00443 public:
00444 DocumentFragmentImpl(DocumentPtr *doc);
00445 DocumentFragmentImpl(const DocumentFragmentImpl &other);
00446
00447
00448 virtual DOMString nodeName() const;
00449 virtual unsigned short nodeType() const;
00450 virtual NodeImpl *cloneNode ( bool deep );
00451
00452
00453 virtual bool childTypeAllowed( unsigned short type );
00454 };
00455
00456
00457 class DocumentTypeImpl : public NodeImpl
00458 {
00459 public:
00460 DocumentTypeImpl(DOMImplementationImpl *_implementation, DocumentPtr *doc,
00461 const DOMString &qualifiedName, const DOMString &publicId,
00462 const DOMString &systemId);
00463 ~DocumentTypeImpl();
00464
00465
00466 NamedNodeMapImpl *entities() const { return m_entities; }
00467 NamedNodeMapImpl *notations() const { return m_notations; }
00468
00469 DOMString name() const { return m_qualifiedName; }
00470 DOMString publicId() const { return m_publicId; }
00471 DOMString systemId() const { return m_systemId; }
00472 DOMString internalSubset() const { return m_subset; }
00473
00474
00475 virtual DOMString nodeName() const;
00476 virtual unsigned short nodeType() const;
00477 virtual bool childTypeAllowed( unsigned short type );
00478 virtual NodeImpl *cloneNode ( bool deep );
00479
00480
00481 void setName(const DOMString& n) { m_qualifiedName = n; }
00482 DOMImplementationImpl *implementation() const { return m_implementation; }
00483 void copyFrom(const DocumentTypeImpl&);
00484
00485 protected:
00486 DOMImplementationImpl *m_implementation;
00487 NamedNodeMapImpl* m_entities;
00488 NamedNodeMapImpl* m_notations;
00489
00490 DOMString m_qualifiedName;
00491 DOMString m_publicId;
00492 DOMString m_systemId;
00493 DOMString m_subset;
00494 };
00495
00496 };
00497 #endif