29
#include "CachedResourceHandle.h"
30
#include "CheckedRadioButtons.h"
31
#include "ContainerNode.h"
32
#include "CollectionCache.h"
33
#include "CollectionType.h"
31
35
#include "DocumentMarker.h"
32
#include "HTMLCollection.h"
33
#include "HTMLFormElement.h"
34
37
#include "ScriptExecutionContext.h"
35
#include "StringHash.h"
37
39
#include <wtf/HashCountedSet.h>
38
#include <wtf/ListHashSet.h>
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
46
#define FRAME_LOADS_USER_STYLESHEET 0
40
#include <wtf/OwnPtr.h>
41
#include <wtf/PassOwnPtr.h>
49
43
namespace WebCore {
51
46
class AXObjectCache;
54
47
class CDATASection;
55
48
class CachedCSSStyleSheet;
56
class CanvasRenderingContext2D;
50
class CanvasRenderingContext;
57
51
class CharacterData;
58
52
class CSSStyleDeclaration;
59
53
class CSSStyleSelector;
211
207
// DOM methods & attributes for Document
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);
236
DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
237
DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
238
DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
239
DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
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);
213
252
DocumentType* doctype() const { return m_docType.get(); }
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;
256
Element* documentElement() const
258
if (!m_documentElement)
259
cacheDocumentElement();
260
return m_documentElement.get();
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()); }
234
279
Element* elementFromPoint(int x, int y) const;
280
PassRefPtr<Range> caretRangeFromPoint(int x, int y);
235
282
String readyState() const;
236
String inputEncoding() const;
237
284
String defaultCharset() const;
239
String charset() const { return inputEncoding(); }
240
String characterSet() const { return inputEncoding(); }
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(); }
242
291
void setCharset(const String&);
279
328
// quirks mode for historical compatibility reasons.
280
329
Element* findAnchor(const String& name);
282
HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
331
CollectionCache* collectionInfo(CollectionType type)
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];
290
HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, const AtomicString& name);
292
// DOM methods overridden from parent classes
294
virtual String nodeName() const;
295
virtual NodeType nodeType() const;
339
CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name);
297
341
// Other methods (not part of DOM)
298
342
virtual bool isHTMLDocument() const { return false; }
299
343
virtual bool isImageDocument() const { return false; }
301
345
virtual bool isSVGDocument() const { return false; }
347
static bool isSVGDocument() { return false; }
303
349
virtual bool isPluginDocument() const { return false; }
304
350
virtual bool isMediaDocument() const { return false; }
306
352
virtual bool isWMLDocument() const { return false; }
355
bool isXHTMLMPDocument() const;
356
bool shouldProcessNoscriptElement() const { return m_shouldProcessNoScriptElement; }
357
void setShouldProcessNoscriptElement(bool shouldDo) { m_shouldProcessNoScriptElement = shouldDo; }
359
virtual bool isFrameSet() const { return false; }
309
361
CSSStyleSelector* styleSelector() const { return m_styleSelector; }
567
625
CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
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);
574
void setWindowInlineEventListenerForTypeAndAttribute(const AtomicString& eventType, Attribute*);
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);
580
void addPendingFrameUnloadEventCount();
581
void removePendingFrameUnloadEventCount();
582
void addPendingFrameBeforeUnloadEventCount();
583
void removePendingFrameBeforeUnloadEventCount();
585
PassRefPtr<EventListener> createEventListener(const String& functionName, const String& code, Node*);
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
773
806
DOMSelection* getSelection() const;
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);
779
812
bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
780
void initDNSPrefetch();
781
813
void parseDNSPrefetchControlHeader(const String&);
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.
786
void addTimeout(int timeoutId, DOMTimer*);
787
void removeTimeout(int timeoutId);
788
DOMTimer* findTimeout(int timeoutId);
821
typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache;
822
JSWrapperCache& wrapperCache() { return m_wrapperCache; }
824
virtual void finishedParsing();
826
bool inPageCache() const { return m_inPageCache; }
827
void setInPageCache(bool flag);
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();
836
void registerForMediaVolumeCallbacks(Element*);
837
void unregisterForMediaVolumeCallbacks(Element*);
838
void mediaVolumeDidChange();
840
void setShouldCreateRenderers(bool);
841
bool shouldCreateRenderers();
843
void setDecoder(PassRefPtr<TextResourceDecoder>);
844
TextResourceDecoder* decoder() const { return m_decoder.get(); }
846
String displayStringModifiedByEncoding(const String&) const;
847
PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
848
void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
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; }
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>&);
863
virtual void removeAllEventListeners();
865
CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
868
const SVGDocumentExtensions* svgExtensions();
869
SVGDocumentExtensions* accessSVGExtensions();
872
void initSecurityContext();
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*);
879
bool processingLoadEvent() const { return m_processingLoadEvent; }
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();
890
void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
891
bool usingGeolocation() const { return m_usingGeolocation; };
894
void setContainsWMLContent(bool value) { m_containsWMLContent = value; }
895
bool containsWMLContent() const { return m_containsWMLContent; }
897
void resetWMLPageState();
898
void initializeWMLPageState();
791
902
Document(Frame*, bool isXHTML);
904
void setStyleSelector(CSSStyleSelector* styleSelector) { m_styleSelector = styleSelector; }
906
void clearXMLVersion() { m_xmlVersion = String(); }
909
virtual bool isDocument() const { return true; }
910
virtual void removedLastRef();
911
virtual void determineParseMode() { }
913
virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
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);
794
921
virtual void refScriptExecutionContext() { ref(); }
795
922
virtual void derefScriptExecutionContext() { deref(); }
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.
927
void initDNSPrefetch();
929
String encoding() const;
931
void executeScriptSoonTimerFired(Timer<Document>*);
934
void updateFocusAppearanceTimerFired(Timer<Document>*);
935
void updateBaseURL();
937
void cacheDocumentElement() const;
800
939
CSSStyleSelector* m_styleSelector;
801
940
bool m_didCalculateStyleSelector;
947
1081
String m_contentLanguage;
951
void setInPageCache(bool flag);
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();
960
void registerForMediaVolumeCallbacks(Element*);
961
void unregisterForMediaVolumeCallbacks(Element*);
962
void mediaVolumeDidChange();
964
void setShouldCreateRenderers(bool);
965
bool shouldCreateRenderers();
967
void setDecoder(PassRefPtr<TextResourceDecoder>);
968
TextResourceDecoder* decoder() const { return m_decoder.get(); }
970
UChar backslashAsCurrencySymbol() const;
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; }
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>&);
985
void removeAllEventListenersFromAllNodes();
987
void registerDisconnectedNodeWithEventListeners(Node*);
988
void unregisterDisconnectedNodeWithEventListeners(Node*);
990
HTMLFormElement::CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
993
const SVGDocumentExtensions* svgExtensions();
994
SVGDocumentExtensions* accessSVGExtensions();
997
void initSecurityContext();
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*);
1004
bool processingLoadEvent() const { return m_processingLoadEvent; }
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();
1015
void setUsingGeolocation(bool f) { m_usingGeolocation = f; }
1016
bool usingGeolocation() const { return m_usingGeolocation; };
1019
void resetWMLPageState();
1023
void clearXMLVersion() { m_xmlVersion = String(); }
1027
void removeAllDisconnectedNodeEventListeners();
1028
void imageLoadEventTimerFired(Timer<Document>*);
1029
void updateFocusAppearanceTimerFired(Timer<Document>*);
1030
void updateBaseURL();
1084
bool m_shouldProcessNoScriptElement;
1032
1087
RenderObject* m_savedRenderer;
1033
1088
int m_secureForms;