2019-06-15 23:49:44 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-21 19:45:35 +03:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2019-06-15 23:49:44 +03:00
|
|
|
#include <AK/Vector.h>
|
2019-09-21 15:32:17 +03:00
|
|
|
#include <LibDraw/Rect.h>
|
|
|
|
#include <LibHTML/CSS/StyleProperties.h>
|
2019-07-03 08:25:04 +03:00
|
|
|
#include <LibHTML/Layout/ComputedStyle.h>
|
2019-09-25 12:40:37 +03:00
|
|
|
#include <LibHTML/RenderingContext.h>
|
2019-06-25 20:46:01 +03:00
|
|
|
#include <LibHTML/TreeNode.h>
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-09-29 12:43:33 +03:00
|
|
|
class Document;
|
2019-09-29 00:02:22 +03:00
|
|
|
class Element;
|
2019-07-01 08:28:37 +03:00
|
|
|
class LayoutBlock;
|
2019-09-29 00:02:22 +03:00
|
|
|
class LayoutNode;
|
2019-09-29 12:43:33 +03:00
|
|
|
class Node;
|
2019-09-29 00:02:22 +03:00
|
|
|
|
|
|
|
struct HitTestResult {
|
|
|
|
RefPtr<LayoutNode> layout_node;
|
|
|
|
};
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-06-25 20:46:01 +03:00
|
|
|
class LayoutNode : public TreeNode<LayoutNode> {
|
2019-06-15 23:49:44 +03:00
|
|
|
public:
|
|
|
|
virtual ~LayoutNode();
|
|
|
|
|
2019-06-16 12:28:47 +03:00
|
|
|
const Rect& rect() const { return m_rect; }
|
2019-06-16 22:35:03 +03:00
|
|
|
Rect& rect() { return m_rect; }
|
2019-06-16 12:28:47 +03:00
|
|
|
void set_rect(const Rect& rect) { m_rect = rect; }
|
|
|
|
|
2019-07-03 08:25:04 +03:00
|
|
|
ComputedStyle& style() { return m_style; }
|
|
|
|
const ComputedStyle& style() const { return m_style; }
|
2019-06-16 14:44:09 +03:00
|
|
|
|
2019-09-29 00:02:22 +03:00
|
|
|
virtual HitTestResult hit_test(const Point&) const;
|
|
|
|
|
2019-06-16 12:28:47 +03:00
|
|
|
bool is_anonymous() const { return !m_node; }
|
2019-06-15 23:49:44 +03:00
|
|
|
const Node* node() const { return m_node; }
|
|
|
|
|
2019-09-29 12:43:33 +03:00
|
|
|
const Document& document() const;
|
|
|
|
|
2019-06-15 23:49:44 +03:00
|
|
|
template<typename Callback>
|
|
|
|
inline void for_each_child(Callback callback) const
|
|
|
|
{
|
|
|
|
for (auto* node = first_child(); node; node = node->next_sibling())
|
|
|
|
callback(*node);
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:35:03 +03:00
|
|
|
template<typename Callback>
|
|
|
|
inline void for_each_child(Callback callback)
|
|
|
|
{
|
|
|
|
for (auto* node = first_child(); node; node = node->next_sibling())
|
|
|
|
callback(*node);
|
|
|
|
}
|
|
|
|
|
2019-06-15 23:49:44 +03:00
|
|
|
virtual const char* class_name() const { return "LayoutNode"; }
|
|
|
|
virtual bool is_text() const { return false; }
|
2019-07-01 08:28:37 +03:00
|
|
|
virtual bool is_block() const { return false; }
|
2019-07-08 18:42:23 +03:00
|
|
|
virtual bool is_inline() const { return false; }
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-06-16 22:35:03 +03:00
|
|
|
virtual void layout();
|
2019-09-25 12:40:37 +03:00
|
|
|
virtual void render(RenderingContext&);
|
2019-06-16 22:35:03 +03:00
|
|
|
|
2019-07-01 08:28:37 +03:00
|
|
|
const LayoutBlock* containing_block() const;
|
|
|
|
|
2019-07-08 18:42:23 +03:00
|
|
|
virtual LayoutNode& inline_wrapper() { return *this; }
|
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
const StyleProperties& style_properties() const { return m_style_properties; }
|
2019-07-24 08:34:07 +03:00
|
|
|
|
2019-06-15 23:49:44 +03:00
|
|
|
protected:
|
2019-09-21 15:32:17 +03:00
|
|
|
explicit LayoutNode(const Node*, StyleProperties&&);
|
2019-06-15 23:49:44 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
const Node* m_node { nullptr };
|
2019-06-25 20:46:01 +03:00
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
StyleProperties m_style_properties;
|
2019-07-03 08:25:04 +03:00
|
|
|
ComputedStyle m_style;
|
2019-06-16 12:28:47 +03:00
|
|
|
Rect m_rect;
|
2019-06-15 23:49:44 +03:00
|
|
|
};
|