/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) * (C) 2006 Alexey Proskuryakov (ap@webkit.org) * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. * * 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., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #ifndef Document_h #define Document_h #include "Attr.h" #include "Color.h" #include "DeprecatedPtrList.h" #include "DeprecatedValueList.h" #include "DocumentMarker.h" #include "HTMLCollection.h" #include "HTMLFormElement.h" #include "KURL.h" #include "StringHash.h" #include "Timer.h" #include #include namespace WebCore { class AXObjectCache; class Attr; class Attribute; class CDATASection; class CSSStyleDeclaration; class CSSStyleSelector; class CSSStyleSheet; class Comment; class DOMImplementation; class DOMWindow; class DocLoader; class DocumentFragment; class DocumentType; class EditingText; class Element; class EntityReference; class Event; class EventListener; class Frame; class FrameView; class HTMLDocument; class HTMLElement; class HTMLFormControlElementWithState; class HTMLFormElement; class HTMLHeadElement; class HTMLImageLoader; class HTMLInputElement; class HTMLMapElement; class IntPoint; class JSEditor; class MouseEventWithHitTestResults; class NameNodeList; class NodeFilter; class NodeIterator; class NodeList; class Page; class PlatformMouseEvent; class ProcessingInstruction; class Range; class RegisteredEventListener; class RenderArena; class Settings; class StyleSheet; class StyleSheetList; class Text; class TextResourceDecoder; class Tokenizer; class TreeWalker; #if ENABLE(XBL) class XBLBindingManager; #endif #if ENABLE(XPATH) class XPathEvaluator; class XPathExpression; class XPathNSResolver; class XPathResult; #endif struct DashboardRegionValue; struct HitTestRequest; #if ENABLE(SVG) class SVGDocumentExtensions; #endif typedef int ExceptionCode; class FormElementKey { public: FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0); ~FormElementKey(); FormElementKey(const FormElementKey&); FormElementKey& operator=(const FormElementKey&); AtomicStringImpl* name() const { return m_name; } AtomicStringImpl* type() const { return m_type; } private: void ref() const; void deref() const; AtomicStringImpl* m_name; AtomicStringImpl* m_type; }; inline bool operator==(const FormElementKey& a, const FormElementKey& b) { return a.name() == b.name() && a.type() == b.type(); } struct FormElementKeyHash { static unsigned hash(const FormElementKey&); static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; } }; struct FormElementKeyHashTraits : WTF::GenericHashTraits { static FormElementKey deletedValue(); }; class Document : public ContainerNode { public: Document(DOMImplementation*, Frame*, bool isXHTML = false); ~Document(); virtual void removedLastRef(); // Nodes belonging to this document hold "self-only" references - // these are enough to keep the document from being destroyed, but // not enough to keep it from removing its children. This allows a // node that outlives its document to still have a valid document // pointer without introducing reference cycles void selfOnlyRef() { ++m_selfOnlyRefCount; } void selfOnlyDeref() { --m_selfOnlyRefCount; if (!m_selfOnlyRefCount && !refCount()) delete this; } // DOM methods & attributes for Document virtual DocumentType* doctype() const; // May return 0 for HTML documents DocumentType* realDocType() const { return m_docType.get(); } DOMImplementation* implementation() const; virtual void childrenChanged(); Element* documentElement() const; virtual PassRefPtr createElement(const String& tagName, ExceptionCode&); PassRefPtr createDocumentFragment (); PassRefPtr createTextNode(const String& data); PassRefPtr createComment(const String& data); PassRefPtr createCDATASection(const String& data, ExceptionCode&); PassRefPtr createProcessingInstruction(const String& target, const String& data, ExceptionCode&); PassRefPtr createAttribute(const String& name, ExceptionCode& ec) { return createAttributeNS(String(), name, ec); } PassRefPtr createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); PassRefPtr createEntityReference(const String& name, ExceptionCode&); PassRefPtr importNode(Node* importedNode, bool deep, ExceptionCode&); virtual PassRefPtr createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); PassRefPtr createElement(const QualifiedName&, bool createdByParser, ExceptionCode& ec); Element* getElementById(const AtomicString&) const; Element* elementFromPoint(int x, int y) const; String readyState() const; String inputEncoding() const; String defaultCharset() const; String charset() const { return inputEncoding(); } String characterSet() const { return inputEncoding(); } void setCharset(const String&); String xmlEncoding() const { return m_xmlEncoding; } String xmlVersion() const { return m_xmlVersion; } bool xmlStandalone() const { return m_xmlStandalone; } void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLTokenizer void setXMLVersion(const String&, ExceptionCode&); void setXMLStandalone(bool, ExceptionCode&); String documentURI() const; void setDocumentURI(const String&); virtual String baseURI() const; PassRefPtr adoptNode(PassRefPtr source, ExceptionCode&); PassRefPtr getElementsByName(const String& elementName); // Actually part of JSHTMLDocument, but used for giving XML documents a window title as well String title() const { return m_title; } void setTitle(const String&, Element* titleElement = 0); void removeTitle(Element* titleElement); PassRefPtr images(); PassRefPtr embeds(); PassRefPtr plugins(); // an alias for embeds() required for the JS DOM bindings. PassRefPtr applets(); PassRefPtr links(); PassRefPtr forms(); PassRefPtr anchors(); PassRefPtr all(); PassRefPtr objects(); PassRefPtr scripts(); PassRefPtr windowNamedItems(const String& name); PassRefPtr documentNamedItems(const String& name); HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type) { if ((int)type < HTMLCollection::UnnamedCollectionTypes) return m_collectionInfo + type; return 0; } HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type type, const String& name); // DOM methods overridden from parent classes virtual String nodeName() const; virtual NodeType nodeType() const; // Other methods (not part of DOM) virtual bool isDocumentNode() const { return true; } virtual bool isHTMLDocument() const { return false; } virtual bool isImageDocument() const { return false; } #if ENABLE(SVG) virtual bool isSVGDocument() const { return false; } #endif virtual bool isPluginDocument() const { return false; } CSSStyleSelector* styleSelector() const { return m_styleSelector; } Element* getElementByAccessKey(const String& key) const; /** * 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() const { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets #if USE(LOW_BANDWIDTH_DISPLAY) || m_inLowBandwidthDisplay #endif ; } /** * Increments the number of pending sheets. The elements * invoke this to add themselves to the loading list. */ void addPendingSheet() { m_pendingStylesheets++; } bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; } void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; } /** * 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 in a HTML document), searching for stylesheets. Stylesheets can be contained in * ,