/* * 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, 2008 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef Document_h #define Document_h #include "Attr.h" #include "Color.h" #include "DeprecatedPtrList.h" #include "DocumentMarker.h" #include "HTMLCollection.h" #include "HTMLFormElement.h" #include "KURL.h" #include "ScriptExecutionContext.h" #include "StringHash.h" #include "Timer.h" #include #include // FIXME: We should move Mac off of the old Frame-based user stylesheet loading // code and onto the new code in Page. We can't do that until the code in Page // supports non-file: URLs, however. #if PLATFORM(MAC) || PLATFORM(QT) #define FRAME_LOADS_USER_STYLESHEET 1 #else #define FRAME_LOADS_USER_STYLESHEET 0 #endif namespace WebCore { class AXObjectCache; class Attr; class Attribute; class CDATASection; class CachedCSSStyleSheet; class CanvasRenderingContext2D; class CharacterData; class CSSStyleDeclaration; class CSSStyleSelector; class CSSStyleSheet; class Comment; class Database; class DOMImplementation; class DOMSelection; class DOMWindow; class DatabaseThread; class DocLoader; class DocumentFragment; class DocumentType; class EditingText; class Element; class EntityReference; class Event; class EventListener; class Frame; class FrameView; class HTMLCanvasElement; class HTMLDocument; class HTMLElement; class HTMLFormControlElementWithState; class HTMLFormElement; class HTMLHeadElement; class HTMLInputElement; class HTMLMapElement; class ImageLoader; class IntPoint; class JSNode; class MouseEventWithHitTestResults; class NodeFilter; class NodeIterator; class Page; class PlatformMouseEvent; class ProcessingInstruction; class Range; class RegisteredEventListener; class RenderArena; class SecurityOrigin; class Settings; class StyleSheet; class StyleSheetList; class Text; class TextResourceDecoder; class Tokenizer; class TreeWalker; class XMLHttpRequest; #if ENABLE(SVG) class SVGDocumentExtensions; #endif #if ENABLE(XBL) class XBLBindingManager; #endif #if ENABLE(XPATH) class XPathEvaluator; class XPathExpression; class XPathNSResolver; class XPathResult; #endif #if ENABLE(DASHBOARD_SUPPORT) struct DashboardRegionValue; #endif struct HitTestRequest; 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; } // Hash table deleted values, which are only constructed and never copied or destroyed. FormElementKey(WTF::HashTableDeletedValueType) : m_name(hashTableDeletedValue()) { } bool isHashTableDeletedValue() const { return m_name == hashTableDeletedValue(); } private: void ref() const; void deref() const; static AtomicStringImpl* hashTableDeletedValue() { return reinterpret_cast(-1); } 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; } static const bool safeToCompareToEmptyOrDeleted = true; }; struct FormElementKeyHashTraits : WTF::GenericHashTraits { static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormElementKey(WTF::HashTableDeletedValue); } static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); } }; class Document : public ContainerNode, public ScriptExecutionContext { public: static PassRefPtr create(Frame* frame) { return new Document(frame, false); } static PassRefPtr createXHTML(Frame* frame) { return new Document(frame, true); } virtual ~Document(); virtual bool isDocument() const { return true; } using ContainerNode::ref; using ContainerNode::deref; 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() { ASSERT(!m_deletionHasBegun); ++m_selfOnlyRefCount; } void selfOnlyDeref() { ASSERT(!m_deletionHasBegun); --m_selfOnlyRefCount; if (!m_selfOnlyRefCount && !refCount()) { #ifndef NDEBUG m_deletionHasBegun = true; #endif delete this; } } // DOM methods & attributes for Document DocumentType* doctype() const { return m_docType.get(); } DOMImplementation* implementation() const; virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); Element* documentElement() const; virtual PassRefPtr createElement(const AtomicString& 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, true); } PassRefPtr createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false); 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; bool hasElementWithId(AtomicStringImpl* id) const; bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); } 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 contentLanguage() const { return m_contentLanguage; } void setContentLanguage(const String& lang) { m_contentLanguage = lang; } 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 { return m_documentURI; } void setDocumentURI(const String&); virtual KURL baseURI() const; PassRefPtr adoptNode(PassRefPtr source, ExceptionCode&); 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) { ASSERT(type >= HTMLCollection::FirstUnnamedDocumentCachedType); unsigned index = type - HTMLCollection::FirstUnnamedDocumentCachedType; ASSERT(index < HTMLCollection::NumUnnamedDocumentCachedTypes); return &m_collectionInfo[index]; } HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, const AtomicString& name); // DOM methods overridden from parent classes virtual String nodeName() const; virtual NodeType nodeType() const; // Other methods (not part of DOM) 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; } virtual bool isMediaDocument() 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 removePendingSheet(); /** * 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++; } void addStyleSheetCandidateNode(Node*, bool createdByParser); void removeStyleSheetCandidateNode(Node*); 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 * ,