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

LibWeb: Add BrowsingContext::container() to align with the spec

We already have a base class for frame elements that we call
BrowsingContextContainer. This patch makes BrowsingContext::container()
actually return one of those.

This makes us match the spec names, and also solves a FIXME about having
a shared base for <frame> and <iframe>. (We already had the shared base,
but the pointer we had there wasn't tightly typed enough.)
This commit is contained in:
Andreas Kling 2021-09-09 02:07:32 +02:00
parent 5356de1c58
commit d1100dd6bc
3 changed files with 18 additions and 19 deletions

View file

@ -302,10 +302,8 @@ void FrameLoader::resource_did_load()
else else
browsing_context().set_viewport_scroll_offset({ 0, 0 }); browsing_context().set_viewport_scroll_offset({ 0, 0 });
if (auto* host_element = browsing_context().host_element()) { if (auto* container = browsing_context().container())
// FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe> container->nested_browsing_context_did_load({});
verify_cast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({});
}
if (auto* page = browsing_context().page()) if (auto* page = browsing_context().page())
page->client().page_did_finish_loading(url); page->client().page_did_finish_loading(url);

View file

@ -18,12 +18,12 @@
namespace Web { namespace Web {
BrowsingContext::BrowsingContext(Page& page, DOM::Element* host_element, BrowsingContext& top_level_browsing_context) BrowsingContext::BrowsingContext(Page& page, HTML::BrowsingContextContainer* container, BrowsingContext& top_level_browsing_context)
: m_page(page) : m_page(page)
, m_top_level_browsing_context(top_level_browsing_context) , m_top_level_browsing_context(top_level_browsing_context)
, m_loader(*this) , m_loader(*this)
, m_event_handler({}, *this) , m_event_handler({}, *this)
, m_host_element(host_element) , m_container(container)
{ {
m_cursor_blink_timer = Core::Timer::construct(500, [this] { m_cursor_blink_timer = Core::Timer::construct(500, [this] {
if (!is_focused_context()) if (!is_focused_context())
@ -35,8 +35,8 @@ BrowsingContext::BrowsingContext(Page& page, DOM::Element* host_element, Browsin
}); });
} }
BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context) BrowsingContext::BrowsingContext(HTML::BrowsingContextContainer& container, BrowsingContext& top_level_browsing_context)
: BrowsingContext(*top_level_browsing_context.page(), &host_element, top_level_browsing_context) : BrowsingContext(*top_level_browsing_context.page(), &container, top_level_browsing_context)
{ {
} }
@ -147,8 +147,8 @@ void BrowsingContext::set_needs_display(Gfx::IntRect const& rect)
return; return;
} }
if (host_element() && host_element()->layout_node()) if (container() && container()->layout_node())
host_element()->layout_node()->set_needs_display(); container()->layout_node()->set_needs_display();
} }
void BrowsingContext::scroll_to_anchor(String const& fragment) void BrowsingContext::scroll_to_anchor(String const& fragment)
@ -199,11 +199,11 @@ Gfx::IntPoint BrowsingContext::to_top_level_position(Gfx::IntPoint const& a_posi
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
if (ancestor->is_top_level()) if (ancestor->is_top_level())
break; break;
if (!ancestor->host_element()) if (!ancestor->container())
return {}; return {};
if (!ancestor->host_element()->layout_node()) if (!ancestor->container()->layout_node())
return {}; return {};
position.translate_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>()); position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position().to_type<int>());
} }
return position; return position;
} }

View file

@ -15,6 +15,7 @@
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
#include <LibGfx/Size.h> #include <LibGfx/Size.h>
#include <LibWeb/DOM/Position.h> #include <LibWeb/DOM/Position.h>
#include <LibWeb/HTML/BrowsingContextContainer.h>
#include <LibWeb/Loader/FrameLoader.h> #include <LibWeb/Loader/FrameLoader.h>
#include <LibWeb/Page/EventHandler.h> #include <LibWeb/Page/EventHandler.h>
#include <LibWeb/TreeNode.h> #include <LibWeb/TreeNode.h>
@ -23,7 +24,7 @@ namespace Web {
class BrowsingContext : public TreeNode<BrowsingContext> { class BrowsingContext : public TreeNode<BrowsingContext> {
public: public:
static NonnullRefPtr<BrowsingContext> create_nested(DOM::Element& host_element, BrowsingContext& top_level_browsing_context) { return adopt_ref(*new BrowsingContext(host_element, top_level_browsing_context)); } static NonnullRefPtr<BrowsingContext> create_nested(HTML::BrowsingContextContainer& container, BrowsingContext& top_level_browsing_context) { return adopt_ref(*new BrowsingContext(container, top_level_browsing_context)); }
static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page)); } static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page)); }
~BrowsingContext(); ~BrowsingContext();
@ -66,8 +67,8 @@ public:
BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; } BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; }
BrowsingContext const& top_level_browsing_context() const { return *m_top_level_browsing_context; } BrowsingContext const& top_level_browsing_context() const { return *m_top_level_browsing_context; }
DOM::Element* host_element() { return m_host_element; } HTML::BrowsingContextContainer* container() { return m_container; }
DOM::Element const* host_element() const { return m_host_element; } HTML::BrowsingContextContainer const* container() const { return m_container; }
Gfx::IntPoint to_top_level_position(Gfx::IntPoint const&); Gfx::IntPoint to_top_level_position(Gfx::IntPoint const&);
Gfx::IntRect to_top_level_rect(Gfx::IntRect const&); Gfx::IntRect to_top_level_rect(Gfx::IntRect const&);
@ -91,8 +92,8 @@ public:
HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; } HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
private: private:
explicit BrowsingContext(Page&, DOM::Element* host_element, BrowsingContext& top_level_browsing_context); explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*, BrowsingContext& top_level_browsing_context);
explicit BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context); explicit BrowsingContext(HTML::BrowsingContextContainer&, BrowsingContext& top_level_browsing_context);
explicit BrowsingContext(Page&); explicit BrowsingContext(Page&);
void reset_cursor_blink_cycle(); void reset_cursor_blink_cycle();
@ -106,7 +107,7 @@ private:
FrameLoader m_loader; FrameLoader m_loader;
EventHandler m_event_handler; EventHandler m_event_handler;
WeakPtr<DOM::Element> m_host_element; WeakPtr<HTML::BrowsingContextContainer> m_container;
RefPtr<DOM::Document> m_document; RefPtr<DOM::Document> m_document;
Gfx::IntSize m_size; Gfx::IntSize m_size;
Gfx::IntPoint m_viewport_scroll_offset; Gfx::IntPoint m_viewport_scroll_offset;