Skip to content

Commit 945c4ca

Browse files
committed
LibWeb/HTML: Implement NavigationTransition.to
Corresponds to: whatwg/html@f19930f
1 parent 43bd534 commit 945c4ca

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

Libraries/LibWeb/HTML/Navigation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,13 @@ bool Navigation::inner_navigate_event_firing_algorithm(
11231123
// 3. Assert: fromNHE is not null.
11241124
VERIFY(from_nhe != nullptr);
11251125

1126-
// 4. Set navigation's transition to a new NavigationTransition created in navigation's relevant realm,
1127-
// whose navigation type is navigationType, whose from entry is fromNHE, and whose finished promise is a new promise
1128-
// created in navigation's relevant realm.
1129-
m_transition = NavigationTransition::create(realm, navigation_type, *from_nhe, WebIDL::create_promise(realm));
1126+
// 4. Set navigation's transition to a new NavigationTransition created in navigation's relevant realm, with
1127+
// navigation type: navigationType
1128+
// from entry: fromNHE
1129+
// destination: event's destination
1130+
// FIXME: committed promise: a new promise created in navigation's relevant realm
1131+
// finished promise: a new promise created in navigation's relevant realm
1132+
m_transition = NavigationTransition::create(realm, navigation_type, *from_nhe, event->destination(), WebIDL::create_promise(realm));
11301133

11311134
// 5. Mark as handled navigation's transition's finished promise.
11321135
WebIDL::mark_promise_as_handled(*m_transition->finished());

Libraries/LibWeb/HTML/NavigationTransition.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <LibJS/Runtime/Realm.h>
99
#include <LibWeb/Bindings/Intrinsics.h>
1010
#include <LibWeb/Bindings/NavigationTransitionPrototype.h>
11+
#include <LibWeb/HTML/NavigationDestination.h>
1112
#include <LibWeb/HTML/NavigationHistoryEntry.h>
1213
#include <LibWeb/HTML/NavigationTransition.h>
1314
#include <LibWeb/WebIDL/Promise.h>
@@ -16,15 +17,16 @@ namespace Web::HTML {
1617

1718
GC_DEFINE_ALLOCATOR(NavigationTransition);
1819

19-
GC::Ref<NavigationTransition> NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<WebIDL::Promise> finished_promise)
20+
GC::Ref<NavigationTransition> NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> finished_promise)
2021
{
21-
return realm.create<NavigationTransition>(realm, navigation_type, from_entry, finished_promise);
22+
return realm.create<NavigationTransition>(realm, navigation_type, from_entry, destination, finished_promise);
2223
}
2324

24-
NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<WebIDL::Promise> finished_promise)
25+
NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> finished_promise)
2526
: Bindings::PlatformObject(realm)
2627
, m_navigation_type(navigation_type)
2728
, m_from_entry(from_entry)
29+
, m_destination(destination)
2830
, m_finished_promise(finished_promise)
2931
{
3032
}
@@ -41,6 +43,7 @@ void NavigationTransition::visit_edges(JS::Cell::Visitor& visitor)
4143
{
4244
Base::visit_edges(visitor);
4345
visitor.visit(m_from_entry);
46+
visitor.visit(m_destination);
4447
visitor.visit(m_finished_promise);
4548
}
4649

Libraries/LibWeb/HTML/NavigationTransition.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,58 @@ class NavigationTransition : public Bindings::PlatformObject {
1717
GC_DECLARE_ALLOCATOR(NavigationTransition);
1818

1919
public:
20-
[[nodiscard]] static GC::Ref<NavigationTransition> create(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<WebIDL::Promise>);
20+
[[nodiscard]] static GC::Ref<NavigationTransition> create(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise>);
2121

2222
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-navigationtype
23-
Bindings::NavigationType navigation_type() const { return m_navigation_type; }
23+
Bindings::NavigationType navigation_type() const
24+
{
25+
// The navigationType getter steps are to return this's navigation type.
26+
return m_navigation_type;
27+
}
2428

2529
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-from
26-
GC::Ref<NavigationHistoryEntry> from() const { return m_from_entry; }
30+
GC::Ref<NavigationHistoryEntry> from() const
31+
{
32+
// The from getter steps are to return this's from entry.
33+
return m_from_entry;
34+
}
35+
36+
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-to
37+
GC::Ref<NavigationDestination> to() const
38+
{
39+
// The to getter steps are to return this's destination.
40+
return m_destination;
41+
}
2742

2843
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-finished
29-
GC::Ref<WebIDL::Promise> finished() const { return m_finished_promise; }
44+
GC::Ref<WebIDL::Promise> finished() const
45+
{
46+
// The finished getter steps are to return this's finished promise.
47+
return m_finished_promise;
48+
}
3049

3150
virtual ~NavigationTransition() override;
3251

3352
private:
34-
NavigationTransition(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<WebIDL::Promise>);
53+
NavigationTransition(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise>);
3554

3655
virtual void initialize(JS::Realm&) override;
3756
virtual void visit_edges(JS::Cell::Visitor&) override;
3857

3958
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-navigationtype
59+
// Each NavigationTransition has an associated navigation type, which is a NavigationType.
4060
Bindings::NavigationType m_navigation_type;
4161

4262
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-from
63+
// Each NavigationTransition has an associated from entry, which is a NavigationHistoryEntry.
4364
GC::Ref<NavigationHistoryEntry> m_from_entry;
4465

66+
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-destination
67+
// Each NavigationTransition has an associated destination, which is a NavigationDestination.
68+
GC::Ref<NavigationDestination> m_destination;
69+
4570
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-finished
71+
// Each NavigationTransition has an associated finished promise, which is a promise.
4672
GC::Ref<WebIDL::Promise> m_finished_promise;
4773
};
4874

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#import <HTML/NavigationType.idl>
1+
#import <HTML/NavigationDestination.idl>
22
#import <HTML/NavigationHistoryEntry.idl>
3+
#import <HTML/NavigationType.idl>
34

45
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigationtransition
56
[Exposed=Window]
67
interface NavigationTransition {
78
readonly attribute NavigationType navigationType;
89
readonly attribute NavigationHistoryEntry from;
10+
readonly attribute NavigationDestination to;
11+
// FIXME: readonly attribute Promise<undefined> committed;
912
readonly attribute Promise<undefined> finished;
1013
};

0 commit comments

Comments
 (0)