diff options
author | Andreas Kling <kling@serenityos.org> | 2022-12-12 11:46:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-19 18:26:45 +0200 |
commit | 2d602dcb3481897070a7ba9f72d5a869074b66f2 (patch) | |
tree | 809f99148a6f77662a622908a263362dc47824ae | |
parent | d8ccc2d54ef46600260f395edeb85c9a08cc0485 (diff) | |
download | serenity-2d602dcb3481897070a7ba9f72d5a869074b66f2.zip |
LibWeb: Add HTML::Navigable
This is the first step towards implementing the new "navigable" concept
from the HTML spec.
Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Forward.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Navigable.cpp | 83 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Navigable.h | 71 |
4 files changed, 156 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index d86f1e4c28..ab165ec566 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -313,6 +313,7 @@ set(SOURCES HTML/MessagePort.cpp HTML/MimeType.cpp HTML/MimeTypeArray.cpp + HTML/Navigable.cpp HTML/NavigableContainer.cpp HTML/Navigator.cpp HTML/NavigatorID.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 64aa6c2b16..4c751844cf 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -369,6 +369,7 @@ class MessageEvent; class MessagePort; class MimeType; class MimeTypeArray; +class Navigable; class NavigableContainer; class Navigator; struct NavigationParams; diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp new file mode 100644 index 0000000000..c6cd1efcff --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/DOM/Document.h> +#include <LibWeb/HTML/BrowsingContext.h> +#include <LibWeb/HTML/DocumentState.h> +#include <LibWeb/HTML/Navigable.h> +#include <LibWeb/HTML/SessionHistoryEntry.h> + +namespace Web::HTML { + +Navigable::Navigable() = default; + +Navigable::~Navigable() = default; + +void Navigable::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_parent); + visitor.visit(m_current_session_history_entry); + visitor.visit(m_active_session_history_entry); + visitor.visit(m_container); +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-document +JS::GCPtr<DOM::Document> Navigable::active_document() +{ + // A navigable's active document is its active session history entry's document. + return m_active_session_history_entry->document_state->document(); +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-bc +JS::GCPtr<BrowsingContext> Navigable::active_browsing_context() +{ + // A navigable's active browsing context is its active document's browsing context. + // If this navigable is a traversable navigable, then its active browsing context will be a top-level browsing context. + if (auto document = active_document()) + return document->browsing_context(); + return nullptr; +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-wp +JS::GCPtr<HTML::WindowProxy> Navigable::active_window_proxy() +{ + // A navigable's active WindowProxy is its active browsing context's associated WindowProxy. + if (auto browsing_context = active_browsing_context()) + return browsing_context->window_proxy(); + return nullptr; +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-window +JS::GCPtr<HTML::Window> Navigable::active_window() +{ + // A navigable's active window is its active WindowProxy's [[Window]]. + if (auto window_proxy = active_window_proxy()) + return window_proxy->window(); + return nullptr; +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-target +String Navigable::target_name() const +{ + // FIXME: A navigable's target name is its active session history entry's document state's navigable target name. + dbgln("FIXME: Implement Navigable::target_name()"); + return {}; +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-container +JS::GCPtr<NavigableContainer> Navigable::container() const +{ + // The container of a navigable navigable is the navigable container whose nested navigable is navigable, or null if there is no such element. + return m_container; +} + +void Navigable::set_container(JS::GCPtr<NavigableContainer> container) +{ + m_container = container; +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.h b/Userland/Libraries/LibWeb/HTML/Navigable.h new file mode 100644 index 0000000000..e96fe5db0d --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Navigable.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibJS/Heap/Cell.h> +#include <LibWeb/Forward.h> + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable +class Navigable : public JS::Cell { + JS_CELL(Navigable, JS::Cell); + +public: + virtual ~Navigable() override; + + String const& id() const { return m_id; }; + JS::GCPtr<Navigable> parent() const { return m_parent; }; + + bool is_closing() const { return m_closing; }; + void set_closing(bool value) { m_closing = value; }; + + bool is_delaying_load_events() const { return m_delaying_load_events; }; + void set_delaying_load_events(bool value) { m_delaying_load_events = value; }; + + JS::GCPtr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; }; + JS::GCPtr<SessionHistoryEntry> current_session_history_entry() const { return m_current_session_history_entry; }; + + JS::GCPtr<DOM::Document> active_document(); + JS::GCPtr<BrowsingContext> active_browsing_context(); + JS::GCPtr<WindowProxy> active_window_proxy(); + JS::GCPtr<Window> active_window(); + + String target_name() const; + + JS::GCPtr<NavigableContainer> container() const; + void set_container(JS::GCPtr<NavigableContainer>); + +protected: + Navigable(); + + virtual void visit_edges(Cell::Visitor&) override; + +private: + // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id + String m_id; + + // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent + JS::GCPtr<Navigable> m_parent; + + // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry + JS::GCPtr<SessionHistoryEntry> m_current_session_history_entry; + + // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry + JS::GCPtr<SessionHistoryEntry> m_active_session_history_entry; + + // https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing + bool m_closing { false }; + + // https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode + bool m_delaying_load_events { false }; + + // Implied link between navigable and its container. + JS::GCPtr<NavigableContainer> m_container; +}; + +} |