Document.h 45 KB

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