Document.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/Function.h>
  10. #include <AK/HashMap.h>
  11. #include <AK/OwnPtr.h>
  12. #include <AK/String.h>
  13. #include <AK/Vector.h>
  14. #include <AK/WeakPtr.h>
  15. #include <LibCore/DateTime.h>
  16. #include <LibCore/Forward.h>
  17. #include <LibJS/Console.h>
  18. #include <LibJS/Forward.h>
  19. #include <LibURL/URL.h>
  20. #include <LibUnicode/Forward.h>
  21. #include <LibWeb/CSS/CSSStyleSheet.h>
  22. #include <LibWeb/CSS/StyleSheetList.h>
  23. #include <LibWeb/Cookie/Cookie.h>
  24. #include <LibWeb/DOM/NonElementParentNode.h>
  25. #include <LibWeb/DOM/ParentNode.h>
  26. #include <LibWeb/HTML/BrowsingContext.h>
  27. #include <LibWeb/HTML/CrossOrigin/OpenerPolicy.h>
  28. #include <LibWeb/HTML/DocumentReadyState.h>
  29. #include <LibWeb/HTML/HTMLScriptElement.h>
  30. #include <LibWeb/HTML/History.h>
  31. #include <LibWeb/HTML/LazyLoadingElement.h>
  32. #include <LibWeb/HTML/NavigationType.h>
  33. #include <LibWeb/HTML/Origin.h>
  34. #include <LibWeb/HTML/SandboxingFlagSet.h>
  35. #include <LibWeb/HTML/Scripting/Environments.h>
  36. #include <LibWeb/HTML/VisibilityState.h>
  37. #include <LibWeb/InvalidateDisplayList.h>
  38. #include <LibWeb/WebIDL/ExceptionOr.h>
  39. #include <LibWeb/WebIDL/ObservableArray.h>
  40. namespace Web::DOM {
  41. enum class QuirksMode {
  42. No,
  43. Limited,
  44. Yes
  45. };
  46. // https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
  47. struct DocumentLoadTimingInfo {
  48. // https://html.spec.whatwg.org/multipage/dom.html#navigation-start-time
  49. double navigation_start_time { 0 };
  50. // https://html.spec.whatwg.org/multipage/dom.html#dom-interactive-time
  51. double dom_interactive_time { 0 };
  52. // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-start-time
  53. double dom_content_loaded_event_start_time { 0 };
  54. // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-end-time
  55. double dom_content_loaded_event_end_time { 0 };
  56. // https://html.spec.whatwg.org/multipage/dom.html#dom-complete-time
  57. double dom_complete_time { 0 };
  58. // https://html.spec.whatwg.org/multipage/dom.html#load-event-start-time
  59. double load_event_start_time { 0 };
  60. // https://html.spec.whatwg.org/multipage/dom.html#load-event-end-time
  61. double load_event_end_time { 0 };
  62. };
  63. // https://html.spec.whatwg.org/multipage/dom.html#document-unload-timing-info
  64. struct DocumentUnloadTimingInfo {
  65. // https://html.spec.whatwg.org/multipage/dom.html#unload-event-start-time
  66. double unload_event_start_time { 0 };
  67. // https://html.spec.whatwg.org/multipage/dom.html#unload-event-end-time
  68. double unload_event_end_time { 0 };
  69. };
  70. struct ElementCreationOptions {
  71. Optional<String> is;
  72. };
  73. enum class PolicyControlledFeature {
  74. Autoplay,
  75. };
  76. class Document
  77. : public ParentNode
  78. , public NonElementParentNode<Document>
  79. , public HTML::GlobalEventHandlers {
  80. WEB_PLATFORM_OBJECT(Document, ParentNode);
  81. JS_DECLARE_ALLOCATOR(Document);
  82. public:
  83. enum class Type {
  84. XML,
  85. HTML
  86. };
  87. enum class TemporaryDocumentForFragmentParsing {
  88. No,
  89. Yes,
  90. };
  91. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_and_initialize(Type, String content_type, HTML::NavigationParams const&);
  92. [[nodiscard]] static JS::NonnullGCPtr<Document> create(JS::Realm&, URL::URL const& url = "about:blank"sv);
  93. [[nodiscard]] static JS::NonnullGCPtr<Document> create_for_fragment_parsing(JS::Realm&);
  94. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&);
  95. virtual ~Document() override;
  96. // AD-HOC: This number increments whenever a node is added or removed from the document, or an element attribute changes.
  97. // It can be used as a crude invalidation mechanism for caches that depend on the DOM structure.
  98. u64 dom_tree_version() const { return m_dom_tree_version; }
  99. void bump_dom_tree_version() { ++m_dom_tree_version; }
  100. WebIDL::ExceptionOr<void> populate_with_html_head_and_body();
  101. JS::GCPtr<Selection::Selection> get_selection() const;
  102. String cookie(Cookie::Source = Cookie::Source::NonHttp);
  103. void set_cookie(StringView, Cookie::Source = Cookie::Source::NonHttp);
  104. String fg_color() const;
  105. void set_fg_color(String const&);
  106. String link_color() const;
  107. void set_link_color(String const&);
  108. String vlink_color() const;
  109. void set_vlink_color(String const&);
  110. String alink_color() const;
  111. void set_alink_color(String const&);
  112. String bg_color() const;
  113. void set_bg_color(String const&);
  114. String referrer() const;
  115. void set_referrer(String);
  116. void set_url(const URL::URL& url) { m_url = url; }
  117. URL::URL url() const { return m_url; }
  118. URL::URL fallback_base_url() const;
  119. URL::URL base_url() const;
  120. void update_base_element(Badge<HTML::HTMLBaseElement>);
  121. JS::GCPtr<HTML::HTMLBaseElement const> first_base_element_with_href_in_tree_order() const;
  122. String url_string() const { return MUST(m_url.to_string()); }
  123. String document_uri() const { return url_string(); }
  124. HTML::Origin origin() const;
  125. void set_origin(HTML::Origin const& origin);
  126. HTML::OpenerPolicy const& opener_policy() const { return m_opener_policy; }
  127. void set_opener_policy(HTML::OpenerPolicy policy) { m_opener_policy = move(policy); }
  128. URL::URL parse_url(StringView) const;
  129. CSS::StyleComputer& style_computer() { return *m_style_computer; }
  130. const CSS::StyleComputer& style_computer() const { return *m_style_computer; }
  131. CSS::StyleSheetList& style_sheets();
  132. CSS::StyleSheetList const& style_sheets() const;
  133. void for_each_active_css_style_sheet(Function<void(CSS::CSSStyleSheet&)>&& callback) const;
  134. CSS::StyleSheetList* style_sheets_for_bindings() { return &style_sheets(); }
  135. Optional<String> get_style_sheet_source(CSS::StyleSheetIdentifier const&) const;
  136. virtual FlyString node_name() const override { return "#document"_fly_string; }
  137. void set_hovered_node(Node*);
  138. Node* hovered_node() { return m_hovered_node.ptr(); }
  139. Node const* hovered_node() const { return m_hovered_node.ptr(); }
  140. void set_inspected_node(Node*, Optional<CSS::Selector::PseudoElement::Type>);
  141. Node* inspected_node() { return m_inspected_node.ptr(); }
  142. Node const* inspected_node() const { return m_inspected_node.ptr(); }
  143. Layout::Node* inspected_layout_node();
  144. Layout::Node const* inspected_layout_node() const { return const_cast<Document*>(this)->inspected_layout_node(); }
  145. Element* document_element();
  146. Element const* document_element() const;
  147. HTML::HTMLHtmlElement* html_element();
  148. HTML::HTMLHeadElement* head();
  149. JS::GCPtr<HTML::HTMLTitleElement> title_element();
  150. StringView dir() const;
  151. void set_dir(String const&);
  152. HTML::HTMLElement* body();
  153. HTML::HTMLHtmlElement const* html_element() const
  154. {
  155. return const_cast<Document*>(this)->html_element();
  156. }
  157. HTML::HTMLHeadElement const* head() const
  158. {
  159. return const_cast<Document*>(this)->head();
  160. }
  161. JS::GCPtr<HTML::HTMLTitleElement const> title_element() const
  162. {
  163. return const_cast<Document*>(this)->title_element();
  164. }
  165. HTML::HTMLElement const* body() const
  166. {
  167. return const_cast<Document*>(this)->body();
  168. }
  169. WebIDL::ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
  170. String title() const;
  171. WebIDL::ExceptionOr<void> set_title(String const&);
  172. HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
  173. HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); }
  174. void set_browsing_context(HTML::BrowsingContext*);
  175. Page& page();
  176. Page const& page() const;
  177. Color background_color() const;
  178. Vector<CSS::BackgroundLayerData> const* background_layers() const;
  179. Color normal_link_color() const;
  180. void set_normal_link_color(Color);
  181. Color active_link_color() const;
  182. void set_active_link_color(Color);
  183. Color visited_link_color() const;
  184. void set_visited_link_color(Color);
  185. void update_style();
  186. void update_layout();
  187. void update_paint_and_hit_testing_properties_if_needed();
  188. void update_animated_style_if_needed();
  189. void set_needs_layout();
  190. void invalidate_layout_tree();
  191. void invalidate_stacking_context_tree();
  192. virtual bool is_child_allowed(Node const&) const override;
  193. Layout::Viewport const* layout_node() const;
  194. Layout::Viewport* layout_node();
  195. Painting::ViewportPaintable const* paintable() const;
  196. Painting::ViewportPaintable* paintable();
  197. void schedule_style_update();
  198. void schedule_layout_update();
  199. JS::NonnullGCPtr<NodeList> get_elements_by_name(FlyString const&);
  200. JS::NonnullGCPtr<HTMLCollection> applets();
  201. JS::NonnullGCPtr<HTMLCollection> anchors();
  202. JS::NonnullGCPtr<HTMLCollection> images();
  203. JS::NonnullGCPtr<HTMLCollection> embeds();
  204. JS::NonnullGCPtr<HTMLCollection> plugins();
  205. JS::NonnullGCPtr<HTMLCollection> links();
  206. JS::NonnullGCPtr<HTMLCollection> forms();
  207. JS::NonnullGCPtr<HTMLCollection> scripts();
  208. JS::NonnullGCPtr<HTML::HTMLAllCollection> all();
  209. // https://drafts.csswg.org/css-font-loading/#font-source
  210. JS::NonnullGCPtr<CSS::FontFaceSet> fonts();
  211. void clear();
  212. void capture_events();
  213. void release_events();
  214. String const& source() const { return m_source; }
  215. void set_source(String source) { m_source = move(source); }
  216. HTML::EnvironmentSettingsObject& relevant_settings_object() const;
  217. WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(String const& local_name, Variant<String, ElementCreationOptions> const& options);
  218. WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(Optional<FlyString> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options);
  219. JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
  220. JS::NonnullGCPtr<Text> create_text_node(String const& data);
  221. WebIDL::ExceptionOr<JS::NonnullGCPtr<CDATASection>> create_cdata_section(String const& data);
  222. JS::NonnullGCPtr<Comment> create_comment(String const& data);
  223. WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(String const& target, String const& data);
  224. WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute(String const& local_name);
  225. WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(Optional<FlyString> const& namespace_, String const& qualified_name);
  226. WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(StringView interface);
  227. JS::NonnullGCPtr<Range> create_range();
  228. void set_pending_parsing_blocking_script(HTML::HTMLScriptElement*);
  229. HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script.ptr(); }
  230. JS::NonnullGCPtr<HTML::HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>);
  231. void add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  232. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>);
  233. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; }
  234. void add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  235. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>);
  236. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; }
  237. void add_script_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  238. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>);
  239. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_in_order_as_soon_as_possible() { return m_scripts_to_execute_in_order_as_soon_as_possible; }
  240. QuirksMode mode() const { return m_quirks_mode; }
  241. bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
  242. void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
  243. Type document_type() const { return m_type; }
  244. void set_document_type(Type type) { m_type = type; }
  245. // https://dom.spec.whatwg.org/#html-document
  246. bool is_html_document() const { return m_type == Type::HTML; }
  247. // https://dom.spec.whatwg.org/#xml-document
  248. bool is_xml_document() const { return m_type == Type::XML; }
  249. WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep);
  250. void adopt_node(Node&);
  251. WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>);
  252. DocumentType const* doctype() const;
  253. String const& compat_mode() const;
  254. void set_editable(bool editable) { m_editable = editable; }
  255. virtual bool is_editable() const final;
  256. Element* focused_element() { return m_focused_element.ptr(); }
  257. Element const* focused_element() const { return m_focused_element.ptr(); }
  258. void set_focused_element(Element*);
  259. Element const* active_element() const { return m_active_element.ptr(); }
  260. void set_active_element(Element*);
  261. Element const* target_element() const { return m_target_element.ptr(); }
  262. void set_target_element(Element*);
  263. void scroll_to_the_fragment();
  264. void scroll_to_the_beginning_of_the_document();
  265. bool created_for_appropriate_template_contents() const { return m_created_for_appropriate_template_contents; }
  266. JS::NonnullGCPtr<Document> appropriate_template_contents_owner_document();
  267. StringView ready_state() const;
  268. HTML::DocumentReadyState readiness() const { return m_readiness; }
  269. void update_readiness(HTML::DocumentReadyState);
  270. String last_modified() const;
  271. [[nodiscard]] JS::GCPtr<HTML::Window> window() const { return m_window; }
  272. void set_window(HTML::Window&);
  273. WebIDL::ExceptionOr<void> write(Vector<String> const& strings);
  274. WebIDL::ExceptionOr<void> writeln(Vector<String> const& strings);
  275. WebIDL::ExceptionOr<Document*> open(Optional<String> const& = {}, Optional<String> const& = {});
  276. WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> open(StringView url, StringView name, StringView features);
  277. WebIDL::ExceptionOr<void> close();
  278. JS::GCPtr<HTML::WindowProxy const> default_view() const;
  279. JS::GCPtr<HTML::WindowProxy> default_view();
  280. String const& content_type() const { return m_content_type; }
  281. void set_content_type(String content_type) { m_content_type = move(content_type); }
  282. bool has_encoding() const { return m_encoding.has_value(); }
  283. Optional<String> const& encoding() const { return m_encoding; }
  284. String encoding_or_default() const { return m_encoding.value_or("UTF-8"_string); }
  285. void set_encoding(Optional<String> encoding) { m_encoding = move(encoding); }
  286. // NOTE: These are intended for the JS bindings
  287. String character_set() const { return encoding_or_default(); }
  288. String charset() const { return encoding_or_default(); }
  289. String input_encoding() const { return encoding_or_default(); }
  290. bool ready_for_post_load_tasks() const { return m_ready_for_post_load_tasks; }
  291. void set_ready_for_post_load_tasks(bool ready) { m_ready_for_post_load_tasks = ready; }
  292. void completely_finish_loading();
  293. DOMImplementation* implementation();
  294. JS::GCPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script.ptr(); }
  295. void set_current_script(Badge<HTML::HTMLScriptElement>, JS::GCPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); }
  296. u32 ignore_destructive_writes_counter() const { return m_ignore_destructive_writes_counter; }
  297. void increment_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter++; }
  298. void decrement_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter--; }
  299. virtual EventTarget* get_parent(Event const&) override;
  300. String dump_dom_tree_as_json() const;
  301. bool has_a_style_sheet_that_is_blocking_scripts() const;
  302. bool is_fully_active() const;
  303. bool is_active() const;
  304. [[nodiscard]] bool allow_declarative_shadow_roots() const;
  305. void set_allow_declarative_shadow_roots(bool);
  306. JS::NonnullGCPtr<HTML::History> history();
  307. JS::NonnullGCPtr<HTML::History> history() const;
  308. [[nodiscard]] JS::GCPtr<HTML::Location> location();
  309. bool anything_is_delaying_the_load_event() const;
  310. void increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
  311. void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
  312. bool page_showing() const { return m_page_showing; }
  313. void set_page_showing(bool value) { m_page_showing = value; }
  314. bool hidden() const;
  315. StringView visibility_state() const;
  316. // https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
  317. void update_the_visibility_state(HTML::VisibilityState);
  318. // NOTE: This does not fire any events, unlike update_the_visibility_state().
  319. void set_visibility_state(Badge<HTML::BrowsingContext>, HTML::VisibilityState);
  320. void run_the_resize_steps();
  321. void run_the_scroll_steps();
  322. void evaluate_media_queries_and_report_changes();
  323. void add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList>);
  324. JS::NonnullGCPtr<CSS::VisualViewport> visual_viewport();
  325. [[nodiscard]] CSSPixelRect viewport_rect() const;
  326. class ViewportClient {
  327. public:
  328. virtual ~ViewportClient() = default;
  329. virtual void did_set_viewport_rect(CSSPixelRect const&) = 0;
  330. };
  331. void register_viewport_client(ViewportClient&);
  332. void unregister_viewport_client(ViewportClient&);
  333. void inform_all_viewport_clients_about_the_current_viewport_rect();
  334. bool has_focus() const;
  335. void set_parser(Badge<HTML::HTMLParser>, HTML::HTMLParser&);
  336. void detach_parser(Badge<HTML::HTMLParser>);
  337. [[nodiscard]] bool is_temporary_document_for_fragment_parsing() const { return m_temporary_document_for_fragment_parsing == TemporaryDocumentForFragmentParsing::Yes; }
  338. static bool is_valid_name(String const&);
  339. struct PrefixAndTagName {
  340. FlyString prefix;
  341. FlyString tag_name;
  342. };
  343. static WebIDL::ExceptionOr<PrefixAndTagName> validate_qualified_name(JS::Realm&, FlyString const& qualified_name);
  344. JS::NonnullGCPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
  345. JS::NonnullGCPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
  346. void register_node_iterator(Badge<NodeIterator>, NodeIterator&);
  347. void unregister_node_iterator(Badge<NodeIterator>, NodeIterator&);
  348. void register_document_observer(Badge<DocumentObserver>, DocumentObserver&);
  349. void unregister_document_observer(Badge<DocumentObserver>, DocumentObserver&);
  350. template<typename Callback>
  351. void for_each_node_iterator(Callback callback)
  352. {
  353. for (auto& node_iterator : m_node_iterators)
  354. callback(*node_iterator);
  355. }
  356. bool needs_full_style_update() const { return m_needs_full_style_update; }
  357. void set_needs_full_style_update(bool b) { m_needs_full_style_update = b; }
  358. void set_needs_to_refresh_scroll_state(bool b);
  359. bool has_active_favicon() const { return m_active_favicon; }
  360. void check_favicon_after_loading_link_resource();
  361. JS::GCPtr<HTML::CustomElementDefinition> lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const;
  362. void increment_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);
  363. void decrement_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);
  364. // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank
  365. bool is_initial_about_blank() const { return m_is_initial_about_blank; }
  366. void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; }
  367. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-about-base-url
  368. Optional<URL::URL> about_base_url() const { return m_about_base_url; }
  369. void set_about_base_url(Optional<URL::URL> url) { m_about_base_url = url; }
  370. String domain() const;
  371. void set_domain(String const&);
  372. auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; }
  373. auto& pending_scrollend_event_targets() { return m_pending_scrollend_event_targets; }
  374. // https://html.spec.whatwg.org/#completely-loaded
  375. bool is_completely_loaded() const;
  376. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
  377. Optional<String> navigation_id() const;
  378. void set_navigation_id(Optional<String>);
  379. // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set
  380. HTML::SandboxingFlagSet active_sandboxing_flag_set() const;
  381. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
  382. HTML::PolicyContainer policy_container() const;
  383. void set_policy_container(HTML::PolicyContainer);
  384. Vector<JS::Handle<HTML::Navigable>> descendant_navigables();
  385. Vector<JS::Handle<HTML::Navigable>> const descendant_navigables() const;
  386. Vector<JS::Handle<HTML::Navigable>> inclusive_descendant_navigables();
  387. Vector<JS::Handle<HTML::Navigable>> ancestor_navigables();
  388. Vector<JS::Handle<HTML::Navigable>> const ancestor_navigables() const;
  389. Vector<JS::Handle<HTML::Navigable>> inclusive_ancestor_navigables();
  390. Vector<JS::Handle<HTML::Navigable>> document_tree_child_navigables();
  391. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document
  392. void destroy();
  393. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document-and-its-descendants
  394. void destroy_a_document_and_its_descendants(JS::GCPtr<JS::HeapFunction<void()>> after_all_destruction = {});
  395. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document
  396. void abort();
  397. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#abort-a-document-and-its-descendants
  398. void abort_a_document_and_its_descendants();
  399. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#unload-a-document
  400. void unload(JS::GCPtr<Document> new_document = nullptr);
  401. // https://html.spec.whatwg.org/multipage/document-lifecycle.html#unload-a-document-and-its-descendants
  402. void unload_a_document_and_its_descendants(JS::GCPtr<Document> new_document, JS::GCPtr<JS::HeapFunction<void()>> after_all_unloads = {});
  403. // https://html.spec.whatwg.org/multipage/dom.html#active-parser
  404. JS::GCPtr<HTML::HTMLParser> active_parser();
  405. // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info
  406. DocumentLoadTimingInfo& load_timing_info() { return m_load_timing_info; }
  407. DocumentLoadTimingInfo const& load_timing_info() const { return m_load_timing_info; }
  408. void set_load_timing_info(DocumentLoadTimingInfo const& load_timing_info) { m_load_timing_info = load_timing_info; }
  409. // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing
  410. DocumentUnloadTimingInfo& previous_document_unload_timing() { return m_previous_document_unload_timing; }
  411. DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; }
  412. void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; }
  413. // https://w3c.github.io/editing/docs/execCommand/
  414. bool exec_command(String const& command, bool show_ui, String const& value);
  415. bool query_command_enabled(String const& command);
  416. bool query_command_indeterm(String const& command);
  417. bool query_command_state(String const& command);
  418. bool query_command_supported(String const& command);
  419. String query_command_value(String const& command);
  420. bool is_allowed_to_use_feature(PolicyControlledFeature) const;
  421. void did_stop_being_active_document_in_navigable();
  422. String dump_accessibility_tree_as_json();
  423. void make_active();
  424. void set_salvageable(bool value) { m_salvageable = value; }
  425. void make_unsalvageable(String reason);
  426. HTML::ListOfAvailableImages& list_of_available_images();
  427. HTML::ListOfAvailableImages const& list_of_available_images() const;
  428. void register_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, IntersectionObserver::IntersectionObserver&);
  429. void unregister_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, IntersectionObserver::IntersectionObserver&);
  430. void register_resize_observer(Badge<ResizeObserver::ResizeObserver>, ResizeObserver::ResizeObserver&);
  431. void unregister_resize_observer(Badge<ResizeObserver::ResizeObserver>, ResizeObserver::ResizeObserver&);
  432. void run_the_update_intersection_observations_steps(HighResolutionTime::DOMHighResTimeStamp time);
  433. void start_intersection_observing_a_lazy_loading_element(Element&);
  434. void shared_declarative_refresh_steps(StringView input, JS::GCPtr<HTML::HTMLMetaElement const> meta_element = nullptr);
  435. struct TopOfTheDocument { };
  436. using IndicatedPart = Variant<Element*, TopOfTheDocument>;
  437. IndicatedPart determine_the_indicated_part() const;
  438. u32 unload_counter() const { return m_unload_counter; }
  439. HTML::SourceSnapshotParams snapshot_source_snapshot_params() const;
  440. void update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry>, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional<Bindings::NavigationType> navigation_type, Optional<Vector<JS::NonnullGCPtr<HTML::SessionHistoryEntry>>> entries_for_navigation_api = {}, Optional<JS::NonnullGCPtr<HTML::SessionHistoryEntry>> previous_entry_for_activation = {}, bool update_navigation_api = true);
  441. HashMap<URL::URL, JS::GCPtr<HTML::SharedResourceRequest>>& shared_resource_requests();
  442. void restore_the_history_object_state(JS::NonnullGCPtr<HTML::SessionHistoryEntry> entry);
  443. JS::NonnullGCPtr<Animations::DocumentTimeline> timeline();
  444. auto const& last_animation_frame_timestamp() const { return m_last_animation_frame_timestamp; }
  445. void associate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline>);
  446. void disassociate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline>);
  447. struct PendingAnimationEvent {
  448. JS::NonnullGCPtr<DOM::Event> event;
  449. JS::NonnullGCPtr<Animations::Animation> animation;
  450. JS::NonnullGCPtr<DOM::EventTarget> target;
  451. Optional<double> scheduled_event_time;
  452. };
  453. void append_pending_animation_event(PendingAnimationEvent const&);
  454. void update_animations_and_send_events(Optional<double> const& timestamp);
  455. void remove_replaced_animations();
  456. Vector<JS::NonnullGCPtr<Animations::Animation>> get_animations();
  457. bool ready_to_run_scripts() const { return m_ready_to_run_scripts; }
  458. void set_ready_to_run_scripts() { m_ready_to_run_scripts = true; }
  459. JS::GCPtr<HTML::SessionHistoryEntry> latest_entry() const { return m_latest_entry; }
  460. void set_latest_entry(JS::GCPtr<HTML::SessionHistoryEntry> e) { m_latest_entry = e; }
  461. void element_id_changed(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  462. void element_with_id_was_added(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  463. void element_with_id_was_removed(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  464. void element_name_changed(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  465. void element_with_name_was_added(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  466. void element_with_name_was_removed(Badge<DOM::Element>, JS::NonnullGCPtr<DOM::Element> element);
  467. void add_form_associated_element_with_form_attribute(HTML::FormAssociatedElement&);
  468. void remove_form_associated_element_with_form_attribute(HTML::FormAssociatedElement&);
  469. bool design_mode_enabled_state() const { return m_design_mode_enabled; }
  470. void set_design_mode_enabled_state(bool);
  471. String design_mode() const;
  472. WebIDL::ExceptionOr<void> set_design_mode(String const&);
  473. Element const* element_from_point(double x, double y);
  474. Vector<JS::NonnullGCPtr<Element>> elements_from_point(double x, double y);
  475. JS::GCPtr<Element const> scrolling_element() const;
  476. void set_needs_to_resolve_paint_only_properties() { m_needs_to_resolve_paint_only_properties = true; }
  477. void set_needs_animated_style_update() { m_needs_animated_style_update = true; }
  478. virtual JS::Value named_item_value(FlyString const& name) const override;
  479. virtual Vector<FlyString> supported_property_names() const override;
  480. Vector<JS::NonnullGCPtr<DOM::Element>> const& potentially_named_elements() const { return m_potentially_named_elements; }
  481. void gather_active_observations_at_depth(size_t depth);
  482. [[nodiscard]] size_t broadcast_active_resize_observations();
  483. [[nodiscard]] bool has_active_resize_observations();
  484. [[nodiscard]] bool has_skipped_resize_observations();
  485. JS::NonnullGCPtr<WebIDL::ObservableArray> adopted_style_sheets() const;
  486. WebIDL::ExceptionOr<void> set_adopted_style_sheets(JS::Value);
  487. void register_shadow_root(Badge<DOM::ShadowRoot>, DOM::ShadowRoot&);
  488. void unregister_shadow_root(Badge<DOM::ShadowRoot>, DOM::ShadowRoot&);
  489. void for_each_shadow_root(Function<void(DOM::ShadowRoot&)>&& callback);
  490. void add_an_element_to_the_top_layer(JS::NonnullGCPtr<Element>);
  491. void request_an_element_to_be_remove_from_the_top_layer(JS::NonnullGCPtr<Element>);
  492. void remove_an_element_from_the_top_layer_immediately(JS::NonnullGCPtr<Element>);
  493. void process_top_layer_removals();
  494. OrderedHashTable<JS::NonnullGCPtr<Element>> const& top_layer_elements() const { return m_top_layer_elements; }
  495. size_t transition_generation() const { return m_transition_generation; }
  496. // Does document represent an embedded svg img
  497. [[nodiscard]] bool is_decoded_svg() const;
  498. Vector<JS::Handle<DOM::Range>> find_matching_text(String const&, CaseSensitivity);
  499. void parse_html_from_a_string(StringView);
  500. static JS::NonnullGCPtr<Document> parse_html_unsafe(JS::VM&, StringView);
  501. void set_console_client(JS::GCPtr<JS::ConsoleClient> console_client) { m_console_client = console_client; }
  502. JS::GCPtr<JS::ConsoleClient> console_client() const { return m_console_client; }
  503. JS::GCPtr<DOM::Position> cursor_position() const { return m_cursor_position; }
  504. void set_cursor_position(JS::NonnullGCPtr<DOM::Position>);
  505. bool increment_cursor_position_offset();
  506. bool decrement_cursor_position_offset();
  507. bool increment_cursor_position_to_next_word();
  508. bool decrement_cursor_position_to_previous_word();
  509. bool cursor_blink_state() const { return m_cursor_blink_state; }
  510. void user_did_edit_document_text(Badge<EditEventHandler>);
  511. // Cached pointer to the last known node navigable.
  512. // If this document is currently the "active document" of the cached navigable, the cache is still valid.
  513. JS::GCPtr<HTML::Navigable> cached_navigable();
  514. void set_cached_navigable(JS::GCPtr<HTML::Navigable>);
  515. [[nodiscard]] bool needs_repaint() const { return m_needs_repaint; }
  516. void set_needs_display(InvalidateDisplayList = InvalidateDisplayList::Yes);
  517. void set_needs_display(CSSPixelRect const&, InvalidateDisplayList = InvalidateDisplayList::Yes);
  518. struct PaintConfig {
  519. bool paint_overlay { false };
  520. bool should_show_line_box_borders { false };
  521. bool has_focus { false };
  522. Optional<Gfx::IntRect> canvas_fill_rect {};
  523. bool operator==(PaintConfig const& other) const = default;
  524. };
  525. RefPtr<Painting::DisplayList> record_display_list(PaintConfig);
  526. void invalidate_display_list();
  527. Unicode::Segmenter& grapheme_segmenter() const;
  528. Unicode::Segmenter& word_segmenter() const;
  529. struct StepsToFireBeforeunloadResult {
  530. bool unload_prompt_shown { false };
  531. bool unload_prompt_canceled { false };
  532. };
  533. StepsToFireBeforeunloadResult steps_to_fire_beforeunload(bool unload_prompt_shown);
  534. protected:
  535. virtual void initialize(JS::Realm&) override;
  536. virtual void visit_edges(Cell::Visitor&) override;
  537. Document(JS::Realm&, URL::URL const&, TemporaryDocumentForFragmentParsing = TemporaryDocumentForFragmentParsing::No);
  538. private:
  539. // ^HTML::GlobalEventHandlers
  540. virtual JS::GCPtr<EventTarget> global_event_handlers_to_event_target(FlyString const&) final { return *this; }
  541. void tear_down_layout_tree();
  542. void update_active_element();
  543. void run_unloading_cleanup_steps();
  544. void evaluate_media_rules();
  545. WebIDL::ExceptionOr<void> run_the_document_write_steps(StringView);
  546. void queue_intersection_observer_task();
  547. void queue_an_intersection_observer_entry(IntersectionObserver::IntersectionObserver&, HighResolutionTime::DOMHighResTimeStamp time, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> root_bounds, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, JS::NonnullGCPtr<Element> target);
  548. Element* find_a_potential_indicated_element(FlyString const& fragment) const;
  549. void dispatch_events_for_animation_if_necessary(JS::NonnullGCPtr<Animations::Animation>);
  550. void reset_cursor_blink_cycle();
  551. JS::NonnullGCPtr<Page> m_page;
  552. OwnPtr<CSS::StyleComputer> m_style_computer;
  553. JS::GCPtr<CSS::StyleSheetList> m_style_sheets;
  554. JS::GCPtr<Node> m_hovered_node;
  555. JS::GCPtr<Node> m_inspected_node;
  556. Optional<CSS::Selector::PseudoElement::Type> m_inspected_pseudo_element;
  557. JS::GCPtr<Node> m_active_favicon;
  558. WeakPtr<HTML::BrowsingContext> m_browsing_context;
  559. URL::URL m_url;
  560. JS::GCPtr<HTML::Window> m_window;
  561. JS::GCPtr<Layout::Viewport> m_layout_root;
  562. Optional<Color> m_normal_link_color;
  563. Optional<Color> m_active_link_color;
  564. Optional<Color> m_visited_link_color;
  565. JS::GCPtr<HTML::HTMLParser> m_parser;
  566. bool m_active_parser_was_aborted { false };
  567. String m_source;
  568. JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;
  569. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished;
  570. // https://html.spec.whatwg.org/multipage/scripting.html#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
  571. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_in_order_as_soon_as_possible;
  572. // https://html.spec.whatwg.org/multipage/scripting.html#set-of-scripts-that-will-execute-as-soon-as-possible
  573. Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible;
  574. QuirksMode m_quirks_mode { QuirksMode::No };
  575. // https://dom.spec.whatwg.org/#concept-document-type
  576. Type m_type { Type::XML };
  577. bool m_editable { false };
  578. JS::GCPtr<Element> m_focused_element;
  579. JS::GCPtr<Element> m_active_element;
  580. JS::GCPtr<Element> m_target_element;
  581. bool m_created_for_appropriate_template_contents { false };
  582. JS::GCPtr<Document> m_associated_inert_template_document;
  583. JS::GCPtr<Document> m_appropriate_template_contents_owner_document;
  584. HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading };
  585. String m_content_type { "application/xml"_string };
  586. Optional<String> m_encoding;
  587. bool m_ready_for_post_load_tasks { false };
  588. JS::GCPtr<DOMImplementation> m_implementation;
  589. JS::GCPtr<HTML::HTMLScriptElement> m_current_script;
  590. bool m_should_invalidate_styles_on_attribute_changes { true };
  591. u32 m_ignore_destructive_writes_counter { 0 };
  592. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#unload-counter
  593. u32 m_unload_counter { 0 };
  594. // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#throw-on-dynamic-markup-insertion-counter
  595. u32 m_throw_on_dynamic_markup_insertion_counter { 0 };
  596. // https://html.spec.whatwg.org/multipage/semantics.html#script-blocking-style-sheet-counter
  597. u32 m_script_blocking_style_sheet_counter { 0 };
  598. JS::GCPtr<HTML::History> m_history;
  599. size_t m_number_of_things_delaying_the_load_event { 0 };
  600. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#concept-document-salvageable
  601. bool m_salvageable { true };
  602. // https://html.spec.whatwg.org/#page-showing
  603. bool m_page_showing { false };
  604. // Used by run_the_resize_steps().
  605. Optional<Gfx::IntSize> m_last_viewport_size;
  606. HashTable<ViewportClient*> m_viewport_clients;
  607. // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scroll-event-targets
  608. Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scroll_event_targets;
  609. // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scrollend-event-targets
  610. Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scrollend_event_targets;
  611. // Used by evaluate_media_queries_and_report_changes().
  612. Vector<WeakPtr<CSS::MediaQueryList>> m_media_query_lists;
  613. bool m_needs_layout { false };
  614. bool m_needs_full_style_update { false };
  615. bool m_needs_animated_style_update { false };
  616. HashTable<JS::GCPtr<NodeIterator>> m_node_iterators;
  617. HashTable<JS::NonnullGCPtr<DocumentObserver>> m_document_observers;
  618. // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank
  619. bool m_is_initial_about_blank { false };
  620. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-about-base-url
  621. Optional<URL::URL> m_about_base_url;
  622. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop
  623. HTML::OpenerPolicy m_opener_policy;
  624. // https://html.spec.whatwg.org/multipage/dom.html#the-document's-referrer
  625. String m_referrer;
  626. // https://dom.spec.whatwg.org/#concept-document-origin
  627. HTML::Origin m_origin;
  628. JS::GCPtr<HTMLCollection> m_applets;
  629. JS::GCPtr<HTMLCollection> m_anchors;
  630. JS::GCPtr<HTMLCollection> m_images;
  631. JS::GCPtr<HTMLCollection> m_embeds;
  632. JS::GCPtr<HTMLCollection> m_links;
  633. JS::GCPtr<HTMLCollection> m_forms;
  634. JS::GCPtr<HTMLCollection> m_scripts;
  635. JS::GCPtr<HTML::HTMLAllCollection> m_all;
  636. // https://drafts.csswg.org/css-font-loading/#font-source
  637. JS::GCPtr<CSS::FontFaceSet> m_fonts;
  638. // https://html.spec.whatwg.org/#completely-loaded-time
  639. Optional<AK::UnixDateTime> m_completely_loaded_time;
  640. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
  641. Optional<String> m_navigation_id;
  642. // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set
  643. HTML::SandboxingFlagSet m_active_sandboxing_flag_set;
  644. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
  645. HTML::PolicyContainer m_policy_container;
  646. // https://html.spec.whatwg.org/multipage/interaction.html#visibility-state
  647. HTML::VisibilityState m_visibility_state { HTML::VisibilityState::Hidden };
  648. // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info
  649. DocumentLoadTimingInfo m_load_timing_info;
  650. // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing
  651. DocumentUnloadTimingInfo m_previous_document_unload_timing;
  652. // https://w3c.github.io/selection-api/#dfn-selection
  653. JS::GCPtr<Selection::Selection> m_selection;
  654. // NOTE: This is a cache to make finding the first <base href> element O(1).
  655. JS::GCPtr<HTML::HTMLBaseElement const> m_first_base_element_with_href_in_tree_order;
  656. // https://html.spec.whatwg.org/multipage/images.html#list-of-available-images
  657. JS::GCPtr<HTML::ListOfAvailableImages> m_list_of_available_images;
  658. JS::GCPtr<CSS::VisualViewport> m_visual_viewport;
  659. // NOTE: Not in the spec per say, but Document must be able to access all IntersectionObservers whose root is in the document.
  660. OrderedHashTable<JS::NonnullGCPtr<IntersectionObserver::IntersectionObserver>> m_intersection_observers;
  661. // https://www.w3.org/TR/intersection-observer/#document-intersectionobservertaskqueued
  662. // Each document has an IntersectionObserverTaskQueued flag which is initialized to false.
  663. bool m_intersection_observer_task_queued { false };
  664. // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-load-intersection-observer
  665. // Each Document has a lazy load intersection observer, initially set to null but can be set to an IntersectionObserver instance.
  666. JS::GCPtr<IntersectionObserver::IntersectionObserver> m_lazy_load_intersection_observer;
  667. Vector<JS::NonnullGCPtr<ResizeObserver::ResizeObserver>> m_resize_observers;
  668. // https://html.spec.whatwg.org/multipage/semantics.html#will-declaratively-refresh
  669. // A Document object has an associated will declaratively refresh (a boolean). It is initially false.
  670. bool m_will_declaratively_refresh { false };
  671. RefPtr<Core::Timer> m_active_refresh_timer;
  672. TemporaryDocumentForFragmentParsing m_temporary_document_for_fragment_parsing { TemporaryDocumentForFragmentParsing::No };
  673. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#latest-entry
  674. JS::GCPtr<HTML::SessionHistoryEntry> m_latest_entry;
  675. HashMap<URL::URL, JS::GCPtr<HTML::SharedResourceRequest>> m_shared_resource_requests;
  676. // https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document
  677. HashTable<JS::NonnullGCPtr<Animations::AnimationTimeline>> m_associated_animation_timelines;
  678. // https://www.w3.org/TR/web-animations-1/#document-default-document-timeline
  679. JS::GCPtr<Animations::DocumentTimeline> m_default_timeline;
  680. Optional<double> m_last_animation_frame_timestamp;
  681. // https://www.w3.org/TR/web-animations-1/#pending-animation-event-queue
  682. Vector<PendingAnimationEvent> m_pending_animation_event_queue;
  683. RefPtr<Core::Timer> m_animation_driver_timer;
  684. // https://drafts.csswg.org/css-transitions-2/#current-transition-generation
  685. size_t m_transition_generation { 0 };
  686. bool m_needs_to_call_page_did_load { false };
  687. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#scripts-may-run-for-the-newly-created-document
  688. bool m_ready_to_run_scripts { false };
  689. Vector<HTML::FormAssociatedElement*> m_form_associated_elements_with_form_attribute;
  690. Vector<JS::NonnullGCPtr<DOM::Element>> m_potentially_named_elements;
  691. bool m_design_mode_enabled { false };
  692. bool m_needs_to_resolve_paint_only_properties { true };
  693. mutable JS::GCPtr<WebIDL::ObservableArray> m_adopted_style_sheets;
  694. Vector<JS::NonnullGCPtr<DOM::ShadowRoot>> m_shadow_roots;
  695. Optional<Core::DateTime> m_last_modified;
  696. u64 m_dom_tree_version { 0 };
  697. // https://drafts.csswg.org/css-position-4/#document-top-layer
  698. // Documents have a top layer, an ordered set containing elements from the document.
  699. // Elements in the top layer do not lay out normally based on their position in the document;
  700. // instead they generate boxes as if they were siblings of the root element.
  701. OrderedHashTable<JS::NonnullGCPtr<Element>> m_top_layer_elements;
  702. OrderedHashTable<JS::NonnullGCPtr<Element>> m_top_layer_pending_removals;
  703. // https://dom.spec.whatwg.org/#document-allow-declarative-shadow-roots
  704. bool m_allow_declarative_shadow_roots { false };
  705. JS::GCPtr<JS::ConsoleClient> m_console_client;
  706. JS::GCPtr<DOM::Position> m_cursor_position;
  707. RefPtr<Core::Timer> m_cursor_blink_timer;
  708. bool m_cursor_blink_state { false };
  709. // NOTE: This is WeakPtr, not GCPtr, on purpose. We don't want the document to keep some old detached navigable alive.
  710. WeakPtr<HTML::Navigable> m_cached_navigable;
  711. bool m_needs_repaint { false };
  712. Optional<PaintConfig> m_cached_display_list_paint_config;
  713. RefPtr<Painting::DisplayList> m_cached_display_list;
  714. mutable OwnPtr<Unicode::Segmenter> m_grapheme_segmenter;
  715. mutable OwnPtr<Unicode::Segmenter> m_word_segmenter;
  716. };
  717. template<>
  718. inline bool Node::fast_is<Document>() const { return is_document(); }
  719. }