diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp
index 22a9d0a9100..45482fd91d2 100644
--- a/Libraries/LibHTML/DOM/Document.cpp
+++ b/Libraries/LibHTML/DOM/Document.cpp
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
#include
#include
@@ -63,3 +64,12 @@ String Document::title() const
return title_element->text_content();
}
+
+void Document::attach_to_frame(Badge, Frame& frame)
+{
+ m_frame = frame.make_weak_ptr();
+}
+
+void Document::detach_from_frame(Badge, Frame&)
+{
+}
diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h
index ce779e52f2a..46d8fe15810 100644
--- a/Libraries/LibHTML/DOM/Document.h
+++ b/Libraries/LibHTML/DOM/Document.h
@@ -3,10 +3,12 @@
#include
#include
#include
+#include
#include
#include
#include
+class Frame;
class HTMLHtmlElement;
class HTMLHeadElement;
class LayoutNode;
@@ -36,8 +38,15 @@ public:
String title() const;
+ void attach_to_frame(Badge, Frame&);
+ void detach_from_frame(Badge, Frame&);
+
+ Frame* frame() { return m_frame.ptr(); }
+ const Frame* frame() const { return m_frame.ptr(); }
+
private:
OwnPtr m_style_resolver;
NonnullRefPtrVector m_sheets;
RefPtr m_hovered_node;
+ WeakPtr m_frame;
};
diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp
new file mode 100644
index 00000000000..ee2ae46a79c
--- /dev/null
+++ b/Libraries/LibHTML/Frame.cpp
@@ -0,0 +1,31 @@
+#include
+#include
+
+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 00000000000..4915ebe0f74
--- /dev/null
+++ b/Libraries/LibHTML/Frame.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+
+class Document;
+
+class Frame
+ : public TreeNode
+ , public Weakable {
+public:
+ static NonnullRefPtr 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 m_document;
+ Size m_size;
+};
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index d286e5b2de8..fe4c97b4ec1 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -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 ffa99578c28..61d374d01cd 100644
--- a/Libraries/LibHTML/HtmlView.h
+++ b/Libraries/LibHTML/HtmlView.h
@@ -3,15 +3,20 @@
#include
#include
+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 on_link_click;
Function on_title_change;
@@ -26,6 +31,7 @@ protected:
private:
void layout_and_sync_size();
+ RefPtr m_main_frame;
RefPtr m_document;
RefPtr m_layout_root;
};
diff --git a/Libraries/LibHTML/Layout/ComputedStyle.h b/Libraries/LibHTML/Layout/ComputedStyle.h
index f603e6cd7f8..feaa8d9f975 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 4f1d3fd45e5..4fc43aca315 100644
--- a/Libraries/LibHTML/Layout/LayoutDocument.cpp
+++ b/Libraries/LibHTML/Layout/LayoutDocument.cpp
@@ -1,3 +1,4 @@
+#include
#include
LayoutDocument::LayoutDocument(const Document& document, NonnullRefPtr 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 61081b967c6..24d366362c8 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 = \