Document.h 45 KB

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