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