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, 2010 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2011 Google Inc. All rights reserved.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
31 #include "CheckedRadioButtons.h"
32 #include "CollectionCache.h"
33 #include "CollectionType.h"
35 #include "DOMTimeStamp.h"
36 #include "DocumentEventQueue.h"
37 #include "DocumentTiming.h"
40 #include "LayoutTypes.h"
41 #include "PageVisibilityState.h"
42 #include "PlatformScreen.h"
43 #include "QualifiedName.h"
44 #include "ScriptExecutionContext.h"
45 #include "SecurityPolicy.h"
46 #include "StringWithDirection.h"
48 #include "TreeScope.h"
49 #include "ViewportArguments.h"
50 #include "WebKitMutationObserver.h"
51 #include <wtf/Deque.h>
52 #include <wtf/FixedArray.h>
53 #include <wtf/OwnPtr.h>
54 #include <wtf/PassOwnPtr.h>
55 #include <wtf/PassRefPtr.h>
62 class CSSStyleDeclaration;
63 class CSSStyleSelector;
66 class CachedCSSStyleSheet;
67 class CachedResourceLoader;
69 class CanvasRenderingContext;
72 class DOMImplementation;
77 class DocumentFragment;
79 class DocumentMarkerController;
81 class DocumentWeakReference;
84 class EntityReference;
88 class FormAssociatedElement;
91 class HTMLCanvasElement;
93 class HTMLAllCollection;
96 class HTMLFormElement;
97 class HTMLFrameOwnerElement;
98 class HTMLHeadElement;
99 class HTMLInputElement;
100 class HTMLMapElement;
101 class HitTestRequest;
104 class DOMWrapperWorld;
106 class MediaCanStartListener;
107 class MediaQueryList;
108 class MediaQueryMatcher;
109 class MouseEventWithHitTestResults;
113 class PlatformMouseEvent;
114 class ProcessingInstruction;
116 class RegisteredEventListener;
119 class RenderFullScreen;
120 class ScriptableDocumentParser;
121 class ScriptElementData;
123 class SecurityOrigin;
124 class SerializedScriptValue;
125 class SegmentedString;
128 class StyleSheetList;
130 class TextResourceDecoder;
131 class DocumentParser;
133 class XMLHttpRequest;
134 class XPathEvaluator;
135 class XPathExpression;
136 class XPathNSResolver;
140 class SVGDocumentExtensions;
144 class TransformSource;
147 #if ENABLE(DASHBOARD_SUPPORT)
148 struct DashboardRegionValue;
151 #if ENABLE(TOUCH_EVENTS)
156 #if ENABLE(REQUEST_ANIMATION_FRAME)
157 class RequestAnimationFrameCallback;
158 class ScriptedAnimationController;
161 #if ENABLE(MICRODATA)
162 class MicroDataItemList;
165 typedef int ExceptionCode;
167 class FormElementKey {
169 FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
171 FormElementKey(const FormElementKey&);
172 FormElementKey& operator=(const FormElementKey&);
174 AtomicStringImpl* name() const { return m_name; }
175 AtomicStringImpl* type() const { return m_type; }
177 // Hash table deleted values, which are only constructed and never copied or destroyed.
178 FormElementKey(WTF::HashTableDeletedValueType) : m_name(hashTableDeletedValue()) { }
179 bool isHashTableDeletedValue() const { return m_name == hashTableDeletedValue(); }
185 static AtomicStringImpl* hashTableDeletedValue() { return reinterpret_cast<AtomicStringImpl*>(-1); }
187 AtomicStringImpl* m_name;
188 AtomicStringImpl* m_type;
191 inline bool operator==(const FormElementKey& a, const FormElementKey& b)
193 return a.name() == b.name() && a.type() == b.type();
196 struct FormElementKeyHash {
197 static unsigned hash(const FormElementKey&);
198 static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
199 static const bool safeToCompareToEmptyOrDeleted = true;
202 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
203 static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormElementKey(WTF::HashTableDeletedValue); }
204 static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
207 enum PageshowEventPersistence {
208 PageshowEventNotPersisted = 0,
209 PageshowEventPersisted = 1
212 enum StyleSelectorUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle };
214 class Document : public TreeScope, public ScriptExecutionContext {
216 static PassRefPtr<Document> create(Frame* frame, const KURL& url)
218 return adoptRef(new Document(frame, url, false, false));
220 static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
222 return adoptRef(new Document(frame, url, true, false));
226 typedef ListHashSet<Element*, 64> FormElementListHashSet;
227 const FormElementListHashSet* getFormElements() const { return &m_formElementsWithState; }
229 MediaQueryMatcher* mediaQueryMatcher();
231 using TreeScope::ref;
232 using TreeScope::deref;
234 // Nodes belonging to this document hold guard references -
235 // these are enough to keep the document from being destroyed, but
236 // not enough to keep it from removing its children. This allows a
237 // node that outlives its document to still have a valid document
238 // pointer without introducing reference cycles.
241 ASSERT(!m_deletionHasBegun);
247 ASSERT(!m_deletionHasBegun);
249 if (!m_guardRefCount && !refCount()) {
251 m_deletionHasBegun = true;
257 virtual void removedLastRef();
259 Element* getElementById(const AtomicString& id) const;
261 virtual bool canContainRangeEndPoint() const { return true; }
263 Element* getElementByAccessKey(const String& key);
264 void invalidateAccessKeyMap();
266 // DOM methods & attributes for Document
268 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
269 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
270 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
271 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
272 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
273 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
274 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
275 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
276 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
277 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
278 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
279 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
280 DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
281 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
282 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
283 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
284 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
285 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
286 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
287 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
288 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
289 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
290 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
291 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
292 DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
293 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
295 DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
296 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
297 DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
298 DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
299 DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange);
302 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
303 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
304 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
305 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
306 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
307 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
308 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
309 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
310 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
311 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange);
312 #if ENABLE(TOUCH_EVENTS)
313 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
314 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
315 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
316 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
318 #if ENABLE(FULLSCREEN_API)
319 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
321 #if ENABLE(PAGE_VISIBILITY_API)
322 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange);
325 ViewportArguments viewportArguments() const { return m_viewportArguments; }
327 SecurityPolicy::ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
329 DocumentType* doctype() const { return m_docType.get(); }
331 DOMImplementation* implementation();
333 Element* documentElement() const
335 if (!m_documentElement)
336 cacheDocumentElement();
337 return m_documentElement.get();
340 virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
341 PassRefPtr<DocumentFragment> createDocumentFragment();
342 PassRefPtr<Text> createTextNode(const String& data);
343 PassRefPtr<Comment> createComment(const String& data);
344 PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
345 PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
346 PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
347 PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
348 PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
349 PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); }
350 PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
351 virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
352 PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
355 * Retrieve all nodes that intersect a rect in the window's document, until it is fully enclosed by
356 * the boundaries of a node.
358 * @param centerX x reference for the rectangle in CSS pixels
359 * @param centerY y reference for the rectangle in CSS pixels
360 * @param topPadding How much to expand the top of the rectangle
361 * @param rightPadding How much to expand the right of the rectangle
362 * @param bottomPadding How much to expand the bottom of the rectangle
363 * @param leftPadding How much to expand the left of the rectangle
364 * @param ignoreClipping whether or not to ignore the root scroll frame when retrieving the element.
365 * If false, this method returns null for coordinates outside of the viewport.
367 PassRefPtr<NodeList> nodesFromRect(int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
368 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping) const;
369 Element* elementFromPoint(int x, int y) const;
370 PassRefPtr<Range> caretRangeFromPoint(int x, int y);
372 String readyState() const;
374 String defaultCharset() const;
376 String inputEncoding() const { return Document::encoding(); }
377 String charset() const { return Document::encoding(); }
378 String characterSet() const { return Document::encoding(); }
380 String encoding() const;
382 void setCharset(const String&);
384 void setContent(const String&);
386 String suggestedMIMEType() const;
388 String contentLanguage() const { return m_contentLanguage; }
389 void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
391 String xmlEncoding() const { return m_xmlEncoding; }
392 String xmlVersion() const { return m_xmlVersion; }
393 bool xmlStandalone() const { return m_xmlStandalone; }
395 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
396 void setXMLVersion(const String&, ExceptionCode&);
397 void setXMLStandalone(bool, ExceptionCode&);
399 String documentURI() const { return m_documentURI; }
400 void setDocumentURI(const String&);
402 virtual KURL baseURI() const;
404 #if ENABLE(PAGE_VISIBILITY_API)
405 String webkitVisibilityState() const;
406 bool webkitHidden() const;
407 void dispatchVisibilityStateChangeEvent();
410 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
412 PassRefPtr<HTMLCollection> images();
413 PassRefPtr<HTMLCollection> embeds();
414 PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
415 PassRefPtr<HTMLCollection> applets();
416 PassRefPtr<HTMLCollection> links();
417 PassRefPtr<HTMLCollection> forms();
418 PassRefPtr<HTMLCollection> anchors();
419 PassRefPtr<HTMLCollection> objects();
420 PassRefPtr<HTMLCollection> scripts();
421 PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
422 PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
424 PassRefPtr<HTMLAllCollection> all();
426 CollectionCache* collectionInfo(CollectionType type)
428 ASSERT(type >= FirstUnnamedDocumentCachedType);
429 unsigned index = type - FirstUnnamedDocumentCachedType;
430 ASSERT(index < NumUnnamedDocumentCachedTypes);
431 m_collectionInfo[index].checkConsistency();
432 return &m_collectionInfo[index];
435 CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name);
437 // Other methods (not part of DOM)
438 bool isHTMLDocument() const { return m_isHTML; }
439 bool isXHTMLDocument() const { return m_isXHTML; }
440 virtual bool isImageDocument() const { return false; }
442 virtual bool isSVGDocument() const { return false; }
443 bool hasSVGRootNode() const;
445 static bool isSVGDocument() { return false; }
446 static bool hasSVGRootNode() { return false; }
448 virtual bool isPluginDocument() const { return false; }
449 virtual bool isMediaDocument() const { return false; }
450 virtual bool isFrameSet() const { return false; }
452 PassRefPtr<CSSValuePool> cssValuePool() const;
454 CSSStyleSelector* styleSelectorIfExists() const { return m_styleSelector.get(); }
456 bool isViewSource() const { return m_isViewSource; }
457 void setIsViewSource(bool);
459 bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
461 CSSStyleSelector* styleSelector()
463 if (!m_styleSelector)
464 createStyleSelector();
465 return m_styleSelector.get();
469 * Updates the pending sheet count and then calls updateStyleSelector.
471 void removePendingSheet();
474 * This method returns true if all top-level stylesheets have loaded (including
475 * any @imports that they may be loading).
477 bool haveStylesheetsLoaded() const
479 return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets;
483 * Increments the number of pending sheets. The <link> elements
484 * invoke this to add themselves to the loading list.
486 void addPendingSheet() { m_pendingStylesheets++; }
488 void addStyleSheetCandidateNode(Node*, bool createdByParser);
489 void removeStyleSheetCandidateNode(Node*);
491 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
492 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
495 * Called when one or more stylesheets in the document may have been added, removed or changed.
497 * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in
498 * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
499 * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
500 * constructed from these which is used to create the a new style selector which collates all of the stylesheets
501 * found and is used to calculate the derived styles for all rendering objects.
503 void styleSelectorChanged(StyleSelectorUpdateFlag);
504 void recalcStyleSelector();
506 bool usesSiblingRules() const { return m_usesSiblingRules || m_usesSiblingRulesOverride; }
507 void setUsesSiblingRules(bool b) { m_usesSiblingRulesOverride = b; }
508 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
509 bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
510 void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
511 bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules || m_usesBeforeAfterRulesOverride; }
512 void setUsesBeforeAfterRules(bool b) { m_usesBeforeAfterRulesOverride = b; }
513 bool usesRemUnits() const { return m_usesRemUnits; }
514 void setUsesRemUnits(bool b) { m_usesRemUnits = b; }
515 bool usesLinkRules() const { return linkColor() != visitedLinkColor() || m_usesLinkRules; }
516 void setUsesLinkRules(bool b) { m_usesLinkRules = b; }
518 // Machinery for saving and restoring state when you leave and then go back to a page.
519 void registerFormElementWithState(Element* e) { m_formElementsWithState.add(e); }
520 void unregisterFormElementWithState(Element* e) { m_formElementsWithState.remove(e); }
521 Vector<String> formElementsState() const;
522 void setStateForNewFormElements(const Vector<String>&);
523 bool hasStateForNewFormElements() const;
524 bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
526 void registerFormElementWithFormAttribute(FormAssociatedElement*);
527 void unregisterFormElementWithFormAttribute(FormAssociatedElement*);
528 void resetFormElementsOwner();
530 FrameView* view() const; // can be NULL
531 Frame* frame() const { return m_frame; } // can be NULL
532 Page* page() const; // can be NULL
533 Settings* settings() const; // can be NULL
535 PassRefPtr<Range> createRange();
537 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
538 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
540 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
541 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
543 // Special support for editing
544 PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
545 PassRefPtr<EditingText> createEditingTextNode(const String&);
547 void recalcStyle(StyleChange = NoChange);
548 bool childNeedsAndNotInStyleRecalc();
549 virtual void updateStyleIfNeeded();
551 void updateLayoutIgnorePendingStylesheets();
552 PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
553 PassRefPtr<RenderStyle> styleForPage(int pageIndex);
555 void registerCustomFont(FontData*);
557 // Returns true if page box (margin boxes and page borders) is visible.
558 bool isPageBoxVisible(int pageIndex);
560 // Returns the preferred page size and margins in pixels, assuming 96
561 // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
562 // marginLeft must be initialized to the default values that are used if
563 // auto is specified.
564 void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
566 static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
567 CachedResourceLoader* cachedResourceLoader() { return m_cachedResourceLoader.get(); }
569 virtual void attach();
570 virtual void detach();
572 // Override ScriptExecutionContext methods to do additional work
573 virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) OVERRIDE;
574 virtual void resumeActiveDOMObjects() OVERRIDE;
576 RenderArena* renderArena() { return m_renderArena.get(); }
578 RenderView* renderView() const;
580 void clearAXObjectCache();
581 AXObjectCache* axObjectCache() const;
582 bool axObjectCacheExists() const;
584 // to get visually ordered hebrew and arabic pages right
585 void setVisuallyOrdered();
586 bool visuallyOrdered() const { return m_visuallyOrdered; }
588 DocumentLoader* loader() const;
590 void open(Document* ownerDocument = 0);
593 // close() is the DOM API document.close()
595 // In some situations (see the code), we ignore document.close().
596 // explicitClose() bypass these checks and actually tries to close the
598 void explicitClose();
599 // implicitClose() actually does the work of closing the input stream.
600 void implicitClose();
602 void cancelParsing();
604 void write(const SegmentedString& text, Document* ownerDocument = 0);
605 void write(const String& text, Document* ownerDocument = 0);
606 void writeln(const String& text, Document* ownerDocument = 0);
608 bool wellFormed() const { return m_wellFormed; }
610 const KURL& url() const { return m_url; }
611 void setURL(const KURL&);
613 const KURL& baseURL() const { return m_baseURL; }
614 void setBaseURLOverride(const KURL&);
615 const KURL& baseURLOverride() const { return m_baseURLOverride; }
616 const String& baseTarget() const { return m_baseTarget; }
617 void processBaseElement();
619 KURL completeURL(const String&) const;
621 virtual String userAgent(const KURL&) const;
623 virtual void disableEval();
625 CSSStyleSheet* pageUserSheet();
626 void clearPageUserSheet();
627 void updatePageUserSheet();
629 const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
630 void clearPageGroupUserSheets();
631 void updatePageGroupUserSheets();
633 void addUserSheet(PassRefPtr<CSSStyleSheet> userSheet);
635 CSSStyleSheet* elementSheet();
636 CSSStyleSheet* mappedElementSheet();
638 virtual PassRefPtr<DocumentParser> createParser();
639 DocumentParser* parser() const { return m_parser.get(); }
640 ScriptableDocumentParser* scriptableDocumentParser() const;
642 bool printing() const { return m_printing; }
643 void setPrinting(bool p) { m_printing = p; }
645 bool paginatedForScreen() const { return m_paginatedForScreen; }
646 void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
648 bool paginated() const { return printing() || paginatedForScreen(); }
650 enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode };
652 virtual void setCompatibilityModeFromDoctype() { }
653 void setCompatibilityMode(CompatibilityMode m);
654 void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
655 CompatibilityMode compatibilityMode() const { return m_compatibilityMode; }
657 String compatMode() const;
659 bool inQuirksMode() const { return m_compatibilityMode == QuirksMode; }
660 bool inLimitedQuirksMode() const { return m_compatibilityMode == LimitedQuirksMode; }
661 bool inNoQuirksMode() const { return m_compatibilityMode == NoQuirksMode; }
668 void setReadyState(ReadyState);
669 void setParsing(bool);
670 bool parsing() const { return m_bParsing; }
671 int minimumLayoutDelay();
673 bool shouldScheduleLayout();
674 bool isLayoutTimerActive();
675 int elapsedTime() const;
677 void setTextColor(const Color& color) { m_textColor = color; }
678 Color textColor() const { return m_textColor; }
680 const Color& linkColor() const { return m_linkColor; }
681 const Color& visitedLinkColor() const { return m_visitedLinkColor; }
682 const Color& activeLinkColor() const { return m_activeLinkColor; }
683 void setLinkColor(const Color& c) { m_linkColor = c; }
684 void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
685 void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
686 void resetLinkColor();
687 void resetVisitedLinkColor();
688 void resetActiveLinkColor();
690 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
692 StyleSheetList* styleSheets();
694 /* Newly proposed CSS3 mechanism for selecting alternate
695 stylesheets using the DOM. May be subject to change as
698 String preferredStylesheetSet() const;
699 String selectedStylesheetSet() const;
700 void setSelectedStylesheetSet(const String&);
702 bool setFocusedNode(PassRefPtr<Node>);
703 Node* focusedNode() const { return m_focusedNode.get(); }
705 void getFocusableNodes(Vector<RefPtr<Node> >&);
707 // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough
708 // for WebCore to ignore the autofocus attribute on any form controls
709 bool ignoreAutofocus() const { return m_ignoreAutofocus; };
710 void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; };
712 void setHoverNode(PassRefPtr<Node>);
713 Node* hoverNode() const { return m_hoverNode.get(); }
715 void setActiveNode(PassRefPtr<Node>);
716 Node* activeNode() const { return m_activeNode.get(); }
718 void focusedNodeRemoved();
719 void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
720 void hoveredNodeDetached(Node*);
721 void activeChainNodeDetached(Node*);
723 // Updates for :target (CSS3 selector).
724 void setCSSTarget(Element*);
725 Element* cssTarget() const { return m_cssTarget; }
727 void scheduleForcedStyleRecalc();
728 void scheduleStyleRecalc();
729 void unscheduleStyleRecalc();
730 bool isPendingStyleRecalc() const;
731 void styleRecalcTimerFired(Timer<Document>*);
733 void attachNodeIterator(NodeIterator*);
734 void detachNodeIterator(NodeIterator*);
735 void moveNodeIteratorsToNewDocument(Node*, Document*);
737 void attachRange(Range*);
738 void detachRange(Range*);
740 void nodeChildrenChanged(ContainerNode*);
741 // nodeChildrenWillBeRemoved is used when removing all node children at once.
742 void nodeChildrenWillBeRemoved(ContainerNode*);
743 // nodeWillBeRemoved is only safe when removing one node at a time.
744 void nodeWillBeRemoved(Node*);
746 void textInserted(Node*, unsigned offset, unsigned length);
747 void textRemoved(Node*, unsigned offset, unsigned length);
748 void textNodesMerged(Text* oldNode, unsigned offset);
749 void textNodeSplit(Text* oldNode);
751 DOMWindow* defaultView() const { return domWindow(); }
752 DOMWindow* domWindow() const;
754 // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
755 void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
756 EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
757 void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
758 void dispatchWindowLoadEvent();
760 PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
762 // keep track of what types of event listeners are registered, so we don't
763 // dispatch events unnecessarily
765 DOMSUBTREEMODIFIED_LISTENER = 0x01,
766 DOMNODEINSERTED_LISTENER = 0x02,
767 DOMNODEREMOVED_LISTENER = 0x04,
768 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 0x08,
769 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
770 DOMATTRMODIFIED_LISTENER = 0x20,
771 DOMCHARACTERDATAMODIFIED_LISTENER = 0x40,
772 OVERFLOWCHANGED_LISTENER = 0x80,
773 ANIMATIONEND_LISTENER = 0x100,
774 ANIMATIONSTART_LISTENER = 0x200,
775 ANIMATIONITERATION_LISTENER = 0x400,
776 TRANSITIONEND_LISTENER = 0x800,
777 BEFORELOAD_LISTENER = 0x1000,
778 TOUCH_LISTENER = 0x2000,
779 SCROLL_LISTENER = 0x4000
782 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
783 void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
784 void addListenerTypeIfNeeded(const AtomicString& eventType);
786 #if ENABLE(MUTATION_OBSERVERS)
787 bool hasSubtreeMutationObserverOfType(WebKitMutationObserver::MutationType type) const
789 return m_subtreeMutationObserverTypes & type;
791 bool hasSubtreeMutationObserver() const { return m_subtreeMutationObserverTypes; }
792 void addSubtreeMutationObserverTypes(MutationObserverOptions types) { m_subtreeMutationObserverTypes |= types; }
795 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
797 int nodeAbsIndex(Node*);
798 Node* nodeWithAbsIndex(int absIndex);
801 * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
802 * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
803 * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
804 * specified in a HTML file.
806 * @param equiv The http header name (value of the meta tag's "equiv" attribute)
807 * @param content The header value (value of the meta tag's "content" attribute)
809 void processHttpEquiv(const String& equiv, const String& content);
810 void processViewport(const String& features);
811 void processReferrerPolicy(const String& policy);
813 // Returns the owning element in the parent document.
814 // Returns 0 if this is the top level document.
815 HTMLFrameOwnerElement* ownerElement() const;
817 // Used by DOM bindings; no direction known.
818 String title() const { return m_title.string(); }
819 void setTitle(const String&);
821 void setTitleElement(const StringWithDirection&, Element* titleElement);
822 void removeTitle(Element* titleElement);
824 String cookie(ExceptionCode&) const;
825 void setCookie(const String&, ExceptionCode&);
827 String referrer() const;
829 String domain() const;
830 void setDomain(const String& newDomain, ExceptionCode&);
832 String lastModified() const;
834 // The cookieURL is used to query the cookie database for this document's
835 // cookies. For example, if the cookie URL is http://example.com, we'll
836 // use the non-Secure cookies for example.com when computing
839 // Q: How is the cookieURL different from the document's URL?
840 // A: The two URLs are the same almost all the time. However, if one
841 // document inherits the security context of another document, it
842 // inherits its cookieURL but not its URL.
844 const KURL& cookieURL() const { return m_cookieURL; }
845 void setCookieURL(const KURL& url) { m_cookieURL = url; }
847 // The firstPartyForCookies is used to compute whether this document
848 // appears in a "third-party" context for the purpose of third-party
849 // cookie blocking. The document is in a third-party context if the
850 // cookieURL and the firstPartyForCookies are from different hosts.
852 // Note: Some ports (including possibly Apple's) only consider the
853 // document in a third-party context if the cookieURL and the
854 // firstPartyForCookies have a different registry-controlled
857 const KURL& firstPartyForCookies() const { return m_firstPartyForCookies; }
858 void setFirstPartyForCookies(const KURL& url) { m_firstPartyForCookies = url; }
860 // The following implements the rule from HTML 4 for what valid names are.
861 // To get this right for all the XML cases, we probably have to improve this or move it
862 // and make it sensitive to the type of document.
863 static bool isValidName(const String&);
865 // The following breaks a qualified name into a prefix and a local name.
866 // It also does a validity check, and returns false if the qualified name
867 // is invalid. It also sets ExceptionCode when name is invalid.
868 static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
870 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
871 static bool hasPrefixNamespaceMismatch(const QualifiedName&);
873 HTMLElement* body() const;
874 void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
876 HTMLHeadElement* head();
878 DocumentMarkerController* markers() const { return m_markers.get(); }
880 bool directionSetOnDocumentElement() const { return m_directionSetOnDocumentElement; }
881 bool writingModeSetOnDocumentElement() const { return m_writingModeSetOnDocumentElement; }
882 void setDirectionSetOnDocumentElement(bool b) { m_directionSetOnDocumentElement = b; }
883 void setWritingModeSetOnDocumentElement(bool b) { m_writingModeSetOnDocumentElement = b; }
885 bool execCommand(const String& command, bool userInterface = false, const String& value = String());
886 bool queryCommandEnabled(const String& command);
887 bool queryCommandIndeterm(const String& command);
888 bool queryCommandState(const String& command);
889 bool queryCommandSupported(const String& command);
890 String queryCommandValue(const String& command);
892 KURL openSearchDescriptionURL();
894 // designMode support
895 enum InheritedBool { off = false, on = true, inherit };
896 void setDesignMode(InheritedBool value);
897 InheritedBool getDesignMode() const;
898 bool inDesignMode() const;
900 Document* parentDocument() const;
901 Document* topDocument() const;
903 int docID() const { return m_docID; }
905 ScriptRunner* scriptRunner() { return m_scriptRunner.get(); }
908 void applyXSLTransform(ProcessingInstruction* pi);
909 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
910 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
912 void setTransformSource(PassOwnPtr<TransformSource>);
913 TransformSource* transformSource() const { return m_transformSource.get(); }
916 void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; }
917 uint64_t domTreeVersion() const { return m_domTreeVersion; }
919 void setDocType(PassRefPtr<DocumentType>);
921 // XPathEvaluator methods
922 PassRefPtr<XPathExpression> createExpression(const String& expression,
923 XPathNSResolver* resolver,
925 PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver);
926 PassRefPtr<XPathResult> evaluate(const String& expression,
928 XPathNSResolver* resolver,
933 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
935 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; }
937 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
939 const Vector<IconURL>& iconURLs() const;
940 void addIconURL(const String& url, const String& mimeType, const String& size, IconType);
942 void setUseSecureKeyboardEntryWhenActive(bool);
943 bool useSecureKeyboardEntryWhenActive() const;
945 void updateFocusAppearanceSoon(bool restorePreviousSelection);
946 void cancelFocusAppearanceUpdate();
948 // FF method for accessing the selection added for compatibility.
949 DOMSelection* getSelection() const;
951 // Extension for manipulating canvas drawing contexts for use in CSS
952 CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
953 HTMLCanvasElement* getCSSCanvasElement(const String& name);
955 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
956 void parseDNSPrefetchControlHeader(const String&);
958 virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
959 virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
961 virtual void suspendScriptedAnimationControllerCallbacks();
962 virtual void resumeScriptedAnimationControllerCallbacks();
964 void windowScreenDidChange(PlatformDisplayID);
966 virtual void finishedParsing();
968 bool inPageCache() const { return m_inPageCache; }
969 void setInPageCache(bool flag);
971 // Elements can register themselves for the "documentWillBecomeInactive()" and
972 // "documentDidBecomeActive()" callbacks
973 void registerForDocumentActivationCallbacks(Element*);
974 void unregisterForDocumentActivationCallbacks(Element*);
975 void documentWillBecomeInactive();
976 void documentDidBecomeActive();
978 void registerForMediaVolumeCallbacks(Element*);
979 void unregisterForMediaVolumeCallbacks(Element*);
980 void mediaVolumeDidChange();
982 void registerForPrivateBrowsingStateChangedCallbacks(Element*);
983 void unregisterForPrivateBrowsingStateChangedCallbacks(Element*);
984 void privateBrowsingStateDidChange();
986 void setShouldCreateRenderers(bool);
987 bool shouldCreateRenderers();
989 void setDecoder(PassRefPtr<TextResourceDecoder>);
990 TextResourceDecoder* decoder() const { return m_decoder.get(); }
992 String displayStringModifiedByEncoding(const String&) const;
993 PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
994 void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
996 // Quirk for the benefit of Apple's Dictionary application.
997 void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
998 bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; }
1000 #if ENABLE(DASHBOARD_SUPPORT)
1001 void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
1002 bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
1003 bool hasDashboardRegions () const { return m_hasDashboardRegions; }
1004 void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; }
1005 const Vector<DashboardRegionValue>& dashboardRegions() const;
1006 void setDashboardRegions(const Vector<DashboardRegionValue>&);
1009 virtual void removeAllEventListeners();
1011 CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
1014 const SVGDocumentExtensions* svgExtensions();
1015 SVGDocumentExtensions* accessSVGExtensions();
1018 void initSecurityContext();
1020 // Explicitly override the security origin for this document.
1021 // Note: It is dangerous to change the security origin of a document
1022 // that already contains content.
1023 void setSecurityOrigin(PassRefPtr<SecurityOrigin>);
1025 void updateURLForPushOrReplaceState(const KURL&);
1026 void statePopped(SerializedScriptValue*);
1028 bool processingLoadEvent() const { return m_processingLoadEvent; }
1029 bool loadEventFinished() const { return m_loadEventFinished; }
1031 #if ENABLE(SQL_DATABASE)
1032 virtual bool allowDatabaseAccess() const;
1033 virtual void databaseExceededQuota(const String& name);
1036 virtual bool isContextThread() const;
1037 virtual bool isJSExecutionForbidden() const { return false; }
1039 void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
1040 bool usingGeolocation() const { return m_usingGeolocation; };
1042 bool containsValidityStyleRules() const { return m_containsValidityStyleRules; }
1043 void setContainsValidityStyleRules() { m_containsValidityStyleRules = true; }
1045 void enqueueWindowEvent(PassRefPtr<Event>);
1046 void enqueueDocumentEvent(PassRefPtr<Event>);
1047 void enqueuePageshowEvent(PageshowEventPersistence);
1048 void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
1049 void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject);
1050 virtual DocumentEventQueue* eventQueue() const { return m_eventQueue.get(); }
1052 void addMediaCanStartListener(MediaCanStartListener*);
1053 void removeMediaCanStartListener(MediaCanStartListener*);
1054 MediaCanStartListener* takeAnyMediaCanStartListener();
1056 const QualifiedName& idAttributeName() const { return m_idAttributeName; }
1058 #if ENABLE(FULLSCREEN_API)
1059 bool webkitIsFullScreen() const { return m_fullScreenElement.get(); }
1060 bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
1061 Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
1063 enum FullScreenCheckType {
1064 EnforceIFrameAllowFulScreenRequirement,
1065 ExemptIFrameAllowFulScreenRequirement,
1068 void requestFullScreenForElement(Element*, unsigned short flags, FullScreenCheckType);
1069 void webkitCancelFullScreen();
1071 void webkitWillEnterFullScreenForElement(Element*);
1072 void webkitDidEnterFullScreenForElement(Element*);
1073 void webkitWillExitFullScreenForElement(Element*);
1074 void webkitDidExitFullScreenForElement(Element*);
1076 void setFullScreenRenderer(RenderFullScreen*);
1077 RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; }
1078 void fullScreenRendererDestroyed();
1080 void setFullScreenRendererSize(const IntSize&);
1081 void setFullScreenRendererBackgroundColor(Color);
1083 void fullScreenChangeDelayTimerFired(Timer<Document>*);
1084 bool fullScreenIsAllowedForElement(Element*) const;
1085 void fullScreenElementRemoved();
1086 void removeFullScreenElementOfSubtree(Node*, bool amongChildrenOnly = false);
1087 bool isAnimatingFullScreen() const;
1088 void setAnimatingFullScreen(bool);
1091 // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event.
1092 void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; }
1093 void decrementLoadEventDelayCount();
1094 bool isDelayingLoadEvent() const { return m_loadEventDelayCount; }
1096 #if ENABLE(TOUCH_EVENTS)
1097 PassRefPtr<Touch> createTouch(DOMWindow*, EventTarget*, int identifier, int pageX, int pageY, int screenX, int screenY, int radiusX, int radiusY, float rotationAngle, float force, ExceptionCode&) const;
1098 PassRefPtr<TouchList> createTouchList(ExceptionCode&) const;
1101 const DocumentTiming* timing() const { return &m_documentTiming; }
1103 #if ENABLE(REQUEST_ANIMATION_FRAME)
1104 int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>, Element*);
1105 void webkitCancelRequestAnimationFrame(int id);
1106 void serviceScriptedAnimations(DOMTimeStamp);
1109 virtual EventTarget* errorEventTarget();
1110 virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
1112 void initDNSPrefetch();
1114 unsigned wheelEventHandlerCount() const { return m_wheelEventHandlerCount; }
1115 void didAddWheelEventHandler();
1116 void didRemoveWheelEventHandler();
1118 bool visualUpdatesAllowed() const;
1120 #if ENABLE(MICRODATA)
1121 PassRefPtr<NodeList> getItems(const String& typeNames);
1122 void removeCachedMicroDataItemList(MicroDataItemList*, const String&);
1125 bool isInDocumentWrite() { return m_writeRecursionDepth > 0; }
1127 void suspendScheduledTasks();
1128 void resumeScheduledTasks();
1131 Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
1133 void clearXMLVersion() { m_xmlVersion = String(); }
1136 friend class IgnoreDestructiveWriteCountIncrementer;
1138 void detachParser();
1140 typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data);
1141 void processArguments(const String& features, void* data, ArgumentsCallback);
1143 virtual bool isDocument() const { return true; }
1145 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
1147 virtual String nodeName() const;
1148 virtual NodeType nodeType() const;
1149 virtual bool childTypeAllowed(NodeType) const;
1150 virtual PassRefPtr<Node> cloneNode(bool deep);
1151 virtual bool canReplaceChild(Node* newChild, Node* oldChild);
1153 virtual void refScriptExecutionContext() { ref(); }
1154 virtual void derefScriptExecutionContext() { deref(); }
1156 virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls.
1157 virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above.
1159 virtual double minimumTimerInterval() const;
1161 void updateTitle(const StringWithDirection&);
1162 void updateFocusAppearanceTimerFired(Timer<Document>*);
1163 void updateBaseURL();
1165 void cacheDocumentElement() const;
1167 void buildAccessKeyMap(TreeScope* root);
1169 void createStyleSelector();
1171 void deleteCustomFonts();
1173 PassRefPtr<NodeList> handleZeroPadding(const HitTestRequest&, HitTestResult&) const;
1175 void loadEventDelayTimerFired(Timer<Document>*);
1177 void pendingTasksTimerFired(Timer<Document>*);
1179 static void didReceiveTask(void*);
1181 #if ENABLE(PAGE_VISIBILITY_API)
1182 PageVisibilityState visibilityState() const;
1185 int m_guardRefCount;
1187 OwnPtr<CSSStyleSelector> m_styleSelector;
1188 bool m_didCalculateStyleSelector;
1189 bool m_hasDirtyStyleSelector;
1190 Vector<OwnPtr<FontData> > m_customFonts;
1192 mutable RefPtr<CSSValuePool> m_cssValuePool;
1195 OwnPtr<CachedResourceLoader> m_cachedResourceLoader;
1196 RefPtr<DocumentParser> m_parser;
1200 KURL m_url; // Document.URL: The URL from which this document was retrieved.
1201 KURL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs.
1202 KURL m_baseURLOverride; // An alternative base URL that takes precedence ove m_baseURL (but not m_baseElementURL).
1203 KURL m_baseElementURL; // The URL set by the <base> element.
1204 KURL m_cookieURL; // The URL to use for cookie access.
1205 KURL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.
1207 // Document.documentURI:
1208 // Although URL-like, Document.documentURI can actually be set to any
1209 // string by content. Document.documentURI affects m_baseURL unless the
1210 // document contains a <base> element, in which case the <base> element
1211 // takes precedence.
1212 String m_documentURI;
1214 String m_baseTarget;
1216 RefPtr<DocumentType> m_docType;
1217 OwnPtr<DOMImplementation> m_implementation;
1219 // Track the number of currently loading top-level stylesheets needed for rendering.
1220 // Sheets loaded using the @import directive are not included in this count.
1221 // We use this count of pending sheets to detect when we can begin attaching
1222 // elements and when it is safe to execute scripts.
1223 int m_pendingStylesheets;
1225 // But sometimes you need to ignore pending stylesheet count to
1226 // force an immediate layout when requested by JS.
1227 bool m_ignorePendingStylesheets;
1229 // If we do ignore the pending stylesheet count, then we need to add a boolean
1230 // to track that this happened so that we can do a full repaint when the stylesheets
1231 // do eventually load.
1232 PendingSheetLayout m_pendingSheetLayout;
1234 bool m_hasNodesWithPlaceholderStyle;
1236 RefPtr<CSSStyleSheet> m_elemSheet;
1237 RefPtr<CSSStyleSheet> m_mappedElementSheet;
1238 RefPtr<CSSStyleSheet> m_pageUserSheet;
1239 mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
1240 OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_userSheets;
1241 mutable bool m_pageGroupUserSheetCacheValid;
1244 bool m_paginatedForScreen;
1246 bool m_ignoreAutofocus;
1248 CompatibilityMode m_compatibilityMode;
1249 bool m_compatibilityModeLocked; // This is cheaper than making setCompatibilityMode virtual.
1253 RefPtr<Node> m_focusedNode;
1254 RefPtr<Node> m_hoverNode;
1255 RefPtr<Node> m_activeNode;
1256 mutable RefPtr<Element> m_documentElement;
1258 uint64_t m_domTreeVersion;
1259 static uint64_t s_globalTreeVersion;
1261 HashSet<NodeIterator*> m_nodeIterators;
1262 HashSet<Range*> m_ranges;
1264 unsigned short m_listenerTypes;
1266 #if ENABLE(MUTATION_OBSERVERS)
1267 MutationObserverOptions m_subtreeMutationObserverTypes;
1270 RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set.
1272 typedef ListHashSet<Node*, 32> StyleSheetCandidateListHashSet;
1273 StyleSheetCandidateListHashSet m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>)
1275 FormElementListHashSet m_formElementsWithState;
1276 typedef ListHashSet<RefPtr<FormAssociatedElement>, 32> FormAssociatedElementListHashSet;
1277 FormAssociatedElementListHashSet m_formElementsWithFormAttribute;
1279 typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
1280 FormElementStateMap m_stateForNewFormElements;
1283 Color m_visitedLinkColor;
1284 Color m_activeLinkColor;
1286 String m_preferredStylesheetSet;
1287 String m_selectedStylesheetSet;
1289 bool m_loadingSheet;
1290 bool m_visuallyOrdered;
1291 ReadyState m_readyState;
1294 Timer<Document> m_styleRecalcTimer;
1295 bool m_pendingStyleRecalcShouldForce;
1296 bool m_inStyleRecalc;
1297 bool m_closeAfterStyleRecalc;
1299 bool m_usesSiblingRules;
1300 bool m_usesSiblingRulesOverride;
1301 bool m_usesFirstLineRules;
1302 bool m_usesFirstLetterRules;
1303 bool m_usesBeforeAfterRules;
1304 bool m_usesBeforeAfterRulesOverride;
1305 bool m_usesRemUnits;
1306 bool m_usesLinkRules;
1307 bool m_gotoAnchorNeededAfterStylesheetsLoad;
1308 bool m_isDNSPrefetchEnabled;
1309 bool m_haveExplicitlyDisabledDNSPrefetch;
1310 bool m_frameElementsShouldIgnoreScrolling;
1311 bool m_containsValidityStyleRules;
1312 bool m_updateFocusAppearanceRestoresSelection;
1314 // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter
1315 unsigned m_ignoreDestructiveWriteCount;
1317 StringWithDirection m_title;
1318 StringWithDirection m_rawTitle;
1319 bool m_titleSetExplicitly;
1320 RefPtr<Element> m_titleElement;
1322 OwnPtr<RenderArena> m_renderArena;
1324 mutable AXObjectCache* m_axObjectCache;
1325 OwnPtr<DocumentMarkerController> m_markers;
1327 Timer<Document> m_updateFocusAppearanceTimer;
1329 Element* m_cssTarget;
1331 // FIXME: Merge these 2 variables into an enum. Also, FrameLoader::m_didCallImplicitClose
1332 // is almost a duplication of this data, so that should probably get merged in too.
1333 // FIXME: Document::m_processingLoadEvent and DocumentLoader::m_wasOnloadHandled are roughly the same
1334 // and should be merged.
1335 bool m_processingLoadEvent;
1336 bool m_loadEventFinished;
1338 RefPtr<SerializedScriptValue> m_pendingStateObject;
1340 bool m_overMinimumLayoutThreshold;
1342 OwnPtr<ScriptRunner> m_scriptRunner;
1345 OwnPtr<TransformSource> m_transformSource;
1346 RefPtr<Document> m_transformSourceDocument;
1349 int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
1351 String m_xmlEncoding;
1352 String m_xmlVersion;
1353 bool m_xmlStandalone;
1355 String m_contentLanguage;
1357 RenderObject* m_savedRenderer;
1359 RefPtr<TextResourceDecoder> m_decoder;
1361 InheritedBool m_designMode;
1363 CheckedRadioButtons m_checkedRadioButtons;
1365 typedef HashMap<AtomicStringImpl*, CollectionCache*> NamedCollectionMap;
1366 FixedArray<CollectionCache, NumUnnamedDocumentCachedTypes> m_collectionInfo;
1367 FixedArray<NamedCollectionMap, NumNamedDocumentCachedTypes> m_nameCollectionInfo;
1369 RefPtr<XPathEvaluator> m_xpathEvaluator;
1372 OwnPtr<SVGDocumentExtensions> m_svgExtensions;
1375 #if ENABLE(DASHBOARD_SUPPORT)
1376 Vector<DashboardRegionValue> m_dashboardRegions;
1377 bool m_hasDashboardRegions;
1378 bool m_dashboardRegionsDirty;
1381 HashMap<String, RefPtr<HTMLCanvasElement> > m_cssCanvasElements;
1383 bool m_createRenderers;
1385 Vector<IconURL> m_iconURLs;
1387 HashSet<Element*> m_documentActivationCallbackElements;
1388 HashSet<Element*> m_mediaVolumeCallbackElements;
1389 HashSet<Element*> m_privateBrowsingStateChangedElements;
1391 HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey;
1392 bool m_accessKeyMapValid;
1394 bool m_useSecureKeyboardEntryWhenActive;
1399 bool m_isViewSource;
1400 bool m_sawElementsInKnownNamespaces;
1402 bool m_usingGeolocation;
1404 RefPtr<DocumentEventQueue> m_eventQueue;
1406 RefPtr<DocumentWeakReference> m_weakReference;
1408 HashSet<MediaCanStartListener*> m_mediaCanStartListeners;
1410 QualifiedName m_idAttributeName;
1412 #if ENABLE(FULLSCREEN_API)
1413 bool m_areKeysEnabledInFullScreen;
1414 RefPtr<Element> m_fullScreenElement;
1415 RenderFullScreen* m_fullScreenRenderer;
1416 Timer<Document> m_fullScreenChangeDelayTimer;
1417 Deque<RefPtr<Element> > m_fullScreenChangeEventTargetQueue;
1418 bool m_isAnimatingFullScreen;
1419 LayoutRect m_savedPlaceholderFrameRect;
1420 RefPtr<RenderStyle> m_savedPlaceholderRenderStyle;
1423 int m_loadEventDelayCount;
1424 Timer<Document> m_loadEventDelayTimer;
1426 ViewportArguments m_viewportArguments;
1428 SecurityPolicy::ReferrerPolicy m_referrerPolicy;
1430 bool m_directionSetOnDocumentElement;
1431 bool m_writingModeSetOnDocumentElement;
1433 DocumentTiming m_documentTiming;
1434 RefPtr<MediaQueryMatcher> m_mediaQueryMatcher;
1435 bool m_writeRecursionIsTooDeep;
1436 unsigned m_writeRecursionDepth;
1438 unsigned m_wheelEventHandlerCount;
1440 #if ENABLE(REQUEST_ANIMATION_FRAME)
1441 OwnPtr<ScriptedAnimationController> m_scriptedAnimationController;
1444 Timer<Document> m_pendingTasksTimer;
1445 Vector<OwnPtr<Task> > m_pendingTasks;
1448 // Put these methods here, because they require the Document definition, but we really want to inline them.
1450 inline bool Node::isDocumentNode() const
1452 return this == m_document;
1455 inline Node::Node(Document* document, ConstructionType type)
1457 , m_document(document)
1463 document->guardRef();
1464 #if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS)
1465 trackForDebugging();
1469 } // namespace WebCore
1471 #endif // Document_h