📄 dom_docimpl.h
字号:
/* * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) * (C) 2002-2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#ifndef _DOM_DocumentImpl_h_#define _DOM_DocumentImpl_h_#include "xml/dom_elementimpl.h"#include "xml/dom_textimpl.h"#include "xml/dom2_traversalimpl.h"#include "misc/shared.h"#include "misc/loader.h"#include <qstringlist.h>#include <qptrlist.h>#include <qobject.h>#include <qintcache.h>#include <qintdict.h>#include <qdict.h>#include <qmap.h>#include <kurl.h>class QPaintDevice;class QTextCodec;class QPaintDeviceMetrics;class KHTMLView;namespace khtml { class Tokenizer; class CSSStyleSelector; class DocLoader; class CSSStyleSelectorList; class RenderArena; class RenderObject; class CounterNode; class CachedObject; class CachedCSSStyleSheet;}namespace DOM { class AbstractViewImpl; class AttrImpl; class CDATASectionImpl; class CSSStyleSheetImpl; class CommentImpl; class DocumentFragmentImpl; class DocumentImpl; class DocumentType; class DocumentTypeImpl; class ElementImpl; class EntityReferenceImpl; class EventImpl; class EventListener; class GenericRONamedNodeMapImpl; class HTMLDocumentImpl; class HTMLElementImpl; class HTMLImageElementImpl; class NodeFilter; class NodeFilterImpl; class NodeIteratorImpl; class NodeListImpl; class ProcessingInstructionImpl; class RangeImpl; class RegisteredEventListener; class StyleSheetImpl; class StyleSheetListImpl; class TextImpl; class TreeWalkerImpl;class DOMImplementationImpl : public khtml::Shared<DOMImplementationImpl>{public: DOMImplementationImpl(); ~DOMImplementationImpl(); // DOM methods & attributes for DOMImplementation bool hasFeature ( const DOMString &feature, const DOMString &version ); DocumentTypeImpl *createDocumentType( const DOMString &qualifiedName, const DOMString &publicId, const DOMString &systemId, int &exceptioncode ); DocumentImpl *createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName, const DocumentType &doctype, int &exceptioncode ); DOMImplementationImpl* getInterface(const DOMString& feature) const; // From the DOMImplementationCSS interface CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media, int &exceptioncode); // From the HTMLDOMImplementation interface HTMLDocumentImpl* createHTMLDocument( const DOMString& title); // Other methods (not part of DOM) DocumentImpl *createDocument( KHTMLView *v = 0 ); HTMLDocumentImpl *createHTMLDocument( KHTMLView *v = 0 ); // Returns the static instance of this class - only one instance of this class should // ever be present, and is used as a factory method for creating DocumentImpl objects static DOMImplementationImpl *instance();protected: static DOMImplementationImpl *m_instance;};/** * @internal A cache of element name (or id) to pointer * ### KDE4, QHash: better to store values here */class ElementMappingCache{public: /** For each name, we hold a reference count, and a pointer. If the item is in the table, which implies reference count is > 1, the name is a valid key. If the pointer is non-null, it points to the appropriate mapping */ struct ItemInfo { int ref; ElementImpl* nd; }; ElementMappingCache(); /** Add a pointer as just one of candidates, not neccesserily the proper one */ void add(const QString& id, ElementImpl* nd); /** Set the pointer as the definite mapping; it must have already been added */ void set(const QString& id, ElementImpl* nd); /** Remove the item; it must have already been added. */ void remove(const QString& id, ElementImpl* nd); /** Returns true if the item exists */ bool contains(const QString& id); /** Returns the information for the given ID */ ItemInfo* get(const QString& id);private: QDict<ItemInfo> m_dict;};/** * @internal */class DocumentImpl : public QObject, private khtml::CachedObjectClient, public NodeBaseImpl{ Q_OBJECTpublic: DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v); ~DocumentImpl(); // DOM methods & attributes for Document DocumentTypeImpl *doctype() const; DOMImplementationImpl *implementation() const; ElementImpl *documentElement() const; virtual ElementImpl *createElement ( const DOMString &tagName, int* pExceptioncode = 0 ); virtual AttrImpl *createAttribute( const DOMString &tagName, int* pExceptioncode = 0 ); DocumentFragmentImpl *createDocumentFragment (); TextImpl *createTextNode ( DOMStringImpl* data ) { return new TextImpl( docPtr(), data); } TextImpl *createTextNode ( const QString& data ) { return createTextNode(new DOMStringImpl(data.unicode(), data.length())); } CommentImpl *createComment ( DOMStringImpl* data ); CDATASectionImpl *createCDATASection ( DOMStringImpl* data ); ProcessingInstructionImpl *createProcessingInstruction ( const DOMString &target, DOMStringImpl* data ); EntityReferenceImpl *createEntityReference ( const DOMString &name ); NodeImpl *importNode( NodeImpl *importedNode, bool deep, int &exceptioncode ); virtual ElementImpl *createElementNS ( const DOMString &_namespaceURI, const DOMString &_qualifiedName, int* pExceptioncode = 0 ); virtual AttrImpl *createAttributeNS( const DOMString &_namespaceURI, const DOMString &_qualifiedName, int* pExceptioncode = 0 ); ElementImpl *getElementById ( const DOMString &elementId ) const; // Actually part of HTMLDocument, but used for giving XML documents a window title as well DOMString title() const { return m_title; } void setTitle(const DOMString& _title); // DOM methods overridden from parent classes virtual DOMString nodeName() const; virtual unsigned short nodeType() const; // Other methods (not part of DOM) virtual bool isDocumentNode() const { return true; } virtual bool isHTMLDocument() const { return false; } virtual ElementImpl *createHTMLElement ( const DOMString &tagName ); khtml::CSSStyleSelector *styleSelector() { return m_styleSelector; } /** * Updates the pending sheet count and then calls updateStyleSelector. */ void styleSheetLoaded(); /** * This method returns true if all top-level stylesheets have loaded (including * any @imports that they may be loading). */ bool haveStylesheetsLoaded() { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets; } /** * Increments the number of pending sheets. The <link> elements * invoke this to add themselves to the loading list. */ void addPendingSheet() { m_pendingStylesheets++; } /** * Returns true if the document has pending stylesheets * loading. */ bool hasPendingSheets() const { return m_pendingStylesheets; } /** * Called when one or more stylesheets in the document may have been added, removed or changed. * * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is * constructed from these which is used to create the a new style selector which collates all of the stylesheets * found and is used to calculate the derived styles for all rendering objects. */ void updateStyleSelector(); void recalcStyleSelector(); bool usesDescendantRules() { return m_usesDescendantRules; } void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; } QString nextState(); // Query all registered elements for their state QStringList docState(); bool unsubmittedFormChanges(); void registerMaintainsState(NodeImpl* e) { m_maintainsState.append(e); } void deregisterMaintainsState(NodeImpl* e) { m_maintainsState.removeRef(e); } // Set the state the document should restore to void setRestoreState( const QStringList &s) { m_state = s; } KHTMLView *view() const { return m_view; } KHTMLPart* part() const; RangeImpl *createRange(); NodeIteratorImpl *createNodeIterator(NodeImpl *root, unsigned long whatToShow, NodeFilter &filter, bool entityReferenceExpansion, int &exceptioncode); TreeWalkerImpl *createTreeWalker(NodeImpl *root, unsigned long whatToShow, NodeFilterImpl *filter, bool entityReferenceExpansion, int &exceptioncode); virtual void recalcStyle( StyleChange = NoChange ); static QPtrList<DocumentImpl> * changedDocuments; virtual void updateRendering(); void updateLayout(); static void updateDocumentsRendering(); khtml::DocLoader *docLoader() { return m_docLoader; } virtual void attach(); virtual void detach(); khtml::RenderArena* renderArena() { return m_renderArena; } // to get visually ordered hebrew and arabic pages right void setVisuallyOrdered(); // to get URL decoding right void setDecoderCodec(const QTextCodec *codec); void setSelection(NodeImpl* s, int sp, NodeImpl* e, int ep); void clearSelection(); void open ( bool clearEventListeners = true ); virtual void close ( ); void write ( const DOMString &text ); void write ( const QString &text ); void writeln ( const DOMString &text ); void finishParsing ( ); KURL URL() const { return m_url; } void setURL(const QString& url) { m_url = url; } KURL baseURL() const { return m_baseURL.isEmpty() ? m_url : m_baseURL; } void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; } QString baseTarget() const { return m_baseTarget; } void setBaseTarget(const QString& baseTarget) { m_baseTarget = baseTarget; } QString completeURL(const QString& url) const { return KURL(baseURL(),url,m_decoderMibEnum).url(); }; DOMString canonURL(const DOMString& url) const { return url.isEmpty() ? url : completeURL(url.string()); } void setUserStyleSheet(const QString& sheet); QString userStyleSheet() const { return m_usersheet; } void setPrintStyleSheet(const QString& sheet) { m_printSheet = sheet; } QString printStyleSheet() const { return m_printSheet; } CSSStyleSheetImpl* elementSheet(); virtual khtml::Tokenizer *createTokenizer(); khtml::Tokenizer *tokenizer() { return m_tokenizer; } QPaintDeviceMetrics *paintDeviceMetrics() { return m_paintDeviceMetrics; } QPaintDevice *paintDevice() const { return m_paintDevice; } void setPaintDevice( QPaintDevice *dev ); enum HTMLMode { Html3 = 0, Html4 = 1, XHtml = 2 }; enum ParseMode { Unknown, Compat, Transitional, Strict }; virtual void determineParseMode( const QString &str ); void setParseMode( ParseMode m ) { pMode = m; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -