2019-09-29 06:32:00 -03:00
|
|
|
#include <LibGUI/GPainter.h>
|
2019-09-29 06:50:35 -03:00
|
|
|
#include <LibHTML/DOM/Document.h>
|
2019-09-28 18:02:22 -03:00
|
|
|
#include <LibHTML/DOM/Element.h>
|
2019-10-09 16:25:29 -03:00
|
|
|
#include <LibHTML/Frame.h>
|
2019-07-01 02:28:37 -03:00
|
|
|
#include <LibHTML/Layout/LayoutBlock.h>
|
2019-06-15 18:41:15 -03:00
|
|
|
#include <LibHTML/Layout/LayoutNode.h>
|
2019-06-15 17:49:44 -03:00
|
|
|
|
2019-10-07 04:50:31 -03:00
|
|
|
LayoutNode::LayoutNode(const Node* node)
|
2019-06-15 17:49:44 -03:00
|
|
|
: m_node(node)
|
|
|
|
|
{
|
2019-10-04 16:05:52 -03:00
|
|
|
if (m_node)
|
|
|
|
|
m_node->set_layout_node({}, this);
|
2019-06-15 17:49:44 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LayoutNode::~LayoutNode()
|
|
|
|
|
{
|
2019-10-13 07:34:25 -03:00
|
|
|
if (m_node && m_node->layout_node() == this)
|
2019-10-04 16:05:52 -03:00
|
|
|
m_node->set_layout_node({}, nullptr);
|
2019-06-15 17:49:44 -03:00
|
|
|
}
|
|
|
|
|
|
2019-06-16 16:35:03 -03:00
|
|
|
void LayoutNode::layout()
|
|
|
|
|
{
|
|
|
|
|
for_each_child([](auto& child) {
|
|
|
|
|
child.layout();
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-07-01 02:28:37 -03:00
|
|
|
|
|
|
|
|
const LayoutBlock* LayoutNode::containing_block() const
|
|
|
|
|
{
|
|
|
|
|
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
2019-10-15 09:19:52 -03:00
|
|
|
if (is<LayoutBlock>(*ancestor))
|
|
|
|
|
return to<LayoutBlock>(ancestor);
|
2019-07-01 02:28:37 -03:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-09-25 06:40:37 -03:00
|
|
|
|
|
|
|
|
void LayoutNode::render(RenderingContext& context)
|
|
|
|
|
{
|
2019-10-09 16:25:29 -03:00
|
|
|
if (!is_visible())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-09-29 13:05:37 -03:00
|
|
|
// TODO: render our border
|
2019-09-25 06:40:37 -03:00
|
|
|
for_each_child([&](auto& child) {
|
|
|
|
|
child.render(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-28 18:02:22 -03:00
|
|
|
|
|
|
|
|
HitTestResult LayoutNode::hit_test(const Point& position) const
|
|
|
|
|
{
|
2019-10-15 11:48:38 -03:00
|
|
|
HitTestResult result;
|
2019-09-28 18:02:22 -03:00
|
|
|
for_each_child([&](auto& child) {
|
|
|
|
|
auto child_result = child.hit_test(position);
|
|
|
|
|
if (child_result.layout_node)
|
|
|
|
|
result = child_result;
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-09-29 06:43:33 -03:00
|
|
|
|
|
|
|
|
const Document& LayoutNode::document() const
|
|
|
|
|
{
|
|
|
|
|
if (is_anonymous())
|
|
|
|
|
return parent()->document();
|
|
|
|
|
return node()->document();
|
|
|
|
|
}
|
2019-10-05 18:20:35 -03:00
|
|
|
|
|
|
|
|
void LayoutNode::split_into_lines(LayoutBlock& container)
|
|
|
|
|
{
|
|
|
|
|
for_each_child([&](auto& child) {
|
|
|
|
|
if (child.is_inline()) {
|
|
|
|
|
child.split_into_lines(container);
|
|
|
|
|
} else {
|
|
|
|
|
// FIXME: Support block children of inlines.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-09 16:25:29 -03:00
|
|
|
|
|
|
|
|
void LayoutNode::set_needs_display()
|
|
|
|
|
{
|
|
|
|
|
}
|