1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:57:34 +00:00

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.
This commit is contained in:
Andreas Kling 2021-09-26 12:22:16 +02:00
parent 8496024756
commit a2f77a2e39
3 changed files with 20 additions and 8 deletions

View file

@ -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));
}

View file

@ -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;