diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn index 62e755667b6..8d27c49d760 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/HTML/BUILD.gn @@ -127,6 +127,7 @@ source_set("HTML") { "NavigationCurrentEntryChangeEvent.cpp", "NavigationDestination.cpp", "NavigationHistoryEntry.cpp", + "NavigationTransition.cpp", "Navigator.cpp", "NavigatorID.cpp", "PageTransitionEvent.cpp", diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni index 1506239f298..2fc876085bc 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni @@ -186,6 +186,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.idl", "//Userland/Libraries/LibWeb/HTML/NavigationDestination.idl", "//Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.idl", + "//Userland/Libraries/LibWeb/HTML/NavigationTransition.idl", "//Userland/Libraries/LibWeb/HTML/Navigator.idl", "//Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl", "//Userland/Libraries/LibWeb/HTML/Path2D.idl", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 80b4bcfbac8..03d0855bb1f 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -354,6 +354,7 @@ set(SOURCES HTML/NavigationDestination.cpp HTML/NavigationCurrentEntryChangeEvent.cpp HTML/NavigationHistoryEntry.cpp + HTML/NavigationTransition.cpp HTML/Navigator.cpp HTML/NavigatorID.cpp HTML/PageTransitionEvent.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 59629827dc4..f9b4ae99b72 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -417,6 +417,7 @@ class NavigableContainer; class Navigation; class NavigationCurrentEntryChangeEvent; class NavigationHistoryEntry; +class NavigationTransition; class Navigator; struct NavigationParams; class Origin; diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.cpp b/Userland/Libraries/LibWeb/HTML/Navigation.cpp index ab0b0c8f45d..b1339bb2244 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigation.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace Web::HTML { @@ -39,6 +40,7 @@ void Navigation::visit_edges(JS::Cell::Visitor& visitor) Base::visit_edges(visitor); for (auto& entry : m_entry_list) visitor.visit(entry); + visitor.visit(m_transition); } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-entries diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.h b/Userland/Libraries/LibWeb/HTML/Navigation.h index 7c96133db78..d7758da4fb0 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.h +++ b/Userland/Libraries/LibWeb/HTML/Navigation.h @@ -53,6 +53,9 @@ public: bool can_go_back() const; bool can_go_forward() const; + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-transition + JS::GCPtr transition() const { return m_transition; } + // Event Handlers void set_onnavigate(WebIDL::CallbackType*); WebIDL::CallbackType* onnavigate(); @@ -85,6 +88,10 @@ private: // https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-current-entry-index // Each Navigation has an associated current entry index, an integer, initially −1. i64 m_current_entry_index { -1 }; + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigation-transition + // Each Navigation has a transition, which is a NavigationTransition or null, initially null. + JS::GCPtr m_transition { nullptr }; }; } diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.idl b/Userland/Libraries/LibWeb/HTML/Navigation.idl index fce3741b1b3..1605749c581 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.idl +++ b/Userland/Libraries/LibWeb/HTML/Navigation.idl @@ -1,6 +1,7 @@ #import #import #import +#import // https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-interface [Exposed=Window] @@ -8,7 +9,7 @@ interface Navigation : EventTarget { sequence entries(); readonly attribute NavigationHistoryEntry? currentEntry; undefined updateCurrentEntry(NavigationUpdateCurrentEntryOptions options); - // FIXME: readonly attribute NavigationTransition? transition; + readonly attribute NavigationTransition? transition; readonly attribute boolean canGoBack; readonly attribute boolean canGoForward; diff --git a/Userland/Libraries/LibWeb/HTML/NavigationTransition.cpp b/Userland/Libraries/LibWeb/HTML/NavigationTransition.cpp new file mode 100644 index 00000000000..f7173a5148a --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/NavigationTransition.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace Web::HTML { + +JS::NonnullGCPtr NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, JS::NonnullGCPtr from_entry, JS::GCPtr finished_promise) +{ + return realm.heap().allocate(realm, realm, navigation_type, from_entry, finished_promise); +} + +NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, JS::NonnullGCPtr from_entry, JS::GCPtr finished_promise) + : Bindings::PlatformObject(realm) + , m_navigation_type(navigation_type) + , m_from_entry(from_entry) + , m_finished_promise(finished_promise) +{ +} + +NavigationTransition::~NavigationTransition() = default; + +void NavigationTransition::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "NavigationTransition")); +} + +void NavigationTransition::visit_edges(JS::Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_from_entry); + visitor.visit(m_finished_promise); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/NavigationTransition.h b/Userland/Libraries/LibWeb/HTML/NavigationTransition.h new file mode 100644 index 00000000000..ae7f7575d99 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/NavigationTransition.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigationtransition +class NavigationTransition : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(NavigationTransition, Bindings::PlatformObject); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Bindings::NavigationType, JS::NonnullGCPtr, JS::GCPtr); + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-navigationtype + Bindings::NavigationType navigation_type() const { return m_navigation_type; } + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-from + JS::NonnullGCPtr from() const { return m_from_entry; } + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-finished + JS::GCPtr finished() const { return m_finished_promise; } + + virtual ~NavigationTransition() override; + +private: + NavigationTransition(JS::Realm&, Bindings::NavigationType, JS::NonnullGCPtr, JS::GCPtr); + + virtual void initialize(JS::Realm&) override; + virtual void visit_edges(JS::Cell::Visitor&) override; + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-navigationtype + Bindings::NavigationType m_navigation_type; + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-from + JS::NonnullGCPtr m_from_entry; + + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-finished + JS::GCPtr m_finished_promise; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/NavigationTransition.idl b/Userland/Libraries/LibWeb/HTML/NavigationTransition.idl new file mode 100644 index 00000000000..04cb6d56680 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/NavigationTransition.idl @@ -0,0 +1,9 @@ +#import +#import + +[Exposed=Window, UseNewAKString] +interface NavigationTransition { + readonly attribute NavigationType navigationType; + readonly attribute NavigationHistoryEntry from; + readonly attribute Promise finished; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 934d3462897..1d78332d54f 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -172,6 +172,7 @@ libweb_js_bindings(HTML/Navigation) libweb_js_bindings(HTML/NavigationCurrentEntryChangeEvent) libweb_js_bindings(HTML/NavigationDestination) libweb_js_bindings(HTML/NavigationHistoryEntry) +libweb_js_bindings(HTML/NavigationTransition) libweb_js_bindings(HTML/Navigator) libweb_js_bindings(HTML/PageTransitionEvent) libweb_js_bindings(HTML/Path2D)