mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
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.
This commit is contained in:
parent
508edcd217
commit
831fdcaabc
7 changed files with 70 additions and 4 deletions
|
@ -420,6 +420,7 @@ libweb_js_wrapper(HTML/ImageData)
|
|||
libweb_js_wrapper(HTML/MessageChannel)
|
||||
libweb_js_wrapper(HTML/MessageEvent)
|
||||
libweb_js_wrapper(HTML/MessagePort)
|
||||
libweb_js_wrapper(HTML/PageTransitionEvent)
|
||||
libweb_js_wrapper(HTML/SubmitEvent)
|
||||
libweb_js_wrapper(HTML/WebSocket)
|
||||
libweb_js_wrapper(HighResolutionTime/Performance)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <LibWeb/DOM/EventDispatcher.h>
|
||||
#include <LibWeb/DOM/Timer.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/PageTransitionEvent.h>
|
||||
#include <LibWeb/HighResolutionTime/Performance.h>
|
||||
#include <LibWeb/Layout/InitialContainingBlock.h>
|
||||
#include <LibWeb/Page/BrowsingContext.h>
|
||||
|
@ -276,4 +277,22 @@ float Window::scroll_y() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#fire-a-page-transition-event
|
||||
void Window::fire_a_page_transition_event(FlyString event_name, bool persisted)
|
||||
{
|
||||
// To fire a page transition event named eventName at a Window window with a boolean persisted,
|
||||
// fire an event named eventName at window, using PageTransitionEvent,
|
||||
// with the persisted attribute initialized to persisted,
|
||||
auto event = HTML::PageTransitionEvent::create(move(event_name), persisted);
|
||||
|
||||
// ...the cancelable attribute intialized to true,
|
||||
event->set_cancelable(true);
|
||||
|
||||
// the bubbles attribute initialized to true,
|
||||
event->set_bubbles(true);
|
||||
|
||||
// and legacy target override flag set.
|
||||
dispatch_event(move(event));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,6 +83,8 @@ public:
|
|||
float scroll_x() const;
|
||||
float scroll_y() const;
|
||||
|
||||
void fire_a_page_transition_event(FlyString event_name, bool persisted);
|
||||
|
||||
private:
|
||||
explicit Window(Document&);
|
||||
|
||||
|
|
|
@ -346,6 +346,7 @@ class MessageEventWrapper;
|
|||
class MessagePortWrapper;
|
||||
class MouseEventWrapper;
|
||||
class NodeWrapper;
|
||||
class PageTransitionEventWrapper;
|
||||
class PerformanceTimingWrapper;
|
||||
class PerformanceWrapper;
|
||||
class ProcessingInstructionWrapper;
|
||||
|
|
36
Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h
Normal file
36
Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h
Normal file
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
5
Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl
Normal file
5
Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
interface PageTransitionEvent : Event {
|
||||
|
||||
readonly attribute boolean persisted;
|
||||
|
||||
};
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue