From 57fbeff92561c16feb3b7fe82c57c46e7e3301a6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Sep 2021 02:07:39 +0200 Subject: [PATCH] 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. --- .../Libraries/LibWeb/Page/BrowsingContext.cpp | 36 +++++++++---------- .../Libraries/LibWeb/Page/BrowsingContext.h | 3 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp index 0691e935d4c..4f1265563dc 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp @@ -18,30 +18,12 @@ 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(); -} - -BrowsingContext::BrowsingContext(Page& page) - : m_page(page) - , m_top_level_browsing_context(*this) - , m_loader(*this) - , m_event_handler({}, *this) -{ - setup(); -} - -BrowsingContext::~BrowsingContext() -{ -} - -void BrowsingContext::setup() { m_cursor_blink_timer = Core::Timer::construct(500, [this] { if (!is_focused_context()) @@ -53,6 +35,20 @@ void BrowsingContext::setup() }); } +BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context) + : BrowsingContext(*top_level_browsing_context.page(), &host_element, top_level_browsing_context) +{ +} + +BrowsingContext::BrowsingContext(Page& page) + : BrowsingContext(page, nullptr, *this) +{ +} + +BrowsingContext::~BrowsingContext() +{ +} + void BrowsingContext::did_edit(Badge) { reset_cursor_blink_cycle(); diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.h b/Userland/Libraries/LibWeb/Page/BrowsingContext.h index 77229647a27..344d1e179a3 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.h @@ -91,13 +91,12 @@ public: HashMap 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 m_page; BrowsingContext& m_top_level_browsing_context;