LayoutNode.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <AK/NonnullRefPtr.h>
  3. #include <AK/Vector.h>
  4. #include <LibHTML/Layout/ComputedStyle.h>
  5. #include <LibHTML/TreeNode.h>
  6. #include <LibDraw/Rect.h>
  7. class Node;
  8. class LayoutBlock;
  9. class StyledNode;
  10. class LayoutNode : public TreeNode<LayoutNode> {
  11. public:
  12. virtual ~LayoutNode();
  13. const Rect& rect() const { return m_rect; }
  14. Rect& rect() { return m_rect; }
  15. void set_rect(const Rect& rect) { m_rect = rect; }
  16. ComputedStyle& style() { return m_style; }
  17. const ComputedStyle& style() const { return m_style; }
  18. bool is_anonymous() const { return !m_node; }
  19. const Node* node() const { return m_node; }
  20. template<typename Callback>
  21. inline void for_each_child(Callback callback) const
  22. {
  23. for (auto* node = first_child(); node; node = node->next_sibling())
  24. callback(*node);
  25. }
  26. template<typename Callback>
  27. inline void for_each_child(Callback callback)
  28. {
  29. for (auto* node = first_child(); node; node = node->next_sibling())
  30. callback(*node);
  31. }
  32. virtual const char* class_name() const { return "LayoutNode"; }
  33. virtual bool is_text() const { return false; }
  34. virtual bool is_block() const { return false; }
  35. virtual bool is_inline() const { return false; }
  36. virtual void layout();
  37. const LayoutBlock* containing_block() const;
  38. virtual LayoutNode& inline_wrapper() { return *this; }
  39. StyledNode* styled_node() { return m_styled_node; }
  40. const StyledNode* styled_node() const { return m_styled_node; }
  41. protected:
  42. explicit LayoutNode(const Node*, const StyledNode*);
  43. private:
  44. const Node* m_node { nullptr };
  45. RefPtr<StyledNode> m_styled_node;
  46. ComputedStyle m_style;
  47. Rect m_rect;
  48. };