~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/dom/Document.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4
4
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
5
5
 *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6
 
 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7
 
 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
 
6
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
 
7
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8
8
 *
9
9
 * This library is free software; you can redistribute it and/or
10
10
 * modify it under the terms of the GNU Library General Public
26
26
#ifndef Document_h
27
27
#define Document_h
28
28
 
29
 
#include "Attr.h"
 
29
#include "CachedResourceHandle.h"
 
30
#include "CheckedRadioButtons.h"
 
31
#include "ContainerNode.h"
 
32
#include "CollectionCache.h"
 
33
#include "CollectionType.h"
30
34
#include "Color.h"
31
35
#include "DocumentMarker.h"
32
 
#include "HTMLCollection.h"
33
 
#include "HTMLFormElement.h"
 
36
#include "Page.h"
34
37
#include "ScriptExecutionContext.h"
35
 
#include "StringHash.h"
36
38
#include "Timer.h"
37
39
#include <wtf/HashCountedSet.h>
38
 
#include <wtf/ListHashSet.h>
39
 
 
40
 
// FIXME: We should move Mac off of the old Frame-based user stylesheet loading
41
 
// code and onto the new code in Page. We can't do that until the code in Page
42
 
// supports non-file: URLs, however.
43
 
#if PLATFORM(MAC) || PLATFORM(QT)
44
 
#define FRAME_LOADS_USER_STYLESHEET 1
45
 
#else
46
 
#define FRAME_LOADS_USER_STYLESHEET 0
47
 
#endif
 
40
#include <wtf/OwnPtr.h>
 
41
#include <wtf/PassOwnPtr.h>
48
42
 
49
43
namespace WebCore {
50
44
 
 
45
    class Attr;
51
46
    class AXObjectCache;
52
 
    class Attr;
53
 
    class Attribute;
54
47
    class CDATASection;
55
48
    class CachedCSSStyleSheet;
56
 
    class CanvasRenderingContext2D;
 
49
    class CachedScript;
 
50
    class CanvasRenderingContext;
57
51
    class CharacterData;
58
52
    class CSSStyleDeclaration;
59
53
    class CSSStyleSelector;
62
56
    class Database;
63
57
    class DOMImplementation;
64
58
    class DOMSelection;
65
 
    class DOMTimer;
66
59
    class DOMWindow;
67
60
    class DatabaseThread;
68
61
    class DocLoader;
75
68
    class EventListener;
76
69
    class Frame;
77
70
    class FrameView;
 
71
    class HitTestRequest;
78
72
    class HTMLCanvasElement;
 
73
    class HTMLCollection;
79
74
    class HTMLDocument;
80
75
    class HTMLElement;
81
 
    class HTMLFormControlElementWithState;
82
76
    class HTMLFormElement;
83
77
    class HTMLHeadElement;
84
78
    class HTMLInputElement;
85
79
    class HTMLMapElement;
86
 
    class ImageLoader;
 
80
    class InspectorTimelineAgent;
87
81
    class IntPoint;
88
82
    class JSNode;
89
83
    class MouseEventWithHitTestResults;
90
84
    class NodeFilter;
91
85
    class NodeIterator;
92
 
    class Page;
93
86
    class PlatformMouseEvent;
94
87
    class ProcessingInstruction;
95
88
    class Range;
96
89
    class RegisteredEventListener;
97
90
    class RenderArena;
 
91
    class RenderView;
 
92
    class ScriptElementData;
98
93
    class SecurityOrigin;
 
94
    class SegmentedString;
99
95
    class Settings;
100
96
    class StyleSheet;
101
97
    class StyleSheetList;
109
105
    class SVGDocumentExtensions;
110
106
#endif
111
107
    
 
108
#if ENABLE(XSLT)
 
109
    class TransformSource;
 
110
#endif
 
111
 
112
112
#if ENABLE(XBL)
113
113
    class XBLBindingManager;
114
114
#endif
123
123
#if ENABLE(DASHBOARD_SUPPORT)
124
124
    struct DashboardRegionValue;
125
125
#endif
126
 
    struct HitTestRequest;
127
126
 
128
127
    typedef int ExceptionCode;
129
128
 
171
170
public:
172
171
    static PassRefPtr<Document> create(Frame* frame)
173
172
    {
174
 
        return new Document(frame, false);
 
173
        return adoptRef(new Document(frame, false));
175
174
    }
176
175
    static PassRefPtr<Document> createXHTML(Frame* frame)
177
176
    {
178
 
        return new Document(frame, true);
 
177
        return adoptRef(new Document(frame, true));
179
178
    }
180
179
    virtual ~Document();
181
180
 
182
 
    virtual bool isDocument() const { return true; }
183
 
 
184
181
    using ContainerNode::ref;
185
182
    using ContainerNode::deref;
186
 
    virtual void removedLastRef();
187
183
 
188
184
    // Nodes belonging to this document hold "self-only" references -
189
185
    // these are enough to keep the document from being destroyed, but
210
206
 
211
207
    // DOM methods & attributes for Document
212
208
 
 
209
    DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
 
210
    DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
 
211
    DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
 
212
    DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
 
213
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
 
214
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
 
215
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
 
216
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
 
217
    DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
 
218
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
 
219
    DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
 
220
    DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
 
221
    DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
 
222
    DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
 
223
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
 
224
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
 
225
    DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
 
226
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
 
227
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
 
228
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
 
229
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
 
230
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
 
231
    DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
 
232
    DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
 
233
    DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
 
234
    DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
 
235
 
 
236
    DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
 
237
    DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
 
238
    DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
 
239
    DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
 
240
 
 
241
    // WebKit extensions
 
242
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
 
243
    DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
 
244
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
 
245
    DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
 
246
    DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
 
247
    DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
 
248
    DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
 
249
    DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
 
250
    DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
 
251
 
213
252
    DocumentType* doctype() const { return m_docType.get(); }
214
253
 
215
254
    DOMImplementation* implementation() const;
216
 
    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
217
 
    Element* documentElement() const;
 
255
    
 
256
    Element* documentElement() const
 
257
    {
 
258
        if (!m_documentElement)
 
259
            cacheDocumentElement();
 
260
        return m_documentElement.get();
 
261
    }
 
262
    
218
263
    virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
219
 
    PassRefPtr<DocumentFragment> createDocumentFragment ();
 
264
    PassRefPtr<DocumentFragment> createDocumentFragment();
220
265
    PassRefPtr<Text> createTextNode(const String& data);
221
266
    PassRefPtr<Comment> createComment(const String& data);
222
267
    PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
223
268
    PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
224
 
    PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode& ec) { return createAttributeNS(String(), name, ec, true); }
 
269
    PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
225
270
    PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
226
271
    PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
227
272
    PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
228
273
    virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
229
 
    PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser, ExceptionCode& ec);
 
274
    PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
230
275
    Element* getElementById(const AtomicString&) const;
231
276
    bool hasElementWithId(AtomicStringImpl* id) const;
232
277
    bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
233
278
 
234
279
    Element* elementFromPoint(int x, int y) const;
 
280
    PassRefPtr<Range> caretRangeFromPoint(int x, int y);
 
281
 
235
282
    String readyState() const;
236
 
    String inputEncoding() const;
 
283
 
237
284
    String defaultCharset() const;
238
 
 
239
 
    String charset() const { return inputEncoding(); }
240
 
    String characterSet() const { return inputEncoding(); }
 
285
    
 
286
    // Synonyms backing similar DOM attributes. Use Document::encoding() to avoid virtual dispatch.
 
287
    String inputEncoding() const { return Document::encoding(); }
 
288
    String charset() const { return Document::encoding(); }
 
289
    String characterSet() const { return Document::encoding(); }
241
290
 
242
291
    void setCharset(const String&);
243
292
 
279
328
    // quirks mode for historical compatibility reasons.
280
329
    Element* findAnchor(const String& name);
281
330
 
282
 
    HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
 
331
    CollectionCache* collectionInfo(CollectionType type)
283
332
    {
284
 
        ASSERT(type >= HTMLCollection::FirstUnnamedDocumentCachedType);
285
 
        unsigned index = type - HTMLCollection::FirstUnnamedDocumentCachedType;
286
 
        ASSERT(index < HTMLCollection::NumUnnamedDocumentCachedTypes);
 
333
        ASSERT(type >= FirstUnnamedDocumentCachedType);
 
334
        unsigned index = type - FirstUnnamedDocumentCachedType;
 
335
        ASSERT(index < NumUnnamedDocumentCachedTypes);
287
336
        return &m_collectionInfo[index]; 
288
337
    }
289
338
 
290
 
    HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, const AtomicString& name);
291
 
 
292
 
    // DOM methods overridden from  parent classes
293
 
 
294
 
    virtual String nodeName() const;
295
 
    virtual NodeType nodeType() const;
 
339
    CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name);
296
340
 
297
341
    // Other methods (not part of DOM)
298
342
    virtual bool isHTMLDocument() const { return false; }
299
343
    virtual bool isImageDocument() const { return false; }
300
344
#if ENABLE(SVG)
301
345
    virtual bool isSVGDocument() const { return false; }
 
346
#else
 
347
    static bool isSVGDocument() { return false; }
302
348
#endif
303
349
    virtual bool isPluginDocument() const { return false; }
304
350
    virtual bool isMediaDocument() const { return false; }
305
351
#if ENABLE(WML)
306
352
    virtual bool isWMLDocument() const { return false; }
307
353
#endif
 
354
#if ENABLE(XHTMLMP)
 
355
    bool isXHTMLMPDocument() const; 
 
356
    bool shouldProcessNoscriptElement() const { return m_shouldProcessNoScriptElement; }
 
357
    void setShouldProcessNoscriptElement(bool shouldDo) { m_shouldProcessNoScriptElement = shouldDo; }
 
358
#endif
 
359
    virtual bool isFrameSet() const { return false; }
308
360
    
309
361
    CSSStyleSelector* styleSelector() const { return m_styleSelector; }
310
362
 
321
373
     */
322
374
    bool haveStylesheetsLoaded() const
323
375
    {
324
 
        return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets
325
 
#if USE(LOW_BANDWIDTH_DISPLAY)
326
 
            || m_inLowBandwidthDisplay
327
 
#endif
328
 
            ;
 
376
        return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets;
329
377
    }
330
378
 
331
379
    /**
361
409
    void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; }
362
410
    bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
363
411
    void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
 
412
    bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules; }
 
413
    void setUsesBeforeAfterRules(bool b) { m_usesBeforeAfterRules = b; }
 
414
    bool usesRemUnits() const { return m_usesRemUnits; }
 
415
    void setUsesRemUnits(bool b) { m_usesRemUnits = b; }
364
416
 
365
417
    // Machinery for saving and restoring state when you leave and then go back to a page.
366
 
    void registerFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.add(e); }
367
 
    void unregisterFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.remove(e); }
 
418
    void registerFormElementWithState(Element* e) { m_formElementsWithState.add(e); }
 
419
    void unregisterFormElementWithState(Element* e) { m_formElementsWithState.remove(e); }
368
420
    Vector<String> formElementsState() const;
369
421
    void setStateForNewFormElements(const Vector<String>&);
370
422
    bool hasStateForNewFormElements() const;
374
426
    Frame* frame() const { return m_frame; } // can be NULL
375
427
    Page* page() const; // can be NULL
376
428
    Settings* settings() const; // can be NULL
 
429
#if ENABLE(INSPECTOR)
 
430
    InspectorTimelineAgent* inspectorTimelineAgent() const; // can be NULL
 
431
#endif
377
432
 
378
433
    PassRefPtr<Range> createRange();
379
434
 
387
442
    PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
388
443
    PassRefPtr<EditingText> createEditingTextNode(const String&);
389
444
 
390
 
    virtual void recalcStyle( StyleChange = NoChange );
391
 
    virtual void updateRendering();
 
445
    virtual void recalcStyle(StyleChange = NoChange);
 
446
    bool childNeedsAndNotInStyleRecalc();
 
447
    virtual void updateStyleIfNeeded();
392
448
    void updateLayout();
393
449
    void updateLayoutIgnorePendingStylesheets();
394
 
    static void updateDocumentsRendering();
 
450
    static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
395
451
    DocLoader* docLoader() { return m_docLoader; }
396
452
 
397
453
    virtual void attach();
398
454
    virtual void detach();
399
455
 
400
 
    void clearFramePointer();
401
 
 
402
456
    RenderArena* renderArena() { return m_renderArena; }
403
457
 
 
458
    RenderView* renderView() const;
 
459
 
404
460
    void clearAXObjectCache();
405
461
    AXObjectCache* axObjectCache() const;
406
462
    
413
469
    void implicitClose();
414
470
    void cancelParsing();
415
471
 
 
472
    void write(const SegmentedString& text, Document* ownerDocument = 0);
416
473
    void write(const String& text, Document* ownerDocument = 0);
417
474
    void writeln(const String& text, Document* ownerDocument = 0);
418
475
    void finishParsing();
433
490
 
434
491
    KURL completeURL(const String&) const;
435
492
 
436
 
    // from cachedObjectClient
437
 
    virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*);
438
 
 
439
 
#if FRAME_LOADS_USER_STYLESHEET
440
 
    void setUserStyleSheet(const String& sheet);
441
 
#endif
442
 
 
443
 
    String userStyleSheet() const;
 
493
    virtual String userAgent(const KURL&) const;
 
494
 
 
495
    CSSStyleSheet* pageUserSheet();
 
496
    void clearPageUserSheet();
 
497
 
 
498
    const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
 
499
    void clearPageGroupUserSheets();
444
500
 
445
501
    CSSStyleSheet* elementSheet();
446
502
    CSSStyleSheet* mappedElementSheet();
 
503
    
447
504
    virtual Tokenizer* createTokenizer();
448
505
    Tokenizer* tokenizer() { return m_tokenizer; }
449
506
    
452
509
 
453
510
    enum ParseMode { Compat, AlmostStrict, Strict };
454
511
 
455
 
private:
456
 
    virtual void determineParseMode() {}
457
 
    
458
 
public:
459
512
    void setParseMode(ParseMode m) { m_parseMode = m; }
460
513
    ParseMode parseMode() const { return m_parseMode; }
461
514
 
484
537
    
485
538
    MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&);
486
539
 
487
 
    virtual bool childTypeAllowed(NodeType);
488
 
    virtual PassRefPtr<Node> cloneNode(bool deep);
489
 
 
490
 
    virtual bool canReplaceChild(Node* newChild, Node* oldChild);
491
 
    
492
540
    StyleSheetList* styleSheets();
493
541
 
494
542
    /* Newly proposed CSS3 mechanism for selecting alternate
502
550
    bool setFocusedNode(PassRefPtr<Node>);
503
551
    Node* focusedNode() const { return m_focusedNode.get(); }
504
552
 
 
553
    void getFocusableNodes(Vector<RefPtr<Node> >&);
 
554
    
505
555
    // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 
506
556
    // for WebCore to ignore the autofocus attribute on any form controls
507
557
    bool ignoreAutofocus() const { return m_ignoreAutofocus; };
519
569
    void activeChainNodeDetached(Node*);
520
570
 
521
571
    // Updates for :target (CSS3 selector).
522
 
    void setCSSTarget(Node*);
523
 
    Node* getCSSTarget() const;
 
572
    void setCSSTarget(Element*);
 
573
    Element* cssTarget() const { return m_cssTarget; }
524
574
    
525
 
    void setDocumentChanged(bool);
 
575
    void scheduleStyleRecalc();
 
576
    void unscheduleStyleRecalc();
 
577
    void styleRecalcTimerFired(Timer<Document>*);
526
578
 
527
579
    void attachNodeIterator(NodeIterator*);
528
580
    void detachNodeIterator(NodeIterator*);
541
593
    DOMWindow* defaultView() const { return domWindow(); } 
542
594
    DOMWindow* domWindow() const;
543
595
 
 
596
    // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
 
597
    void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
 
598
    EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
 
599
    void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
 
600
    void dispatchWindowLoadEvent();
 
601
 
544
602
    PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
545
603
 
546
604
    // keep track of what types of event listeners are registered, so we don't
566
624
 
567
625
    CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
568
626
 
569
 
    void handleWindowEvent(Event*, bool useCapture);
570
 
    void setWindowInlineEventListenerForType(const AtomicString& eventType, PassRefPtr<EventListener>);
571
 
    EventListener* windowInlineEventListenerForType(const AtomicString& eventType);
572
 
    void removeWindowInlineEventListenerForType(const AtomicString& eventType);
573
 
 
574
 
    void setWindowInlineEventListenerForTypeAndAttribute(const AtomicString& eventType, Attribute*);
575
 
 
576
 
    void addWindowEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
577
 
    void removeWindowEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
578
 
    bool hasWindowEventListener(const AtomicString& eventType);
579
 
    
580
 
    void addPendingFrameUnloadEventCount();
581
 
    void removePendingFrameUnloadEventCount();
582
 
    void addPendingFrameBeforeUnloadEventCount();
583
 
    void removePendingFrameBeforeUnloadEventCount();
584
 
 
585
 
    PassRefPtr<EventListener> createEventListener(const String& functionName, const String& code, Node*);
586
 
 
587
627
    /**
588
628
     * Searches through the document, starting from fromNode, for the next selectable element that comes after fromNode.
589
629
     * The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab indexes
624
664
     */
625
665
    void processHttpEquiv(const String& equiv, const String& content);
626
666
    
627
 
    void dispatchImageLoadEventSoon(ImageLoader*);
628
 
    void dispatchImageLoadEventsNow();
629
 
    void removeImage(ImageLoader*);
630
 
    
631
667
    // Returns the owning element in the parent document.
632
668
    // Returns 0 if this is the top level document.
633
669
    Element* ownerElement() const;
642
678
    String referrer() const;
643
679
 
644
680
    String domain() const;
645
 
    void setDomain(const String& newDomain);
 
681
    void setDomain(const String& newDomain, ExceptionCode&);
646
682
 
647
683
    String lastModified() const;
648
684
 
649
685
    const KURL& cookieURL() const { return m_cookieURL; }
650
686
 
651
 
    const KURL& policyBaseURL() const { return m_policyBaseURL; }
652
 
    void setPolicyBaseURL(const KURL& url) { m_policyBaseURL = url; }
 
687
    const KURL& firstPartyForCookies() const { return m_firstPartyForCookies; }
 
688
    void setFirstPartyForCookies(const KURL& url) { m_firstPartyForCookies = url; }
653
689
    
654
690
    // The following implements the rule from HTML 4 for what valid names are.
655
691
    // To get this right for all the XML cases, we probably have to improve this or move it
671
707
    void removeImageMap(HTMLMapElement*);
672
708
    HTMLMapElement* getImageMap(const String& url) const;
673
709
 
674
 
    HTMLElement* body();
 
710
    HTMLElement* body() const;
675
711
    void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
676
712
 
677
713
    HTMLHeadElement* head();
694
730
    void setRenderedRectForMarker(Node*, DocumentMarker, const IntRect&);
695
731
    void invalidateRenderedRectsForMarkersInRect(const IntRect&);
696
732
    void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
 
733
    void setMarkersActive(Range*, bool);
 
734
    void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
697
735
 
698
736
    DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
699
737
    Vector<DocumentMarker> markersForNode(Node*);
710
748
 
711
749
    int docID() const { return m_docID; }
712
750
 
 
751
    void executeScriptSoon(ScriptElementData*, CachedResourceHandle<CachedScript>);
 
752
 
713
753
#if ENABLE(XSLT)
714
754
    void applyXSLTransform(ProcessingInstruction* pi);
715
 
    void setTransformSource(void* doc);
716
 
    const void* transformSource() { return m_transformSource; }
717
755
    PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
718
756
    void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
 
757
 
 
758
    void setTransformSource(PassOwnPtr<TransformSource>);
 
759
    TransformSource* transformSource() const { return m_transformSource.get(); }
719
760
#endif
720
761
 
721
762
#if ENABLE(XBL)
728
769
 
729
770
    void setDocType(PassRefPtr<DocumentType>);
730
771
 
731
 
    virtual void finishedParsing();
732
 
 
733
772
#if ENABLE(XPATH)
734
773
    // XPathEvaluator methods
735
774
    PassRefPtr<XPathExpression> createExpression(const String& expression,
755
794
 
756
795
    void setUseSecureKeyboardEntryWhenActive(bool);
757
796
    bool useSecureKeyboardEntryWhenActive() const;
758
 
    
759
 
#if USE(LOW_BANDWIDTH_DISPLAY)
760
 
    void setDocLoader(DocLoader* loader) { m_docLoader = loader; }
761
 
    bool inLowBandwidthDisplay() const { return m_inLowBandwidthDisplay; }
762
 
    void setLowBandwidthDisplay(bool lowBandWidth) { m_inLowBandwidthDisplay = lowBandWidth; }
763
 
#endif
764
 
    
 
797
 
765
798
    void addNodeListCache() { ++m_numNodeListCaches; }
766
799
    void removeNodeListCache() { ASSERT(m_numNodeListCaches > 0); --m_numNodeListCaches; }
767
800
    bool hasNodeListCaches() const { return m_numNodeListCaches; }
773
806
    DOMSelection* getSelection() const;
774
807
    
775
808
    // Extension for manipulating canvas drawing contexts for use in CSS
776
 
    CanvasRenderingContext2D* getCSSCanvasContext(const String& type, const String& name, int width, int height);
 
809
    CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
777
810
    HTMLCanvasElement* getCSSCanvasElement(const String& name);
778
811
 
779
812
    bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
780
 
    void initDNSPrefetch();
781
813
    void parseDNSPrefetchControlHeader(const String&);
782
814
 
783
815
    virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL);
 
816
    virtual void addMessage(MessageDestination, MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
 
817
    virtual void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const ScriptString& sourceString);
 
818
    virtual void scriptImported(unsigned long, const String&);
784
819
    virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously.
785
820
 
786
 
    void addTimeout(int timeoutId, DOMTimer*);
787
 
    void removeTimeout(int timeoutId);
788
 
    DOMTimer* findTimeout(int timeoutId);
789
 
    
 
821
    typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache;
 
822
    JSWrapperCache& wrapperCache() { return m_wrapperCache; }
 
823
 
 
824
    virtual void finishedParsing();
 
825
 
 
826
    bool inPageCache() const { return m_inPageCache; }
 
827
    void setInPageCache(bool flag);
 
828
    
 
829
    // Elements can register themselves for the "documentWillBecomeInactive()" and  
 
830
    // "documentDidBecomeActive()" callbacks
 
831
    void registerForDocumentActivationCallbacks(Element*);
 
832
    void unregisterForDocumentActivationCallbacks(Element*);
 
833
    void documentWillBecomeInactive();
 
834
    void documentDidBecomeActive();
 
835
 
 
836
    void registerForMediaVolumeCallbacks(Element*);
 
837
    void unregisterForMediaVolumeCallbacks(Element*);
 
838
    void mediaVolumeDidChange();
 
839
 
 
840
    void setShouldCreateRenderers(bool);
 
841
    bool shouldCreateRenderers();
 
842
 
 
843
    void setDecoder(PassRefPtr<TextResourceDecoder>);
 
844
    TextResourceDecoder* decoder() const { return m_decoder.get(); }
 
845
 
 
846
    String displayStringModifiedByEncoding(const String&) const;
 
847
    PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
 
848
    void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
 
849
 
 
850
    // Quirk for the benefit of Apple's Dictionary application.
 
851
    void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
 
852
    bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; }
 
853
 
 
854
#if ENABLE(DASHBOARD_SUPPORT)
 
855
    void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
 
856
    bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
 
857
    bool hasDashboardRegions () const { return m_hasDashboardRegions; }
 
858
    void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; }
 
859
    const Vector<DashboardRegionValue>& dashboardRegions() const;
 
860
    void setDashboardRegions(const Vector<DashboardRegionValue>&);
 
861
#endif
 
862
 
 
863
    virtual void removeAllEventListeners();
 
864
 
 
865
    CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
 
866
    
 
867
#if ENABLE(SVG)
 
868
    const SVGDocumentExtensions* svgExtensions();
 
869
    SVGDocumentExtensions* accessSVGExtensions();
 
870
#endif
 
871
 
 
872
    void initSecurityContext();
 
873
 
 
874
    // Explicitly override the security origin for this document.
 
875
    // Note: It is dangerous to change the security origin of a document
 
876
    //       that already contains content.
 
877
    void setSecurityOrigin(SecurityOrigin*);
 
878
 
 
879
    bool processingLoadEvent() const { return m_processingLoadEvent; }
 
880
 
 
881
#if ENABLE(DATABASE)
 
882
    void addOpenDatabase(Database*);
 
883
    void removeOpenDatabase(Database*);
 
884
    DatabaseThread* databaseThread();   // Creates the thread as needed, but not if it has been already terminated.
 
885
    void setHasOpenDatabases() { m_hasOpenDatabases = true; }
 
886
    bool hasOpenDatabases() { return m_hasOpenDatabases; }
 
887
    void stopDatabases();
 
888
#endif
 
889
 
 
890
    void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
 
891
    bool usingGeolocation() const { return m_usingGeolocation; };
 
892
 
 
893
#if ENABLE(WML)
 
894
    void setContainsWMLContent(bool value) { m_containsWMLContent = value; }
 
895
    bool containsWMLContent() const { return m_containsWMLContent; }
 
896
 
 
897
    void resetWMLPageState();
 
898
    void initializeWMLPageState();
 
899
#endif
 
900
 
790
901
protected:
791
902
    Document(Frame*, bool isXHTML);
792
903
 
 
904
    void setStyleSelector(CSSStyleSelector* styleSelector) { m_styleSelector = styleSelector; }
 
905
 
 
906
    void clearXMLVersion() { m_xmlVersion = String(); }
 
907
 
793
908
private:
 
909
    virtual bool isDocument() const { return true; }
 
910
    virtual void removedLastRef();
 
911
    virtual void determineParseMode() { }
 
912
 
 
913
    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
914
 
 
915
    virtual String nodeName() const;
 
916
    virtual NodeType nodeType() const;
 
917
    virtual bool childTypeAllowed(NodeType);
 
918
    virtual PassRefPtr<Node> cloneNode(bool deep);
 
919
    virtual bool canReplaceChild(Node* newChild, Node* oldChild);
 
920
 
794
921
    virtual void refScriptExecutionContext() { ref(); }
795
922
    virtual void derefScriptExecutionContext() { deref(); }
796
923
 
797
924
    virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls.
798
925
    virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above.
799
926
 
 
927
    void initDNSPrefetch();
 
928
 
 
929
    String encoding() const;
 
930
 
 
931
    void executeScriptSoonTimerFired(Timer<Document>*);
 
932
 
 
933
    void updateTitle();
 
934
    void updateFocusAppearanceTimerFired(Timer<Document>*);
 
935
    void updateBaseURL();
 
936
 
 
937
    void cacheDocumentElement() const;
 
938
 
800
939
    CSSStyleSelector* m_styleSelector;
801
940
    bool m_didCalculateStyleSelector;
802
941
 
810
949
    KURL m_baseURL;  // Node.baseURI: The URL to use when resolving relative URLs.
811
950
    KURL m_baseElementURL;  // The URL set by the <base> element.
812
951
    KURL m_cookieURL;  // The URL to use for cookie access.
813
 
    KURL m_policyBaseURL;  // The policy URL for third-party cookie blocking.
 
952
    KURL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.
814
953
 
815
954
    // Document.documentURI:
816
955
    // Although URL-like, Document.documentURI can actually be set to any
824
963
    RefPtr<DocumentType> m_docType;
825
964
    mutable RefPtr<DOMImplementation> m_implementation;
826
965
 
827
 
    RefPtr<StyleSheet> m_sheet;
828
 
#if FRAME_LOADS_USER_STYLESHEET
829
 
    String m_usersheet;
830
 
#endif
831
 
 
832
966
    // Track the number of currently loading top-level stylesheets.  Sheets
833
967
    // loaded using the @import directive are not included in this count.
834
968
    // We use this count of pending sheets to detect when we can begin attaching
848
982
 
849
983
    RefPtr<CSSStyleSheet> m_elemSheet;
850
984
    RefPtr<CSSStyleSheet> m_mappedElementSheet;
 
985
    RefPtr<CSSStyleSheet> m_pageUserSheet;
 
986
    mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
 
987
    mutable bool m_pageGroupUserSheetCacheValid;
851
988
 
852
989
    bool m_printing;
853
990
    
872
1009
    RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set.
873
1010
    ListHashSet<Node*> m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>)
874
1011
 
875
 
    RegisteredEventListenerVector m_windowEventListeners;
876
 
 
877
1012
    typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
878
 
    ListHashSet<HTMLFormControlElementWithState*> m_formElementsWithState;
 
1013
    ListHashSet<Element*> m_formElementsWithState;
879
1014
    FormElementStateMap m_stateForNewFormElements;
880
1015
    
881
1016
    Color m_linkColor;
888
1023
    bool m_loadingSheet;
889
1024
    bool visuallyOrdered;
890
1025
    bool m_bParsing;
891
 
    bool m_docChanged;
 
1026
    Timer<Document> m_styleRecalcTimer;
892
1027
    bool m_inStyleRecalc;
893
1028
    bool m_closeAfterStyleRecalc;
894
1029
    bool m_usesDescendantRules;
895
1030
    bool m_usesSiblingRules;
896
1031
    bool m_usesFirstLineRules;
897
1032
    bool m_usesFirstLetterRules;
 
1033
    bool m_usesBeforeAfterRules;
 
1034
    bool m_usesRemUnits;
898
1035
    bool m_gotoAnchorNeededAfterStylesheetsLoad;
899
1036
    bool m_isDNSPrefetchEnabled;
900
1037
    bool m_haveExplicitlyDisabledDNSPrefetch;
912
1049
 
913
1050
    mutable AXObjectCache* m_axObjectCache;
914
1051
    
915
 
    Vector<ImageLoader*> m_imageLoadEventDispatchSoonList;
916
 
    Vector<ImageLoader*> m_imageLoadEventDispatchingList;
917
 
    Timer<Document> m_imageLoadEventTimer;
918
 
 
919
1052
    Timer<Document> m_updateFocusAppearanceTimer;
920
1053
 
921
 
    Node* m_cssTarget;
 
1054
    Element* m_cssTarget;
922
1055
    
923
1056
    bool m_processingLoadEvent;
924
1057
    double m_startTime;
925
1058
    bool m_overMinimumLayoutThreshold;
 
1059
 
 
1060
    Vector<std::pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > m_scriptsToExecuteSoon;
 
1061
    Timer<Document> m_executeScriptSoonTimer;
926
1062
    
927
1063
#if ENABLE(XSLT)
928
 
    void* m_transformSource;
 
1064
    OwnPtr<TransformSource> m_transformSource;
929
1065
    RefPtr<Document> m_transformSourceDocument;
930
1066
#endif
931
1067
 
936
1072
    typedef HashMap<AtomicStringImpl*, HTMLMapElement*> ImageMapsByName;
937
1073
    ImageMapsByName m_imageMapsByName;
938
1074
 
939
 
    HashSet<Node*> m_disconnectedNodesWithEventListeners;
940
 
 
941
1075
    int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
942
1076
 
943
1077
    String m_xmlEncoding;
946
1080
 
947
1081
    String m_contentLanguage;
948
1082
 
949
 
public:
950
 
    bool inPageCache();
951
 
    void setInPageCache(bool flag);
952
 
    
953
 
    // Elements can register themselves for the "documentWillBecomeInactive()" and  
954
 
    // "documentDidBecomeActive()" callbacks
955
 
    void registerForDocumentActivationCallbacks(Element*);
956
 
    void unregisterForDocumentActivationCallbacks(Element*);
957
 
    void documentWillBecomeInactive();
958
 
    void documentDidBecomeActive();
959
 
 
960
 
    void registerForMediaVolumeCallbacks(Element*);
961
 
    void unregisterForMediaVolumeCallbacks(Element*);
962
 
    void mediaVolumeDidChange();
963
 
 
964
 
    void setShouldCreateRenderers(bool);
965
 
    bool shouldCreateRenderers();
966
 
    
967
 
    void setDecoder(PassRefPtr<TextResourceDecoder>);
968
 
    TextResourceDecoder* decoder() const { return m_decoder.get(); }
969
 
 
970
 
    UChar backslashAsCurrencySymbol() const;
971
 
 
972
 
    // Quirk for the benefit of Apple's Dictionary application.
973
 
    void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
974
 
    bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; }
975
 
 
976
 
#if ENABLE(DASHBOARD_SUPPORT)
977
 
    void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
978
 
    bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
979
 
    bool hasDashboardRegions () const { return m_hasDashboardRegions; }
980
 
    void setHasDashboardRegions (bool f) { m_hasDashboardRegions = f; }
981
 
    const Vector<DashboardRegionValue>& dashboardRegions() const;
982
 
    void setDashboardRegions(const Vector<DashboardRegionValue>&);
983
 
#endif
984
 
 
985
 
    void removeAllEventListenersFromAllNodes();
986
 
 
987
 
    void registerDisconnectedNodeWithEventListeners(Node*);
988
 
    void unregisterDisconnectedNodeWithEventListeners(Node*);
989
 
    
990
 
    HTMLFormElement::CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
991
 
    
992
 
#if ENABLE(SVG)
993
 
    const SVGDocumentExtensions* svgExtensions();
994
 
    SVGDocumentExtensions* accessSVGExtensions();
995
 
#endif
996
 
 
997
 
    void initSecurityContext();
998
 
 
999
 
    // Explicitly override the security origin for this document.
1000
 
    // Note: It is dangerous to change the security origin of a document
1001
 
    //       that already contains content.
1002
 
    void setSecurityOrigin(SecurityOrigin*);
1003
 
 
1004
 
    bool processingLoadEvent() const { return m_processingLoadEvent; }
1005
 
 
1006
 
#if ENABLE(DATABASE)
1007
 
    void addOpenDatabase(Database*);
1008
 
    void removeOpenDatabase(Database*);
1009
 
    DatabaseThread* databaseThread();   // Creates the thread as needed, but not if it has been already terminated.
1010
 
    void setHasOpenDatabases() { m_hasOpenDatabases = true; }
1011
 
    bool hasOpenDatabases() { return m_hasOpenDatabases; }
1012
 
    void stopDatabases();
1013
 
#endif
1014
 
    
1015
 
    void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
1016
 
    bool usingGeolocation() const { return m_usingGeolocation; };
1017
 
 
1018
 
#if ENABLE(WML)
1019
 
    void resetWMLPageState();
1020
 
#endif
1021
 
 
1022
 
protected:
1023
 
    void clearXMLVersion() { m_xmlVersion = String(); }
1024
 
 
1025
 
private:
1026
 
    void updateTitle();
1027
 
    void removeAllDisconnectedNodeEventListeners();
1028
 
    void imageLoadEventTimerFired(Timer<Document>*);
1029
 
    void updateFocusAppearanceTimerFired(Timer<Document>*);
1030
 
    void updateBaseURL();
 
1083
#if ENABLE(XHTMLMP)
 
1084
    bool m_shouldProcessNoScriptElement;
 
1085
#endif
1031
1086
 
1032
1087
    RenderObject* m_savedRenderer;
1033
1088
    int m_secureForms;
1046
1101
    
1047
1102
    int m_selfOnlyRefCount;
1048
1103
 
1049
 
    HTMLFormElement::CheckedRadioButtons m_checkedRadioButtons;
 
1104
    CheckedRadioButtons m_checkedRadioButtons;
1050
1105
 
1051
 
    typedef HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo*> NamedCollectionMap;
1052
 
    HTMLCollection::CollectionInfo m_collectionInfo[HTMLCollection::NumUnnamedDocumentCachedTypes];
1053
 
    NamedCollectionMap m_nameCollectionInfo[HTMLCollection::NumNamedDocumentCachedTypes];
 
1106
    typedef HashMap<AtomicStringImpl*, CollectionCache*> NamedCollectionMap;
 
1107
    CollectionCache m_collectionInfo[NumUnnamedDocumentCachedTypes];
 
1108
    NamedCollectionMap m_nameCollectionInfo[NumNamedDocumentCachedTypes];
1054
1109
 
1055
1110
#if ENABLE(XPATH)
1056
1111
    RefPtr<XPathEvaluator> m_xpathEvaluator;
1082
1137
 
1083
1138
    unsigned m_numNodeListCaches;
1084
1139
 
1085
 
public:
1086
 
    typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache;
1087
 
    JSWrapperCache& wrapperCache() { return m_wrapperCache; }
1088
 
private:
1089
1140
    JSWrapperCache m_wrapperCache;
1090
1141
 
1091
1142
#if ENABLE(DATABASE)
1097
1148
    
1098
1149
    bool m_usingGeolocation;
1099
1150
 
1100
 
#if USE(LOW_BANDWIDTH_DISPLAY)
1101
 
    bool m_inLowBandwidthDisplay;
 
1151
#if ENABLE(WML)
 
1152
    bool m_containsWMLContent;
1102
1153
#endif
1103
 
 
1104
 
    typedef HashMap<int, DOMTimer*> TimeoutsMap;
1105
 
    TimeoutsMap m_timeouts;
1106
1154
};
1107
1155
 
1108
1156
inline bool Document::hasElementWithId(AtomicStringImpl* id) const
1113
1161
    
1114
1162
inline bool Node::isDocumentNode() const
1115
1163
{
1116
 
    return this == m_document.get();
1117
 
}
 
1164
    return this == m_document;
 
1165
}
 
1166
 
 
1167
#if ENABLE(INSPECTOR)
 
1168
inline InspectorTimelineAgent* Document::inspectorTimelineAgent() const {
 
1169
    return page() ? page()->inspectorTimelineAgent() : 0;
 
1170
}
 
1171
#endif
1118
1172
 
1119
1173
} // namespace WebCore
1120
1174