-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Document.h
2322 lines (1769 loc) · 91.6 KB
/
Document.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* (C) 2006 Alexey Proskuryakov (ap@webkit.org)
* Copyright (C) 2004-2020 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* 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
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#pragma once
#include "CSSPropertyNames.h"
#include "CSSRegisteredCustomProperty.h"
#include "CanvasBase.h"
#include "ClientOrigin.h"
#include "Color.h"
#include "ContainerNode.h"
#include "CrossOriginOpenerPolicy.h"
#include "DisabledAdaptations.h"
#include "DocumentEventTiming.h"
#include "FocusOptions.h"
#include "FontSelectorClient.h"
#include "FrameDestructionObserver.h"
#include "FrameIdentifier.h"
#include "FrameLoaderTypes.h"
#include "GraphicsTypes.h"
#include "OrientationNotifier.h"
#include "PageIdentifier.h"
#include "PlatformEvent.h"
#include "PlaybackTargetClientContextIdentifier.h"
#include "ReferrerPolicy.h"
#include "RegistrableDomain.h"
#include "RenderPtr.h"
#include "ReportingClient.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
#include "StringWithDirection.h"
#include "Supplementable.h"
#include "Timer.h"
#include "TreeScope.h"
#include "UserActionElementSet.h"
#include "ViewportArguments.h"
#include "VisibilityState.h"
#include <wtf/Deque.h>
#include <wtf/FixedVector.h>
#include <wtf/Forward.h>
#include <wtf/HashCountedSet.h>
#include <wtf/HashSet.h>
#include <wtf/Logger.h>
#include <wtf/ObjectIdentifier.h>
#include <wtf/Observer.h>
#include <wtf/UniqueRef.h>
#include <wtf/WeakHashSet.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/AtomStringHash.h>
#if PLATFORM(IOS_FAMILY)
#include "EventTrackingRegions.h"
#endif
#if ENABLE(IOS_TOUCH_EVENTS)
#include <wtf/ThreadingPrimitives.h>
#endif
namespace JSC {
class CallFrame;
class InputCursor;
}
namespace WTF {
class TextStream;
}
namespace PAL {
class SessionID;
class TextEncoding;
}
namespace WebCore {
class AXObjectCache;
class AppHighlightStorage;
class Attr;
class CanvasBase;
class CDATASection;
class CSSCustomPropertyValue;
class CSSFontSelector;
class CSSStyleDeclaration;
class CSSStyleSheet;
class CachedCSSStyleSheet;
class CachedFrameBase;
class CachedResourceLoader;
class CachedScript;
class CanvasRenderingContext2D;
class CharacterData;
class Comment;
class ConstantPropertyMap;
class DOMImplementation;
class DOMSelection;
class DOMWindow;
class DOMWrapperWorld;
class Database;
class DatabaseThread;
class DeviceMotionClient;
class DeviceMotionController;
class DeviceOrientationAndMotionAccessController;
class DeviceOrientationClient;
class DeviceOrientationController;
class DocumentFontLoader;
class DocumentFragment;
class DocumentLoader;
class DocumentMarkerController;
class DocumentParser;
class DocumentSharedObjectPool;
class DocumentTimeline;
class DocumentTimelinesController;
class DocumentType;
class EditingBehavior;
class Editor;
class EventLoop;
class EventLoopTaskGroup;
class ExtensionStyleSheets;
class FloatQuad;
class FloatRect;
class FontFaceSet;
class FontLoadRequest;
class FormController;
class Frame;
class FrameSelection;
class FrameView;
class FullscreenManager;
class GPUCanvasContext;
class HTMLAllCollection;
class HTMLAttachmentElement;
class HTMLBodyElement;
class HTMLCanvasElement;
class HTMLCollection;
class HTMLDialogElement;
class HTMLDocument;
class HTMLElement;
class HTMLFrameOwnerElement;
class HTMLHeadElement;
class HTMLIFrameElement;
class HTMLImageElement;
class HTMLMapElement;
class HTMLMediaElement;
class HTMLMetaElement;
class HTMLVideoElement;
class HighlightRegister;
class HitTestLocation;
class HitTestRequest;
class HitTestResult;
class IdleCallbackController;
class IdleRequestCallback;
class ImageBitmapRenderingContext;
class IntPoint;
class IntersectionObserver;
class JSNode;
class LayoutPoint;
class LayoutRect;
class LazyLoadImageObserver;
class LiveNodeList;
class Locale;
class Location;
class MediaCanStartListener;
class MediaPlaybackTarget;
class MediaPlaybackTargetClient;
class MediaProducer;
class MediaQueryList;
class MediaQueryMatcher;
class MessagePortChannelProvider;
class ModalContainerObserver;
class MouseEventWithHitTestResults;
class NodeFilter;
class NodeIterator;
class Page;
class PaintWorklet;
class PaintWorkletGlobalScope;
class PlatformMouseEvent;
class ProcessingInstruction;
class QualifiedName;
class Quirks;
class RTCNetworkManager;
class Range;
class Region;
class RenderTreeBuilder;
class RenderView;
class ReportingScope;
class RequestAnimationFrameCallback;
class ResizeObserver;
class SVGDocumentExtensions;
class SVGElement;
class SVGSVGElement;
class SVGUseElement;
class SWClientConnection;
class ScriptModuleLoader;
class ScriptRunner;
class ScriptableDocumentParser;
class ScriptedAnimationController;
class SecurityOrigin;
class SegmentedString;
class SelectorQuery;
class SelectorQueryCache;
class SerializedScriptValue;
class Settings;
class SpeechRecognition;
class StorageConnection;
class StringCallback;
class StyleSheet;
class StyleSheetContents;
class StyleSheetList;
class Text;
class TextAutoSizing;
class TextManipulationController;
class TextResourceDecoder;
class TransformSource;
class TreeWalker;
class UndoManager;
class VisibilityChangeClient;
class VisitedLinkState;
class WebAnimation;
class WebGL2RenderingContext;
class WebGLRenderingContext;
class WhitespaceCache;
class WindowEventLoop;
class WindowProxy;
class XPathEvaluator;
class XPathExpression;
class XPathNSResolver;
class XPathResult;
#if ENABLE(CONTENT_CHANGE_OBSERVER)
class ContentChangeObserver;
class DOMTimerHoldingTank;
#endif
struct ApplicationManifest;
struct BoundaryPoint;
struct HighlightRangeData;
struct IntersectionObserverData;
struct SecurityPolicyViolationEventInit;
template<typename> class ExceptionOr;
enum CollectionType;
enum class MediaProducerMediaState : uint32_t;
enum class MediaProducerMediaCaptureKind : uint8_t;
enum class MediaProducerMutedState : uint8_t;
enum class RouteSharingPolicy : uint8_t;
enum class ShouldOpenExternalURLsPolicy : uint8_t;
enum class RenderingUpdateStep : uint32_t;
enum class StyleColorOptions : uint8_t;
enum class MutationObserverOptionType : uint8_t;
enum class ViolationReportType : uint8_t;
using MediaProducerMediaStateFlags = OptionSet<MediaProducerMediaState>;
using MediaProducerMutedStateFlags = OptionSet<MediaProducerMutedState>;
using PlatformDisplayID = uint32_t;
namespace Style {
class Resolver;
class Scope;
class Update;
}
enum PageshowEventPersistence { PageshowEventNotPersisted, PageshowEventPersisted };
enum NodeListInvalidationType {
DoNotInvalidateOnAttributeChanges,
InvalidateOnClassAttrChange,
InvalidateOnIdNameAttrChange,
InvalidateOnNameAttrChange,
InvalidateOnForTypeAttrChange,
InvalidateForFormControls,
InvalidateOnHRefAttrChange,
InvalidateOnAnyAttrChange,
};
const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
enum class EventHandlerRemoval { One, All };
using EventTargetSet = HashCountedSet<Node*>;
enum class DocumentCompatibilityMode : unsigned char {
NoQuirksMode = 1,
QuirksMode = 1 << 1,
LimitedQuirksMode = 1 << 2
};
enum DimensionsCheck { WidthDimensionsCheck = 1 << 0, HeightDimensionsCheck = 1 << 1, AllDimensionsCheck = 1 << 2 };
enum class HttpEquivPolicy {
Enabled,
DisabledBySettings,
DisabledByContentDispositionAttachmentSandbox
};
enum class CustomElementNameValidationStatus {
Valid,
FirstCharacterIsNotLowercaseASCIILetter,
ContainsNoHyphen,
ContainsUppercaseASCIILetter,
ContainsDisallowedCharacter,
ConflictsWithStandardElementName
};
using RenderingContext = std::variant<
#if ENABLE(WEBGL)
RefPtr<WebGLRenderingContext>,
#endif
#if ENABLE(WEBGL2)
RefPtr<WebGL2RenderingContext>,
#endif
RefPtr<ImageBitmapRenderingContext>,
RefPtr<CanvasRenderingContext2D>
>;
class DocumentParserYieldToken {
WTF_MAKE_FAST_ALLOCATED;
public:
WEBCORE_EXPORT DocumentParserYieldToken(Document&);
WEBCORE_EXPORT ~DocumentParserYieldToken();
private:
WeakPtr<Document, WeakPtrImplWithEventTargetData> m_document;
};
class Document
: public ContainerNode
, public TreeScope
, public ScriptExecutionContext
, public FontSelectorClient
, public FrameDestructionObserver
, public Supplementable<Document>
, public Logger::Observer
, public CanvasObserver
, public ReportingClient {
WTF_MAKE_ISO_ALLOCATED_EXPORT(Document, WEBCORE_EXPORT);
public:
using EventTarget::weakPtrFactory;
using EventTarget::WeakValueType;
using EventTarget::WeakPtrImplType;
inline static Ref<Document> create(const Settings&, const URL&);
static Ref<Document> createNonRenderedPlaceholder(Frame&, const URL&);
static Ref<Document> create(Document&);
virtual ~Document();
// Nodes belonging to this document increase referencingNodeCount -
// these are enough to keep the document from being destroyed, but
// not enough to keep it from removing its children. This allows a
// node that outlives its document to still have a valid document
// pointer without introducing reference cycles.
void incrementReferencingNodeCount()
{
ASSERT(!m_deletionHasBegun);
++m_referencingNodeCount;
}
void decrementReferencingNodeCount()
{
ASSERT(!m_deletionHasBegun || !m_referencingNodeCount);
--m_referencingNodeCount;
if (!m_referencingNodeCount && !refCount()) {
#if ASSERT_ENABLED
m_deletionHasBegun = true;
#endif
m_refCountAndParentBit = s_refCountIncrement; // Avoid double destruction through use of Ref<T>/RefPtr<T>. (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.)
delete this;
}
}
unsigned referencingNodeCount() const { return m_referencingNodeCount; }
void removedLastRef();
using DocumentsMap = HashMap<ScriptExecutionContextIdentifier, Document*>;
WEBCORE_EXPORT static DocumentsMap::ValuesIteratorRange allDocuments();
WEBCORE_EXPORT static DocumentsMap& allDocumentsMap();
MediaQueryMatcher& mediaQueryMatcher();
using ContainerNode::ref;
using ContainerNode::deref;
using TreeScope::rootNode;
bool canContainRangeEndPoint() const final { return true; }
Element* elementForAccessKey(const String& key);
void invalidateAccessKeyCache();
ExceptionOr<SelectorQuery&> selectorQueryForString(const String&);
void clearSelectorQueryCache();
void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; }
WEBCORE_EXPORT ViewportArguments viewportArguments() const;
OptionSet<DisabledAdaptations> disabledAdaptations() const { return m_disabledAdaptations; }
#if ASSERT_ENABLED
bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; }
#endif
void setReferrerPolicy(ReferrerPolicy);
ReferrerPolicy referrerPolicy() const final { return m_referrerPolicy.value_or(ReferrerPolicy::Default); }
WEBCORE_EXPORT DocumentType* doctype() const;
WEBCORE_EXPORT DOMImplementation& implementation();
Element* documentElement() const { return m_documentElement.get(); }
static ptrdiff_t documentElementMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentElement); }
WEBCORE_EXPORT Element* activeElement();
WEBCORE_EXPORT bool hasFocus() const;
void whenVisible(Function<void()>&&);
bool hasManifest() const;
WEBCORE_EXPORT ExceptionOr<Ref<Element>> createElementForBindings(const AtomString& tagName);
WEBCORE_EXPORT Ref<DocumentFragment> createDocumentFragment();
WEBCORE_EXPORT Ref<Text> createTextNode(String&& data);
WEBCORE_EXPORT Ref<Comment> createComment(String&& data);
WEBCORE_EXPORT ExceptionOr<Ref<CDATASection>> createCDATASection(String&& data);
WEBCORE_EXPORT ExceptionOr<Ref<ProcessingInstruction>> createProcessingInstruction(String&& target, String&& data);
WEBCORE_EXPORT ExceptionOr<Ref<Attr>> createAttribute(const AtomString& name);
WEBCORE_EXPORT ExceptionOr<Ref<Attr>> createAttributeNS(const AtomString& namespaceURI, const AtomString& qualifiedName, bool shouldIgnoreNamespaceChecks = false);
WEBCORE_EXPORT ExceptionOr<Ref<Node>> importNode(Node& nodeToImport, bool deep);
WEBCORE_EXPORT ExceptionOr<Ref<Element>> createElementNS(const AtomString& namespaceURI, const AtomString& qualifiedName);
WEBCORE_EXPORT Ref<Element> createElement(const QualifiedName&, bool createdByParser);
static CustomElementNameValidationStatus validateCustomElementName(const AtomString&);
WEBCORE_EXPORT RefPtr<Range> caretRangeFromPoint(int x, int y);
std::optional<BoundaryPoint> caretPositionFromPoint(const LayoutPoint& clientPoint);
WEBCORE_EXPORT Element* scrollingElementForAPI();
WEBCORE_EXPORT Element* scrollingElement();
enum ReadyState { Loading, Interactive, Complete };
ReadyState readyState() const { return m_readyState; }
WEBCORE_EXPORT String defaultCharsetForLegacyBindings() const;
inline String charset() const;
WEBCORE_EXPORT String characterSetWithUTF8Fallback() const;
inline PAL::TextEncoding textEncoding() const;
inline AtomString encoding() const;
WEBCORE_EXPORT void setCharset(const String&); // Used by ObjC / GOBject bindings only.
void setContent(const String&);
String suggestedMIMEType() const;
void overrideMIMEType(const String&);
WEBCORE_EXPORT String contentType() const;
const AtomString& contentLanguage() const { return m_contentLanguage; }
void setContentLanguage(const AtomString&);
const AtomString& effectiveDocumentElementLanguage() const;
void setDocumentElementLanguage(const AtomString&);
TextDirection documentElementTextDirection() const { return m_documentElementTextDirection; }
void setDocumentElementTextDirection(TextDirection textDirection) { m_documentElementTextDirection = textDirection; }
String xmlEncoding() const { return m_xmlEncoding; }
String xmlVersion() const { return m_xmlVersion; }
enum class StandaloneStatus : uint8_t { Unspecified, Standalone, NotStandalone };
bool xmlStandalone() const { return m_xmlStandalone == StandaloneStatus::Standalone; }
StandaloneStatus xmlStandaloneStatus() const { return m_xmlStandalone; }
bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
bool shouldPreventEnteringBackForwardCacheForTesting() const { return m_shouldPreventEnteringBackForwardCacheForTesting; }
void preventEnteringBackForwardCacheForTesting() { m_shouldPreventEnteringBackForwardCacheForTesting = true; }
void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
WEBCORE_EXPORT ExceptionOr<void> setXMLVersion(const String&);
WEBCORE_EXPORT void setXMLStandalone(bool);
void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration; }
String documentURI() const { return m_documentURI; }
WEBCORE_EXPORT void setDocumentURI(const String&);
WEBCORE_EXPORT VisibilityState visibilityState() const;
void visibilityStateChanged();
WEBCORE_EXPORT bool hidden() const;
void setTimerThrottlingEnabled(bool);
bool isTimerThrottlingEnabled() const { return m_isTimerThrottlingEnabled; }
void setVisibilityHiddenDueToDismissal(bool);
WEBCORE_EXPORT ExceptionOr<Ref<Node>> adoptNode(Node& source);
WEBCORE_EXPORT Ref<HTMLCollection> images();
WEBCORE_EXPORT Ref<HTMLCollection> embeds();
WEBCORE_EXPORT Ref<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
WEBCORE_EXPORT Ref<HTMLCollection> applets();
WEBCORE_EXPORT Ref<HTMLCollection> links();
WEBCORE_EXPORT Ref<HTMLCollection> forms();
WEBCORE_EXPORT Ref<HTMLCollection> anchors();
WEBCORE_EXPORT Ref<HTMLCollection> scripts();
Ref<HTMLCollection> all();
Ref<HTMLCollection> allFilteredByName(const AtomString&);
Ref<HTMLCollection> windowNamedItems(const AtomString&);
Ref<HTMLCollection> documentNamedItems(const AtomString&);
// Other methods (not part of DOM)
bool isSynthesized() const { return m_isSynthesized; }
enum class DocumentClass : uint16_t {
HTML = 1,
XHTML = 1 << 1,
Image = 1 << 2,
Plugin = 1 << 3,
Media = 1 << 4,
SVG = 1 << 5,
Text = 1 << 6,
XML = 1 << 7,
#if ENABLE(MODEL_ELEMENT)
Model = 1 << 8,
#endif
PDF = 1 << 9,
};
using DocumentClasses = OptionSet<DocumentClass>;
bool isHTMLDocument() const { return m_documentClasses.contains(DocumentClass::HTML); }
bool isXHTMLDocument() const { return m_documentClasses.contains(DocumentClass::XHTML); }
bool isXMLDocument() const { return m_documentClasses.contains(DocumentClass::XML); }
bool isImageDocument() const { return m_documentClasses.contains(DocumentClass::Image); }
bool isSVGDocument() const { return m_documentClasses.contains(DocumentClass::SVG); }
bool isPluginDocument() const { return m_documentClasses.contains(DocumentClass::Plugin); }
bool isMediaDocument() const { return m_documentClasses.contains(DocumentClass::Media); }
bool isTextDocument() const { return m_documentClasses.contains(DocumentClass::Text); }
#if ENABLE(MODEL_ELEMENT)
bool isModelDocument() const { return m_documentClasses.contains(DocumentClass::Model); }
#endif
bool isPDFDocument() const { return m_documentClasses.contains(DocumentClass::PDF); }
bool hasSVGRootNode() const;
virtual bool isFrameSet() const { return false; }
static ptrdiff_t documentClassesMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentClasses); }
static uint32_t isHTMLDocumentClassFlag() { return static_cast<uint32_t>(DocumentClass::HTML); }
bool isSrcdocDocument() const { return m_isSrcdocDocument; }
bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
Style::Resolver& userAgentShadowTreeStyleResolver();
CSSFontSelector& fontSelector() { return m_fontSelector; }
const CSSFontSelector& fontSelector() const { return m_fontSelector; }
WEBCORE_EXPORT bool haveStylesheetsLoaded() const;
bool isIgnoringPendingStylesheets() const { return m_ignorePendingStylesheets; }
WEBCORE_EXPORT StyleSheetList& styleSheets();
Style::Scope& styleScope() { return *m_styleScope; }
const Style::Scope& styleScope() const { return *m_styleScope; }
ExtensionStyleSheets& extensionStyleSheets() { return *m_extensionStyleSheets; }
const ExtensionStyleSheets& extensionStyleSheets() const { return *m_extensionStyleSheets; }
bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
void updateElementsAffectedByMediaQueries();
void evaluateMediaQueriesAndReportChanges();
FormController& formController();
Vector<AtomString> formElementsState() const;
void setStateForNewFormElements(const Vector<AtomString>&);
WEBCORE_EXPORT FrameView* view() const; // Can be null.
WEBCORE_EXPORT Page* page() const; // Can be null.
const Settings& settings() const { return m_settings.get(); }
EditingBehavior editingBehavior() const;
const Quirks& quirks() const { return m_quirks; }
float deviceScaleFactor() const;
WEBCORE_EXPORT bool useSystemAppearance() const;
WEBCORE_EXPORT bool useElevatedUserInterfaceLevel() const;
WEBCORE_EXPORT bool useDarkAppearance(const RenderStyle*) const;
OptionSet<StyleColorOptions> styleColorOptions(const RenderStyle*) const;
CompositeOperator compositeOperatorForBackgroundColor(const Color&, const RenderObject&) const;
WEBCORE_EXPORT Ref<Range> createRange();
// The last bool parameter is for ObjC bindings.
WEBCORE_EXPORT Ref<NodeIterator> createNodeIterator(Node& root, unsigned long whatToShow = 0xFFFFFFFF, RefPtr<NodeFilter>&& = nullptr, bool = false);
// The last bool parameter is for ObjC bindings.
WEBCORE_EXPORT Ref<TreeWalker> createTreeWalker(Node& root, unsigned long whatToShow = 0xFFFFFFFF, RefPtr<NodeFilter>&& = nullptr, bool = false);
// Special support for editing
WEBCORE_EXPORT Ref<CSSStyleDeclaration> createCSSStyleDeclaration();
Ref<Text> createEditingTextNode(String&&);
enum class ResolveStyleType { Normal, Rebuild };
void resolveStyle(ResolveStyleType = ResolveStyleType::Normal);
WEBCORE_EXPORT bool updateStyleIfNeeded();
bool needsStyleRecalc() const;
unsigned lastStyleUpdateSizeForTesting() const { return m_lastStyleUpdateSizeForTesting; }
WEBCORE_EXPORT void updateLayout();
// updateLayoutIgnorePendingStylesheets() forces layout even if we are waiting for pending stylesheet loads,
// so calling this may cause a flash of unstyled content (FOUC).
enum class RunPostLayoutTasks { Asynchronously, Synchronously };
WEBCORE_EXPORT void updateLayoutIgnorePendingStylesheets(RunPostLayoutTasks = RunPostLayoutTasks::Asynchronously);
std::unique_ptr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element&, const RenderStyle* parentStyle, PseudoId = PseudoId::None);
// Returns true if page box (margin boxes and page borders) is visible.
WEBCORE_EXPORT bool isPageBoxVisible(int pageIndex);
// 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.
WEBCORE_EXPORT void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
CachedResourceLoader& cachedResourceLoader() { return m_cachedResourceLoader; }
void didBecomeCurrentDocumentInFrame();
void destroyRenderTree();
void willBeRemovedFromFrame();
// Override ScriptExecutionContext methods to do additional work
WEBCORE_EXPORT bool shouldBypassMainWorldContentSecurityPolicy() const final;
void suspendActiveDOMObjects(ReasonForSuspension) final;
void resumeActiveDOMObjects(ReasonForSuspension) final;
void stopActiveDOMObjects() final;
const Settings::Values& settingsValues() const final { return settings().values(); }
void suspendDeviceMotionAndOrientationUpdates();
void resumeDeviceMotionAndOrientationUpdates();
void suspendFontLoading();
RenderView* renderView() const { return m_renderView.get(); }
bool renderTreeBeingDestroyed() const { return m_renderTreeBeingDestroyed; }
bool hasLivingRenderTree() const { return renderView() && !renderTreeBeingDestroyed(); }
void updateRenderTree(std::unique_ptr<const Style::Update> styleUpdate);
bool updateLayoutIfDimensionsOutOfDate(Element&, DimensionsCheck = AllDimensionsCheck);
inline AXObjectCache* existingAXObjectCache() const;
WEBCORE_EXPORT AXObjectCache* axObjectCache() const;
void clearAXObjectCache();
WEBCORE_EXPORT std::optional<PageIdentifier> pageID() const;
std::optional<FrameIdentifier> frameID() const;
// to get visually ordered hebrew and arabic pages right
void setVisuallyOrdered();
bool visuallyOrdered() const { return m_visuallyOrdered; }
WEBCORE_EXPORT DocumentLoader* loader() const;
WEBCORE_EXPORT ExceptionOr<RefPtr<WindowProxy>> openForBindings(DOMWindow& activeWindow, DOMWindow& firstDOMWindow, const String& url, const AtomString& name, const String& features);
WEBCORE_EXPORT ExceptionOr<Document&> openForBindings(Document* entryDocument, const String&, const String&);
// FIXME: We should rename this at some point and give back the name 'open' to the HTML specified ones.
WEBCORE_EXPORT ExceptionOr<void> open(Document* entryDocument = nullptr);
void implicitOpen();
WEBCORE_EXPORT ExceptionOr<void> closeForBindings();
// FIXME: We should rename this at some point and give back the name 'close' to the HTML specified one.
WEBCORE_EXPORT void close();
// 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.
void implicitClose();
void cancelParsing();
ExceptionOr<void> write(Document* entryDocument, SegmentedString&&);
WEBCORE_EXPORT ExceptionOr<void> write(Document* entryDocument, FixedVector<String>&&);
WEBCORE_EXPORT ExceptionOr<void> writeln(Document* entryDocument, FixedVector<String>&&);
bool wellFormed() const { return m_wellFormed; }
const URL& url() const final { return m_url; }
void setURL(const URL&);
const URL& urlForBindings() const { return m_url.isEmpty() ? aboutBlankURL() : m_url; }
const URL& creationURL() const { return m_creationURL; }
// To understand how these concepts relate to one another, please see the
// comments surrounding their declaration.
const URL& baseURL() const { return m_baseURL; }
void setBaseURLOverride(const URL&);
const URL& baseURLOverride() const { return m_baseURLOverride; }
const URL& baseElementURL() const { return m_baseElementURL; }
const AtomString& baseTarget() const { return m_baseTarget; }
void processBaseElement();
WEBCORE_EXPORT URL completeURL(const String&, ForceUTF8 = ForceUTF8::No) const final;
URL completeURL(const String&, const URL& baseURLOverride, ForceUTF8 = ForceUTF8::No) const;
inline bool shouldMaskURLForBindings(const URL&) const;
inline const URL& maskedURLForBindingsIfNeeded(const URL&) const;
static StaticStringImpl& maskedURLStringForBindings();
static const URL& maskedURLForBindings();
String userAgent(const URL&) const final;
void disableEval(const String& errorMessage) final;
void disableWebAssembly(const String& errorMessage) final;
IDBClient::IDBConnectionProxy* idbConnectionProxy() final;
StorageConnection* storageConnection();
SocketProvider* socketProvider() final;
RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
#if ENABLE(WEB_RTC)
RTCNetworkManager* rtcNetworkManager() { return m_rtcNetworkManager.get(); }
WEBCORE_EXPORT void setRTCNetworkManager(Ref<RTCNetworkManager>&&);
#endif
bool canNavigate(Frame* targetFrame, const URL& destinationURL = URL());
bool usesStyleBasedEditability() const;
void setHasElementUsingStyleBasedEditability();
virtual Ref<DocumentParser> createParser();
DocumentParser* parser() const { return m_parser.get(); }
ScriptableDocumentParser* scriptableDocumentParser() const;
bool printing() const { return m_printing; }
void setPrinting(bool p) { m_printing = p; }
bool paginatedForScreen() const { return m_paginatedForScreen; }
void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
bool paginated() const { return printing() || paginatedForScreen(); }
void setCompatibilityMode(DocumentCompatibilityMode);
void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
static ptrdiff_t compatibilityModeMemoryOffset() { return OBJECT_OFFSETOF(Document, m_compatibilityMode); }
WEBCORE_EXPORT String compatMode() const;
bool inQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::QuirksMode; }
bool inLimitedQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::LimitedQuirksMode; }
bool inNoQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::NoQuirksMode; }
void setReadyState(ReadyState);
void setParsing(bool);
bool parsing() const { return m_bParsing; }
bool shouldScheduleLayout() const;
bool isLayoutPending() const;
#if !LOG_DISABLED
Seconds timeSinceDocumentCreation() const { return MonotonicTime::now() - m_documentCreationTime; };
#endif
const Color& themeColor();
void setTextColor(const Color& color) { m_textColor = color; }
const 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; }
void resetLinkColor();
void resetVisitedLinkColor();
void resetActiveLinkColor();
VisitedLinkState& visitedLinkState() const { return *m_visitedLinkState; }
MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
// Returns whether focus was blocked. A true value does not necessarily mean the element was focused.
// The element could have already been focused or may not be focusable (e.g. <input disabled>).
WEBCORE_EXPORT bool setFocusedElement(Element*, const FocusOptions& = { });
Element* focusedElement() const { return m_focusedElement.get(); }
bool wasLastFocusByClick() const { return m_latestFocusTrigger == FocusTrigger::Click; }
void setLatestFocusTrigger(FocusTrigger trigger) { m_latestFocusTrigger = trigger; }
UserActionElementSet& userActionElements() { return m_userActionElements; }
const UserActionElementSet& userActionElements() const { return m_userActionElements; }
void setFocusNavigationStartingNode(Node*);
Element* focusNavigationStartingNode(FocusDirection) const;
void didRejectSyncXHRDuringPageDismissal();
bool shouldIgnoreSyncXHRs() const;
enum class NodeRemoval { Node, ChildrenOfNode };
void adjustFocusedNodeOnNodeRemoval(Node&, NodeRemoval = NodeRemoval::Node);
void adjustFocusNavigationNodeOnNodeRemoval(Node&, NodeRemoval = NodeRemoval::Node);
bool isAutofocusProcessed() const { return m_isAutofocusProcessed; }
void setAutofocusProcessed() { m_isAutofocusProcessed = true; }
void appendAutofocusCandidate(Element&);
void clearAutofocusCandidates() { m_autofocusCandidates.clear(); }
void flushAutofocusCandidates();
void hoveredElementDidDetach(Element&);
void elementInActiveChainDidDetach(Element&);
enum class CaptureChange : uint8_t { Yes, No };
void updateHoverActiveState(const HitTestRequest&, Element*, CaptureChange = CaptureChange::No);
// Updates for :target (CSS3 selector).
void setCSSTarget(Element*);
Element* cssTarget() const { return m_cssTarget; }
WEBCORE_EXPORT void scheduleFullStyleRebuild();
void scheduleStyleRecalc();
void unscheduleStyleRecalc();
bool hasPendingStyleRecalc() const;
bool hasPendingFullStyleRebuild() const;
void registerNodeListForInvalidation(LiveNodeList&);
void unregisterNodeListForInvalidation(LiveNodeList&);
WEBCORE_EXPORT void registerCollection(HTMLCollection&);
WEBCORE_EXPORT void unregisterCollection(HTMLCollection&);
void collectionCachedIdNameMap(const HTMLCollection&);
void collectionWillClearIdNameMap(const HTMLCollection&);
bool shouldInvalidateNodeListAndCollectionCaches() const;
bool shouldInvalidateNodeListAndCollectionCachesForAttribute(const QualifiedName& attrName) const;
template <typename InvalidationFunction>
void invalidateNodeListAndCollectionCaches(InvalidationFunction);
void attachNodeIterator(NodeIterator&);
void detachNodeIterator(NodeIterator&);
void moveNodeIteratorsToNewDocument(Node& node, Document& newDocument)
{
if (!m_nodeIterators.isEmpty())
moveNodeIteratorsToNewDocumentSlowCase(node, newDocument);
}
void attachRange(Range&);
void detachRange(Range&);
void updateRangesAfterChildrenChanged(ContainerNode&);
// nodeChildrenWillBeRemoved is used when removing all node children at once.
void nodeChildrenWillBeRemoved(ContainerNode&);
// nodeWillBeRemoved is only safe when removing one node at a time.
void nodeWillBeRemoved(Node&);
void parentlessNodeMovedToNewDocument(Node&);
enum class AcceptChildOperation { Replace, InsertOrAdd };
bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;
void textInserted(Node&, unsigned offset, unsigned length);
void textRemoved(Node&, unsigned offset, unsigned length);
void textNodesMerged(Text& oldNode, unsigned offset);
void textNodeSplit(Text& oldNode);
void createDOMWindow();
void takeDOMWindowFrom(Document&);
DOMWindow* domWindow() const { return m_domWindow.get(); }
// In DOM Level 2, the Document's DOMWindow is called the defaultView.
WEBCORE_EXPORT WindowProxy* windowProxy() const;
inline bool hasBrowsingContext() const; // Defined in DocumentInlines.h.
Document& contextDocument() const;
void setContextDocument(Document& document) { m_contextDocument = document; }
// Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
void setWindowAttributeEventListener(const AtomString& eventType, const QualifiedName& attributeName, const AtomString& value, DOMWrapperWorld&);
WEBCORE_EXPORT void dispatchWindowEvent(Event&, EventTarget* = nullptr);
void dispatchWindowLoadEvent();
WEBCORE_EXPORT ExceptionOr<Ref<Event>> createEvent(const String& eventType);
// keep track of what types of event listeners are registered, so we don't
// dispatch events unnecessarily
// FIXME: Consider using OptionSet.
enum ListenerType {
DOMSUBTREEMODIFIED_LISTENER = 1 << 0,
DOMNODEINSERTED_LISTENER = 1 << 1,
DOMNODEREMOVED_LISTENER = 1 << 2,
DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 1 << 3,
DOMNODEINSERTEDINTODOCUMENT_LISTENER = 1 << 4,
DOMCHARACTERDATAMODIFIED_LISTENER = 1 << 5,
OVERFLOWCHANGED_LISTENER = 1 << 6,
TRANSITIONEND_LISTENER = 1 << 7,
SCROLL_LISTENER = 1 << 8,
FORCEWILLBEGIN_LISTENER = 1 << 9,
FORCECHANGED_LISTENER = 1 << 10,
FORCEDOWN_LISTENER = 1 << 11,
FORCEUP_LISTENER = 1 << 12,
FOCUSIN_LISTENER = 1 << 13,
FOCUSOUT_LISTENER = 1 << 14,
};
bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
bool hasListenerTypeForEventType(PlatformEvent::Type) const;
void addListenerTypeIfNeeded(const AtomString& eventType);
inline bool hasMutationObserversOfType(MutationObserverOptionType) const;
bool hasMutationObservers() const { return !m_mutationObserverTypes.isEmpty(); }
void addMutationObserverTypes(MutationObserverOptions types) { m_mutationObserverTypes.add(types); }
CSSStyleDeclaration* getOverrideStyle(Element*, const String&) { return nullptr; }
// Handles an HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
// when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
// tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
// specified in an HTML file.
void processMetaHttpEquiv(const String& equiv, const AtomString& content, bool isInDocumentHead);
#if PLATFORM(IOS_FAMILY)
void processFormatDetection(const String&);
// Called when <meta name="apple-mobile-web-app-orientations"> changes.
void processWebAppOrientations();
#endif
#if ENABLE(CONTENT_CHANGE_OBSERVER)
WEBCORE_EXPORT ContentChangeObserver& contentChangeObserver();
DOMTimerHoldingTank* domTimerHoldingTankIfExists() { return m_domTimerHoldingTank.get(); }
DOMTimerHoldingTank& domTimerHoldingTank();
#endif
void processViewport(const String& features, ViewportArguments::Type origin);
void processDisabledAdaptations(const String& adaptations);
void updateViewportArguments();
void processReferrerPolicy(const String& policy, ReferrerPolicySource);
void metaElementThemeColorChanged(HTMLMetaElement&);
#if ENABLE(DARK_MODE_CSS)
void processColorScheme(const String& colorScheme);
#endif
#if ENABLE(APPLICATION_MANIFEST)
void processApplicationManifest(const ApplicationManifest&);
#endif
// Returns the owning element in the parent document.
// Returns nullptr if this is the top level document.
WEBCORE_EXPORT HTMLFrameOwnerElement* ownerElement() const;
// Used by DOM bindings; no direction known.
const String& title() const { return m_title.string; }
WEBCORE_EXPORT void setTitle(String&&);
const StringWithDirection& titleWithDirection() const { return m_title; }
WEBCORE_EXPORT const AtomString& dir() const;
WEBCORE_EXPORT void setDir(const AtomString&);
void titleElementAdded(Element& titleElement);
void titleElementRemoved(Element& titleElement);
void titleElementTextChanged(Element& titleElement);
WEBCORE_EXPORT ExceptionOr<String> cookie();
WEBCORE_EXPORT ExceptionOr<void> setCookie(const String&);
WEBCORE_EXPORT String referrer();
WEBCORE_EXPORT String domain() const;
ExceptionOr<void> setDomain(const String& newDomain);
void overrideLastModified(const std::optional<WallTime>&);
WEBCORE_EXPORT String lastModified() const;
// The cookieURL is used to query the cookie database for this document's
// cookies. For example, if the cookie URL is http://example.com, we'll
// use the non-Secure cookies for example.com when computing