summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-26 12:22:16 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-26 12:47:51 +0200
commita2f77a2e3966db737c74e5c7c4d53610969d7302 (patch)
tree68f87b588de8b04548528fa5fa8efd86a3a39058 /Userland/Libraries/LibWeb/DOM
parent84960247563a103b4cc330e9b07f936bd5f93a10 (diff)
downloadserenity-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/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp20
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h4
2 files changed, 18 insertions, 6 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;