diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index aa5eeffebc..e6a64c3994 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -897,8 +897,23 @@ void Document::set_active_element(Element* element) m_layout_root->set_needs_display(); } -void Document::set_ready_state(const String& ready_state) +String Document::ready_state() const { + switch (m_ready_state) { + case HTML::DocumentReadyState::Loading: + return "loading"sv; + case HTML::DocumentReadyState::Interactive: + return "interactive"sv; + case HTML::DocumentReadyState::Complete: + return "complete"sv; + } + VERIFY_NOT_REACHED(); +} + +void Document::set_ready_state(HTML::DocumentReadyState ready_state) +{ + if (m_ready_state == ready_state) + return; m_ready_state = ready_state; dispatch_event(Event::create(HTML::EventNames::readystatechange)); } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 83977757d8..47682b87f9 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -226,8 +227,8 @@ public: const Document* associated_inert_template_document() const { return m_associated_inert_template_document; } void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = document; } - const String& ready_state() const { return m_ready_state; } - void set_ready_state(const String&); + String ready_state() const; + void set_ready_state(HTML::DocumentReadyState); void ref_from_node(Badge) { @@ -358,7 +359,7 @@ private: bool m_created_for_appropriate_template_contents { false }; RefPtr m_associated_inert_template_document; - String m_ready_state { "loading" }; + HTML::DocumentReadyState m_ready_state { HTML::DocumentReadyState::Loading }; String m_content_type { "application/xml" }; Optional m_encoding; diff --git a/Userland/Libraries/LibWeb/HTML/DocumentReadyState.h b/Userland/Libraries/LibWeb/HTML/DocumentReadyState.h new file mode 100644 index 0000000000..d487fec747 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DocumentReadyState.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Web::HTML { + +enum class DocumentReadyState { + Loading, + Interactive, + Complete, +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 74508b327a..e3fb50a352 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -188,7 +188,7 @@ void HTMLParser::the_end() // FIXME: 2. Set the insertion point to undefined. // 3. Update the current document readiness to "interactive". - m_document->set_ready_state("interactive"); + m_document->set_ready_state(HTML::DocumentReadyState::Interactive); // 4. Pop all the nodes off the stack of open elements. while (!m_stack_of_open_elements.is_empty()) @@ -240,7 +240,7 @@ void HTMLParser::the_end() // 9. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following steps: queue_global_task(HTML::Task::Source::DOMManipulation, *m_document, [document = m_document]() mutable { // 1. Update the current document readiness to "complete". - document->set_ready_state("complete"); + document->set_ready_state(HTML::DocumentReadyState::Complete); // 2. If the Document object's browsing context is null, then abort these steps. if (!document->browsing_context())