Skip to content

Commit d1100dd

Browse files
committed
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.)
1 parent 5356de1 commit d1100dd

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

Userland/Libraries/LibWeb/Loader/FrameLoader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ void FrameLoader::resource_did_load()
302302
else
303303
browsing_context().set_viewport_scroll_offset({ 0, 0 });
304304

305-
if (auto* host_element = browsing_context().host_element()) {
306-
// FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe>
307-
verify_cast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({});
308-
}
305+
if (auto* container = browsing_context().container())
306+
container->nested_browsing_context_did_load({});
309307

310308
if (auto* page = browsing_context().page())
311309
page->client().page_did_finish_loading(url);

Userland/Libraries/LibWeb/Page/BrowsingContext.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
namespace Web {
2020

21-
BrowsingContext::BrowsingContext(Page& page, DOM::Element* host_element, BrowsingContext& top_level_browsing_context)
21+
BrowsingContext::BrowsingContext(Page& page, HTML::BrowsingContextContainer* container, BrowsingContext& top_level_browsing_context)
2222
: m_page(page)
2323
, m_top_level_browsing_context(top_level_browsing_context)
2424
, m_loader(*this)
2525
, m_event_handler({}, *this)
26-
, m_host_element(host_element)
26+
, m_container(container)
2727
{
2828
m_cursor_blink_timer = Core::Timer::construct(500, [this] {
2929
if (!is_focused_context())
@@ -35,8 +35,8 @@ BrowsingContext::BrowsingContext(Page& page, DOM::Element* host_element, Browsin
3535
});
3636
}
3737

38-
BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context)
39-
: BrowsingContext(*top_level_browsing_context.page(), &host_element, top_level_browsing_context)
38+
BrowsingContext::BrowsingContext(HTML::BrowsingContextContainer& container, BrowsingContext& top_level_browsing_context)
39+
: BrowsingContext(*top_level_browsing_context.page(), &container, top_level_browsing_context)
4040
{
4141
}
4242

@@ -147,8 +147,8 @@ void BrowsingContext::set_needs_display(Gfx::IntRect const& rect)
147147
return;
148148
}
149149

150-
if (host_element() && host_element()->layout_node())
151-
host_element()->layout_node()->set_needs_display();
150+
if (container() && container()->layout_node())
151+
container()->layout_node()->set_needs_display();
152152
}
153153

154154
void BrowsingContext::scroll_to_anchor(String const& fragment)
@@ -199,11 +199,11 @@ Gfx::IntPoint BrowsingContext::to_top_level_position(Gfx::IntPoint const& a_posi
199199
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
200200
if (ancestor->is_top_level())
201201
break;
202-
if (!ancestor->host_element())
202+
if (!ancestor->container())
203203
return {};
204-
if (!ancestor->host_element()->layout_node())
204+
if (!ancestor->container()->layout_node())
205205
return {};
206-
position.translate_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>());
206+
position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position().to_type<int>());
207207
}
208208
return position;
209209
}

Userland/Libraries/LibWeb/Page/BrowsingContext.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <LibGfx/Rect.h>
1616
#include <LibGfx/Size.h>
1717
#include <LibWeb/DOM/Position.h>
18+
#include <LibWeb/HTML/BrowsingContextContainer.h>
1819
#include <LibWeb/Loader/FrameLoader.h>
1920
#include <LibWeb/Page/EventHandler.h>
2021
#include <LibWeb/TreeNode.h>
@@ -23,7 +24,7 @@ namespace Web {
2324

2425
class BrowsingContext : public TreeNode<BrowsingContext> {
2526
public:
26-
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)); }
27+
static NonnullRefPtr<BrowsingContext> create_nested(HTML::BrowsingContextContainer& container, BrowsingContext& top_level_browsing_context) { return adopt_ref(*new BrowsingContext(container, top_level_browsing_context)); }
2728
static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page)); }
2829
~BrowsingContext();
2930

@@ -66,8 +67,8 @@ class BrowsingContext : public TreeNode<BrowsingContext> {
6667
BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; }
6768
BrowsingContext const& top_level_browsing_context() const { return *m_top_level_browsing_context; }
6869

69-
DOM::Element* host_element() { return m_host_element; }
70-
DOM::Element const* host_element() const { return m_host_element; }
70+
HTML::BrowsingContextContainer* container() { return m_container; }
71+
HTML::BrowsingContextContainer const* container() const { return m_container; }
7172

7273
Gfx::IntPoint to_top_level_position(Gfx::IntPoint const&);
7374
Gfx::IntRect to_top_level_rect(Gfx::IntRect const&);
@@ -91,8 +92,8 @@ class BrowsingContext : public TreeNode<BrowsingContext> {
9192
HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
9293

9394
private:
94-
explicit BrowsingContext(Page&, DOM::Element* host_element, BrowsingContext& top_level_browsing_context);
95-
explicit BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context);
95+
explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*, BrowsingContext& top_level_browsing_context);
96+
explicit BrowsingContext(HTML::BrowsingContextContainer&, BrowsingContext& top_level_browsing_context);
9697
explicit BrowsingContext(Page&);
9798

9899
void reset_cursor_blink_cycle();
@@ -106,7 +107,7 @@ class BrowsingContext : public TreeNode<BrowsingContext> {
106107
FrameLoader m_loader;
107108
EventHandler m_event_handler;
108109

109-
WeakPtr<DOM::Element> m_host_element;
110+
WeakPtr<HTML::BrowsingContextContainer> m_container;
110111
RefPtr<DOM::Document> m_document;
111112
Gfx::IntSize m_size;
112113
Gfx::IntPoint m_viewport_scroll_offset;

0 commit comments

Comments
 (0)