summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-08 02:07:39 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-08 11:07:14 +0200
commit57fbeff92561c16feb3b7fe82c57c46e7e3301a6 (patch)
tree083c8c52e2452b88a925a5ca742cc8482e40e7ff /Userland/Libraries
parent9d03ea6f74d3e479e3426479933cd7b9ba9270b8 (diff)
downloadserenity-57fbeff92561c16feb3b7fe82c57c46e7e3301a6.zip
LibWeb: Use delegating constructors in BrowsingContext
This avoids having two nearly-identical initializer lists and and an awkward setup() function that every constructor must call.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Page/BrowsingContext.cpp34
-rw-r--r--Userland/Libraries/LibWeb/Page/BrowsingContext.h3
2 files changed, 16 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
index 0691e935d4..4f1265563d 100644
--- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
@@ -18,39 +18,35 @@
namespace Web {
-BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context)
- : m_page(*top_level_browsing_context.page())
+BrowsingContext::BrowsingContext(Page& page, DOM::Element* host_element, BrowsingContext& top_level_browsing_context)
+ : m_page(page)
, m_top_level_browsing_context(top_level_browsing_context)
, m_loader(*this)
, m_event_handler({}, *this)
, m_host_element(host_element)
{
- setup();
+ m_cursor_blink_timer = Core::Timer::construct(500, [this] {
+ if (!is_focused_context())
+ return;
+ if (m_cursor_position.node() && m_cursor_position.node()->layout_node()) {
+ m_cursor_blink_state = !m_cursor_blink_state;
+ m_cursor_position.node()->layout_node()->set_needs_display();
+ }
+ });
}
-BrowsingContext::BrowsingContext(Page& page)
- : m_page(page)
- , m_top_level_browsing_context(*this)
- , m_loader(*this)
- , m_event_handler({}, *this)
+BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context)
+ : BrowsingContext(*top_level_browsing_context.page(), &host_element, top_level_browsing_context)
{
- setup();
}
-BrowsingContext::~BrowsingContext()
+BrowsingContext::BrowsingContext(Page& page)
+ : BrowsingContext(page, nullptr, *this)
{
}
-void BrowsingContext::setup()
+BrowsingContext::~BrowsingContext()
{
- m_cursor_blink_timer = Core::Timer::construct(500, [this] {
- if (!is_focused_context())
- return;
- if (m_cursor_position.node() && m_cursor_position.node()->layout_node()) {
- m_cursor_blink_state = !m_cursor_blink_state;
- m_cursor_position.node()->layout_node()->set_needs_display();
- }
- });
}
void BrowsingContext::did_edit(Badge<EditEventHandler>)
diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.h b/Userland/Libraries/LibWeb/Page/BrowsingContext.h
index 77229647a2..344d1e179a 100644
--- a/Userland/Libraries/LibWeb/Page/BrowsingContext.h
+++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.h
@@ -91,13 +91,12 @@ public:
HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
private:
+ explicit BrowsingContext(Page&, DOM::Element* host_element, BrowsingContext& top_level_browsing_context);
explicit BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context);
explicit BrowsingContext(Page&);
void reset_cursor_blink_cycle();
- void setup();
-
WeakPtr<Page> m_page;
BrowsingContext& m_top_level_browsing_context;