1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibWeb: Update Page to use navigables

This commit is contained in:
Aliaksandr Kalenik 2023-08-27 17:06:39 +02:00 committed by Andreas Kling
parent f91b34ef2e
commit ee50d9b2b5
9 changed files with 41 additions and 25 deletions

View file

@ -1012,7 +1012,7 @@ void Document::update_layout()
browsing_context()->set_needs_display(); browsing_context()->set_needs_display();
if (browsing_context()->is_top_level() && browsing_context()->active_document() == this) { if (navigable()->is_traversable()) {
if (auto* page = this->page()) if (auto* page = this->page())
page->client().page_did_layout(); page->client().page_did_layout();
} }

View file

@ -49,6 +49,7 @@
#include <LibWeb/HTML/HTMLTextAreaElement.h> #include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/HTML/Numbers.h> #include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h> #include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h> #include <LibWeb/Infra/Strings.h>
@ -1514,8 +1515,9 @@ static ErrorOr<void> scroll_an_element_into_view(DOM::Element& element, Bindings
if (!layout_node) if (!layout_node)
return Error::from_string_view("Element has no parent layout node that is a box."sv); return Error::from_string_view("Element has no parent layout node that is a box."sv);
if (element.document().browsing_context() == &page->top_level_browsing_context()) if (auto navigable = element.document().navigable()) {
page->client().page_did_request_scroll_into_view(verify_cast<Layout::Box>(*layout_node).paintable_box()->absolute_padding_box_rect()); element.document().navigable()->traversable_navigable()->page()->client().page_did_request_scroll_into_view(verify_cast<Layout::Box>(*layout_node).paintable_box()->absolute_padding_box_rect());
}
return {}; return {};
} }

View file

@ -531,7 +531,7 @@ void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> docume
// AD-HOC: // AD-HOC:
document->set_browsing_context(this); document->set_browsing_context(this);
if (m_page && m_page->top_level_browsing_context_is_initialized() && this == &m_page->top_level_browsing_context()) if (m_page && m_page->top_level_traversable_is_initialized() && this == &m_page->top_level_browsing_context())
m_page->client().page_did_change_title(document->title()); m_page->client().page_did_change_title(document->title());
if (previously_active_document && previously_active_document != document.ptr()) if (previously_active_document && previously_active_document != document.ptr())

View file

@ -21,6 +21,7 @@
#include <LibWeb/HTML/EventNames.h> #include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/HTMLLinkElement.h> #include <LibWeb/HTML/HTMLLinkElement.h>
#include <LibWeb/HTML/PotentialCORSRequest.h> #include <LibWeb/HTML/PotentialCORSRequest.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h> #include <LibWeb/Page/Page.h>
@ -458,11 +459,9 @@ bool HTMLLinkElement::load_favicon_and_use_if_window_is_active()
if (!page) if (!page)
return favicon_bitmap; return favicon_bitmap;
if (document().browsing_context() == &page->top_level_browsing_context()) if (navigable() && navigable()->is_traversable()) {
if (favicon_bitmap) { navigable()->traversable_navigable()->page()->client().page_did_change_favicon(*favicon_bitmap);
page->client().page_did_change_favicon(*favicon_bitmap); }
return true;
}
return false; return false;
} }

View file

@ -6,6 +6,7 @@
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLTitleElement.h> #include <LibWeb/HTML/HTMLTitleElement.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/Page/Page.h> #include <LibWeb/Page/Page.h>
namespace Web::HTML { namespace Web::HTML {
@ -26,9 +27,8 @@ void HTMLTitleElement::initialize(JS::Realm& realm)
void HTMLTitleElement::children_changed() void HTMLTitleElement::children_changed()
{ {
HTMLElement::children_changed(); HTMLElement::children_changed();
if (auto* page = document().page()) { if (navigable() && navigable()->is_traversable()) {
if (document().browsing_context() == &page->top_level_browsing_context()) navigable()->traversable_navigable()->page()->client().page_did_change_title(document().title());
page->client().page_did_change_title(document().title());
} }
} }

View file

@ -71,6 +71,11 @@ Vector<JS::Handle<Navigable>> Navigable::child_navigables() const
return results; return results;
} }
bool Navigable::is_traversable() const
{
return is<TraversableNavigable>(*this);
}
Navigable::Navigable() Navigable::Navigable()
{ {
all_navigables().set(this); all_navigables().set(this);

View file

@ -51,6 +51,8 @@ public:
Vector<JS::Handle<Navigable>> child_navigables() const; Vector<JS::Handle<Navigable>> child_navigables() const;
bool is_traversable() const;
String const& id() const { return m_id; } String const& id() const { return m_id; }
JS::GCPtr<Navigable> parent() const { return m_parent; } JS::GCPtr<Navigable> parent() const { return m_parent; }

View file

@ -16,6 +16,7 @@
#include <LibWeb/HTML/HTMLMediaElement.h> #include <LibWeb/HTML/HTMLMediaElement.h>
#include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h> #include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/Page/Page.h> #include <LibWeb/Page/Page.h>
#include <LibWeb/Platform/EventLoopPlugin.h> #include <LibWeb/Platform/EventLoopPlugin.h>
@ -24,7 +25,7 @@ namespace Web {
Page::Page(PageClient& client) Page::Page(PageClient& client)
: m_client(client) : m_client(client)
{ {
m_top_level_browsing_context = JS::make_handle(*HTML::BrowsingContext::create_a_new_top_level_browsing_context(*this)); m_top_level_traversable = JS::make_handle(HTML::TraversableNavigable::create_a_fresh_top_level_traversable(*this, AK::URL("about:blank")).release_value_but_fixme_should_propagate_errors());
} }
Page::~Page() = default; Page::~Page() = default;
@ -43,17 +44,16 @@ void Page::set_focused_browsing_context(Badge<EventHandler>, HTML::BrowsingConte
void Page::load(const AK::URL& url) void Page::load(const AK::URL& url)
{ {
top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation); (void)top_level_traversable()->navigate(url, *top_level_traversable()->active_document());
} }
void Page::load(LoadRequest& request) void Page::load(LoadRequest&)
{ {
top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
} }
void Page::load_html(StringView html, const AK::URL& url) void Page::load_html(StringView html, const AK::URL& url)
{ {
top_level_browsing_context().loader().load_html(html, url); (void)top_level_traversable()->navigate(url, *top_level_traversable()->active_document(), String::from_utf8(html).release_value_but_fixme_should_propagate_errors());
} }
bool Page::has_ongoing_navigation() const bool Page::has_ongoing_navigation() const
@ -167,19 +167,24 @@ bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
return focused_context().event_handler().handle_keyup(key, modifiers, code_point); return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
} }
bool Page::top_level_browsing_context_is_initialized() const bool Page::top_level_traversable_is_initialized() const
{ {
return m_top_level_browsing_context; return m_top_level_traversable;
} }
HTML::BrowsingContext& Page::top_level_browsing_context() HTML::BrowsingContext& Page::top_level_browsing_context()
{ {
return *m_top_level_browsing_context; return *m_top_level_traversable->active_browsing_context();
} }
HTML::BrowsingContext const& Page::top_level_browsing_context() const HTML::BrowsingContext const& Page::top_level_browsing_context() const
{ {
return *m_top_level_browsing_context; return *m_top_level_traversable->active_browsing_context();
}
JS::NonnullGCPtr<HTML::TraversableNavigable> Page::top_level_traversable() const
{
return *m_top_level_traversable;
} }
template<typename ResponseType> template<typename ResponseType>
@ -376,8 +381,8 @@ JS::GCPtr<HTML::HTMLMediaElement> Page::media_context_menu_element()
void Page::set_user_style(String source) void Page::set_user_style(String source)
{ {
m_user_style_sheet_source = source; m_user_style_sheet_source = source;
if (top_level_browsing_context_is_initialized() && top_level_browsing_context().active_document()) { if (top_level_traversable_is_initialized() && top_level_traversable()->active_document()) {
top_level_browsing_context().active_document()->style_computer().invalidate_rule_cache(); top_level_traversable()->active_document()->style_computer().invalidate_rule_cache();
} }
} }

View file

@ -46,11 +46,13 @@ public:
PageClient const& client() const { return m_client; } PageClient const& client() const { return m_client; }
// FIXME: This is a hack. // FIXME: This is a hack.
bool top_level_browsing_context_is_initialized() const; bool top_level_traversable_is_initialized() const;
HTML::BrowsingContext& top_level_browsing_context(); HTML::BrowsingContext& top_level_browsing_context();
HTML::BrowsingContext const& top_level_browsing_context() const; HTML::BrowsingContext const& top_level_browsing_context() const;
JS::NonnullGCPtr<HTML::TraversableNavigable> top_level_traversable() const;
HTML::BrowsingContext& focused_context(); HTML::BrowsingContext& focused_context();
HTML::BrowsingContext const& focused_context() const { return const_cast<Page*>(this)->focused_context(); } HTML::BrowsingContext const& focused_context() const { return const_cast<Page*>(this)->focused_context(); }
@ -145,9 +147,10 @@ private:
PageClient& m_client; PageClient& m_client;
JS::Handle<HTML::BrowsingContext> m_top_level_browsing_context;
WeakPtr<HTML::BrowsingContext> m_focused_context; WeakPtr<HTML::BrowsingContext> m_focused_context;
JS::Handle<HTML::TraversableNavigable> m_top_level_traversable;
// FIXME: Enable this by default once CORS preflight checks are supported. // FIXME: Enable this by default once CORS preflight checks are supported.
bool m_same_origin_policy_enabled { false }; bool m_same_origin_policy_enabled { false };