diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-25 21:19:03 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-25 21:19:21 +0100 |
commit | 8dc6f7cd4f3408a4c8551c68127d8167d87c28c2 (patch) | |
tree | 9c1cadffe7d3961f9f08b40136725bd9cdbb9066 /Libraries | |
parent | 94bc46ee70a8f0c642297828dab8ab6502d03bd9 (diff) | |
download | serenity-8dc6f7cd4f3408a4c8551c68127d8167d87c28c2.zip |
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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibHTML/Frame.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibHTML/Frame.h | 10 | ||||
-rw-r--r-- | 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 <LibHTML/DOM/Document.h> #include <LibHTML/Frame.h> +#include <LibHTML/HtmlView.h> -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 <AK/Function.h> #include <AK/Noncopyable.h> #include <AK/RefPtr.h> +#include <AK/WeakPtr.h> #include <LibDraw/Rect.h> #include <LibDraw/Size.h> #include <LibHTML/TreeNode.h> class Document; +class HtmlView; class Frame : public TreeNode<Frame> { public: - static NonnullRefPtr<Frame> create() { return adopt(*new Frame); } + static NonnullRefPtr<Frame> 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<void(const Rect&)> on_set_needs_display; private: - Frame(); + explicit Frame(HtmlView&); + WeakPtr<HtmlView> m_html_view; RefPtr<Document> 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()) { |