/* * 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, 2009, 2010, 2012 Apple Inc. All rights reserved. * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2011 Google 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 "CollectionType.h" #include "Color.h" #include "ContainerNode.h" #include "DOMTimeStamp.h" #include "DocumentEventQueue.h" #include "DocumentTiming.h" #include "IconURL.h" #include "InspectorCounters.h" #include "IntRect.h" #include "LayoutTypes.h" #include "MutationObserver.h" #include "PageVisibilityState.h" #include "PlatformScreen.h" #include "QualifiedName.h" #include "ReferrerPolicy.h" #include "ScriptExecutionContext.h" #include "StringWithDirection.h" #include "Timer.h" #include "TreeScope.h" #include "ViewportArguments.h" #include #include #include #include #include namespace WebCore { class AXObjectCache; class Attr; class CDATASection; class CSSStyleDeclaration; class CSSStyleSheet; class CachedCSSStyleSheet; class CachedResourceLoader; class CachedScript; class CanvasRenderingContext; class CharacterData; class Comment; class ContextFeatures; class DOMImplementation; class DOMSelection; class DOMWindow; class Database; class DatabaseThread; class DocumentFragment; class DocumentLoader; class DocumentMarkerController; class DocumentParser; class DocumentType; class DocumentWeakReference; class DynamicNodeListCacheBase; class EditingText; class Element; class EntityReference; class Event; class EventListener; class FloatRect; class FloatQuad; class FontData; class FormController; class Frame; class FrameView; class HTMLCanvasElement; class HTMLCollection; class HTMLAllCollection; class HTMLDocument; class HTMLElement; class HTMLFrameOwnerElement; class HTMLHeadElement; class HTMLIFrameElement; class HTMLMapElement; class HTMLNameCollection; class HitTestRequest; class HitTestResult; class IntPoint; class DOMWrapperWorld; class JSNode; class MediaCanStartListener; class MediaQueryList; class MediaQueryMatcher; class MouseEventWithHitTestResults; class NodeFilter; class NodeIterator; class NodeRareData; class Page; class PlatformMouseEvent; class ProcessingInstruction; class Range; class RegisteredEventListener; class RenderArena; class RenderView; class RenderFullScreen; class ScriptableDocumentParser; class ScriptElementData; class ScriptRunner; class SecurityOrigin; class SelectorQueryCache; class SerializedScriptValue; class SegmentedString; class Settings; class StyleResolver; class StyleSheet; class StyleSheetContents; class StyleSheetList; class Text; class TextResourceDecoder; class TreeWalker; class UndoManager; class WebKitNamedFlow; class WebKitNamedFlowCollection; class XMLHttpRequest; class XPathEvaluator; class XPathExpression; class XPathNSResolver; class XPathResult; #if ENABLE(SVG) class SVGDocumentExtensions; #endif #if ENABLE(XSLT) class TransformSource; #endif #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) struct DashboardRegionValue; #endif #if ENABLE(TOUCH_EVENTS) class Touch; class TouchList; #endif #if ENABLE(REQUEST_ANIMATION_FRAME) class RequestAnimationFrameCallback; class ScriptedAnimationController; #endif #if ENABLE(MICRODATA) class MicroDataItemList; #endif #if ENABLE(LINK_PRERENDER) class Prerenderer; #endif #if ENABLE(TEXT_AUTOSIZING) class TextAutosizer; #endif #if ENABLE(CSP_NEXT) class DOMSecurityPolicy; #endif typedef int ExceptionCode; enum PageshowEventPersistence { PageshowEventNotPersisted = 0, PageshowEventPersisted = 1 }; enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded }; enum NodeListInvalidationType { DoNotInvalidateOnAttributeChanges = 0, InvalidateOnClassAttrChange, InvalidateOnIdNameAttrChange, InvalidateOnNameAttrChange, InvalidateOnForAttrChange, InvalidateForFormControls, InvalidateOnHRefAttrChange, InvalidateOnItemAttrChange, InvalidateOnAnyAttrChange, }; const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1; class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext { public: static PassRefPtr create(Frame* frame, const KURL& url) { return adoptRef(new Document(frame, url, false, false)); } static PassRefPtr createXHTML(Frame* frame, const KURL& url) { return adoptRef(new Document(frame, url, true, false)); } virtual ~Document(); MediaQueryMatcher* mediaQueryMatcher(); using ContainerNode::ref; using ContainerNode::deref; // Nodes belonging to this document hold guard 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 guardRef() { ASSERT(!m_deletionHasBegun); ++m_guardRefCount; } void guardDeref() { ASSERT(!m_deletionHasBegun); --m_guardRefCount; if (!m_guardRefCount && !refCount()) { #ifndef NDEBUG m_deletionHasBegun = true; #endif delete this; } } Element* getElementById(const AtomicString& id) const; virtual bool canContainRangeEndPoint() const { return true; } Element* getElementByAccessKey(const String& key); void invalidateAccessKeyMap(); SelectorQueryCache* selectorQueryCache(); // DOM methods & attributes for Document DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); DEFINE_ATTRIBUTE_EVENT_LISTENER(change); DEFINE_ATTRIBUTE_EVENT_LISTENER(click); DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu); DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick); DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter); DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover); DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave); DEFINE_ATTRIBUTE_EVENT_LISTENER(drop); DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart); DEFINE_ATTRIBUTE_EVENT_LISTENER(drag); DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend); DEFINE_ATTRIBUTE_EVENT_LISTENER(input); DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid); DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown); DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress); DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup); DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown); DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove); DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout); DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover); DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup); DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel); DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll); DEFINE_ATTRIBUTE_EVENT_LISTENER(select); DEFINE_ATTRIBUTE_EVENT_LISTENER(submit); DEFINE_ATTRIBUTE_EVENT_LISTENER(blur); DEFINE_ATTRIBUTE_EVENT_LISTENER(error); DEFINE_ATTRIBUTE_EVENT_LISTENER(focus); DEFINE_ATTRIBUTE_EVENT_LISTENER(load); DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange); // WebKit extensions DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut); DEFINE_ATTRIBUTE_EVENT_LISTENER(cut); DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy); DEFINE_ATTRIBUTE_EVENT_LISTENER(copy); DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste); DEFINE_ATTRIBUTE_EVENT_LISTENER(paste); DEFINE_ATTRIBUTE_EVENT_LISTENER(reset); DEFINE_ATTRIBUTE_EVENT_LISTENER(search); DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart); DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange); #if ENABLE(TOUCH_EVENTS) DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart); DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove); DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend); DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel); #endif #if ENABLE(FULLSCREEN_API) DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange); DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror); #endif #if ENABLE(POINTER_LOCK) DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockchange); DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockerror); #endif #if ENABLE(PAGE_VISIBILITY_API) DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange); #endif ViewportArguments viewportArguments() const { return m_viewportArguments; } #ifndef NDEBUG bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; } #endif void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; } ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } DocumentType* doctype() const { return m_docType.get(); } DOMImplementation* implementation(); Element* documentElement() const { return m_documentElement.get(); } 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&); PassRefPtr createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false); PassRefPtr createEntityReference(const String& name, ExceptionCode&); PassRefPtr importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); } PassRefPtr importNode(Node* importedNode, bool deep, ExceptionCode&); virtual PassRefPtr createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); PassRefPtr createElement(const QualifiedName&, bool createdByParser); bool cssRegionsEnabled() const; #if ENABLE(CSS_REGIONS) PassRefPtr webkitGetFlowByName(const String&); #endif WebKitNamedFlowCollection* namedFlows(); bool regionBasedColumnsEnabled() const; bool cssGridLayoutEnabled() const; /** * Retrieve all nodes that intersect a rect in the window's document, until it is fully enclosed by * the boundaries of a node. * * @param centerX x reference for the rectangle in CSS pixels * @param centerY y reference for the rectangle in CSS pixels * @param topPadding How much to expand the top of the rectangle * @param rightPadding How much to expand the right of the rectangle * @param bottomPadding How much to expand the bottom of the rectangle * @param leftPadding How much to expand the left of the rectangle * @param ignoreClipping whether or not to ignore the root scroll frame when retrieving the element. * If false, this method returns null for coordinates outside of the viewport. */ PassRefPtr nodesFromRect(int centerX, int centerY, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent) const; Element* elementFromPoint(int x, int y) const; PassRefPtr caretRangeFromPoint(int x, int y); String readyState() const; String defaultCharset() const; String inputEncoding() const { return Document::encoding(); } String charset() const { return Document::encoding(); } String characterSet() const { return Document::encoding(); } String encoding() const; void setCharset(const String&); void setContent(const String&); String suggestedMIMEType() const; String contentLanguage() const { return m_contentLanguage; } void setContentLanguage(const String&); String xmlEncoding() const { return m_xmlEncoding; } String xmlVersion() const { return m_xmlVersion; } enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone }; bool xmlStandalone() const { return m_xmlStandalone == Standalone; } StandaloneStatus xmlStandaloneStatus() const { return static_cast(m_xmlStandalone); } bool hasXMLDeclaration() const { return m_hasXMLDeclaration; } void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser void setXMLVersion(const String&, ExceptionCode&); void setXMLStandalone(bool, ExceptionCode&); void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; } String documentURI() const { return m_documentURI; } void setDocumentURI(const String&); virtual KURL baseURI() const; #if ENABLE(PAGE_VISIBILITY_API) String webkitVisibilityState() const; bool webkitHidden() const; void dispatchVisibilityStateChangeEvent(); #endif #if ENABLE(CSP_NEXT) DOMSecurityPolicy* securityPolicy(); #endif 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 objects(); PassRefPtr scripts(); PassRefPtr all(); void removeCachedHTMLCollection(HTMLCollection*, CollectionType); PassRefPtr windowNamedItems(const AtomicString& name); PassRefPtr documentNamedItems(const AtomicString& name); void removeWindowNamedItemCache(HTMLCollection*, const AtomicString&); void removeDocumentNamedItemCache(HTMLCollection*, const AtomicString&); // Other methods (not part of DOM) bool isHTMLDocument() const { return m_isHTML; } bool isXHTMLDocument() const { return m_isXHTML; } virtual bool isImageDocument() const { return false; } #if ENABLE(SVG) virtual bool isSVGDocument() const { return false; } bool hasSVGRootNode() const; #else static bool isSVGDocument() { return false; } static bool hasSVGRootNode() { return false; } #endif virtual bool isPluginDocument() const { return false; } virtual bool isMediaDocument() const { return false; } virtual bool isFrameSet() const { return false; } bool isSrcdocDocument() const { return m_isSrcdocDocument; } NodeRareData* documentRareData() const { return m_documentRareData; }; void setDocumentRareData(NodeRareData*); StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); } bool isViewSource() const { return m_isViewSource; } void setIsViewSource(bool); bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; } StyleResolver* styleResolver() { if (!m_styleResolver) createStyleResolver(); return m_styleResolver.get(); } /** * Updates the pending sheet count and then calls updateActiveStylesheets. */ enum RemovePendingSheetNotificationType { RemovePendingSheetNotifyImmediately, RemovePendingSheetNotifyLater }; void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately); void notifyRemovePendingSheetIfNeeded(); /** * 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; } /** * 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 resolver 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 * ,