summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-26 12:39:27 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-26 12:47:51 +0200
commit831fdcaabc95817d4bff9c8bd8a6741227a0b371 (patch)
tree3a7fcd8b6bcbfbdc28ad648a402c2a819d5842e7 /Userland/Libraries/LibWeb/HTML
parent508edcd217b23c0cc0107a094269e65373b813de (diff)
downloadserenity-831fdcaabc95817d4bff9c8bd8a6741227a0b371.zip
LibWeb: Add the PageTransitionEvent interface and fire "pageshow" events
We now fire "pageshow" events at the appropriate time during document loading (done by the parser.) Note that there are no corresponding "pagehide" events yet.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h36
-rw-r--r--Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl5
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp10
3 files changed, 47 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h
new file mode 100644
index 0000000000..7c3602ed1f
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/DOM/Event.h>
+
+namespace Web::HTML {
+
+class PageTransitionEvent final : public DOM::Event {
+public:
+ using WrapperType = Bindings::PageTransitionEventWrapper;
+
+ static NonnullRefPtr<PageTransitionEvent> create(FlyString event_name, bool persisted)
+ {
+ return adopt_ref(*new PageTransitionEvent(move(event_name), persisted));
+ }
+
+ virtual ~PageTransitionEvent() override = default;
+
+ bool persisted() const { return m_persisted; }
+
+protected:
+ PageTransitionEvent(FlyString event_name, bool persisted)
+ : DOM::Event(move(event_name))
+ , m_persisted(persisted)
+ {
+ }
+
+ bool m_persisted { false };
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl
new file mode 100644
index 0000000000..e569647c3a
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl
@@ -0,0 +1,5 @@
+interface PageTransitionEvent : Event {
+
+ readonly attribute boolean persisted;
+
+};
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index be45d48140..7a117bea5d 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -246,14 +246,15 @@ void HTMLParser::the_end()
if (!document->browsing_context())
return;
- // FIXME: 3. Let window be the Document's relevant global object.
+ // 3. Let window be the Document's relevant global object.
+ NonnullRefPtr<DOM::Window> window = document->window();
// FIXME: 4. Set the Document's load timing info's load event start time to the current high resolution time given window.
// 5. Fire an event named load at window, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
// We should reorganize this so that the flag appears explicitly here instead.
- document->window().dispatch_event(DOM::Event::create(HTML::EventNames::load));
+ window->dispatch_event(DOM::Event::create(HTML::EventNames::load));
// FIXME: 6. Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL.
@@ -267,7 +268,8 @@ void HTMLParser::the_end()
// 10. Set the Document's page showing flag to true.
document->set_page_showing(true);
- // FIXME: 11. Fire a page transition event named pageshow at window with false.
+ // 11. Fire a page transition event named pageshow at window with false.
+ window->fire_a_page_transition_event(HTML::EventNames::pageshow, false);
// 12. Completely finish loading the Document.
document->completely_finish_loading();