Put date into field that was used to activate DatePicker instead of currectly focused...
[framework/web/webkit-efl.git] / Source / WebCore / dom / Document.h
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, 2010, 2012 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.
10  *
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.
15  *
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.
20  *
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.
25  *
26  */
27
28 #ifndef Document_h
29 #define Document_h
30
31 #include "CollectionType.h"
32 #include "Color.h"
33 #include "ContainerNode.h"
34 #include "DOMTimeStamp.h"
35 #include "DocumentEventQueue.h"
36 #include "DocumentTiming.h"
37 #include "IconURL.h"
38 #include "InspectorCounters.h"
39 #include "IntRect.h"
40 #include "LayoutTypes.h"
41 #include "MutationObserver.h"
42 #include "PageVisibilityState.h"
43 #include "PlatformScreen.h"
44 #include "QualifiedName.h"
45 #include "ReferrerPolicy.h"
46 #include "ScriptExecutionContext.h"
47 #include "StringWithDirection.h"
48 #include "Timer.h"
49 #include "TreeScope.h"
50 #include "ViewportArguments.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>
56
57 namespace WebCore {
58
59 class AXObjectCache;
60 class Attr;
61 class CDATASection;
62 class CSSStyleDeclaration;
63 class CSSStyleSheet;
64 class CachedCSSStyleSheet;
65 class CachedResourceLoader;
66 class CachedScript;
67 class CanvasRenderingContext;
68 class CharacterData;
69 class Comment;
70 class ContextFeatures;
71 class DOMImplementation;
72 class DOMSelection;
73 class DOMWindow;
74 class Database;
75 class DatabaseThread;
76 class DocumentFragment;
77 class DocumentLoader;
78 class DocumentMarkerController;
79 class DocumentParser;
80 class DocumentType;
81 class DocumentWeakReference;
82 class DynamicNodeListCacheBase;
83 class EditingText;
84 class Element;
85 class EntityReference;
86 class Event;
87 class EventListener;
88 class FloatRect;
89 class FloatQuad;
90 class FontData;
91 class FormController;
92 class Frame;
93 class FrameView;
94 class HTMLCanvasElement;
95 class HTMLCollection;
96 class HTMLAllCollection;
97 class HTMLDocument;
98 class HTMLElement;
99 class HTMLFrameOwnerElement;
100 class HTMLHeadElement;
101 class HTMLIFrameElement;
102 class HTMLMapElement;
103 class HTMLNameCollection;
104 class HitTestRequest;
105 class HitTestResult;
106 class IntPoint;
107 class DOMWrapperWorld;
108 class JSNode;
109 class MediaCanStartListener;
110 class MediaQueryList;
111 class MediaQueryMatcher;
112 class MouseEventWithHitTestResults;
113 class NodeFilter;
114 class NodeIterator;
115 class NodeRareData;
116 class Page;
117 class PlatformMouseEvent;
118 class ProcessingInstruction;
119 class Range;
120 class RegisteredEventListener;
121 class RenderArena;
122 class RenderView;
123 class RenderFullScreen;
124 class ScriptableDocumentParser;
125 class ScriptElementData;
126 class ScriptRunner;
127 class SecurityOrigin;
128 class SelectorQueryCache;
129 class SerializedScriptValue;
130 class SegmentedString;
131 class Settings;
132 class StyleResolver;
133 class StyleSheet;
134 class StyleSheetContents;
135 class StyleSheetList;
136 class Text;
137 class TextResourceDecoder;
138 class TreeWalker;
139 class UndoManager;
140 class WebKitNamedFlow;
141 class WebKitNamedFlowCollection;
142 class XMLHttpRequest;
143 class XPathEvaluator;
144 class XPathExpression;
145 class XPathNSResolver;
146 class XPathResult;
147
148 #if ENABLE(SVG)
149 class SVGDocumentExtensions;
150 #endif
151
152 #if ENABLE(XSLT)
153 class TransformSource;
154 #endif
155
156 #if ENABLE(DASHBOARD_SUPPORT)
157 struct DashboardRegionValue;
158 #endif
159
160 #if ENABLE(TOUCH_EVENTS)
161 class Touch;
162 class TouchList;
163 #endif
164
165 #if ENABLE(REQUEST_ANIMATION_FRAME)
166 class RequestAnimationFrameCallback;
167 class ScriptedAnimationController;
168 #endif
169
170 #if ENABLE(MICRODATA)
171 class MicroDataItemList;
172 #endif
173
174 #if ENABLE(LINK_PRERENDER)
175 class Prerenderer;
176 #endif
177
178 #if ENABLE(TEXT_AUTOSIZING)
179 class TextAutosizer;
180 #endif
181
182 #if ENABLE(CSP_NEXT)
183 class DOMSecurityPolicy;
184 #endif
185
186 typedef int ExceptionCode;
187
188 enum PageshowEventPersistence {
189     PageshowEventNotPersisted = 0,
190     PageshowEventPersisted = 1
191 };
192
193 enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded };
194
195 enum NodeListInvalidationType {
196     DoNotInvalidateOnAttributeChanges = 0,
197     InvalidateOnClassAttrChange,
198     InvalidateOnIdNameAttrChange,
199     InvalidateOnNameAttrChange,
200     InvalidateOnForAttrChange,
201     InvalidateForFormControls,
202     InvalidateOnHRefAttrChange,
203     InvalidateOnItemAttrChange,
204     InvalidateOnAnyAttrChange,
205 };
206 const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
207
208 class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
209 public:
210     static PassRefPtr<Document> create(Frame* frame, const KURL& url)
211     {
212         return adoptRef(new Document(frame, url, false, false));
213     }
214     static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
215     {
216         return adoptRef(new Document(frame, url, true, false));
217     }
218     virtual ~Document();
219
220     MediaQueryMatcher* mediaQueryMatcher();
221
222     using ContainerNode::ref;
223     using ContainerNode::deref;
224
225     // Nodes belonging to this document hold guard references -
226     // these are enough to keep the document from being destroyed, but
227     // not enough to keep it from removing its children. This allows a
228     // node that outlives its document to still have a valid document
229     // pointer without introducing reference cycles.
230     void guardRef()
231     {
232         ASSERT(!m_deletionHasBegun);
233         ++m_guardRefCount;
234     }
235
236     void guardDeref()
237     {
238         ASSERT(!m_deletionHasBegun);
239         --m_guardRefCount;
240         if (!m_guardRefCount && !refCount()) {
241 #ifndef NDEBUG
242             m_deletionHasBegun = true;
243 #endif
244             delete this;
245         }
246     }
247
248     Element* getElementById(const AtomicString& id) const;
249
250     virtual bool canContainRangeEndPoint() const { return true; }
251
252     Element* getElementByAccessKey(const String& key);
253     void invalidateAccessKeyMap();
254
255     SelectorQueryCache* selectorQueryCache();
256
257     // DOM methods & attributes for Document
258
259     DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
260     DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
261     DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
262     DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
263     DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
264     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
265     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
266     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
267     DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
268     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
269     DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
270     DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
271     DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
272     DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
273     DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
274     DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
275     DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
276     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
277     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
278     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
279     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
280     DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
281     DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
282     DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
283     DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
284     DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
285
286     DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
287     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
288     DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
289     DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
290     DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange);
291
292     // WebKit extensions
293     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
294     DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
295     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
296     DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
297     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
298     DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
299     DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
300     DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
301     DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
302     DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange);
303 #if ENABLE(TOUCH_EVENTS)
304     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
305     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
306     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
307     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
308 #endif
309 #if ENABLE(FULLSCREEN_API)
310     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
311     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
312 #endif
313 #if ENABLE(POINTER_LOCK)
314     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockchange);
315     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockerror);
316 #endif
317 #if ENABLE(PAGE_VISIBILITY_API)
318     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange);
319 #endif
320
321     ViewportArguments viewportArguments() const { return m_viewportArguments; }
322 #ifndef NDEBUG
323     bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; }
324 #endif
325
326     void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
327     ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
328
329     DocumentType* doctype() const { return m_docType.get(); }
330
331     DOMImplementation* implementation();
332     
333     Element* documentElement() const
334     {
335         return m_documentElement.get();
336     }
337     
338     virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
339     PassRefPtr<DocumentFragment> createDocumentFragment();
340     PassRefPtr<Text> createTextNode(const String& data);
341     PassRefPtr<Comment> createComment(const String& data);
342     PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
343     PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
344     PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
345     PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
346     PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
347     PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); }
348     PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
349     virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
350     PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
351
352     bool cssRegionsEnabled() const;
353 #if ENABLE(CSS_REGIONS)
354     PassRefPtr<WebKitNamedFlow> webkitGetFlowByName(const String&);
355 #endif
356
357     WebKitNamedFlowCollection* namedFlows();
358
359     bool regionBasedColumnsEnabled() const;
360
361     bool cssGridLayoutEnabled() const;
362
363     /**
364      * Retrieve all nodes that intersect a rect in the window's document, until it is fully enclosed by
365      * the boundaries of a node.
366      *
367      * @param centerX x reference for the rectangle in CSS pixels
368      * @param centerY y reference for the rectangle in CSS pixels
369      * @param topPadding How much to expand the top of the rectangle
370      * @param rightPadding How much to expand the right of the rectangle
371      * @param bottomPadding How much to expand the bottom of the rectangle
372      * @param leftPadding How much to expand the left of the rectangle
373      * @param ignoreClipping whether or not to ignore the root scroll frame when retrieving the element.
374      *        If false, this method returns null for coordinates outside of the viewport.
375      */
376     PassRefPtr<NodeList> nodesFromRect(int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
377                                        unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent) const;
378     Element* elementFromPoint(int x, int y) const;
379     PassRefPtr<Range> caretRangeFromPoint(int x, int y);
380
381     String readyState() const;
382
383     String defaultCharset() const;
384
385     String inputEncoding() const { return Document::encoding(); }
386     String charset() const { return Document::encoding(); }
387     String characterSet() const { return Document::encoding(); }
388
389     String encoding() const;
390
391     void setCharset(const String&);
392
393     void setContent(const String&);
394
395     String suggestedMIMEType() const;
396
397     String contentLanguage() const { return m_contentLanguage; }
398     void setContentLanguage(const String&);
399
400     String xmlEncoding() const { return m_xmlEncoding; }
401     String xmlVersion() const { return m_xmlVersion; }
402     enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone };
403     bool xmlStandalone() const { return m_xmlStandalone == Standalone; }
404     StandaloneStatus xmlStandaloneStatus() const { return static_cast<StandaloneStatus>(m_xmlStandalone); }
405     bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
406
407     void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
408     void setXMLVersion(const String&, ExceptionCode&);
409     void setXMLStandalone(bool, ExceptionCode&);
410     void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; }
411
412     String documentURI() const { return m_documentURI; }
413     void setDocumentURI(const String&);
414
415     virtual KURL baseURI() const;
416
417 #if ENABLE(PAGE_VISIBILITY_API)
418     String webkitVisibilityState() const;
419     bool webkitHidden() const;
420     void dispatchVisibilityStateChangeEvent();
421 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
422     void incrementActiveMediaObjectCount();
423     void decrementActiveMediaObjectCount();
424 #endif
425 #endif
426
427 #if ENABLE(CSP_NEXT)
428     DOMSecurityPolicy* securityPolicy();
429 #endif
430
431     PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
432
433     PassRefPtr<HTMLCollection> images();
434     PassRefPtr<HTMLCollection> embeds();
435     PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
436     PassRefPtr<HTMLCollection> applets();
437     PassRefPtr<HTMLCollection> links();
438     PassRefPtr<HTMLCollection> forms();
439     PassRefPtr<HTMLCollection> anchors();
440     PassRefPtr<HTMLCollection> objects();
441     PassRefPtr<HTMLCollection> scripts();
442     PassRefPtr<HTMLCollection> all();
443     void removeCachedHTMLCollection(HTMLCollection*, CollectionType);
444
445     PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name);
446     PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
447     void removeWindowNamedItemCache(HTMLCollection*, const AtomicString&);
448     void removeDocumentNamedItemCache(HTMLCollection*, const AtomicString&);
449
450     // Other methods (not part of DOM)
451     bool isHTMLDocument() const { return m_isHTML; }
452     bool isXHTMLDocument() const { return m_isXHTML; }
453     virtual bool isImageDocument() const { return false; }
454 #if ENABLE(SVG)
455     virtual bool isSVGDocument() const { return false; }
456     bool hasSVGRootNode() const;
457 #else
458     static bool isSVGDocument() { return false; }
459     static bool hasSVGRootNode() { return false; }
460 #endif
461     virtual bool isPluginDocument() const { return false; }
462     virtual bool isMediaDocument() const { return false; }
463     virtual bool isFrameSet() const { return false; }
464
465     bool isSrcdocDocument() const { return m_isSrcdocDocument; }
466
467     NodeRareData* documentRareData() const { return m_documentRareData; };
468     void setDocumentRareData(NodeRareData*);
469
470     StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); }
471
472     bool isViewSource() const { return m_isViewSource; }
473     void setIsViewSource(bool);
474
475     bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
476
477     StyleResolver* styleResolver()
478     { 
479         if (!m_styleResolver)
480             createStyleResolver();
481         return m_styleResolver.get();
482     }
483
484     /**
485      * Updates the pending sheet count and then calls updateActiveStylesheets.
486      */
487     void removePendingSheet();
488
489     /**
490      * This method returns true if all top-level stylesheets have loaded (including
491      * any @imports that they may be loading).
492      */
493     bool haveStylesheetsLoaded() const
494     {
495         return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets;
496     }
497
498     /**
499      * Increments the number of pending sheets.  The <link> elements
500      * invoke this to add themselves to the loading list.
501      */
502     void addPendingSheet() { m_pendingStylesheets++; }
503
504     void addStyleSheetCandidateNode(Node*, bool createdByParser);
505     void removeStyleSheetCandidateNode(Node*);
506
507     bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
508     void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
509
510     /**
511      * Called when one or more stylesheets in the document may have been added, removed or changed.
512      *
513      * Creates a new style resolver and assign it to this document. This is done by iterating through all nodes in
514      * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
515      * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
516      * constructed from these which is used to create the a new style selector which collates all of the stylesheets
517      * found and is used to calculate the derived styles for all rendering objects.
518      */
519     void styleResolverChanged(StyleResolverUpdateFlag);
520
521     void evaluateMediaQueryList();
522
523     bool usesSiblingRules() const { return m_usesSiblingRules || m_usesSiblingRulesOverride; }
524     void setUsesSiblingRules(bool b) { m_usesSiblingRulesOverride = b; }
525     bool usesFirstLineRules() const { return m_usesFirstLineRules; }
526     bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
527     void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
528     bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules || m_usesBeforeAfterRulesOverride; }
529     void setUsesBeforeAfterRules(bool b) { m_usesBeforeAfterRulesOverride = b; }
530     bool usesRemUnits() const { return m_usesRemUnits; }
531     bool usesLinkRules() const { return linkColor() != visitedLinkColor() || m_usesLinkRules; }
532     void setUsesLinkRules(bool b) { m_usesLinkRules = b; }
533
534     // Never returns 0.
535     FormController* formController();
536     Vector<String> formElementsState() const;
537     void setStateForNewFormElements(const Vector<String>&);
538
539     FrameView* view() const; // can be NULL
540     Frame* frame() const { return m_frame; } // can be NULL
541     Page* page() const; // can be NULL
542     Settings* settings() const; // can be NULL
543
544     PassRefPtr<Range> createRange();
545
546     PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
547         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
548
549     PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, 
550         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
551
552     // Special support for editing
553     PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
554     PassRefPtr<EditingText> createEditingTextNode(const String&);
555
556     void recalcStyle(StyleChange = NoChange);
557     bool childNeedsAndNotInStyleRecalc();
558     virtual void updateStyleIfNeeded();
559     void updateLayout();
560     void updateLayoutIgnorePendingStylesheets();
561     PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
562     PassRefPtr<RenderStyle> styleForPage(int pageIndex);
563
564     void registerCustomFont(PassOwnPtr<FontData>);
565
566     // Returns true if page box (margin boxes and page borders) is visible.
567     bool isPageBoxVisible(int pageIndex);
568
569     // Returns the preferred page size and margins in pixels, assuming 96
570     // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
571     // marginLeft must be initialized to the default values that are used if
572     // auto is specified.
573     void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
574
575     static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
576     CachedResourceLoader* cachedResourceLoader() { return m_cachedResourceLoader.get(); }
577
578     virtual void attach();
579     virtual void detach();
580     void prepareForDestruction();
581
582     // Override ScriptExecutionContext methods to do additional work
583     virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) OVERRIDE;
584     virtual void resumeActiveDOMObjects() OVERRIDE;
585
586     RenderArena* renderArena() { return m_renderArena.get(); }
587
588     RenderView* renderView() const;
589
590     void clearAXObjectCache();
591     AXObjectCache* axObjectCache() const;
592     bool axObjectCacheExists() const;
593     
594     // to get visually ordered hebrew and arabic pages right
595     void setVisuallyOrdered();
596     bool visuallyOrdered() const { return m_visuallyOrdered; }
597     
598     DocumentLoader* loader() const;
599
600     void open(Document* ownerDocument = 0);
601     void implicitOpen();
602
603     // close() is the DOM API document.close()
604     void close();
605     // In some situations (see the code), we ignore document.close().
606     // explicitClose() bypass these checks and actually tries to close the
607     // input stream.
608     void explicitClose();
609     // implicitClose() actually does the work of closing the input stream.
610     void implicitClose();
611
612     void cancelParsing();
613
614     void write(const SegmentedString& text, Document* ownerDocument = 0);
615     void write(const String& text, Document* ownerDocument = 0);
616     void writeln(const String& text, Document* ownerDocument = 0);
617
618     bool wellFormed() const { return m_wellFormed; }
619
620     const KURL& url() const { return m_url; }
621     void setURL(const KURL&);
622
623     // To understand how these concepts relate to one another, please see the
624     // comments surrounding their declaration.
625     const KURL& baseURL() const { return m_baseURL; }
626     void setBaseURLOverride(const KURL&);
627     const KURL& baseURLOverride() const { return m_baseURLOverride; }
628     const KURL& baseElementURL() const { return m_baseElementURL; }
629     const String& baseTarget() const { return m_baseTarget; }
630     void processBaseElement();
631
632     KURL completeURL(const String&) const;
633     KURL completeURL(const String&, const KURL& baseURLOverride) const;
634
635     virtual String userAgent(const KURL&) const;
636
637     virtual void disableEval();
638
639     bool canNavigate(Frame* targetFrame);
640     Frame* findUnsafeParentScrollPropagationBoundary();
641
642     CSSStyleSheet* pageUserSheet();
643     void clearPageUserSheet();
644     void updatePageUserSheet();
645
646     const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
647     void clearPageGroupUserSheets();
648     void updatePageGroupUserSheets();
649
650     const Vector<RefPtr<CSSStyleSheet> >* documentUserSheets() const { return m_userSheets.get(); }
651     void addUserSheet(PassRefPtr<StyleSheetContents> userSheet);
652
653     CSSStyleSheet* elementSheet();
654     
655     virtual PassRefPtr<DocumentParser> createParser();
656     DocumentParser* parser() const { return m_parser.get(); }
657     ScriptableDocumentParser* scriptableDocumentParser() const;
658     
659     bool printing() const { return m_printing; }
660     void setPrinting(bool p) { m_printing = p; }
661
662     bool paginatedForScreen() const { return m_paginatedForScreen; }
663     void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
664     
665     bool paginated() const { return printing() || paginatedForScreen(); }
666
667     enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode };
668
669     virtual void setCompatibilityModeFromDoctype() { }
670     void setCompatibilityMode(CompatibilityMode m);
671     void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
672     CompatibilityMode compatibilityMode() const { return m_compatibilityMode; }
673
674     String compatMode() const;
675
676     bool inQuirksMode() const { return m_compatibilityMode == QuirksMode; }
677     bool inLimitedQuirksMode() const { return m_compatibilityMode == LimitedQuirksMode; }
678     bool inNoQuirksMode() const { return m_compatibilityMode == NoQuirksMode; }
679
680     enum ReadyState {
681         Loading,
682         Interactive,
683         Complete
684     };
685     void setReadyState(ReadyState);
686     void setParsing(bool);
687     bool parsing() const { return m_bParsing; }
688     int minimumLayoutDelay();
689
690     bool shouldScheduleLayout();
691     bool isLayoutTimerActive();
692     int elapsedTime() const;
693     
694     void setTextColor(const Color& color) { m_textColor = color; }
695     Color textColor() const { return m_textColor; }
696
697     const Color& linkColor() const { return m_linkColor; }
698     const Color& visitedLinkColor() const { return m_visitedLinkColor; }
699     const Color& activeLinkColor() const { return m_activeLinkColor; }
700     void setLinkColor(const Color& c) { m_linkColor = c; }
701     void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
702     void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
703     void resetLinkColor();
704     void resetVisitedLinkColor();
705     void resetActiveLinkColor();
706     
707     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
708
709     StyleSheetList* styleSheets();
710
711     /* Newly proposed CSS3 mechanism for selecting alternate
712        stylesheets using the DOM. May be subject to change as
713        spec matures. - dwh
714     */
715     String preferredStylesheetSet() const;
716     String selectedStylesheetSet() const;
717     void setSelectedStylesheetSet(const String&);
718
719     bool setFocusedNode(PassRefPtr<Node>);
720     Node* focusedNode() const { return m_focusedNode.get(); }
721
722 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
723     void setCurrentTargetNode(PassRefPtr<Node>);
724     Node* currentTargetNode() const { return m_currentTargetNode.get(); }
725 #endif
726
727     void getFocusableNodes(Vector<RefPtr<Node> >&);
728     
729     // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 
730     // for WebCore to ignore the autofocus attribute on any form controls
731     bool ignoreAutofocus() const { return m_ignoreAutofocus; };
732     void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; };
733
734     void setHoverNode(PassRefPtr<Node>);
735     Node* hoverNode() const { return m_hoverNode.get(); }
736
737     void setActiveNode(PassRefPtr<Node>);
738     Node* activeNode() const { return m_activeNode.get(); }
739
740     void focusedNodeRemoved();
741     void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
742     void hoveredNodeDetached(Node*);
743     void activeChainNodeDetached(Node*);
744
745     // Updates for :target (CSS3 selector).
746     void setCSSTarget(Element*);
747     Element* cssTarget() const { return m_cssTarget; }
748     
749     void scheduleForcedStyleRecalc();
750     void scheduleStyleRecalc();
751     void unscheduleStyleRecalc();
752     bool isPendingStyleRecalc() const;
753     void styleRecalcTimerFired(Timer<Document>*);
754
755     void registerNodeListCache(DynamicNodeListCacheBase*);
756     void unregisterNodeListCache(DynamicNodeListCacheBase*);
757     bool shouldInvalidateNodeListCaches(const QualifiedName* attrName = 0) const;
758     void invalidateNodeListCaches(const QualifiedName* attrName);
759
760     void attachNodeIterator(NodeIterator*);
761     void detachNodeIterator(NodeIterator*);
762     void moveNodeIteratorsToNewDocument(Node*, Document*);
763
764     void attachRange(Range*);
765     void detachRange(Range*);
766
767     void updateRangesAfterChildrenChanged(ContainerNode*);
768     // nodeChildrenWillBeRemoved is used when removing all node children at once.
769     void nodeChildrenWillBeRemoved(ContainerNode*);
770     // nodeWillBeRemoved is only safe when removing one node at a time.
771     void nodeWillBeRemoved(Node*);
772
773     void textInserted(Node*, unsigned offset, unsigned length);
774     void textRemoved(Node*, unsigned offset, unsigned length);
775     void textNodesMerged(Text* oldNode, unsigned offset);
776     void textNodeSplit(Text* oldNode);
777
778     DOMWindow* defaultView() const { return domWindow(); } 
779     DOMWindow* domWindow() const;
780
781     // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
782     void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
783     EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
784     void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
785     void dispatchWindowLoadEvent();
786
787     PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
788
789     // keep track of what types of event listeners are registered, so we don't
790     // dispatch events unnecessarily
791     enum ListenerType {
792         DOMSUBTREEMODIFIED_LISTENER          = 0x01,
793         DOMNODEINSERTED_LISTENER             = 0x02,
794         DOMNODEREMOVED_LISTENER              = 0x04,
795         DOMNODEREMOVEDFROMDOCUMENT_LISTENER  = 0x08,
796         DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
797         DOMATTRMODIFIED_LISTENER             = 0x20,
798         DOMCHARACTERDATAMODIFIED_LISTENER    = 0x40,
799         OVERFLOWCHANGED_LISTENER             = 0x80,
800         ANIMATIONEND_LISTENER                = 0x100,
801         ANIMATIONSTART_LISTENER              = 0x200,
802         ANIMATIONITERATION_LISTENER          = 0x400,
803         TRANSITIONEND_LISTENER               = 0x800,
804         BEFORELOAD_LISTENER                  = 0x1000,
805         TOUCH_LISTENER                       = 0x2000,
806         SCROLL_LISTENER                      = 0x4000,
807         REGIONLAYOUTUPDATE_LISTENER          = 0x8000
808     };
809
810     bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
811     void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
812     void addListenerTypeIfNeeded(const AtomicString& eventType);
813
814 #if ENABLE(TIZEN_PLUGIN_TOUCH_EVENT)
815     void removeListenerType(const AtomicString& eventType);
816 #endif
817
818 #if ENABLE(MUTATION_OBSERVERS)
819     bool hasMutationObserversOfType(MutationObserver::MutationType type) const
820     {
821         return m_mutationObserverTypes & type;
822     }
823     bool hasMutationObservers() const { return m_mutationObserverTypes; }
824     void addMutationObserverTypes(MutationObserverOptions types) { m_mutationObserverTypes |= types; }
825 #endif
826
827     CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
828
829     int nodeAbsIndex(Node*);
830     Node* nodeWithAbsIndex(int absIndex);
831
832     /**
833      * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
834      * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
835      * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
836      * specified in a HTML file.
837      *
838      * @param equiv The http header name (value of the meta tag's "equiv" attribute)
839      * @param content The header value (value of the meta tag's "content" attribute)
840      */
841     void processHttpEquiv(const String& equiv, const String& content);
842     void processViewport(const String& features, ViewportArguments::Type origin);
843     void updateViewportArguments();
844     void processReferrerPolicy(const String& policy);
845
846     // Returns the owning element in the parent document.
847     // Returns 0 if this is the top level document.
848     HTMLFrameOwnerElement* ownerElement() const;
849
850     HTMLIFrameElement* seamlessParentIFrame() const;
851     bool shouldDisplaySeamlesslyWithParent() const;
852
853     // Used by DOM bindings; no direction known.
854     String title() const { return m_title.string(); }
855     void setTitle(const String&);
856
857     void setTitleElement(const StringWithDirection&, Element* titleElement);
858     void removeTitle(Element* titleElement);
859
860     String cookie(ExceptionCode&) const;
861     void setCookie(const String&, ExceptionCode&);
862
863     String referrer() const;
864
865     String domain() const;
866     void setDomain(const String& newDomain, ExceptionCode&);
867
868     String lastModified() const;
869
870     // The cookieURL is used to query the cookie database for this document's
871     // cookies. For example, if the cookie URL is http://example.com, we'll
872     // use the non-Secure cookies for example.com when computing
873     // document.cookie.
874     //
875     // Q: How is the cookieURL different from the document's URL?
876     // A: The two URLs are the same almost all the time.  However, if one
877     //    document inherits the security context of another document, it
878     //    inherits its cookieURL but not its URL.
879     //
880     const KURL& cookieURL() const { return m_cookieURL; }
881     void setCookieURL(const KURL& url) { m_cookieURL = url; }
882
883     // The firstPartyForCookies is used to compute whether this document
884     // appears in a "third-party" context for the purpose of third-party
885     // cookie blocking.  The document is in a third-party context if the
886     // cookieURL and the firstPartyForCookies are from different hosts.
887     //
888     // Note: Some ports (including possibly Apple's) only consider the
889     //       document in a third-party context if the cookieURL and the
890     //       firstPartyForCookies have a different registry-controlled
891     //       domain.
892     //
893     const KURL& firstPartyForCookies() const { return m_firstPartyForCookies; }
894     void setFirstPartyForCookies(const KURL& url) { m_firstPartyForCookies = url; }
895     
896     // The following implements the rule from HTML 4 for what valid names are.
897     // To get this right for all the XML cases, we probably have to improve this or move it
898     // and make it sensitive to the type of document.
899     static bool isValidName(const String&);
900
901     // The following breaks a qualified name into a prefix and a local name.
902     // It also does a validity check, and returns false if the qualified name
903     // is invalid.  It also sets ExceptionCode when name is invalid.
904     static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
905
906     // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
907     static bool hasValidNamespaceForElements(const QualifiedName&);
908     static bool hasValidNamespaceForAttributes(const QualifiedName&);
909
910     HTMLElement* body() const;
911     void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
912
913     HTMLHeadElement* head();
914
915     DocumentMarkerController* markers() const { return m_markers.get(); }
916
917     bool directionSetOnDocumentElement() const { return m_directionSetOnDocumentElement; }
918     bool writingModeSetOnDocumentElement() const { return m_writingModeSetOnDocumentElement; }
919     void setDirectionSetOnDocumentElement(bool b) { m_directionSetOnDocumentElement = b; }
920     void setWritingModeSetOnDocumentElement(bool b) { m_writingModeSetOnDocumentElement = b; }
921
922     bool execCommand(const String& command, bool userInterface = false, const String& value = String());
923     bool queryCommandEnabled(const String& command);
924     bool queryCommandIndeterm(const String& command);
925     bool queryCommandState(const String& command);
926     bool queryCommandSupported(const String& command);
927     String queryCommandValue(const String& command);
928
929     KURL openSearchDescriptionURL();
930
931     // designMode support
932     enum InheritedBool { off = false, on = true, inherit };    
933     void setDesignMode(InheritedBool value);
934     InheritedBool getDesignMode() const;
935     bool inDesignMode() const;
936
937     Document* parentDocument() const;
938     Document* topDocument() const;
939
940     int docID() const { return m_docID; }
941     
942     ScriptRunner* scriptRunner() { return m_scriptRunner.get(); }
943
944 #if ENABLE(XSLT)
945     void applyXSLTransform(ProcessingInstruction* pi);
946     PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
947     void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
948
949     void setTransformSource(PassOwnPtr<TransformSource>);
950     TransformSource* transformSource() const { return m_transformSource.get(); }
951 #endif
952
953     void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; }
954     uint64_t domTreeVersion() const { return m_domTreeVersion; }
955
956     void setDocType(PassRefPtr<DocumentType>);
957
958     // XPathEvaluator methods
959     PassRefPtr<XPathExpression> createExpression(const String& expression,
960                                                  XPathNSResolver* resolver,
961                                                  ExceptionCode& ec);
962     PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver);
963     PassRefPtr<XPathResult> evaluate(const String& expression,
964                                      Node* contextNode,
965                                      XPathNSResolver* resolver,
966                                      unsigned short type,
967                                      XPathResult* result,
968                                      ExceptionCode& ec);
969
970     enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
971
972     bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; }
973     
974     void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
975
976     const Vector<IconURL>& iconURLs();
977     void addIconURL(const String& url, const String& mimeType, const String& size, IconType);
978
979     void setUseSecureKeyboardEntryWhenActive(bool);
980     bool useSecureKeyboardEntryWhenActive() const;
981
982     void updateFocusAppearanceSoon(bool restorePreviousSelection);
983     void cancelFocusAppearanceUpdate();
984         
985     // Extension for manipulating canvas drawing contexts for use in CSS
986     CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
987     HTMLCanvasElement* getCSSCanvasElement(const String& name);
988
989     bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
990     void parseDNSPrefetchControlHeader(const String&);
991
992     virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
993
994     virtual void suspendScriptedAnimationControllerCallbacks();
995     virtual void resumeScriptedAnimationControllerCallbacks();
996     
997     void windowScreenDidChange(PlatformDisplayID);
998
999     virtual void finishedParsing();
1000
1001     bool inPageCache() const { return m_inPageCache; }
1002     void setInPageCache(bool flag);
1003
1004     // Elements can register themselves for the "documentWillSuspendForPageCache()" and  
1005     // "documentDidResumeFromPageCache()" callbacks
1006     void registerForPageCacheSuspensionCallbacks(Element*);
1007     void unregisterForPageCacheSuspensionCallbacks(Element*);
1008
1009     void documentWillBecomeInactive();
1010     void documentWillSuspendForPageCache();
1011     void documentDidResumeFromPageCache();
1012
1013     void registerForMediaVolumeCallbacks(Element*);
1014     void unregisterForMediaVolumeCallbacks(Element*);
1015     void mediaVolumeDidChange();
1016
1017     void registerForPrivateBrowsingStateChangedCallbacks(Element*);
1018     void unregisterForPrivateBrowsingStateChangedCallbacks(Element*);
1019     void privateBrowsingStateDidChange();
1020
1021     void setShouldCreateRenderers(bool);
1022     bool shouldCreateRenderers();
1023
1024     void setDecoder(PassRefPtr<TextResourceDecoder>);
1025     TextResourceDecoder* decoder() const { return m_decoder.get(); }
1026
1027     String displayStringModifiedByEncoding(const String&) const;
1028     PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
1029     void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
1030
1031     // Quirk for the benefit of Apple's Dictionary application.
1032     void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
1033     bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; }
1034
1035 #if ENABLE(DASHBOARD_SUPPORT)
1036     void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
1037     bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
1038     bool hasDashboardRegions () const { return m_hasDashboardRegions; }
1039     void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; }
1040     const Vector<DashboardRegionValue>& dashboardRegions() const;
1041     void setDashboardRegions(const Vector<DashboardRegionValue>&);
1042 #endif
1043
1044     virtual void removeAllEventListeners();
1045
1046 #if ENABLE(SVG)
1047     const SVGDocumentExtensions* svgExtensions();
1048     SVGDocumentExtensions* accessSVGExtensions();
1049 #endif
1050
1051     void initSecurityContext();
1052     void initContentSecurityPolicy();
1053 #if ENABLE(TIZEN_CSP)
1054     void copyContentSecurityPolicy(Document*);
1055 #endif
1056
1057     void updateURLForPushOrReplaceState(const KURL&);
1058     void statePopped(PassRefPtr<SerializedScriptValue>);
1059
1060     bool processingLoadEvent() const { return m_processingLoadEvent; }
1061     bool loadEventFinished() const { return m_loadEventFinished; }
1062
1063     virtual bool isContextThread() const;
1064     virtual bool isJSExecutionForbidden() const { return false; }
1065
1066     bool containsValidityStyleRules() const { return m_containsValidityStyleRules; }
1067     void setContainsValidityStyleRules() { m_containsValidityStyleRules = true; }
1068
1069     void enqueueWindowEvent(PassRefPtr<Event>);
1070     void enqueueDocumentEvent(PassRefPtr<Event>);
1071     void enqueuePageshowEvent(PageshowEventPersistence);
1072     void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
1073     void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject);
1074     virtual DocumentEventQueue* eventQueue() const { return m_eventQueue.get(); }
1075
1076     void addMediaCanStartListener(MediaCanStartListener*);
1077     void removeMediaCanStartListener(MediaCanStartListener*);
1078     MediaCanStartListener* takeAnyMediaCanStartListener();
1079
1080     const QualifiedName& idAttributeName() const { return m_idAttributeName; }
1081     
1082 #if ENABLE(FULLSCREEN_API)
1083     bool webkitIsFullScreen() const { return m_fullScreenElement.get(); }
1084     bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
1085     Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
1086     
1087     enum FullScreenCheckType {
1088         EnforceIFrameAllowFullScreenRequirement,
1089         ExemptIFrameAllowFullScreenRequirement,
1090     };
1091
1092     void requestFullScreenForElement(Element*, unsigned short flags, FullScreenCheckType);
1093     void webkitCancelFullScreen();
1094     
1095     void webkitWillEnterFullScreenForElement(Element*);
1096     void webkitDidEnterFullScreenForElement(Element*);
1097     void webkitWillExitFullScreenForElement(Element*);
1098     void webkitDidExitFullScreenForElement(Element*);
1099     
1100     void setFullScreenRenderer(RenderFullScreen*);
1101     RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; }
1102     void fullScreenRendererDestroyed();
1103     
1104     void setFullScreenRendererSize(const IntSize&);
1105     void setFullScreenRendererBackgroundColor(Color);
1106     
1107     void fullScreenChangeDelayTimerFired(Timer<Document>*);
1108     bool fullScreenIsAllowedForElement(Element*) const;
1109     void fullScreenElementRemoved();
1110     void removeFullScreenElementOfSubtree(Node*, bool amongChildrenOnly = false);
1111     bool isAnimatingFullScreen() const;
1112     void setAnimatingFullScreen(bool);
1113 #if ENABLE(TIZEN_FULLSCREEN_API)
1114     bool exitFullScreenByHwBackKey() const { return m_exitFullScreenByHwBackKey; }
1115 #endif
1116
1117     // W3C API
1118     bool webkitFullscreenEnabled() const;
1119     Element* webkitFullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.first().get() : 0; }
1120     void webkitExitFullscreen();
1121 #endif
1122
1123 #if ENABLE(POINTER_LOCK)
1124     void webkitExitPointerLock();
1125     Element* webkitPointerLockElement() const;
1126 #endif
1127
1128     // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event.
1129     void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; }
1130     void decrementLoadEventDelayCount();
1131     bool isDelayingLoadEvent() const { return m_loadEventDelayCount; }
1132
1133 #if ENABLE(TOUCH_EVENTS)
1134     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;
1135 #endif
1136
1137     const DocumentTiming* timing() const { return &m_documentTiming; }
1138
1139 #if ENABLE(REQUEST_ANIMATION_FRAME)
1140     int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
1141     void webkitCancelAnimationFrame(int id);
1142     void serviceScriptedAnimations(DOMTimeStamp);
1143 #endif
1144
1145     virtual EventTarget* errorEventTarget();
1146     virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, PassRefPtr<ScriptCallStack>);
1147
1148     void initDNSPrefetch();
1149
1150     unsigned wheelEventHandlerCount() const { return m_wheelEventHandlerCount; }
1151     void didAddWheelEventHandler();
1152     void didRemoveWheelEventHandler();
1153
1154 #if ENABLE(TOUCH_EVENTS)
1155     unsigned touchEventHandlerCount() const { return m_touchEventHandlerCount; }
1156 #else
1157     unsigned touchEventHandlerCount() const { return 0; }
1158 #endif
1159
1160     void didAddTouchEventHandler();
1161     void didRemoveTouchEventHandler();
1162
1163     bool visualUpdatesAllowed() const { return m_visualUpdatesAllowed; }
1164
1165 #if ENABLE(MICRODATA)
1166     PassRefPtr<NodeList> getItems(const String& typeNames);
1167 #endif
1168     
1169 #if ENABLE(UNDO_MANAGER)
1170     PassRefPtr<UndoManager> undoManager();
1171 #endif
1172     
1173     bool isInDocumentWrite() { return m_writeRecursionDepth > 0; }
1174
1175     void suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension);
1176     void resumeScheduledTasks();
1177
1178     IntSize viewportSize() const;
1179
1180 #if ENABLE(LINK_PRERENDER)
1181     Prerenderer* prerenderer() { return m_prerenderer.get(); }
1182 #endif
1183
1184 #if ENABLE(TEXT_AUTOSIZING)
1185     TextAutosizer* textAutosizer() { return m_textAutosizer.get(); }
1186 #endif
1187
1188     void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, RenderObject*);
1189     void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, RenderObject*);
1190
1191     void setContextFeatures(PassRefPtr<ContextFeatures>);
1192     ContextFeatures* contextFeatures() { return m_contextFeatures.get(); }
1193
1194     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
1195
1196 protected:
1197     Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
1198
1199     virtual void didUpdateSecurityOrigin() OVERRIDE;
1200
1201     void clearXMLVersion() { m_xmlVersion = String(); }
1202
1203 private:
1204     friend class Node;
1205     friend class IgnoreDestructiveWriteCountIncrementer;
1206
1207     void removedLastRef();
1208     
1209     void detachParser();
1210
1211     typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data);
1212     void processArguments(const String& features, void* data, ArgumentsCallback);
1213
1214     virtual bool isDocument() const { return true; }
1215
1216     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
1217
1218     virtual String nodeName() const;
1219     virtual NodeType nodeType() const;
1220     virtual bool childTypeAllowed(NodeType) const;
1221     virtual PassRefPtr<Node> cloneNode(bool deep);
1222     virtual bool canReplaceChild(Node* newChild, Node* oldChild);
1223
1224     virtual void refScriptExecutionContext() { ref(); }
1225     virtual void derefScriptExecutionContext() { deref(); }
1226
1227     virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls.
1228     virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above.
1229
1230     virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallStack>);
1231
1232     virtual double minimumTimerInterval() const;
1233
1234     void updateTitle(const StringWithDirection&);
1235     void updateFocusAppearanceTimerFired(Timer<Document>*);
1236     void updateBaseURL();
1237
1238     void buildAccessKeyMap(TreeScope* root);
1239
1240     void createStyleResolver();
1241     void clearStyleResolver();
1242     void combineCSSFeatureFlags();
1243     void resetCSSFeatureFlags();
1244     
1245     bool updateActiveStylesheets(StyleResolverUpdateFlag);
1246     void collectActiveStylesheets(Vector<RefPtr<StyleSheet> >&);
1247     bool testAddedStylesheetRequiresStyleRecalc(StyleSheetContents*);
1248     void analyzeStylesheetChange(StyleResolverUpdateFlag, const Vector<RefPtr<StyleSheet> >& newStylesheets, bool& requiresStyleResolverReset, bool& requiresFullStyleRecalc);
1249
1250     void seamlessParentUpdatedStylesheets();
1251     void notifySeamlessChildDocumentsOfStylesheetUpdate() const;
1252
1253     void deleteCustomFonts();
1254
1255     PassRefPtr<NodeList> handleZeroPadding(const HitTestRequest&, HitTestResult&) const;
1256
1257     void loadEventDelayTimerFired(Timer<Document>*);
1258
1259     void pendingTasksTimerFired(Timer<Document>*);
1260
1261     static void didReceiveTask(void*);
1262
1263 #if ENABLE(PAGE_VISIBILITY_API)
1264     PageVisibilityState visibilityState() const;
1265 #endif
1266
1267     PassRefPtr<HTMLCollection> cachedCollection(CollectionType);
1268
1269 #if ENABLE(FULLSCREEN_API)
1270     void clearFullscreenElementStack();
1271     void popFullscreenElementStack();
1272     void pushFullscreenElementStack(Element*);
1273     void addDocumentToFullScreenChangeEventQueue(Document*);
1274 #endif
1275
1276     void setVisualUpdatesAllowed(ReadyState);
1277     void setVisualUpdatesAllowed(bool);
1278     void visualUpdatesSuppressionTimerFired(Timer<Document>*);
1279
1280     int m_guardRefCount;
1281
1282     OwnPtr<StyleResolver> m_styleResolver;
1283     bool m_didCalculateStyleResolver;
1284     bool m_hasDirtyStyleResolver;
1285     Vector<OwnPtr<FontData> > m_customFonts;
1286
1287     Frame* m_frame;
1288     OwnPtr<CachedResourceLoader> m_cachedResourceLoader;
1289     RefPtr<DocumentParser> m_parser;
1290     RefPtr<ContextFeatures> m_contextFeatures;
1291
1292     bool m_wellFormed;
1293
1294     // Document URLs.
1295     KURL m_url; // Document.URL: The URL from which this document was retrieved.
1296     KURL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs.
1297     KURL m_baseURLOverride; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL).
1298     KURL m_baseElementURL; // The URL set by the <base> element.
1299     KURL m_cookieURL; // The URL to use for cookie access.
1300     KURL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.
1301
1302     // Document.documentURI:
1303     // Although URL-like, Document.documentURI can actually be set to any
1304     // string by content.  Document.documentURI affects m_baseURL unless the
1305     // document contains a <base> element, in which case the <base> element
1306     // takes precedence.
1307     //
1308     // This property is read-only from JavaScript, but writable from Objective C.
1309     String m_documentURI;
1310
1311     String m_baseTarget;
1312
1313     RefPtr<DocumentType> m_docType;
1314     OwnPtr<DOMImplementation> m_implementation;
1315
1316     // Track the number of currently loading top-level stylesheets needed for rendering.
1317     // Sheets loaded using the @import directive are not included in this count.
1318     // We use this count of pending sheets to detect when we can begin attaching
1319     // elements and when it is safe to execute scripts.
1320     int m_pendingStylesheets;
1321
1322     // But sometimes you need to ignore pending stylesheet count to
1323     // force an immediate layout when requested by JS.
1324     bool m_ignorePendingStylesheets;
1325
1326     // If we do ignore the pending stylesheet count, then we need to add a boolean
1327     // to track that this happened so that we can do a full repaint when the stylesheets
1328     // do eventually load.
1329     PendingSheetLayout m_pendingSheetLayout;
1330     
1331     bool m_hasNodesWithPlaceholderStyle;
1332
1333     RefPtr<CSSStyleSheet> m_elemSheet;
1334     RefPtr<CSSStyleSheet> m_pageUserSheet;
1335     mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
1336     OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_userSheets;
1337     mutable bool m_pageGroupUserSheetCacheValid;
1338
1339     bool m_printing;
1340     bool m_paginatedForScreen;
1341
1342     bool m_ignoreAutofocus;
1343
1344     CompatibilityMode m_compatibilityMode;
1345     bool m_compatibilityModeLocked; // This is cheaper than making setCompatibilityMode virtual.
1346
1347     Color m_textColor;
1348
1349     RefPtr<Node> m_focusedNode;
1350     RefPtr<Node> m_hoverNode;
1351     RefPtr<Node> m_activeNode;
1352     RefPtr<Element> m_documentElement;
1353 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1354     RefPtr<Node> m_currentTargetNode;
1355 #endif
1356
1357     uint64_t m_domTreeVersion;
1358     static uint64_t s_globalTreeVersion;
1359     
1360     HashSet<NodeIterator*> m_nodeIterators;
1361     HashSet<Range*> m_ranges;
1362
1363     unsigned short m_listenerTypes;
1364
1365 #if ENABLE(MUTATION_OBSERVERS)
1366     MutationObserverOptions m_mutationObserverTypes;
1367 #endif
1368
1369     RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set.
1370     bool m_hadActiveLoadingStylesheet;
1371     
1372     typedef ListHashSet<Node*, 32> StyleSheetCandidateListHashSet;
1373     StyleSheetCandidateListHashSet m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>)
1374
1375     OwnPtr<FormController> m_formController;
1376
1377     Color m_linkColor;
1378     Color m_visitedLinkColor;
1379     Color m_activeLinkColor;
1380
1381     String m_preferredStylesheetSet;
1382     String m_selectedStylesheetSet;
1383
1384     bool m_loadingSheet;
1385     bool m_visuallyOrdered;
1386     ReadyState m_readyState;
1387     bool m_bParsing;
1388     
1389     Timer<Document> m_styleRecalcTimer;
1390     bool m_pendingStyleRecalcShouldForce;
1391     bool m_inStyleRecalc;
1392     bool m_closeAfterStyleRecalc;
1393
1394     bool m_usesSiblingRules;
1395     bool m_usesSiblingRulesOverride;
1396     bool m_usesFirstLineRules;
1397     bool m_usesFirstLetterRules;
1398     bool m_usesBeforeAfterRules;
1399     bool m_usesBeforeAfterRulesOverride;
1400     bool m_usesRemUnits;
1401     bool m_usesLinkRules;
1402     bool m_gotoAnchorNeededAfterStylesheetsLoad;
1403     bool m_isDNSPrefetchEnabled;
1404     bool m_haveExplicitlyDisabledDNSPrefetch;
1405     bool m_frameElementsShouldIgnoreScrolling;
1406     bool m_containsValidityStyleRules;
1407     bool m_updateFocusAppearanceRestoresSelection;
1408
1409     // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter
1410     unsigned m_ignoreDestructiveWriteCount;
1411
1412     StringWithDirection m_title;
1413     StringWithDirection m_rawTitle;
1414     bool m_titleSetExplicitly;
1415     RefPtr<Element> m_titleElement;
1416
1417     OwnPtr<RenderArena> m_renderArena;
1418
1419     mutable AXObjectCache* m_axObjectCache;
1420     OwnPtr<DocumentMarkerController> m_markers;
1421     
1422     Timer<Document> m_updateFocusAppearanceTimer;
1423
1424     Element* m_cssTarget;
1425
1426     // FIXME: Merge these 2 variables into an enum. Also, FrameLoader::m_didCallImplicitClose
1427     // is almost a duplication of this data, so that should probably get merged in too.
1428     // FIXME: Document::m_processingLoadEvent and DocumentLoader::m_wasOnloadHandled are roughly the same
1429     // and should be merged.
1430     bool m_processingLoadEvent;
1431     bool m_loadEventFinished;
1432
1433     RefPtr<SerializedScriptValue> m_pendingStateObject;
1434     double m_startTime;
1435     bool m_overMinimumLayoutThreshold;
1436     
1437     OwnPtr<ScriptRunner> m_scriptRunner;
1438
1439 #if ENABLE(XSLT)
1440     OwnPtr<TransformSource> m_transformSource;
1441     RefPtr<Document> m_transformSourceDocument;
1442 #endif
1443
1444     int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
1445
1446     String m_xmlEncoding;
1447     String m_xmlVersion;
1448     unsigned m_xmlStandalone : 2;
1449     unsigned m_hasXMLDeclaration : 1;
1450
1451     String m_contentLanguage;
1452
1453     RenderObject* m_savedRenderer;
1454     
1455     RefPtr<TextResourceDecoder> m_decoder;
1456
1457     InheritedBool m_designMode;
1458
1459     HashSet<DynamicNodeListCacheBase*> m_listsInvalidatedAtDocument;
1460     unsigned m_nodeListCounts[numNodeListInvalidationTypes];
1461
1462     HTMLCollection* m_collections[NumUnnamedDocumentCachedTypes];
1463     typedef HashMap<AtomicString, HTMLNameCollection*> NamedCollectionMap;
1464     NamedCollectionMap m_documentNamedItemCollections;
1465     NamedCollectionMap m_windowNamedItemCollections;
1466
1467     RefPtr<XPathEvaluator> m_xpathEvaluator;
1468
1469 #if ENABLE(SVG)
1470     OwnPtr<SVGDocumentExtensions> m_svgExtensions;
1471 #endif
1472
1473 #if ENABLE(DASHBOARD_SUPPORT)
1474     Vector<DashboardRegionValue> m_dashboardRegions;
1475     bool m_hasDashboardRegions;
1476     bool m_dashboardRegionsDirty;
1477 #endif
1478
1479     HashMap<String, RefPtr<HTMLCanvasElement> > m_cssCanvasElements;
1480
1481     bool m_createRenderers;
1482     bool m_inPageCache;
1483     Vector<IconURL> m_iconURLs;
1484
1485     HashSet<Element*> m_documentSuspensionCallbackElements;
1486     HashSet<Element*> m_mediaVolumeCallbackElements;
1487     HashSet<Element*> m_privateBrowsingStateChangedElements;
1488
1489     HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey;    
1490     bool m_accessKeyMapValid;
1491
1492     OwnPtr<SelectorQueryCache> m_selectorQueryCache;
1493
1494     bool m_useSecureKeyboardEntryWhenActive;
1495
1496     bool m_isXHTML;
1497     bool m_isHTML;
1498
1499     bool m_isViewSource;
1500     bool m_sawElementsInKnownNamespaces;
1501     bool m_isSrcdocDocument;
1502
1503     NodeRareData* m_documentRareData;
1504
1505     RefPtr<DocumentEventQueue> m_eventQueue;
1506
1507     RefPtr<DocumentWeakReference> m_weakReference;
1508
1509     HashSet<MediaCanStartListener*> m_mediaCanStartListeners;
1510
1511     QualifiedName m_idAttributeName;
1512
1513 #if ENABLE(FULLSCREEN_API)
1514     bool m_areKeysEnabledInFullScreen;
1515     RefPtr<Element> m_fullScreenElement;
1516     Deque<RefPtr<Element> > m_fullScreenElementStack;
1517     RenderFullScreen* m_fullScreenRenderer;
1518     Timer<Document> m_fullScreenChangeDelayTimer;
1519     Deque<RefPtr<Node> > m_fullScreenChangeEventTargetQueue;
1520     Deque<RefPtr<Node> > m_fullScreenErrorEventTargetQueue;
1521     bool m_isAnimatingFullScreen;
1522 #if ENABLE(TIZEN_FULLSCREEN_API)
1523     bool m_exitFullScreenByHwBackKey;
1524 #endif
1525     LayoutRect m_savedPlaceholderFrameRect;
1526     RefPtr<RenderStyle> m_savedPlaceholderRenderStyle;
1527 #endif
1528
1529     int m_loadEventDelayCount;
1530     Timer<Document> m_loadEventDelayTimer;
1531
1532     ViewportArguments m_viewportArguments;
1533
1534     ReferrerPolicy m_referrerPolicy;
1535
1536     bool m_directionSetOnDocumentElement;
1537     bool m_writingModeSetOnDocumentElement;
1538
1539     DocumentTiming m_documentTiming;
1540     RefPtr<MediaQueryMatcher> m_mediaQueryMatcher;
1541     bool m_writeRecursionIsTooDeep;
1542     unsigned m_writeRecursionDepth;
1543     
1544     unsigned m_wheelEventHandlerCount;
1545 #if ENABLE(TOUCH_EVENTS)
1546     unsigned m_touchEventHandlerCount;
1547 #endif
1548     
1549 #if ENABLE(UNDO_MANAGER)
1550     RefPtr<UndoManager> m_undoManager;
1551 #endif
1552
1553 #if ENABLE(REQUEST_ANIMATION_FRAME)
1554     RefPtr<ScriptedAnimationController> m_scriptedAnimationController;
1555 #endif
1556
1557     Timer<Document> m_pendingTasksTimer;
1558     Vector<OwnPtr<Task> > m_pendingTasks;
1559
1560 #if ENABLE(LINK_PRERENDER)
1561     OwnPtr<Prerenderer> m_prerenderer;
1562 #endif
1563
1564 #if ENABLE(TEXT_AUTOSIZING)
1565     OwnPtr<TextAutosizer> m_textAutosizer;
1566 #endif
1567
1568     bool m_scheduledTasksAreSuspended;
1569     
1570     bool m_visualUpdatesAllowed;
1571     Timer<Document> m_visualUpdatesSuppressionTimer;
1572
1573     RefPtr<WebKitNamedFlowCollection> m_namedFlows;
1574
1575 #if ENABLE(CSP_NEXT)
1576     RefPtr<DOMSecurityPolicy> m_domSecurityPolicy;
1577 #endif
1578
1579 #ifndef NDEBUG
1580     bool m_didDispatchViewportPropertiesChanged;
1581 #endif
1582 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
1583     int m_activeMediaObjectCount;
1584 #endif
1585 };
1586
1587 // Put these methods here, because they require the Document definition, but we really want to inline them.
1588
1589 inline bool Node::isDocumentNode() const
1590 {
1591     return this == m_document;
1592 }
1593
1594 inline Node::Node(Document* document, ConstructionType type)
1595     : m_nodeFlags(type)
1596     , m_document(document)
1597     , m_previous(0)
1598     , m_next(0)
1599     , m_renderer(0)
1600 #if ENABLE(TIZEN_ELEMENT_CREATED_BY_PARSER_INFO_STORE)
1601     , m_createdByParser(true)
1602 #endif
1603 {
1604     if (document)
1605         document->guardRef();
1606 #if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS)
1607     trackForDebugging();
1608 #endif
1609     InspectorCounters::incrementCounter(InspectorCounters::NodeCounter);
1610 }
1611
1612 Node* eventTargetNodeForDocument(Document*);
1613
1614 } // namespace WebCore
1615
1616 #endif // Document_h