diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-26 12:22:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-26 12:47:51 +0200 |
commit | a2f77a2e3966db737c74e5c7c4d53610969d7302 (patch) | |
tree | 68f87b588de8b04548528fa5fa8efd86a3a39058 /Userland | |
parent | 84960247563a103b4cc330e9b07f936bd5f93a10 (diff) | |
download | serenity-a2f77a2e3966db737c74e5c7c4d53610969d7302.zip |
LibWeb: Implement "update the current document readiness" from spec
The only difference from what we were already doing is that setting the
same ready state twice no longer fires a "readystatechange" event.
I don't think that could happen in practice though.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 4 |
3 files changed, 20 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e6a64c3994..7864e3a240 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -899,7 +899,7 @@ void Document::set_active_element(Element* element) String Document::ready_state() const { - switch (m_ready_state) { + switch (m_readiness) { case HTML::DocumentReadyState::Loading: return "loading"sv; case HTML::DocumentReadyState::Interactive: @@ -910,11 +910,23 @@ String Document::ready_state() const VERIFY_NOT_REACHED(); } -void Document::set_ready_state(HTML::DocumentReadyState ready_state) +// https://html.spec.whatwg.org/#update-the-current-document-readiness +void Document::update_readiness(HTML::DocumentReadyState readiness_value) { - if (m_ready_state == ready_state) + // 1. If document's current document readiness equals readinessValue, then return. + if (m_readiness == readiness_value) return; - m_ready_state = ready_state; + + // The spec doesn't actually mention updating the current readiness value. + // FIXME: https://github.com/whatwg/html/issues/7120 + m_readiness = readiness_value; + + // FIXME: 2. If document is associated with an HTML parser, then: + // FIXME: 1. If document is associated with an HTML parser, then: + // FIXME: 2. If readinessValue is "complete", and document's load timing info's DOM complete time is 0, then set document's load timing info's DOM complete time to now. + // FIXME: 3. Otherwise, if readinessValue is "interactive", and document's load timing info's DOM interactive time is 0, then set document's load timing info's DOM interactive time to now. + + // 3. Fire an event named readystatechange at document. dispatch_event(Event::create(HTML::EventNames::readystatechange)); } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 47682b87f9..ab5e5edee3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -228,7 +228,7 @@ public: void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = document; } String ready_state() const; - void set_ready_state(HTML::DocumentReadyState); + void update_readiness(HTML::DocumentReadyState); void ref_from_node(Badge<Node>) { @@ -359,7 +359,7 @@ private: bool m_created_for_appropriate_template_contents { false }; RefPtr<Document> m_associated_inert_template_document; - HTML::DocumentReadyState m_ready_state { HTML::DocumentReadyState::Loading }; + HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading }; String m_content_type { "application/xml" }; Optional<String> m_encoding; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index e3fb50a352..8f84c18adb 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(HTML::DocumentReadyState::Interactive); + m_document->update_readiness(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(HTML::DocumentReadyState::Complete); + document->update_readiness(HTML::DocumentReadyState::Complete); // 2. If the Document object's browsing context is null, then abort these steps. if (!document->browsing_context()) |