mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibWeb: Add NavigationTransition, a transient property of Navigation
This property is useful for web content to determine whether an ongoing navigation has settled or not.
This commit is contained in:
parent
4989375191
commit
3dd3b2019d
11 changed files with 118 additions and 1 deletions
|
@ -127,6 +127,7 @@ source_set("HTML") {
|
||||||
"NavigationCurrentEntryChangeEvent.cpp",
|
"NavigationCurrentEntryChangeEvent.cpp",
|
||||||
"NavigationDestination.cpp",
|
"NavigationDestination.cpp",
|
||||||
"NavigationHistoryEntry.cpp",
|
"NavigationHistoryEntry.cpp",
|
||||||
|
"NavigationTransition.cpp",
|
||||||
"Navigator.cpp",
|
"Navigator.cpp",
|
||||||
"NavigatorID.cpp",
|
"NavigatorID.cpp",
|
||||||
"PageTransitionEvent.cpp",
|
"PageTransitionEvent.cpp",
|
||||||
|
|
|
@ -186,6 +186,7 @@ standard_idl_files = [
|
||||||
"//Userland/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.idl",
|
"//Userland/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/HTML/NavigationDestination.idl",
|
"//Userland/Libraries/LibWeb/HTML/NavigationDestination.idl",
|
||||||
"//Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.idl",
|
"//Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.idl",
|
||||||
|
"//Userland/Libraries/LibWeb/HTML/NavigationTransition.idl",
|
||||||
"//Userland/Libraries/LibWeb/HTML/Navigator.idl",
|
"//Userland/Libraries/LibWeb/HTML/Navigator.idl",
|
||||||
"//Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl",
|
"//Userland/Libraries/LibWeb/HTML/PageTransitionEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/HTML/Path2D.idl",
|
"//Userland/Libraries/LibWeb/HTML/Path2D.idl",
|
||||||
|
|
|
@ -354,6 +354,7 @@ set(SOURCES
|
||||||
HTML/NavigationDestination.cpp
|
HTML/NavigationDestination.cpp
|
||||||
HTML/NavigationCurrentEntryChangeEvent.cpp
|
HTML/NavigationCurrentEntryChangeEvent.cpp
|
||||||
HTML/NavigationHistoryEntry.cpp
|
HTML/NavigationHistoryEntry.cpp
|
||||||
|
HTML/NavigationTransition.cpp
|
||||||
HTML/Navigator.cpp
|
HTML/Navigator.cpp
|
||||||
HTML/NavigatorID.cpp
|
HTML/NavigatorID.cpp
|
||||||
HTML/PageTransitionEvent.cpp
|
HTML/PageTransitionEvent.cpp
|
||||||
|
|
|
@ -417,6 +417,7 @@ class NavigableContainer;
|
||||||
class Navigation;
|
class Navigation;
|
||||||
class NavigationCurrentEntryChangeEvent;
|
class NavigationCurrentEntryChangeEvent;
|
||||||
class NavigationHistoryEntry;
|
class NavigationHistoryEntry;
|
||||||
|
class NavigationTransition;
|
||||||
class Navigator;
|
class Navigator;
|
||||||
struct NavigationParams;
|
struct NavigationParams;
|
||||||
class Origin;
|
class Origin;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <LibWeb/HTML/Navigation.h>
|
#include <LibWeb/HTML/Navigation.h>
|
||||||
#include <LibWeb/HTML/NavigationCurrentEntryChangeEvent.h>
|
#include <LibWeb/HTML/NavigationCurrentEntryChangeEvent.h>
|
||||||
#include <LibWeb/HTML/NavigationHistoryEntry.h>
|
#include <LibWeb/HTML/NavigationHistoryEntry.h>
|
||||||
|
#include <LibWeb/HTML/NavigationTransition.h>
|
||||||
#include <LibWeb/HTML/Window.h>
|
#include <LibWeb/HTML/Window.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -39,6 +40,7 @@ void Navigation::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
for (auto& entry : m_entry_list)
|
for (auto& entry : m_entry_list)
|
||||||
visitor.visit(entry);
|
visitor.visit(entry);
|
||||||
|
visitor.visit(m_transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-entries
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-entries
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
bool can_go_back() const;
|
bool can_go_back() const;
|
||||||
bool can_go_forward() const;
|
bool can_go_forward() const;
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-transition
|
||||||
|
JS::GCPtr<NavigationTransition> transition() const { return m_transition; }
|
||||||
|
|
||||||
// Event Handlers
|
// Event Handlers
|
||||||
void set_onnavigate(WebIDL::CallbackType*);
|
void set_onnavigate(WebIDL::CallbackType*);
|
||||||
WebIDL::CallbackType* onnavigate();
|
WebIDL::CallbackType* onnavigate();
|
||||||
|
@ -85,6 +88,10 @@ private:
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-current-entry-index
|
// 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.
|
// Each Navigation has an associated current entry index, an integer, initially −1.
|
||||||
i64 m_current_entry_index { -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<NavigationTransition> m_transition { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#import <DOM/EventHandler.idl>
|
#import <DOM/EventHandler.idl>
|
||||||
#import <DOM/EventTarget.idl>
|
#import <DOM/EventTarget.idl>
|
||||||
#import <HTML/NavigationHistoryEntry.idl>
|
#import <HTML/NavigationHistoryEntry.idl>
|
||||||
|
#import <HTML/NavigationTransition.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-interface
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-interface
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
|
@ -8,7 +9,7 @@ interface Navigation : EventTarget {
|
||||||
sequence<NavigationHistoryEntry> entries();
|
sequence<NavigationHistoryEntry> entries();
|
||||||
readonly attribute NavigationHistoryEntry? currentEntry;
|
readonly attribute NavigationHistoryEntry? currentEntry;
|
||||||
undefined updateCurrentEntry(NavigationUpdateCurrentEntryOptions options);
|
undefined updateCurrentEntry(NavigationUpdateCurrentEntryOptions options);
|
||||||
// FIXME: readonly attribute NavigationTransition? transition;
|
readonly attribute NavigationTransition? transition;
|
||||||
|
|
||||||
readonly attribute boolean canGoBack;
|
readonly attribute boolean canGoBack;
|
||||||
readonly attribute boolean canGoForward;
|
readonly attribute boolean canGoForward;
|
||||||
|
|
45
Userland/Libraries/LibWeb/HTML/NavigationTransition.cpp
Normal file
45
Userland/Libraries/LibWeb/HTML/NavigationTransition.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Heap/Heap.h>
|
||||||
|
#include <LibJS/Runtime/Promise.h>
|
||||||
|
#include <LibJS/Runtime/Realm.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/Bindings/NavigationTransitionPrototype.h>
|
||||||
|
#include <LibWeb/HTML/NavigationHistoryEntry.h>
|
||||||
|
#include <LibWeb/HTML/NavigationTransition.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<NavigationTransition> NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, JS::NonnullGCPtr<NavigationHistoryEntry> from_entry, JS::GCPtr<JS::Promise> finished_promise)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<NavigationTransition>(realm, realm, navigation_type, from_entry, finished_promise);
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, JS::NonnullGCPtr<NavigationHistoryEntry> from_entry, JS::GCPtr<JS::Promise> 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<Bindings::NavigationTransitionPrototype>(realm, "NavigationTransition"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationTransition::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_from_entry);
|
||||||
|
visitor.visit(m_finished_promise);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
Userland/Libraries/LibWeb/HTML/NavigationTransition.h
Normal file
48
Userland/Libraries/LibWeb/HTML/NavigationTransition.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/HTML/NavigationType.h>
|
||||||
|
|
||||||
|
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<NavigationTransition> create(JS::Realm&, Bindings::NavigationType, JS::NonnullGCPtr<NavigationHistoryEntry>, JS::GCPtr<JS::Promise>);
|
||||||
|
|
||||||
|
// 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<NavigationHistoryEntry> from() const { return m_from_entry; }
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-finished
|
||||||
|
JS::GCPtr<JS::Promise> finished() const { return m_finished_promise; }
|
||||||
|
|
||||||
|
virtual ~NavigationTransition() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
NavigationTransition(JS::Realm&, Bindings::NavigationType, JS::NonnullGCPtr<NavigationHistoryEntry>, JS::GCPtr<JS::Promise>);
|
||||||
|
|
||||||
|
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<NavigationHistoryEntry> m_from_entry;
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-finished
|
||||||
|
JS::GCPtr<JS::Promise> m_finished_promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
9
Userland/Libraries/LibWeb/HTML/NavigationTransition.idl
Normal file
9
Userland/Libraries/LibWeb/HTML/NavigationTransition.idl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#import <HTML/NavigationType.idl>
|
||||||
|
#import <HTML/NavigationHistoryEntry.idl>
|
||||||
|
|
||||||
|
[Exposed=Window, UseNewAKString]
|
||||||
|
interface NavigationTransition {
|
||||||
|
readonly attribute NavigationType navigationType;
|
||||||
|
readonly attribute NavigationHistoryEntry from;
|
||||||
|
readonly attribute Promise<undefined> finished;
|
||||||
|
};
|
|
@ -172,6 +172,7 @@ libweb_js_bindings(HTML/Navigation)
|
||||||
libweb_js_bindings(HTML/NavigationCurrentEntryChangeEvent)
|
libweb_js_bindings(HTML/NavigationCurrentEntryChangeEvent)
|
||||||
libweb_js_bindings(HTML/NavigationDestination)
|
libweb_js_bindings(HTML/NavigationDestination)
|
||||||
libweb_js_bindings(HTML/NavigationHistoryEntry)
|
libweb_js_bindings(HTML/NavigationHistoryEntry)
|
||||||
|
libweb_js_bindings(HTML/NavigationTransition)
|
||||||
libweb_js_bindings(HTML/Navigator)
|
libweb_js_bindings(HTML/Navigator)
|
||||||
libweb_js_bindings(HTML/PageTransitionEvent)
|
libweb_js_bindings(HTML/PageTransitionEvent)
|
||||||
libweb_js_bindings(HTML/Path2D)
|
libweb_js_bindings(HTML/Path2D)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue