1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +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();
if (browsing_context()->is_top_level() && browsing_context()->active_document() == this) {
if (navigable()->is_traversable()) {
if (auto* page = this->page())
page->client().page_did_layout();
}

View file

@ -49,6 +49,7 @@
#include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Infra/CharacterTypes.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)
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())
page->client().page_did_request_scroll_into_view(verify_cast<Layout::Box>(*layout_node).paintable_box()->absolute_padding_box_rect());
if (auto navigable = element.document().navigable()) {
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 {};
}

View file

@ -531,7 +531,7 @@ void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> docume
// AD-HOC:
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());
if (previously_active_document && previously_active_document != document.ptr())

View file

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

View file

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

View file

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

View file

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

View file

@ -16,6 +16,7 @@
#include <LibWeb/HTML/HTMLMediaElement.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
@ -24,7 +25,7 @@ namespace Web {
Page::Page(PageClient& 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;
@ -43,17 +44,16 @@ void Page::set_focused_browsing_context(Badge<EventHandler>, HTML::BrowsingConte
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)
{
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
@ -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);
}
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()
{
return *m_top_level_browsing_context;
return *m_top_level_traversable->active_browsing_context();
}
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>
@ -376,8 +381,8 @@ JS::GCPtr<HTML::HTMLMediaElement> Page::media_context_menu_element()
void Page::set_user_style(String source)
{
m_user_style_sheet_source = source;
if (top_level_browsing_context_is_initialized() && top_level_browsing_context().active_document()) {
top_level_browsing_context().active_document()->style_computer().invalidate_rule_cache();
if (top_level_traversable_is_initialized() && top_level_traversable()->active_document()) {
top_level_traversable()->active_document()->style_computer().invalidate_rule_cache();
}
}

View file

@ -46,11 +46,13 @@ public:
PageClient const& client() const { return m_client; }
// 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 const& top_level_browsing_context() const;
JS::NonnullGCPtr<HTML::TraversableNavigable> top_level_traversable() const;
HTML::BrowsingContext& focused_context();
HTML::BrowsingContext const& focused_context() const { return const_cast<Page*>(this)->focused_context(); }
@ -145,9 +147,10 @@ private:
PageClient& m_client;
JS::Handle<HTML::BrowsingContext> m_top_level_browsing_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.
bool m_same_origin_policy_enabled { false };