📄 document.h
字号:
/* * 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 Apple Inc. All rights reserved. * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * * 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 "DocumentMarker.h"#include "HTMLCollection.h"#include "HTMLFormElement.h"#include "ScriptExecutionContext.h"#include "StringHash.h"#include "Timer.h"#include <wtf/HashCountedSet.h>#include <wtf/ListHashSet.h>// 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#endifnamespace 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 FormControlElementWithState; class Frame; class FrameView; class HitTestRequest; class HTMLCanvasElement; class HTMLDocument; class HTMLElement; 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 RenderView; class SecurityOrigin; class SegmentedString; 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 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<AtomicStringImpl*>(-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<FormElementKey> { 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<Document> create(Frame* frame) { return new Document(frame, false); } static PassRefPtr<Document> 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 { if (!m_documentElement) cacheDocumentElement(); return m_documentElement.get(); } virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&); PassRefPtr<DocumentFragment> createDocumentFragment (); PassRefPtr<Text> createTextNode(const String& data); PassRefPtr<Comment> createComment(const String& data); PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&); PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&); PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode& ec) { return createAttributeNS(String(), name, ec, true); } PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false); PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&); PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&); virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser); 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 defaultCharset() const; // Synonyms backing similar DOM attributes. Use Document::encoding() to avoid virtual dispatch. String inputEncoding() const { return Document::encoding(); } String charset() const { return Document::encoding(); } String characterSet() const { return Document::encoding(); } 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<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&); PassRefPtr<HTMLCollection> images(); PassRefPtr<HTMLCollection> embeds(); PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings. PassRefPtr<HTMLCollection> applets(); PassRefPtr<HTMLCollection> links(); PassRefPtr<HTMLCollection> forms(); PassRefPtr<HTMLCollection> anchors(); PassRefPtr<HTMLCollection> all(); PassRefPtr<HTMLCollection> objects(); PassRefPtr<HTMLCollection> scripts(); PassRefPtr<HTMLCollection> windowNamedItems(const String& name); PassRefPtr<HTMLCollection> documentNamedItems(const String& name); // Find first anchor with the given name. // First searches for an element with the given ID, but if that fails, then looks // for an anchor with the given name. ID matching is always case sensitive, but // Anchor name matching is case sensitive in strict mode and not case sensitive in // quirks mode for historical compatibility reasons. Element* findAnchor(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; }#if ENABLE(WML) virtual bool isWMLDocument() const { return false; }#endif virtual bool isFrameSet() 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; } /** * Increments the number of pending sheets. The <link> 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 <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() const { return m_usesDescendantRules; } void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; } bool usesSiblingRules() const { return m_usesSiblingRules; } void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; } bool usesFirstLineRules() const { return m_usesFirstLineRules; } void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; } bool usesFirstLetterRules() const { return m_usesFirstLetterRules; } void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; } bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules; } void setUsesBeforeAfterRules(bool b) { m_usesBeforeAfterRules = b; } // Machinery for saving and restoring state when you leave and then go back to a page. void registerFormElementWithState(FormControlElementWithState* e) { m_formElementsWithState.add(e); } void unregisterFormElementWithState(FormControlElementWithState* e) { m_formElementsWithState.remove(e); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -