Document.h 60 KB
Newer Older
1
/*
kocienda's avatar
kocienda committed
2
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 4
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
ap's avatar
ap committed
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.
kocienda's avatar
kocienda committed
10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
ddkilzer's avatar
ddkilzer committed
23 24
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
kocienda's avatar
kocienda committed
25 26
 *
 */
27

28 29
#ifndef Document_h
#define Document_h
kocienda's avatar
kocienda committed
30

darin@apple.com's avatar
darin@apple.com committed
31
#include "CollectionType.h"
darin's avatar
darin committed
32
#include "Color.h"
33
#include "ContainerNode.h"
34
#include "DOMTimeStamp.h"
35
#include "DocumentEventQueue.h"
36
#include "DocumentTiming.h"
37
#include "FocusDirection.h"
38
#include "HitTestRequest.h"
39
#include "IconURL.h"
40
#include "InspectorCounters.h"
41
#include "IntRect.h"
42
#include "MutationObserver.h"
43
#include "PageVisibilityState.h"
44
#include "PlatformScreen.h"
45
#include "QualifiedName.h"
46
#include "ReferrerPolicy.h"
ap@webkit.org's avatar
ap@webkit.org committed
47
#include "ScriptExecutionContext.h"
48
#include "StringWithDirection.h"
darin's avatar
darin committed
49
#include "Timer.h"
50
#include "TreeScope.h"
51
#include "UserActionElementSet.h"
52
#include "ViewportArguments.h"
53
#include <wtf/Deque.h>
oliver@apple.com's avatar
oliver@apple.com committed
54
#include <wtf/FixedArray.h>
55
#include <wtf/HashSet.h>
56 57
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
58
#include <wtf/PassRefPtr.h>
59
#include <wtf/WeakPtr.h>
adele's avatar
adele committed
60

61
namespace WebCore {
darin's avatar
darin committed
62

63
class AXObjectCache;
64
class Attr;
65
class CDATASection;
66 67
class CSSStyleDeclaration;
class CSSStyleSheet;
68
class CachedCSSStyleSheet;
69
class CachedResourceLoader;
70 71 72 73
class CachedScript;
class CanvasRenderingContext;
class CharacterData;
class Comment;
74
class ContextFeatures;
75 76
class CustomElementConstructor;
class CustomElementRegistry;
77
class DOMImplementation;
78
class DOMNamedFlowCollection;
79 80
class DOMSelection;
class DOMWindow;
81
class DOMWrapperWorld;
82
class Database;
83 84
class DatabaseThread;
class DocumentFragment;
85
class DocumentLoader;
86
class DocumentMarkerController;
87
class DocumentParser;
88
class DocumentSharedObjectPool;
89
class DocumentStyleSheetCollection;
90 91 92 93 94
class DocumentType;
class Element;
class EntityReference;
class Event;
class EventListener;
95 96
class FloatRect;
class FloatQuad;
97
class FormController;
98 99 100 101 102 103 104 105 106
class Frame;
class FrameView;
class HTMLCanvasElement;
class HTMLCollection;
class HTMLAllCollection;
class HTMLDocument;
class HTMLElement;
class HTMLFrameOwnerElement;
class HTMLHeadElement;
107
class HTMLIFrameElement;
108
class HTMLMapElement;
109
class HTMLNameCollection;
110 111 112
class HitTestRequest;
class HitTestResult;
class IntPoint;
113 114
class LayoutPoint;
class LayoutRect;
115
class LiveNodeListBase;
116 117
class DOMWrapperWorld;
class JSNode;
118
class Locale;
119
class MediaCanStartListener;
120 121
class MediaQueryList;
class MediaQueryMatcher;
122
class MouseEventWithHitTestResults;
123
class NamedFlowCollection;
124 125 126 127 128 129 130 131 132
class NodeFilter;
class NodeIterator;
class Page;
class PlatformMouseEvent;
class ProcessingInstruction;
class Range;
class RegisteredEventListener;
class RenderArena;
class RenderView;
133
class RenderFullScreen;
134 135
class ScriptableDocumentParser;
class ScriptElementData;
136
class ScriptRunner;
137
class SecurityOrigin;
138
class SelectorQueryCache;
139 140 141
class SerializedScriptValue;
class SegmentedString;
class Settings;
142
class StyleResolver;
143
class StyleSheet;
144
class StyleSheetContents;
145 146 147 148
class StyleSheetList;
class Text;
class TextResourceDecoder;
class TreeWalker;
149
class VisitedLinkState;
150
class WebKitNamedFlow;
151
class XMLHttpRequest;
152 153 154 155
class XPathEvaluator;
class XPathExpression;
class XPathNSResolver;
class XPathResult;
darin@apple.com's avatar
darin@apple.com committed
156 157

#if ENABLE(SVG)
158
class SVGDocumentExtensions;
darin@apple.com's avatar
darin@apple.com committed
159
#endif
160

161
#if ENABLE(XSLT)
162
class TransformSource;
163 164
#endif

165
#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION)
166
struct AnnotatedRegionValue;
ddkilzer@apple.com's avatar
ddkilzer@apple.com committed
167
#endif
darin's avatar
darin committed
168

169 170 171 172 173
#if ENABLE(TOUCH_EVENTS)
class Touch;
class TouchList;
#endif

174 175
#if ENABLE(REQUEST_ANIMATION_FRAME)
class RequestAnimationFrameCallback;
176
class ScriptedAnimationController;
177 178
#endif

179 180 181 182
#if ENABLE(MICRODATA)
class MicroDataItemList;
#endif

183 184 185 186
#if ENABLE(TEXT_AUTOSIZING)
class TextAutosizer;
#endif

187 188 189 190
#if ENABLE(CSP_NEXT)
class DOMSecurityPolicy;
#endif

191 192 193 194
#if ENABLE(FONT_LOAD_EVENTS)
class FontLoader;
#endif

195
typedef int ExceptionCode;
196

197 198 199 200
enum PageshowEventPersistence {
    PageshowEventNotPersisted = 0,
    PageshowEventPersisted = 1
};
201

202
enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded };
203

204 205 206
enum NodeListInvalidationType {
    DoNotInvalidateOnAttributeChanges = 0,
    InvalidateOnClassAttrChange,
207
    InvalidateOnIdNameAttrChange,
208 209
    InvalidateOnNameAttrChange,
    InvalidateOnForAttrChange,
210
    InvalidateForFormControls,
211
    InvalidateOnHRefAttrChange,
212
    InvalidateOnItemAttrChange,
213
    InvalidateOnAnyAttrChange,
214
};
215
const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
216

217 218
typedef HashCountedSet<Node*> TouchEventTargetSet;

219 220 221 222 223 224 225 226 227 228 229 230
enum DocumentClass {
    DefaultDocumentClass = 0,
    HTMLDocumentClass = 1,
    XHTMLDocumentClass = 1 << 1,
    ImageDocumentClass = 1 << 2,
    PluginDocumentClass = 1 << 3,
    MediaDocumentClass = 1 << 4,
    SVGDocumentClass = 1 << 5,
};

typedef unsigned char DocumentClassFlags;

231
class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
kocienda's avatar
kocienda committed
232
public:
233
    static PassRefPtr<Document> create(Frame* frame, const KURL& url)
weinig@apple.com's avatar
weinig@apple.com committed
234
    {
235
        return adoptRef(new Document(frame, url));
weinig@apple.com's avatar
weinig@apple.com committed
236
    }
237
    static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
weinig@apple.com's avatar
weinig@apple.com committed
238
    {
239
        return adoptRef(new Document(frame, url, XHTMLDocumentClass));
weinig@apple.com's avatar
weinig@apple.com committed
240
    }
harrison's avatar
harrison committed
241
    virtual ~Document();
kocienda's avatar
kocienda committed
242

243 244
    MediaQueryMatcher* mediaQueryMatcher();

245 246
    using ContainerNode::ref;
    using ContainerNode::deref;
mjs's avatar
mjs committed
247

248
    Element* getElementById(const AtomicString& id) const;
mjs's avatar
mjs committed
249

250 251
    virtual bool canContainRangeEndPoint() const { return true; }

252 253 254
    Element* getElementByAccessKey(const String& key);
    void invalidateAccessKeyMap();

255 256
    SelectorQueryCache* selectorQueryCache();

257
    // DOM methods & attributes for Document
kocienda's avatar
kocienda committed
258

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
277 278
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseenter);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseleave);
279 280 281 282 283 284 285 286 287 288 289 290 291
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);

    DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
292
    DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange);
293 294 295 296 297 298 299 300 301 302 303

    // WebKit extensions
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
304
    DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange);
305 306 307 308
#if ENABLE(TOUCH_EVENTS)
    DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
309
    DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
310
#endif
311 312
#if ENABLE(FULLSCREEN_API)
    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
313
    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
314
#endif
315 316 317 318
#if ENABLE(POINTER_LOCK)
    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockchange);
    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockerror);
#endif
319
#if ENABLE(PAGE_VISIBILITY_API)
320
    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange);
321
#endif
322 323 324
#if ENABLE(CSP_NEXT)
    DEFINE_ATTRIBUTE_EVENT_LISTENER(securitypolicyviolation);
#endif
325

326
    void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; }
327
    ViewportArguments viewportArguments() const { return m_viewportArguments; }
328 329 330
#ifndef NDEBUG
    bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; }
#endif
331

332
    void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
333
    ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
jochen@chromium.org's avatar
jochen@chromium.org committed
334

335
    DocumentType* doctype() const { return m_docType.get(); }
darin's avatar
darin committed
336

337
    DOMImplementation* implementation();
338 339 340 341 342
    
    Element* documentElement() const
    {
        return m_documentElement.get();
    }
343 344

    bool hasManifest() const;
345
    
346
    virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
347
    PassRefPtr<DocumentFragment> createDocumentFragment();
darin's avatar
darin committed
348 349 350 351
    PassRefPtr<Text> createTextNode(const String& data);
    PassRefPtr<Comment> createComment(const String& data);
    PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
    PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
darin@apple.com's avatar
darin@apple.com committed
352
    PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
jchaffraix@webkit.org's avatar
jchaffraix@webkit.org committed
353
    PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
darin's avatar
darin committed
354
    PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
355
    PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); }
darin's avatar
darin committed
356
    PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
357
    PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
jchaffraix@webkit.org's avatar
jchaffraix@webkit.org committed
358
    PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
mjs's avatar
mjs committed
359

360
    bool cssStickyPositionEnabled() const;
361
    bool cssRegionsEnabled() const;
362
    bool cssCompositingEnabled() const;
363
#if ENABLE(CSS_REGIONS)
364
    PassRefPtr<DOMNamedFlowCollection> webkitGetNamedFlows();
365
#endif
366

367
    NamedFlowCollection* namedFlows();
368

369 370
    bool regionBasedColumnsEnabled() const;

371 372
    bool cssGridLayoutEnabled() const;

darin's avatar
darin committed
373
    Element* elementFromPoint(int x, int y) const;
374 375
    PassRefPtr<Range> caretRangeFromPoint(int x, int y);

darin's avatar
darin committed
376
    String readyState() const;
mjs's avatar
mjs committed
377

dimich@chromium.org's avatar
dimich@chromium.org committed
378
    String defaultCharset() const;
379

dimich@chromium.org's avatar
dimich@chromium.org committed
380 381 382
    String inputEncoding() const { return Document::encoding(); }
    String charset() const { return Document::encoding(); }
    String characterSet() const { return Document::encoding(); }
mjs's avatar
mjs committed
383

384 385
    String encoding() const;

mjs's avatar
mjs committed
386
    void setCharset(const String&);
darin's avatar
darin committed
387

388 389
    void setContent(const String&);

390 391
    String suggestedMIMEType() const;

392
    String contentLanguage() const { return m_contentLanguage; }
393
    void setContentLanguage(const String&);
394

ap's avatar
ap committed
395 396
    String xmlEncoding() const { return m_xmlEncoding; }
    String xmlVersion() const { return m_xmlVersion; }
397 398 399 400
    enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone };
    bool xmlStandalone() const { return m_xmlStandalone == Standalone; }
    StandaloneStatus xmlStandaloneStatus() const { return static_cast<StandaloneStatus>(m_xmlStandalone); }
    bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
ap's avatar
ap committed
401

402
    void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
ap's avatar
ap committed
403 404
    void setXMLVersion(const String&, ExceptionCode&);
    void setXMLStandalone(bool, ExceptionCode&);
405
    void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; }
ap's avatar
ap committed
406

abarth@webkit.org's avatar
abarth@webkit.org committed
407
    String documentURI() const { return m_documentURI; }
rwlbuis's avatar
rwlbuis committed
408 409
    void setDocumentURI(const String&);

darin@apple.com's avatar
darin@apple.com committed
410
    virtual KURL baseURI() const;
rwlbuis's avatar
rwlbuis committed
411

412 413
#if ENABLE(PAGE_VISIBILITY_API)
    String webkitVisibilityState() const;
414
    bool webkitHidden() const;
415 416 417
    void dispatchVisibilityStateChangeEvent();
#endif

418 419 420 421
#if ENABLE(CSP_NEXT)
    DOMSecurityPolicy* securityPolicy();
#endif

darin's avatar
darin committed
422 423
    PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);

424 425 426 427 428 429 430 431 432 433 434 435
    PassRefPtr<HTMLCollection> images();
    PassRefPtr<HTMLCollection> embeds();
    PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
    PassRefPtr<HTMLCollection> applets();
    PassRefPtr<HTMLCollection> links();
    PassRefPtr<HTMLCollection> forms();
    PassRefPtr<HTMLCollection> anchors();
    PassRefPtr<HTMLCollection> scripts();
    PassRefPtr<HTMLCollection> all();

    PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name);
    PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
436

437
    // Other methods (not part of DOM)
438 439 440 441 442 443
    bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; }
    bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; }
    bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; }
    bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; }
    bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; }
    bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; }
mjs's avatar
mjs committed
444
#if ENABLE(SVG)
445
    bool hasSVGRootNode() const;
446
#else
447
    static bool hasSVGRootNode() { return false; }
448
#endif
449
    virtual bool isFrameSet() const { return false; }
abarth@webkit.org's avatar
abarth@webkit.org committed
450 451 452

    bool isSrcdocDocument() const { return m_isSrcdocDocument; }

453
    StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); }
454

455 456
    bool isViewSource() const { return m_isViewSource; }
    void setIsViewSource(bool);
457 458 459

    bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }

460
    StyleResolver* ensureStyleResolver()
461
    { 
462 463 464
        if (!m_styleResolver)
            createStyleResolver();
        return m_styleResolver.get();
465
    }
kocienda's avatar
kocienda committed
466

467
    void notifyRemovePendingSheetIfNeeded();
hyatt's avatar
hyatt committed
468

469
    bool haveStylesheetsLoaded() const;
hyatt's avatar
hyatt committed
470

471 472
    // This is a DOM function.
    StyleSheetList* styleSheets();
hyatt's avatar
hyatt committed
473

474
    DocumentStyleSheetCollection* styleSheetCollection() { return m_styleSheetCollection.get(); }
475

thatcher's avatar
thatcher committed
476 477 478
    bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
    void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }

479 480 481
    /**
     * Called when one or more stylesheets in the document may have been added, removed or changed.
     *
482
     * Creates a new style resolver and assign it to this document. This is done by iterating through all nodes in
483 484 485 486 487
     * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
     * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
     * constructed from these which is used to create the a new style selector which collates all of the stylesheets
     * found and is used to calculate the derived styles for all rendering objects.
     */
488
    void styleResolverChanged(StyleResolverUpdateFlag);
489

490 491
    void didAccessStyleResolver();

492 493
    void evaluateMediaQueryList();

494 495
    // Never returns 0.
    FormController* formController();
darin's avatar
darin committed
496 497
    Vector<String> formElementsState() const;
    void setStateForNewFormElements(const Vector<String>&);
498

499
    FrameView* view() const; // can be NULL
darin's avatar
darin committed
500
    Frame* frame() const { return m_frame; } // can be NULL
501
    Page* page() const; // can be NULL
ggaren's avatar
ggaren committed
502
    Settings* settings() const; // can be NULL
kocienda's avatar
kocienda committed
503

darin's avatar
darin committed
504
    PassRefPtr<Range> createRange();
kocienda's avatar
kocienda committed
505

darin's avatar
darin committed
506
    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
darin@apple.com's avatar
darin@apple.com committed
507
        PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
kocienda's avatar
kocienda committed
508

509
    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
darin@apple.com's avatar
darin@apple.com committed
510
        PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
kocienda's avatar
kocienda committed
511

kocienda's avatar
kocienda committed
512
    // Special support for editing
darin's avatar
darin committed
513
    PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
antti@apple.com's avatar
antti@apple.com committed
514
    PassRefPtr<Text> createEditingTextNode(const String&);
kocienda's avatar
kocienda committed
515

antti@apple.com's avatar
antti@apple.com committed
516
    void recalcStyle(StyleChange = NoChange);
517
    bool childNeedsAndNotInStyleRecalc();
518
    void updateStyleIfNeeded();
darin's avatar
darin committed
519
    void updateLayout();
darin's avatar
darin committed
520
    void updateLayoutIgnorePendingStylesheets();
521
    PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
522
    PassRefPtr<RenderStyle> styleForPage(int pageIndex);
523 524

    // Returns true if page box (margin boxes and page borders) is visible.
525
    bool isPageBoxVisible(int pageIndex);
526 527 528 529 530 531 532

    // Returns the preferred page size and margins in pixels, assuming 96
    // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
    // marginLeft must be initialized to the default values that are used if
    // auto is specified.
    void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);

533
    static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
534
    CachedResourceLoader* cachedResourceLoader() { return m_cachedResourceLoader.get(); }
535 536

    virtual void attach();
kocienda's avatar
kocienda committed
537
    virtual void detach();
538
    void prepareForDestruction();
kocienda's avatar
kocienda committed
539

540 541 542 543
    // Override ScriptExecutionContext methods to do additional work
    virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) OVERRIDE;
    virtual void resumeActiveDOMObjects() OVERRIDE;

544
    RenderArena* renderArena() { return m_renderArena.get(); }
545

546 547 548 549 550 551 552 553 554 555 556
    // Implemented in RenderView.h to avoid a cyclic header dependency this just
    // returns renderer so callers can avoid verbose casts.
    RenderView* renderView() const;

    // Shadow the implementations on Node to provide faster access for documents.
    RenderObject* renderer() const { return m_renderer; }
    void setRenderer(RenderObject* renderer)
    {
        m_renderer = renderer;
        Node::setRenderer(renderer);
    }
557

558
    AXObjectCache* existingAXObjectCache() const;
559
    AXObjectCache* axObjectCache() const;
560 561
    void clearAXObjectCache();

kocienda's avatar
kocienda committed
562 563
    // to get visually ordered hebrew and arabic pages right
    void setVisuallyOrdered();
564
    bool visuallyOrdered() const { return m_visuallyOrdered; }
565
    
566
    DocumentLoader* loader() const;
kocienda's avatar
kocienda committed
567

abarth@webkit.org's avatar
abarth@webkit.org committed
568
    void open(Document* ownerDocument = 0);
mjs's avatar
mjs committed
569
    void implicitOpen();
570 571

    // close() is the DOM API document.close()
572
    void close();
573 574 575 576 577
    // In some situations (see the code), we ignore document.close().
    // explicitClose() bypass these checks and actually tries to close the
    // input stream.
    void explicitClose();
    // implicitClose() actually does the work of closing the input stream.
mjs's avatar
mjs committed
578
    void implicitClose();
579

mjs's avatar
mjs committed
580 581
    void cancelParsing();

582
    void write(const SegmentedString& text, Document* ownerDocument = 0);
abarth@webkit.org's avatar
abarth@webkit.org committed
583 584
    void write(const String& text, Document* ownerDocument = 0);
    void writeln(const String& text, Document* ownerDocument = 0);
kocienda's avatar
kocienda committed
585

ap's avatar
ap committed
586 587
    bool wellFormed() const { return m_wellFormed; }

588
    const KURL& url() const { return m_url; }
darin@apple.com's avatar
darin@apple.com committed
589
    void setURL(const KURL&);
590

591 592
    // To understand how these concepts relate to one another, please see the
    // comments surrounding their declaration.
593
    const KURL& baseURL() const { return m_baseURL; }
594 595
    void setBaseURLOverride(const KURL&);
    const KURL& baseURLOverride() const { return m_baseURLOverride; }
596
    const KURL& baseElementURL() const { return m_baseElementURL; }
darin@apple.com's avatar
darin@apple.com committed
597
    const String& baseTarget() const { return m_baseTarget; }
598
    void processBaseElement();
599

darin@apple.com's avatar
darin@apple.com committed
600
    KURL completeURL(const String&) const;
601
    KURL completeURL(const String&, const KURL& baseURLOverride) const;
darin@apple.com's avatar
darin@apple.com committed
602

603 604
    virtual String userAgent(const KURL&) const;

605
    virtual void disableEval(const String& errorMessage);
606

607
    bool canNavigate(Frame* targetFrame);
608
    Frame* findUnsafeParentScrollPropagationBoundary();
609

darin's avatar
darin committed
610
    CSSStyleSheet* elementSheet();
611
    
612
    virtual PassRefPtr<DocumentParser> createParser();
613 614
    DocumentParser* parser() const { return m_parser.get(); }
    ScriptableDocumentParser* scriptableDocumentParser() const;
615
    
616 617
    bool printing() const { return m_printing; }
    void setPrinting(bool p) { m_printing = p; }
kocienda's avatar
kocienda committed
618

619 620 621 622 623
    bool paginatedForScreen() const { return m_paginatedForScreen; }
    void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
    
    bool paginated() const { return printing() || paginatedForScreen(); }

624
    enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode };
kocienda's avatar
kocienda committed
625

626 627 628
    void setCompatibilityMode(CompatibilityMode m);
    void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
    CompatibilityMode compatibilityMode() const { return m_compatibilityMode; }
629

630 631
    String compatMode() const;

632 633 634
    bool inQuirksMode() const { return m_compatibilityMode == QuirksMode; }
    bool inLimitedQuirksMode() const { return m_compatibilityMode == LimitedQuirksMode; }
    bool inNoQuirksMode() const { return m_compatibilityMode == NoQuirksMode; }
635 636 637 638 639 640 641

    enum ReadyState {
        Loading,
        Interactive,
        Complete
    };
    void setReadyState(ReadyState);
darin's avatar
darin committed
642
    void setParsing(bool);
643
    bool parsing() const { return m_bParsing; }
644
    int minimumLayoutDelay();
645

646
    bool shouldScheduleLayout();
647
    bool isLayoutTimerActive();
hyatt's avatar
hyatt committed
648 649
    int elapsedTime() const;
    
650 651 652 653 654 655 656 657 658
    void setTextColor(const Color& color) { m_textColor = color; }
    Color textColor() const { return m_textColor; }

    const Color& linkColor() const { return m_linkColor; }
    const Color& visitedLinkColor() const { return m_visitedLinkColor; }
    const Color& activeLinkColor() const { return m_activeLinkColor; }
    void setLinkColor(const Color& c) { m_linkColor = c; }
    void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
    void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
659 660 661
    void resetLinkColor();
    void resetVisitedLinkColor();
    void resetActiveLinkColor();
662 663
    VisitedLinkState* visitedLinkState() const { return m_visitedLinkState.get(); }

664
    MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
kocienda's avatar
kocienda committed
665

666 667 668 669
    /* Newly proposed CSS3 mechanism for selecting alternate
       stylesheets using the DOM. May be subject to change as
       spec matures. - dwh
    */
darin's avatar
darin committed
670 671
    String preferredStylesheetSet() const;
    String selectedStylesheetSet() const;
darin's avatar
darin committed
672
    void setSelectedStylesheetSet(const String&);
673

674
    bool setFocusedNode(PassRefPtr<Node>, FocusDirection = FocusDirectionNone);
ggaren's avatar
ggaren committed
675
    Node* focusedNode() const { return m_focusedNode.get(); }
676 677
    UserActionElementSet& userActionElements()  { return m_userActionElements; }
    const UserActionElementSet& userActionElements() const { return m_userActionElements; }
kocienda's avatar
kocienda committed
678

adele@apple.com's avatar
adele@apple.com committed
679 680
    void getFocusableNodes(Vector<RefPtr<Node> >&);
    
adele@apple.com's avatar
adele@apple.com committed
681 682 683 684 685
    // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 
    // for WebCore to ignore the autofocus attribute on any form controls
    bool ignoreAutofocus() const { return m_ignoreAutofocus; };
    void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; };

darin's avatar
darin committed
686
    void setHoverNode(PassRefPtr<Node>);
687 688
    Node* hoverNode() const { return m_hoverNode.get(); }

689
    void setActiveElement(PassRefPtr<Element>);
690
    Element* activeElement() const { return m_activeElement.get(); }
691

alice.liu@apple.com's avatar
alice.liu@apple.com committed
692 693
    void focusedNodeRemoved();
    void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
darin's avatar
darin committed
694 695
    void hoveredNodeDetached(Node*);
    void activeChainNodeDetached(Node*);
696

697
    void updateHoverActiveState(const HitTestRequest&, Element*, const PlatformMouseEvent* = 0);
698

699
    // Updates for :target (CSS3 selector).
700 701
    void setCSSTarget(Element*);
    Element* cssTarget() const { return m_cssTarget; }
702
    
703
    void scheduleForcedStyleRecalc();
704 705
    void scheduleStyleRecalc();
    void unscheduleStyleRecalc();
706 707
    bool hasPendingStyleRecalc() const;
    bool hasPendingForcedStyleRecalc() const;
708
    void styleRecalcTimerFired(Timer<Document>*);
709

710 711
    void registerNodeList(LiveNodeListBase*);
    void unregisterNodeList(LiveNodeListBase*);
712
    bool shouldInvalidateNodeListCaches(const QualifiedName* attrName = 0) const;
713
    void invalidateNodeListCaches(const QualifiedName* attrName);
714

darin's avatar
darin committed
715 716
    void attachNodeIterator(NodeIterator*);
    void detachNodeIterator(NodeIterator*);
717
    void moveNodeIteratorsToNewDocument(Node*, Document*);
darin@apple.com's avatar
darin@apple.com committed
718 719 720 721

    void attachRange(Range*);
    void detachRange(Range*);

722
    void updateRangesAfterChildrenChanged(ContainerNode*);
723 724
    // nodeChildrenWillBeRemoved is used when removing all node children at once.
    void nodeChildrenWillBeRemoved(ContainerNode*);
ap@apple.com's avatar
ap@apple.com committed
725
    // nodeWillBeRemoved is only safe when removing one node at a time.
darin@apple.com's avatar
darin@apple.com committed
726
    void nodeWillBeRemoved(Node*);
727
    bool canReplaceChild(Node* newChild, Node* oldChild);
darin@apple.com's avatar
darin@apple.com committed
728 729 730 731 732 733

    void textInserted(Node*, unsigned offset, unsigned length);
    void textRemoved(Node*, unsigned offset, unsigned length);
    void textNodesMerged(Text* oldNode, unsigned offset);
    void textNodeSplit(Text* oldNode);

734 735 736 737 738
    void createDOMWindow();
    void takeDOMWindowFrom(Document*);

    DOMWindow* domWindow() const { return m_domWindow.get(); }
    // In DOM Level 2, the Document's DOMWindow is called the defaultView.
weinig@apple.com's avatar
weinig@apple.com committed
739 740
    DOMWindow* defaultView() const { return domWindow(); } 

741 742
    // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
    void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
weinig@apple.com's avatar
weinig@apple.com committed
743
    EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
744 745
    void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
    void dispatchWindowLoadEvent();
746

darin's avatar
darin committed
747
    PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
kocienda's avatar
kocienda committed
748 749

    // keep track of what types of event listeners are registered, so we don't
750
    // dispatch events unnecessarily
kocienda's avatar
kocienda committed
751
    enum ListenerType {
adamk@chromium.org's avatar