diff options
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibHTML/DOM/Document.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/Document.h | 9 | ||||
-rw-r--r-- | Libraries/LibHTML/Frame.cpp | 31 | ||||
-rw-r--r-- | Libraries/LibHTML/Frame.h | 31 | ||||
-rw-r--r-- | Libraries/LibHTML/HtmlView.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibHTML/HtmlView.h | 8 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/ComputedStyle.h | 5 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutDocument.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibHTML/Makefile.shared | 1 |
9 files changed, 101 insertions, 8 deletions
diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp index 22a9d0a910..45482fd91d 100644 --- a/Libraries/LibHTML/DOM/Document.cpp +++ b/Libraries/LibHTML/DOM/Document.cpp @@ -4,6 +4,7 @@ #include <LibHTML/DOM/HTMLHeadElement.h> #include <LibHTML/DOM/HTMLHtmlElement.h> #include <LibHTML/DOM/HTMLTitleElement.h> +#include <LibHTML/Frame.h> #include <LibHTML/Layout/LayoutDocument.h> #include <stdio.h> @@ -63,3 +64,12 @@ String Document::title() const return title_element->text_content(); } + +void Document::attach_to_frame(Badge<Frame>, Frame& frame) +{ + m_frame = frame.make_weak_ptr(); +} + +void Document::detach_from_frame(Badge<Frame>, Frame&) +{ +} diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h index ce779e52f2..46d8fe1581 100644 --- a/Libraries/LibHTML/DOM/Document.h +++ b/Libraries/LibHTML/DOM/Document.h @@ -3,10 +3,12 @@ #include <AK/NonnullRefPtrVector.h> #include <AK/OwnPtr.h> #include <AK/String.h> +#include <AK/WeakPtr.h> #include <LibHTML/CSS/StyleResolver.h> #include <LibHTML/CSS/StyleSheet.h> #include <LibHTML/DOM/ParentNode.h> +class Frame; class HTMLHtmlElement; class HTMLHeadElement; class LayoutNode; @@ -36,8 +38,15 @@ public: String title() const; + void attach_to_frame(Badge<Frame>, Frame&); + void detach_from_frame(Badge<Frame>, Frame&); + + Frame* frame() { return m_frame.ptr(); } + const Frame* frame() const { return m_frame.ptr(); } + private: OwnPtr<StyleResolver> m_style_resolver; NonnullRefPtrVector<StyleSheet> m_sheets; RefPtr<Node> m_hovered_node; + WeakPtr<Frame> m_frame; }; diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp new file mode 100644 index 0000000000..ee2ae46a79 --- /dev/null +++ b/Libraries/LibHTML/Frame.cpp @@ -0,0 +1,31 @@ +#include <LibHTML/DOM/Document.h> +#include <LibHTML/Frame.h> + +Frame::Frame() +{ +} + +Frame::~Frame() +{ +} + +void Frame::set_document(Document* document) +{ + if (m_document == document) + return; + + if (m_document) + m_document->detach_from_frame({}, *this); + + m_document = document; + + if (m_document) + m_document->attach_to_frame({}, *this); +} + +void Frame::set_size(const Size& size) +{ + if (m_size == size) + return; + m_size = size; +} diff --git a/Libraries/LibHTML/Frame.h b/Libraries/LibHTML/Frame.h new file mode 100644 index 0000000000..4915ebe0f7 --- /dev/null +++ b/Libraries/LibHTML/Frame.h @@ -0,0 +1,31 @@ +#pragma once + +#include <AK/Noncopyable.h> +#include <AK/RefPtr.h> +#include <AK/Weakable.h> +#include <LibDraw/Size.h> +#include <LibHTML/TreeNode.h> + +class Document; + +class Frame + : public TreeNode<Frame> + , public Weakable<Frame> { +public: + static NonnullRefPtr<Frame> create() { return adopt(*new Frame); } + ~Frame(); + + const Document* document() const { return m_document; } + Document* document() { return m_document; } + + void set_document(Document*); + + const Size& size() const { return m_size; } + void set_size(const Size&); + +private: + Frame(); + + RefPtr<Document> m_document; + Size m_size; +}; diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp index d286e5b2de..fe4c97b4ec 100644 --- a/Libraries/LibHTML/HtmlView.cpp +++ b/Libraries/LibHTML/HtmlView.cpp @@ -4,6 +4,7 @@ #include <LibHTML/DOM/Element.h> #include <LibHTML/DOM/HTMLAnchorElement.h> #include <LibHTML/Dump.h> +#include <LibHTML/Frame.h> #include <LibHTML/HtmlView.h> #include <LibHTML/Layout/LayoutNode.h> #include <LibHTML/RenderingContext.h> @@ -11,6 +12,7 @@ HtmlView::HtmlView(GWidget* parent) : GScrollableWidget(parent) + , m_main_frame(Frame::create()) { set_frame_shape(FrameShape::Container); set_frame_shadow(FrameShadow::Sunken); @@ -19,12 +21,18 @@ HtmlView::HtmlView(GWidget* parent) set_background_color(Color::White); } +HtmlView::~HtmlView() +{ +} + void HtmlView::set_document(Document* document) { if (document == m_document) return; m_document = document; + main_frame().set_document(document); + if (document == nullptr) m_layout_root = nullptr; else @@ -46,7 +54,7 @@ void HtmlView::layout_and_sync_size() if (!m_layout_root) return; - m_layout_root->style().size().set_width(available_size().width()); + main_frame().set_size(available_size()); m_layout_root->layout(); set_content_size(m_layout_root->rect().size()); diff --git a/Libraries/LibHTML/HtmlView.h b/Libraries/LibHTML/HtmlView.h index ffa99578c2..61d374d01c 100644 --- a/Libraries/LibHTML/HtmlView.h +++ b/Libraries/LibHTML/HtmlView.h @@ -3,15 +3,20 @@ #include <LibGUI/GScrollableWidget.h> #include <LibHTML/DOM/Document.h> +class Frame; + class HtmlView : public GScrollableWidget { C_OBJECT(HtmlView) public: - virtual ~HtmlView() override {} + virtual ~HtmlView() override; Document* document() { return m_document; } const Document* document() const { return m_document; } void set_document(Document*); + Frame& main_frame() { return *m_main_frame; } + const Frame& main_frame() const { return *m_main_frame; } + Function<void(const String&)> on_link_click; Function<void(const String&)> on_title_change; @@ -26,6 +31,7 @@ protected: private: void layout_and_sync_size(); + RefPtr<Frame> m_main_frame; RefPtr<Document> m_document; RefPtr<LayoutNode> m_layout_root; }; diff --git a/Libraries/LibHTML/Layout/ComputedStyle.h b/Libraries/LibHTML/Layout/ComputedStyle.h index f603e6cd7f..feaa8d9f97 100644 --- a/Libraries/LibHTML/Layout/ComputedStyle.h +++ b/Libraries/LibHTML/Layout/ComputedStyle.h @@ -16,9 +16,6 @@ public: const LengthBox& padding() const { return m_padding; } const LengthBox& border() const { return m_border; } - const Size& size() const { return m_size; } - Size& size() { return m_size; } - struct PixelBox { int top; int right; @@ -32,6 +29,4 @@ private: LengthBox m_margin; LengthBox m_padding; LengthBox m_border; - - Size m_size; }; diff --git a/Libraries/LibHTML/Layout/LayoutDocument.cpp b/Libraries/LibHTML/Layout/LayoutDocument.cpp index 4f1d3fd45e..4fc43aca31 100644 --- a/Libraries/LibHTML/Layout/LayoutDocument.cpp +++ b/Libraries/LibHTML/Layout/LayoutDocument.cpp @@ -1,3 +1,4 @@ +#include <LibHTML/Frame.h> #include <LibHTML/Layout/LayoutDocument.h> LayoutDocument::LayoutDocument(const Document& document, NonnullRefPtr<StyleProperties> style_properties) @@ -11,7 +12,8 @@ LayoutDocument::~LayoutDocument() void LayoutDocument::layout() { - rect().set_width(style().size().width()); + ASSERT(document().frame()); + rect().set_width(document().frame()->size().width()); LayoutNode::layout(); diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared index 61081b967c..24d366362c 100644 --- a/Libraries/LibHTML/Makefile.shared +++ b/Libraries/LibHTML/Makefile.shared @@ -31,6 +31,7 @@ LIBHTML_OBJS = \ Layout/LineBox.o \ Layout/LineBoxFragment.o \ HtmlView.o \ + Frame.o \ Dump.o GENERATED_SOURCES = \ |