From 8dc6f7cd4f3408a4c8551c68127d8167d87c28c2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 25 Nov 2019 21:19:03 +0100 Subject: [PATCH] LibHTML: Give Frame a (weak) back-pointer to the HtmlView This will be the official path from DOM/layout code to the HtmlView for now. Perhaps in the future we will have a fancier abstraction. --- Libraries/LibHTML/Frame.cpp | 4 +++- Libraries/LibHTML/Frame.h | 10 ++++++++-- Libraries/LibHTML/HtmlView.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp index f635528b70..ec0339f737 100644 --- a/Libraries/LibHTML/Frame.cpp +++ b/Libraries/LibHTML/Frame.cpp @@ -1,7 +1,9 @@ #include #include +#include -Frame::Frame() +Frame::Frame(HtmlView& html_view) + : m_html_view(html_view.make_weak_ptr()) { } diff --git a/Libraries/LibHTML/Frame.h b/Libraries/LibHTML/Frame.h index 38a8d8bedb..bf28e8cd34 100644 --- a/Libraries/LibHTML/Frame.h +++ b/Libraries/LibHTML/Frame.h @@ -3,15 +3,17 @@ #include #include #include +#include #include #include #include class Document; +class HtmlView; class Frame : public TreeNode { public: - static NonnullRefPtr create() { return adopt(*new Frame); } + static NonnullRefPtr create(HtmlView& html_view) { return adopt(*new Frame(html_view)); } ~Frame(); const Document* document() const { return m_document; } @@ -19,6 +21,9 @@ public: void set_document(Document*); + HtmlView* html_view() { return m_html_view; } + const HtmlView* html_view() const { return m_html_view; } + const Size& size() const { return m_size; } void set_size(const Size&); @@ -26,8 +31,9 @@ public: Function on_set_needs_display; private: - Frame(); + explicit Frame(HtmlView&); + WeakPtr m_html_view; RefPtr m_document; Size m_size; }; diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp index 50f5d34525..dec45d1fef 100644 --- a/Libraries/LibHTML/HtmlView.cpp +++ b/Libraries/LibHTML/HtmlView.cpp @@ -22,7 +22,7 @@ HtmlView::HtmlView(GWidget* parent) : GScrollableWidget(parent) - , m_main_frame(Frame::create()) + , m_main_frame(Frame::create(*this)) { main_frame().on_set_needs_display = [this](auto& content_rect) { if (content_rect.is_empty()) {