1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibWeb: Implement the inner navigate event firing algorithm

This algorithm is the meat of firing the NavigateEvent at navigation.
In order to implement it, we also need to add some getters/setters on
NavigateEvent. The implemetentation deviates from the spec in when
exactly the NavigateEvent is created. In following the pattern for other
events. we construct the event from the NavigateEventInit structure from
our native code. This makes the code a lot simpler than adding 10
getters to the NavigateEvent that are only ever used just after
construction. I'm not 100% conviced the promise resolution code is
correct, but we can add tests for that later :^).
This commit is contained in:
Andrew Kaster 2023-09-22 18:35:11 -06:00 committed by Alexander Kalenik
parent 0650edc7d7
commit 3935105d0a
3 changed files with 366 additions and 7 deletions

View file

@ -42,6 +42,15 @@ class NavigateEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(NavigateEvent, DOM::Event);
public:
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigateevent-interception-state
enum class InterceptionState {
None,
Intercepted,
Committed,
Scrolled,
Finished
};
[[nodiscard]] static JS::NonnullGCPtr<NavigateEvent> construct_impl(JS::Realm&, FlyString const& event_name, NavigateEventInit const&);
// The navigationType, destination, canIntercept, userInitiated, hashChange, signal, formData,
@ -63,6 +72,12 @@ public:
virtual ~NavigateEvent() override;
JS::NonnullGCPtr<DOM::AbortController> abort_controller() const { return *m_abort_controller; }
InterceptionState interception_state() const { return m_interception_state; }
Vector<NavigationInterceptHandler> const& navigation_handler_list() const { return m_navigation_handler_list; }
void set_abort_controller(JS::NonnullGCPtr<DOM::AbortController> c) { m_abort_controller = c; }
void set_interception_state(InterceptionState s) { m_interception_state = s; }
void set_classic_history_api_state(Optional<SerializationRecord> r) { m_classic_history_api_state = move(r); }
void finish(bool did_fulfill);
@ -78,13 +93,6 @@ private:
void potentially_reset_the_focus();
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigateevent-interception-state
enum class InterceptionState {
None,
Intercepted,
Committed,
Scrolled,
Finished
};
InterceptionState m_interception_state = InterceptionState::None;
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigateevent-navigation-handler-list