Explorar o código

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.
Andreas Kling %!s(int64=3) %!d(string=hai) anos
pai
achega
57fbeff925

+ 15 - 19
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>)

+ 1 - 2
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;