1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibHTML: Add a Frame class, start fleshing out recursive layout.

Layout is initiated from Frame::layout(). It makes the document's layout
node as wide as the frame, and then we'll take it from there.
This commit is contained in:
Andreas Kling 2019-06-16 21:35:03 +02:00
parent f49e5c6732
commit 0db2f3cbe6
9 changed files with 91 additions and 3 deletions

View file

@ -8,3 +8,9 @@ LayoutDocument::LayoutDocument(const Document& document)
LayoutDocument::~LayoutDocument()
{
}
void LayoutDocument::layout()
{
rect().set_width(style().size().width());
LayoutNode::layout();
}

View file

@ -3,14 +3,13 @@
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/DOM/Document.h>
class LayoutDocument : public LayoutNode {
class LayoutDocument final : public LayoutNode {
public:
explicit LayoutDocument(const Document&);
virtual ~LayoutDocument() override;
const Document& node() const { return static_cast<const Document&>(*LayoutNode::node()); }
virtual const char* class_name() const override { return "LayoutDocument"; }
virtual void layout() override;
private:
};

View file

@ -31,3 +31,10 @@ void LayoutNode::append_child(Retained<LayoutNode> node)
if (!m_first_child)
m_first_child = m_last_child;
}
void LayoutNode::layout()
{
for_each_child([](auto& child) {
child.layout();
});
}

View file

@ -16,6 +16,7 @@ public:
int retain_count() const { return m_retain_count; }
const Rect& rect() const { return m_rect; }
Rect& rect() { return m_rect; }
void set_rect(const Rect& rect) { m_rect = rect; }
LayoutStyle& style() { return m_style; }
@ -45,9 +46,18 @@ public:
callback(*node);
}
template<typename Callback>
inline void for_each_child(Callback callback)
{
for (auto* node = first_child(); node; node = node->next_sibling())
callback(*node);
}
virtual const char* class_name() const { return "LayoutNode"; }
virtual bool is_text() const { return false; }
virtual void layout();
protected:
explicit LayoutNode(const Node*);

View file

@ -1,6 +1,7 @@
#pragma once
#include <SharedGraphics/Color.h>
#include <SharedGraphics/Size.h>
struct Box {
int top { 0 };
@ -32,6 +33,9 @@ public:
FontStyle font_style() const { return m_font_style; }
const Size& size() const { return m_size; }
Size& size() { return m_size; }
private:
Color m_text_color;
Color m_background_color;
@ -40,5 +44,7 @@ private:
Box m_margin;
Box m_padding;
Size m_size;
FontStyle m_font_style { FontStyle::Normal };
};