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.
This commit is contained in:
Andreas Kling 2021-09-08 02:07:39 +02:00
parent 9d03ea6f74
commit 57fbeff925
Notes: sideshowbarker 2024-07-18 04:27:29 +09:00
2 changed files with 17 additions and 22 deletions

View File

@ -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<EditEventHandler>)
{
reset_cursor_blink_cycle();

View File

@ -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;