• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2001 Dirk Mueller (mueller@kde.org)
5  *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #ifndef Document_h
27 #define Document_h
28 
29 #include "CachedResourceHandle.h"
30 #include "CheckedRadioButtons.h"
31 #include "ContainerNode.h"
32 #include "CollectionCache.h"
33 #include "CollectionType.h"
34 #include "Color.h"
35 #include "Document.h"
36 #include "DocumentMarker.h"
37 #include "ScriptExecutionContext.h"
38 #include "Timer.h"
39 #if USE(JSC)
40 #include <runtime/WeakGCMap.h>
41 #endif
42 #include <wtf/HashCountedSet.h>
43 #include <wtf/OwnPtr.h>
44 #include <wtf/PassOwnPtr.h>
45 
46 namespace WebCore {
47 
48     class Attr;
49     class AXObjectCache;
50     class CDATASection;
51     class CachedCSSStyleSheet;
52     class CachedScript;
53     class CanvasRenderingContext;
54     class CharacterData;
55     class CSSStyleDeclaration;
56     class CSSStyleSelector;
57     class CSSStyleSheet;
58     class Comment;
59     class Database;
60     class DOMImplementation;
61     class DOMSelection;
62     class DOMWindow;
63     class DatabaseThread;
64     class DocLoader;
65     class DocumentFragment;
66     class DocumentType;
67     class DocumentWeakReference;
68     class EditingText;
69     class Element;
70     class EntityReference;
71     class Event;
72     class EventListener;
73     class Frame;
74     class FrameView;
75     class HTMLCanvasElement;
76     class HTMLCollection;
77     class HTMLAllCollection;
78     class HTMLDocument;
79     class HTMLElement;
80     class HTMLFormElement;
81     class HTMLHeadElement;
82     class HTMLInputElement;
83     class HTMLMapElement;
84     class HistoryItem;
85     class HitTestRequest;
86     class InspectorTimelineAgent;
87     class IntPoint;
88     class DOMWrapperWorld;
89     class JSNode;
90     class MouseEventWithHitTestResults;
91     class NodeFilter;
92     class NodeIterator;
93     class Page;
94     class PlatformMouseEvent;
95     class ProcessingInstruction;
96     class Range;
97     class RegisteredEventListener;
98     class RenderArena;
99     class RenderView;
100     class ScriptElementData;
101     class SecurityOrigin;
102     class SerializedScriptValue;
103     class SegmentedString;
104     class Settings;
105     class StyleSheet;
106     class StyleSheetList;
107     class Text;
108     class TextResourceDecoder;
109     class Tokenizer;
110     class TreeWalker;
111     class XMLHttpRequest;
112 
113 #if ENABLE(SVG)
114     class SVGDocumentExtensions;
115 #endif
116 
117 #if ENABLE(XSLT)
118     class TransformSource;
119 #endif
120 
121 #if ENABLE(XBL)
122     class XBLBindingManager;
123 #endif
124 
125 #if ENABLE(XPATH)
126     class XPathEvaluator;
127     class XPathExpression;
128     class XPathNSResolver;
129     class XPathResult;
130 #endif
131 
132 #if ENABLE(DASHBOARD_SUPPORT)
133     struct DashboardRegionValue;
134 #endif
135 
136 #if ENABLE(TOUCH_EVENTS)
137     class Touch;
138     class TouchList;
139 #endif
140 
141     typedef int ExceptionCode;
142 
143 class FormElementKey {
144 public:
145     FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
146     ~FormElementKey();
147     FormElementKey(const FormElementKey&);
148     FormElementKey& operator=(const FormElementKey&);
149 
name()150     AtomicStringImpl* name() const { return m_name; }
type()151     AtomicStringImpl* type() const { return m_type; }
152 
153     // Hash table deleted values, which are only constructed and never copied or destroyed.
FormElementKey(WTF::HashTableDeletedValueType)154     FormElementKey(WTF::HashTableDeletedValueType) : m_name(hashTableDeletedValue()) { }
isHashTableDeletedValue()155     bool isHashTableDeletedValue() const { return m_name == hashTableDeletedValue(); }
156 
157 private:
158     void ref() const;
159     void deref() const;
160 
hashTableDeletedValue()161     static AtomicStringImpl* hashTableDeletedValue() { return reinterpret_cast<AtomicStringImpl*>(-1); }
162 
163     AtomicStringImpl* m_name;
164     AtomicStringImpl* m_type;
165 };
166 
167 inline bool operator==(const FormElementKey& a, const FormElementKey& b)
168 {
169     return a.name() == b.name() && a.type() == b.type();
170 }
171 
172 struct FormElementKeyHash {
173     static unsigned hash(const FormElementKey&);
equalFormElementKeyHash174     static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
175     static const bool safeToCompareToEmptyOrDeleted = true;
176 };
177 
178 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
constructDeletedValueFormElementKeyHashTraits179     static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormElementKey(WTF::HashTableDeletedValue); }
isDeletedValueFormElementKeyHashTraits180     static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
181 };
182 
183 class Document : public ContainerNode, public ScriptExecutionContext {
184 public:
create(Frame * frame)185     static PassRefPtr<Document> create(Frame* frame)
186     {
187         return adoptRef(new Document(frame, false, false));
188     }
createXHTML(Frame * frame)189     static PassRefPtr<Document> createXHTML(Frame* frame)
190     {
191         return adoptRef(new Document(frame, true, false));
192     }
193     virtual ~Document();
194 
195     using ContainerNode::ref;
196     using ContainerNode::deref;
197 
198     // Nodes belonging to this document hold "self-only" references -
199     // these are enough to keep the document from being destroyed, but
200     // not enough to keep it from removing its children. This allows a
201     // node that outlives its document to still have a valid document
202     // pointer without introducing reference cycles
203 
selfOnlyRef()204     void selfOnlyRef()
205     {
206         ASSERT(!m_deletionHasBegun);
207         ++m_selfOnlyRefCount;
208     }
selfOnlyDeref()209     void selfOnlyDeref()
210     {
211         ASSERT(!m_deletionHasBegun);
212         --m_selfOnlyRefCount;
213         if (!m_selfOnlyRefCount && !refCount()) {
214 #ifndef NDEBUG
215             m_deletionHasBegun = true;
216 #endif
217             delete this;
218         }
219     }
220 
221     // DOM methods & attributes for Document
222 
223     DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
224     DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
225     DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
226     DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
227     DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
228     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
229     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
230     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
231     DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
232     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
233     DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
234     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
235     DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
236     DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
237     DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
238     DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
239     DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
240     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
241     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
242     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
243     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
244     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
245     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
246     DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
247     DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
248     DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
249 
250     DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
251     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
252     DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
253     DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
254 
255     // WebKit extensions
256     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
257     DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
258     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
259     DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
260     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
261     DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
262     DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
263     DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
264     DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
265 #if ENABLE(TOUCH_EVENTS)
266     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
267     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
268     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
269     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
270 #endif
271 
doctype()272     DocumentType* doctype() const { return m_docType.get(); }
273 
274     DOMImplementation* implementation() const;
275 
documentElement()276     Element* documentElement() const
277     {
278         if (!m_documentElement)
279             cacheDocumentElement();
280         return m_documentElement.get();
281     }
282 
283     virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
284     PassRefPtr<DocumentFragment> createDocumentFragment();
285     PassRefPtr<Text> createTextNode(const String& data);
286     PassRefPtr<Comment> createComment(const String& data);
287     PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
288     PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
289     PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
290     PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
291     PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
292     PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
293     virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
294     PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
295     Element* getElementById(const AtomicString&) const;
296     bool hasElementWithId(AtomicStringImpl* id) const;
containsMultipleElementsWithId(const AtomicString & elementId)297     bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
298 
299     Element* elementFromPoint(int x, int y) const;
300     PassRefPtr<Range> caretRangeFromPoint(int x, int y);
301 
302     String readyState() const;
303 
304     String defaultCharset() const;
305 
306     // Synonyms backing similar DOM attributes. Use Document::encoding() to avoid virtual dispatch.
inputEncoding()307     String inputEncoding() const { return Document::encoding(); }
charset()308     String charset() const { return Document::encoding(); }
characterSet()309     String characterSet() const { return Document::encoding(); }
310 
311     void setCharset(const String&);
312 
contentLanguage()313     String contentLanguage() const { return m_contentLanguage; }
setContentLanguage(const String & lang)314     void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
315 
xmlEncoding()316     String xmlEncoding() const { return m_xmlEncoding; }
xmlVersion()317     String xmlVersion() const { return m_xmlVersion; }
xmlStandalone()318     bool xmlStandalone() const { return m_xmlStandalone; }
319 
setXMLEncoding(const String & encoding)320     void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLTokenizer
321     void setXMLVersion(const String&, ExceptionCode&);
322     void setXMLStandalone(bool, ExceptionCode&);
323 
documentURI()324     String documentURI() const { return m_documentURI; }
325     void setDocumentURI(const String&);
326 
327     virtual KURL baseURI() const;
328 
329     PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
330 
331     PassRefPtr<HTMLCollection> images();
332     PassRefPtr<HTMLCollection> embeds();
333     PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
334     PassRefPtr<HTMLCollection> applets();
335     PassRefPtr<HTMLCollection> links();
336     PassRefPtr<HTMLCollection> forms();
337     PassRefPtr<HTMLCollection> anchors();
338     PassRefPtr<HTMLCollection> objects();
339     PassRefPtr<HTMLCollection> scripts();
340     PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
341     PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
342 
343     PassRefPtr<HTMLAllCollection> all();
344 
345     // Find first anchor with the given name.
346     // First searches for an element with the given ID, but if that fails, then looks
347     // for an anchor with the given name. ID matching is always case sensitive, but
348     // Anchor name matching is case sensitive in strict mode and not case sensitive in
349     // quirks mode for historical compatibility reasons.
350     Element* findAnchor(const String& name);
351 
collectionInfo(CollectionType type)352     CollectionCache* collectionInfo(CollectionType type)
353     {
354         ASSERT(type >= FirstUnnamedDocumentCachedType);
355         unsigned index = type - FirstUnnamedDocumentCachedType;
356         ASSERT(index < NumUnnamedDocumentCachedTypes);
357         m_collectionInfo[index].checkConsistency();
358         return &m_collectionInfo[index];
359     }
360 
361     CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name);
362 
363     // Other methods (not part of DOM)
isHTMLDocument()364     bool isHTMLDocument() const { return m_isHTML; }
isImageDocument()365     virtual bool isImageDocument() const { return false; }
366 #if ENABLE(SVG)
isSVGDocument()367     virtual bool isSVGDocument() const { return false; }
368 #else
isSVGDocument()369     static bool isSVGDocument() { return false; }
370 #endif
isPluginDocument()371     virtual bool isPluginDocument() const { return false; }
isMediaDocument()372     virtual bool isMediaDocument() const { return false; }
373 #if ENABLE(WML)
isWMLDocument()374     virtual bool isWMLDocument() const { return false; }
375 #endif
376 #if ENABLE(XHTMLMP)
377     bool isXHTMLMPDocument() const;
shouldProcessNoscriptElement()378     bool shouldProcessNoscriptElement() const { return m_shouldProcessNoScriptElement; }
setShouldProcessNoscriptElement(bool shouldDo)379     void setShouldProcessNoscriptElement(bool shouldDo) { m_shouldProcessNoScriptElement = shouldDo; }
380 #endif
isFrameSet()381     virtual bool isFrameSet() const { return false; }
382 
styleSelector()383     CSSStyleSelector* styleSelector()
384     {
385         if (!m_styleSelector)
386             createStyleSelector();
387         return m_styleSelector.get();
388     }
389 
390     Element* getElementByAccessKey(const String& key) const;
391 
392     /**
393      * Updates the pending sheet count and then calls updateStyleSelector.
394      */
395     void removePendingSheet();
396 
397     /**
398      * This method returns true if all top-level stylesheets have loaded (including
399      * any @imports that they may be loading).
400      */
haveStylesheetsLoaded()401     bool haveStylesheetsLoaded() const
402     {
403         return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets;
404     }
405 
406     /**
407      * Increments the number of pending sheets.  The <link> elements
408      * invoke this to add themselves to the loading list.
409      */
addPendingSheet()410     void addPendingSheet() { m_pendingStylesheets++; }
411 
412     void addStyleSheetCandidateNode(Node*, bool createdByParser);
413     void removeStyleSheetCandidateNode(Node*);
414 
gotoAnchorNeededAfterStylesheetsLoad()415     bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
setGotoAnchorNeededAfterStylesheetsLoad(bool b)416     void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
417 
418     /**
419      * Called when one or more stylesheets in the document may have been added, removed or changed.
420      *
421      * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in
422      * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
423      * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
424      * constructed from these which is used to create the a new style selector which collates all of the stylesheets
425      * found and is used to calculate the derived styles for all rendering objects.
426      */
427     void updateStyleSelector();
428 
429     void recalcStyleSelector();
430 
usesDescendantRules()431     bool usesDescendantRules() const { return m_usesDescendantRules; }
setUsesDescendantRules(bool b)432     void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; }
usesSiblingRules()433     bool usesSiblingRules() const { return m_usesSiblingRules; }
setUsesSiblingRules(bool b)434     void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }
usesFirstLineRules()435     bool usesFirstLineRules() const { return m_usesFirstLineRules; }
setUsesFirstLineRules(bool b)436     void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; }
usesFirstLetterRules()437     bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
setUsesFirstLetterRules(bool b)438     void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
usesBeforeAfterRules()439     bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules; }
setUsesBeforeAfterRules(bool b)440     void setUsesBeforeAfterRules(bool b) { m_usesBeforeAfterRules = b; }
usesRemUnits()441     bool usesRemUnits() const { return m_usesRemUnits; }
setUsesRemUnits(bool b)442     void setUsesRemUnits(bool b) { m_usesRemUnits = b; }
443 
444     // Machinery for saving and restoring state when you leave and then go back to a page.
registerFormElementWithState(Element * e)445     void registerFormElementWithState(Element* e) { m_formElementsWithState.add(e); }
unregisterFormElementWithState(Element * e)446     void unregisterFormElementWithState(Element* e) { m_formElementsWithState.remove(e); }
447     Vector<String> formElementsState() const;
448     void setStateForNewFormElements(const Vector<String>&);
449     bool hasStateForNewFormElements() const;
450     bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
451 
452     FrameView* view() const; // can be NULL
frame()453     Frame* frame() const { return m_frame; } // can be NULL
454     Page* page() const; // can be NULL
455     Settings* settings() const; // can be NULL
456 #if ENABLE(INSPECTOR)
457     InspectorTimelineAgent* inspectorTimelineAgent() const; // can be NULL
458 #endif
459 
460     PassRefPtr<Range> createRange();
461 
462     PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
463         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
464 
465     PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
466         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
467 
468     // Special support for editing
469     PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
470     PassRefPtr<EditingText> createEditingTextNode(const String&);
471 
472     virtual void recalcStyle(StyleChange = NoChange);
473     bool childNeedsAndNotInStyleRecalc();
474     virtual void updateStyleIfNeeded();
475     void updateLayout();
476     void updateLayoutIgnorePendingStylesheets();
477     static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
docLoader()478     DocLoader* docLoader() { return m_docLoader.get(); }
479 
480     virtual void attach();
481     virtual void detach();
482 
renderArena()483     RenderArena* renderArena() { return m_renderArena.get(); }
484 
485     RenderView* renderView() const;
486 
487     void clearAXObjectCache();
488     AXObjectCache* axObjectCache() const;
489 
490     // to get visually ordered hebrew and arabic pages right
491     void setVisuallyOrdered();
visuallyOrdered()492     bool visuallyOrdered() const { return m_visuallyOrdered; }
493 
494     void open(Document* ownerDocument = 0);
495     void implicitOpen();
496     void close();
497     void implicitClose();
498     void cancelParsing();
499 
500     void write(const SegmentedString& text, Document* ownerDocument = 0);
501     void write(const String& text, Document* ownerDocument = 0);
502     void writeln(const String& text, Document* ownerDocument = 0);
503     void finishParsing();
504 
wellFormed()505     bool wellFormed() const { return m_wellFormed; }
506 
url()507     const KURL& url() const { return m_url; }
508     void setURL(const KURL&);
509 
baseURL()510     const KURL& baseURL() const { return m_baseURL; }
511     // Setting the BaseElementURL will change the baseURL.
512     void setBaseElementURL(const KURL&);
513 
baseTarget()514     const String& baseTarget() const { return m_baseTarget; }
515     // Setting the BaseElementTarget will change the baseTarget.
setBaseElementTarget(const String & baseTarget)516     void setBaseElementTarget(const String& baseTarget) { m_baseTarget = baseTarget; }
517 
518     KURL completeURL(const String&) const;
519 
520     virtual String userAgent(const KURL&) const;
521 
522     CSSStyleSheet* pageUserSheet();
523     void clearPageUserSheet();
524 
525     const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
526     void clearPageGroupUserSheets();
527 
528     CSSStyleSheet* elementSheet();
529     CSSStyleSheet* mappedElementSheet();
530 
531     virtual Tokenizer* createTokenizer();
tokenizer()532     Tokenizer* tokenizer() { return m_tokenizer.get(); }
533 
printing()534     bool printing() const { return m_printing; }
setPrinting(bool p)535     void setPrinting(bool p) { m_printing = p; }
536 
537     enum ParseMode { Compat, AlmostStrict, Strict };
538 
setParseMode(ParseMode m)539     void setParseMode(ParseMode m) { m_parseMode = m; }
parseMode()540     ParseMode parseMode() const { return m_parseMode; }
541 
inCompatMode()542     bool inCompatMode() const { return m_parseMode == Compat; }
inAlmostStrictMode()543     bool inAlmostStrictMode() const { return m_parseMode == AlmostStrict; }
inStrictMode()544     bool inStrictMode() const { return m_parseMode == Strict; }
545 
546     void setParsing(bool);
parsing()547     bool parsing() const { return m_bParsing; }
548     int minimumLayoutDelay();
549 
550     // This method is used by Android.
setExtraLayoutDelay(int delay)551     void setExtraLayoutDelay(int delay) { m_extraLayoutDelay = delay; }
552 
553     bool shouldScheduleLayout();
554     int elapsedTime() const;
555 
setTextColor(const Color & color)556     void setTextColor(const Color& color) { m_textColor = color; }
textColor()557     Color textColor() const { return m_textColor; }
558 
linkColor()559     const Color& linkColor() const { return m_linkColor; }
visitedLinkColor()560     const Color& visitedLinkColor() const { return m_visitedLinkColor; }
activeLinkColor()561     const Color& activeLinkColor() const { return m_activeLinkColor; }
setLinkColor(const Color & c)562     void setLinkColor(const Color& c) { m_linkColor = c; }
setVisitedLinkColor(const Color & c)563     void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
setActiveLinkColor(const Color & c)564     void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
565     void resetLinkColor();
566     void resetVisitedLinkColor();
567     void resetActiveLinkColor();
568 
569     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&);
570 
571     StyleSheetList* styleSheets();
572 
573     /* Newly proposed CSS3 mechanism for selecting alternate
574        stylesheets using the DOM. May be subject to change as
575        spec matures. - dwh
576     */
577     String preferredStylesheetSet() const;
578     String selectedStylesheetSet() const;
579     void setSelectedStylesheetSet(const String&);
580 
581     bool setFocusedNode(PassRefPtr<Node>);
focusedNode()582     Node* focusedNode() const { return m_focusedNode.get(); }
583 
584     void getFocusableNodes(Vector<RefPtr<Node> >&);
585 
586     // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough
587     // for WebCore to ignore the autofocus attribute on any form controls
ignoreAutofocus()588     bool ignoreAutofocus() const { return m_ignoreAutofocus; };
589     void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; };
590 
591     void setHoverNode(PassRefPtr<Node>);
hoverNode()592     Node* hoverNode() const { return m_hoverNode.get(); }
593 
594     void setActiveNode(PassRefPtr<Node>);
activeNode()595     Node* activeNode() const { return m_activeNode.get(); }
596 
597     void focusedNodeRemoved();
598     void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
599     void hoveredNodeDetached(Node*);
600     void activeChainNodeDetached(Node*);
601 
602     // Updates for :target (CSS3 selector).
603     void setCSSTarget(Element*);
cssTarget()604     Element* cssTarget() const { return m_cssTarget; }
605 
606     void scheduleStyleRecalc();
607     void unscheduleStyleRecalc();
608     void styleRecalcTimerFired(Timer<Document>*);
609 
610     void attachNodeIterator(NodeIterator*);
611     void detachNodeIterator(NodeIterator*);
612 
613     void attachRange(Range*);
614     void detachRange(Range*);
615 
616     void nodeChildrenChanged(ContainerNode*);
617     void nodeWillBeRemoved(Node*);
618 
619     void textInserted(Node*, unsigned offset, unsigned length);
620     void textRemoved(Node*, unsigned offset, unsigned length);
621     void textNodesMerged(Text* oldNode, unsigned offset);
622     void textNodeSplit(Text* oldNode);
623 
defaultView()624     DOMWindow* defaultView() const { return domWindow(); }
625     DOMWindow* domWindow() const;
626 
627     // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
628     void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
629     EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
630     void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
631     void dispatchWindowLoadEvent();
632 
633     void enqueueStorageEvent(PassRefPtr<Event>);
634     void storageEventTimerFired(Timer<Document>*);
635 
636     PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
637 
638     // keep track of what types of event listeners are registered, so we don't
639     // dispatch events unnecessarily
640     enum ListenerType {
641         DOMSUBTREEMODIFIED_LISTENER          = 0x01,
642         DOMNODEINSERTED_LISTENER             = 0x02,
643         DOMNODEREMOVED_LISTENER              = 0x04,
644         DOMNODEREMOVEDFROMDOCUMENT_LISTENER  = 0x08,
645         DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
646         DOMATTRMODIFIED_LISTENER             = 0x20,
647         DOMCHARACTERDATAMODIFIED_LISTENER    = 0x40,
648         OVERFLOWCHANGED_LISTENER             = 0x80,
649         ANIMATIONEND_LISTENER                = 0x100,
650         ANIMATIONSTART_LISTENER              = 0x200,
651         ANIMATIONITERATION_LISTENER          = 0x400,
652         TRANSITIONEND_LISTENER               = 0x800,
653         BEFORELOAD_LISTENER                  = 0x1000,
654         TOUCH_LISTENER                       = 0x2000
655     };
656 
hasListenerType(ListenerType listenerType)657     bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
addListenerType(ListenerType listenerType)658     void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
659     void addListenerTypeIfNeeded(const AtomicString& eventType);
660 
661     CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
662 
663     /**
664      * Searches through the document, starting from fromNode, for the next selectable element that comes after fromNode.
665      * The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab indexes
666      * first (from lowest to highest), and then elements without tab indexes (in document order).
667      *
668      * @param fromNode The node from which to start searching. The node after this will be focused. May be null.
669      *
670      * @return The focus node that comes after fromNode
671      *
672      * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
673      */
674     Node* nextFocusableNode(Node* start, KeyboardEvent*);
675 
676     /**
677      * Searches through the document, starting from fromNode, for the previous selectable element (that comes _before_)
678      * fromNode. The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab
679      * indexes first (from lowest to highest), and then elements without tab indexes (in document order).
680      *
681      * @param fromNode The node from which to start searching. The node before this will be focused. May be null.
682      *
683      * @return The focus node that comes before fromNode
684      *
685      * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
686      */
687     Node* previousFocusableNode(Node* start, KeyboardEvent*);
688 
689     int nodeAbsIndex(Node*);
690     Node* nodeWithAbsIndex(int absIndex);
691 
692     /**
693      * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
694      * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
695      * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
696      * specified in a HTML file.
697      *
698      * @param equiv The http header name (value of the meta tag's "equiv" attribute)
699      * @param content The header value (value of the meta tag's "content" attribute)
700      */
701     void processHttpEquiv(const String& equiv, const String& content);
702 
703 #ifdef ANDROID_META_SUPPORT
704     /**
705      * Handles viewport like <meta name = "viewport" content = "width = device-width">
706      * or format-detection like <meta name = "format-detection" content = "telephone=no">
707      */
708     void processMetadataSettings(const String& content);
709 #endif
710 
711     // Returns the owning element in the parent document.
712     // Returns 0 if this is the top level document.
713     Element* ownerElement() const;
714 
title()715     String title() const { return m_title; }
716     void setTitle(const String&, Element* titleElement = 0);
717     void removeTitle(Element* titleElement);
718 
719     String cookie(ExceptionCode&) const;
720     void setCookie(const String&, ExceptionCode&);
721 
722     String referrer() const;
723 
724     String domain() const;
725     void setDomain(const String& newDomain, ExceptionCode&);
726 
727     String lastModified() const;
728 
cookieURL()729     const KURL& cookieURL() const { return m_cookieURL; }
730 
firstPartyForCookies()731     const KURL& firstPartyForCookies() const { return m_firstPartyForCookies; }
setFirstPartyForCookies(const KURL & url)732     void setFirstPartyForCookies(const KURL& url) { m_firstPartyForCookies = url; }
733 
734     // The following implements the rule from HTML 4 for what valid names are.
735     // To get this right for all the XML cases, we probably have to improve this or move it
736     // and make it sensitive to the type of document.
737     static bool isValidName(const String&);
738 
739     // The following breaks a qualified name into a prefix and a local name.
740     // It also does a validity check, and returns false if the qualified name
741     // is invalid.  It also sets ExceptionCode when name is invalid.
742     static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
743 
744     // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
745     static bool hasPrefixNamespaceMismatch(const QualifiedName&);
746 
747     void addElementById(const AtomicString& elementId, Element *element);
748     void removeElementById(const AtomicString& elementId, Element *element);
749 
750     void addImageMap(HTMLMapElement*);
751     void removeImageMap(HTMLMapElement*);
752     HTMLMapElement* getImageMap(const String& url) const;
753 
754     HTMLElement* body() const;
755     void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
756 
757     HTMLHeadElement* head();
758 
759     bool execCommand(const String& command, bool userInterface = false, const String& value = String());
760     bool queryCommandEnabled(const String& command);
761     bool queryCommandIndeterm(const String& command);
762     bool queryCommandState(const String& command);
763     bool queryCommandSupported(const String& command);
764     String queryCommandValue(const String& command);
765 
766     void addMarker(Range*, DocumentMarker::MarkerType, String description = String());
767     void addMarker(Node*, DocumentMarker);
768     void copyMarkers(Node *srcNode, unsigned startOffset, int length, Node *dstNode, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
769     void removeMarkers(Range*, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
770     void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
771     void removeMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
772     void removeMarkers(Node*);
773     void repaintMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
774     void setRenderedRectForMarker(Node*, const DocumentMarker&, const IntRect&);
775     void invalidateRenderedRectsForMarkersInRect(const IntRect&);
776     void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
777     void setMarkersActive(Range*, bool);
778     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
779 
780     DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
781     Vector<DocumentMarker> markersForNode(Node*);
782     Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
783 
784     // designMode support
785     enum InheritedBool { off = false, on = true, inherit };
786     void setDesignMode(InheritedBool value);
787     InheritedBool getDesignMode() const;
788     bool inDesignMode() const;
789 
790     Document* parentDocument() const;
791     Document* topDocument() const;
792 
docID()793     int docID() const { return m_docID; }
794 
795     void executeScriptSoon(ScriptElementData*, CachedResourceHandle<CachedScript>);
796 
797 #if ENABLE(XSLT)
798     void applyXSLTransform(ProcessingInstruction* pi);
transformSourceDocument()799     PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
setTransformSourceDocument(Document * doc)800     void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
801 
802     void setTransformSource(PassOwnPtr<TransformSource>);
transformSource()803     TransformSource* transformSource() const { return m_transformSource.get(); }
804 #endif
805 
806 #if ENABLE(XBL)
807     // XBL methods
bindingManager()808     XBLBindingManager* bindingManager() const { return m_bindingManager.get(); }
809 #endif
810 
incDOMTreeVersion()811     void incDOMTreeVersion() { ++m_domtree_version; }
domTreeVersion()812     unsigned domTreeVersion() const { return m_domtree_version; }
813 
814     void setDocType(PassRefPtr<DocumentType>);
815 
816 #if ENABLE(XPATH)
817     // XPathEvaluator methods
818     PassRefPtr<XPathExpression> createExpression(const String& expression,
819                                                  XPathNSResolver* resolver,
820                                                  ExceptionCode& ec);
821     PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver);
822     PassRefPtr<XPathResult> evaluate(const String& expression,
823                                      Node* contextNode,
824                                      XPathNSResolver* resolver,
825                                      unsigned short type,
826                                      XPathResult* result,
827                                      ExceptionCode& ec);
828 #endif // ENABLE(XPATH)
829 
830     enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
831 
didLayoutWithPendingStylesheets()832     bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; }
833 
setHasNodesWithPlaceholderStyle()834     void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
835 
iconURL()836     const String& iconURL() const { return m_iconURL; }
837     void setIconURL(const String& iconURL, const String& type);
838 
839     void setUseSecureKeyboardEntryWhenActive(bool);
840     bool useSecureKeyboardEntryWhenActive() const;
841 
addNodeListCache()842     void addNodeListCache() { ++m_numNodeListCaches; }
removeNodeListCache()843     void removeNodeListCache() { ASSERT(m_numNodeListCaches > 0); --m_numNodeListCaches; }
hasNodeListCaches()844     bool hasNodeListCaches() const { return m_numNodeListCaches; }
845 
846     void updateFocusAppearanceSoon(bool restorePreviousSelection);
847     void cancelFocusAppearanceUpdate();
848 
849     // FF method for accessing the selection added for compatibility.
850     DOMSelection* getSelection() const;
851 
852     // Extension for manipulating canvas drawing contexts for use in CSS
853     CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
854     HTMLCanvasElement* getCSSCanvasElement(const String& name);
855 
isDNSPrefetchEnabled()856     bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
857     void parseDNSPrefetchControlHeader(const String&);
858 
859     virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL);
860     virtual void addMessage(MessageDestination, MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
861     virtual void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const ScriptString& sourceString);
862     virtual void scriptImported(unsigned long, const String&);
863     virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
864 
865 #if USE(JSC)
866     typedef JSC::WeakGCMap<WebCore::Node*, JSNode*> JSWrapperCache;
867     typedef HashMap<DOMWrapperWorld*, JSWrapperCache*> JSWrapperCacheMap;
wrapperCacheMap()868     JSWrapperCacheMap& wrapperCacheMap() { return m_wrapperCacheMap; }
869     JSWrapperCache* getWrapperCache(DOMWrapperWorld* world);
870     JSWrapperCache* createWrapperCache(DOMWrapperWorld*);
871 #endif
872 
873     virtual void finishedParsing();
874 
inPageCache()875     bool inPageCache() const { return m_inPageCache; }
876     void setInPageCache(bool flag);
877 
878     // Elements can register themselves for the "documentWillBecomeInactive()" and
879     // "documentDidBecomeActive()" callbacks
880     void registerForDocumentActivationCallbacks(Element*);
881     void unregisterForDocumentActivationCallbacks(Element*);
882     void documentWillBecomeInactive();
883     void documentDidBecomeActive();
884 
885     void registerForMediaVolumeCallbacks(Element*);
886     void unregisterForMediaVolumeCallbacks(Element*);
887     void mediaVolumeDidChange();
888 
889     void setShouldCreateRenderers(bool);
890     bool shouldCreateRenderers();
891 
892     void setDecoder(PassRefPtr<TextResourceDecoder>);
decoder()893     TextResourceDecoder* decoder() const { return m_decoder.get(); }
894 
895     String displayStringModifiedByEncoding(const String&) const;
896     PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
897     void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
898 
899     // Quirk for the benefit of Apple's Dictionary application.
setFrameElementsShouldIgnoreScrolling(bool ignore)900     void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
frameElementsShouldIgnoreScrolling()901     bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; }
902 
903 #if ENABLE(DASHBOARD_SUPPORT)
setDashboardRegionsDirty(bool f)904     void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
dashboardRegionsDirty()905     bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
hasDashboardRegions()906     bool hasDashboardRegions () const { return m_hasDashboardRegions; }
setHasDashboardRegions(bool f)907     void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; }
908     const Vector<DashboardRegionValue>& dashboardRegions() const;
909     void setDashboardRegions(const Vector<DashboardRegionValue>&);
910 #endif
911 
912     virtual void removeAllEventListeners();
913 
checkedRadioButtons()914     CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
915 
916 #if ENABLE(SVG)
917     const SVGDocumentExtensions* svgExtensions();
918     SVGDocumentExtensions* accessSVGExtensions();
919 #endif
920 
921     void initSecurityContext();
922 
923     // Explicitly override the security origin for this document.
924     // Note: It is dangerous to change the security origin of a document
925     //       that already contains content.
926     void setSecurityOrigin(SecurityOrigin*);
927 
928     void updateURLForPushOrReplaceState(const KURL&);
929     void statePopped(SerializedScriptValue*);
930 
processingLoadEvent()931     bool processingLoadEvent() const { return m_processingLoadEvent; }
932 
933 #if ENABLE(DATABASE)
934     virtual bool isDatabaseReadOnly() const;
935     virtual void databaseExceededQuota(const String& name);
936 #endif
937 
938     virtual bool isContextThread() const;
939 
setUsingGeolocation(bool f)940     void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
usingGeolocation()941     bool usingGeolocation() const { return m_usingGeolocation; };
942 
943 #if ENABLE(WML)
setContainsWMLContent(bool value)944     void setContainsWMLContent(bool value) { m_containsWMLContent = value; }
containsWMLContent()945     bool containsWMLContent() const { return m_containsWMLContent; }
946 
947     void resetWMLPageState();
948     void initializeWMLPageState();
949 #endif
950 
containsValidityStyleRules()951     bool containsValidityStyleRules() const { return m_containsValidityStyleRules; }
setContainsValidityStyleRules()952     void setContainsValidityStyleRules() { m_containsValidityStyleRules = true; }
953 
954 #if ENABLE(TOUCH_EVENTS)
955     PassRefPtr<Touch> createTouch(DOMWindow*, EventTarget*, int identifier, int pageX, int pageY, int screenX, int screenY, ExceptionCode&) const;
956     PassRefPtr<TouchList> createTouchList(ExceptionCode&) const;
957 #endif
958 
959 protected:
960     Document(Frame*, bool isXHTML, bool isHTML);
961 
clearXMLVersion()962     void clearXMLVersion() { m_xmlVersion = String(); }
963 
964 
965 private:
isDocument()966     virtual bool isDocument() const { return true; }
967     virtual void removedLastRef();
determineParseMode()968     virtual void determineParseMode() { }
969 
970     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
971 
972     virtual String nodeName() const;
973     virtual NodeType nodeType() const;
974     virtual bool childTypeAllowed(NodeType);
975     virtual PassRefPtr<Node> cloneNode(bool deep);
976     virtual bool canReplaceChild(Node* newChild, Node* oldChild);
977 
refScriptExecutionContext()978     virtual void refScriptExecutionContext() { ref(); }
derefScriptExecutionContext()979     virtual void derefScriptExecutionContext() { deref(); }
980 
981     virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls.
982     virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above.
983 
984     void initDNSPrefetch();
985 
986     String encoding() const;
987 
988     void executeScriptSoonTimerFired(Timer<Document>*);
989 
990     void updateTitle();
991     void updateFocusAppearanceTimerFired(Timer<Document>*);
992     void updateBaseURL();
993 
994     void cacheDocumentElement() const;
995 
996     void createStyleSelector();
997 
998     OwnPtr<CSSStyleSelector> m_styleSelector;
999     bool m_didCalculateStyleSelector;
1000 
1001     Frame* m_frame;
1002     OwnPtr<DocLoader> m_docLoader;
1003     OwnPtr<Tokenizer> m_tokenizer;
1004     bool m_wellFormed;
1005 
1006     // Document URLs.
1007     KURL m_url;  // Document.URL: The URL from which this document was retrieved.
1008     KURL m_baseURL;  // Node.baseURI: The URL to use when resolving relative URLs.
1009     KURL m_baseElementURL;  // The URL set by the <base> element.
1010     KURL m_cookieURL;  // The URL to use for cookie access.
1011     KURL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.
1012 
1013     // Document.documentURI:
1014     // Although URL-like, Document.documentURI can actually be set to any
1015     // string by content.  Document.documentURI affects m_baseURL unless the
1016     // document contains a <base> element, in which case the <base> element
1017     // takes precedence.
1018     String m_documentURI;
1019 
1020     String m_baseTarget;
1021 
1022     RefPtr<DocumentType> m_docType;
1023     mutable RefPtr<DOMImplementation> m_implementation;
1024 
1025     // Track the number of currently loading top-level stylesheets.  Sheets
1026     // loaded using the @import directive are not included in this count.
1027     // We use this count of pending sheets to detect when we can begin attaching
1028     // elements.
1029     int m_pendingStylesheets;
1030 
1031     // But sometimes you need to ignore pending stylesheet count to
1032     // force an immediate layout when requested by JS.
1033     bool m_ignorePendingStylesheets;
1034 
1035     // If we do ignore the pending stylesheet count, then we need to add a boolean
1036     // to track that this happened so that we can do a full repaint when the stylesheets
1037     // do eventually load.
1038     PendingSheetLayout m_pendingSheetLayout;
1039 
1040     bool m_hasNodesWithPlaceholderStyle;
1041 
1042     RefPtr<CSSStyleSheet> m_elemSheet;
1043     RefPtr<CSSStyleSheet> m_mappedElementSheet;
1044     RefPtr<CSSStyleSheet> m_pageUserSheet;
1045     mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
1046     mutable bool m_pageGroupUserSheetCacheValid;
1047 
1048     bool m_printing;
1049 
1050     bool m_ignoreAutofocus;
1051 
1052     ParseMode m_parseMode;
1053 
1054     Color m_textColor;
1055 
1056     RefPtr<Node> m_focusedNode;
1057     RefPtr<Node> m_hoverNode;
1058     RefPtr<Node> m_activeNode;
1059     mutable RefPtr<Element> m_documentElement;
1060 
1061     unsigned m_domtree_version;
1062 
1063     HashSet<NodeIterator*> m_nodeIterators;
1064     HashSet<Range*> m_ranges;
1065 
1066     unsigned short m_listenerTypes;
1067 
1068     RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set.
1069     ListHashSet<Node*> m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>)
1070 
1071     typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
1072     ListHashSet<Element*> m_formElementsWithState;
1073     FormElementStateMap m_stateForNewFormElements;
1074 
1075     Color m_linkColor;
1076     Color m_visitedLinkColor;
1077     Color m_activeLinkColor;
1078 
1079     String m_preferredStylesheetSet;
1080     String m_selectedStylesheetSet;
1081 
1082     bool m_loadingSheet;
1083     bool m_visuallyOrdered;
1084     bool m_bParsing;
1085     Timer<Document> m_styleRecalcTimer;
1086     bool m_inStyleRecalc;
1087     bool m_closeAfterStyleRecalc;
1088     bool m_usesDescendantRules;
1089     bool m_usesSiblingRules;
1090     bool m_usesFirstLineRules;
1091     bool m_usesFirstLetterRules;
1092     bool m_usesBeforeAfterRules;
1093     bool m_usesRemUnits;
1094     bool m_gotoAnchorNeededAfterStylesheetsLoad;
1095     bool m_isDNSPrefetchEnabled;
1096     bool m_haveExplicitlyDisabledDNSPrefetch;
1097     bool m_frameElementsShouldIgnoreScrolling;
1098     bool m_containsValidityStyleRules;
1099     bool m_updateFocusAppearanceRestoresSelection;
1100 
1101     String m_title;
1102     String m_rawTitle;
1103     bool m_titleSetExplicitly;
1104     RefPtr<Element> m_titleElement;
1105 
1106     OwnPtr<RenderArena> m_renderArena;
1107 
1108     typedef std::pair<Vector<DocumentMarker>, Vector<IntRect> > MarkerMapVectorPair;
1109     typedef HashMap<RefPtr<Node>, MarkerMapVectorPair*> MarkerMap;
1110     MarkerMap m_markers;
1111 
1112 #if !PLATFORM(ANDROID)
1113     mutable AXObjectCache* m_axObjectCache;
1114 #endif
1115 
1116     Timer<Document> m_updateFocusAppearanceTimer;
1117 
1118     Element* m_cssTarget;
1119 
1120     bool m_processingLoadEvent;
1121     RefPtr<SerializedScriptValue> m_pendingStateObject;
1122     HashSet<RefPtr<HistoryItem> > m_associatedHistoryItems;
1123     double m_startTime;
1124     bool m_overMinimumLayoutThreshold;
1125     // This is used to increase the minimum delay between re-layouts. It is set
1126     // using setExtraLayoutDelay to modify the minimum delay used at different
1127     // points during the lifetime of the Document.
1128     int m_extraLayoutDelay;
1129 
1130     Vector<std::pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > m_scriptsToExecuteSoon;
1131     Timer<Document> m_executeScriptSoonTimer;
1132 
1133 #if ENABLE(XSLT)
1134     OwnPtr<TransformSource> m_transformSource;
1135     RefPtr<Document> m_transformSourceDocument;
1136 #endif
1137 
1138 #if ENABLE(XBL)
1139     OwnPtr<XBLBindingManager> m_bindingManager; // The access point through which documents and elements communicate with XBL.
1140 #endif
1141 
1142     typedef HashMap<AtomicStringImpl*, HTMLMapElement*> ImageMapsByName;
1143     ImageMapsByName m_imageMapsByName;
1144 
1145     int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
1146 
1147     String m_xmlEncoding;
1148     String m_xmlVersion;
1149     bool m_xmlStandalone;
1150 
1151     String m_contentLanguage;
1152 
1153 #if ENABLE(XHTMLMP)
1154     bool m_shouldProcessNoScriptElement;
1155 #endif
1156 
1157     RenderObject* m_savedRenderer;
1158 
1159     RefPtr<TextResourceDecoder> m_decoder;
1160 
1161     // We maintain the invariant that m_duplicateIds is the count of all elements with a given ID
1162     // excluding the one referenced in m_elementsById, if any. This means it one less than the total count
1163     // when the first node with a given ID is cached, otherwise the same as the total count.
1164     mutable HashMap<AtomicStringImpl*, Element*> m_elementsById;
1165     mutable HashCountedSet<AtomicStringImpl*> m_duplicateIds;
1166 
1167     mutable HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey;
1168 
1169     InheritedBool m_designMode;
1170 
1171     int m_selfOnlyRefCount;
1172 
1173     CheckedRadioButtons m_checkedRadioButtons;
1174 
1175     typedef HashMap<AtomicStringImpl*, CollectionCache*> NamedCollectionMap;
1176     CollectionCache m_collectionInfo[NumUnnamedDocumentCachedTypes];
1177     NamedCollectionMap m_nameCollectionInfo[NumNamedDocumentCachedTypes];
1178 
1179 #if ENABLE(XPATH)
1180     RefPtr<XPathEvaluator> m_xpathEvaluator;
1181 #endif
1182 
1183 #if ENABLE(SVG)
1184     OwnPtr<SVGDocumentExtensions> m_svgExtensions;
1185 #endif
1186 
1187 #if ENABLE(DASHBOARD_SUPPORT)
1188     Vector<DashboardRegionValue> m_dashboardRegions;
1189     bool m_hasDashboardRegions;
1190     bool m_dashboardRegionsDirty;
1191 #endif
1192 
1193     HashMap<String, RefPtr<HTMLCanvasElement> > m_cssCanvasElements;
1194 
1195     mutable bool m_accessKeyMapValid;
1196     bool m_createRenderers;
1197     bool m_inPageCache;
1198     String m_iconURL;
1199 
1200     HashSet<Element*> m_documentActivationCallbackElements;
1201     HashSet<Element*> m_mediaVolumeCallbackElements;
1202 
1203     bool m_useSecureKeyboardEntryWhenActive;
1204 
1205     bool m_isXHTML;
1206     bool m_isHTML;
1207 
1208     unsigned m_numNodeListCaches;
1209 
1210 #if USE(JSC)
1211     JSWrapperCacheMap m_wrapperCacheMap;
1212     JSWrapperCache* m_normalWorldWrapperCache;
1213 #endif
1214 
1215     bool m_usingGeolocation;
1216 
1217     Timer<Document> m_storageEventTimer;
1218     Vector<RefPtr<Event> > m_storageEventQueue;
1219 
1220 #if ENABLE(WML)
1221     bool m_containsWMLContent;
1222 #endif
1223 
1224     RefPtr<DocumentWeakReference> m_weakReference;
1225 };
1226 
hasElementWithId(AtomicStringImpl * id)1227 inline bool Document::hasElementWithId(AtomicStringImpl* id) const
1228 {
1229     ASSERT(id);
1230     return m_elementsById.contains(id) || m_duplicateIds.contains(id);
1231 }
1232 
isDocumentNode()1233 inline bool Node::isDocumentNode() const
1234 {
1235     return this == m_document;
1236 }
1237 
1238 } // namespace WebCore
1239 
1240 #endif // Document_h
1241