LayoutNode.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <AK/Retained.h>
  3. #include <AK/Vector.h>
  4. #include <LibHTML/Layout/LayoutStyle.h>
  5. #include <SharedGraphics/Rect.h>
  6. class Node;
  7. class LayoutNode {
  8. public:
  9. virtual ~LayoutNode();
  10. void retain();
  11. void release();
  12. int retain_count() const { return m_retain_count; }
  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. LayoutStyle& style() { return m_style; }
  17. const LayoutStyle& style() const { return m_style; }
  18. bool is_anonymous() const { return !m_node; }
  19. const Node* node() const { return m_node; }
  20. const LayoutNode* parent_layout_node() const { return m_parent_node; }
  21. LayoutNode* next_sibling() { return m_next_sibling; }
  22. LayoutNode* previous_sibling() { return m_previous_sibling; }
  23. LayoutNode* first_child() { return m_first_child; }
  24. LayoutNode* last_child() { return m_last_child; }
  25. const LayoutNode* next_sibling() const { return m_next_sibling; }
  26. const LayoutNode* previous_sibling() const { return m_previous_sibling; }
  27. const LayoutNode* first_child() const { return m_first_child; }
  28. const LayoutNode* last_child() const { return m_last_child; }
  29. bool has_children() const { return m_first_child; }
  30. void append_child(Retained<LayoutNode>);
  31. void set_next_sibling(LayoutNode* node) { m_next_sibling = node; }
  32. void set_previous_sibling(LayoutNode* node) { m_previous_sibling = node; }
  33. template<typename Callback>
  34. inline void for_each_child(Callback callback) const
  35. {
  36. for (auto* node = first_child(); node; node = node->next_sibling())
  37. callback(*node);
  38. }
  39. template<typename Callback>
  40. inline void for_each_child(Callback callback)
  41. {
  42. for (auto* node = first_child(); node; node = node->next_sibling())
  43. callback(*node);
  44. }
  45. virtual const char* class_name() const { return "LayoutNode"; }
  46. virtual bool is_text() const { return false; }
  47. virtual void layout();
  48. protected:
  49. explicit LayoutNode(const Node*);
  50. private:
  51. int m_retain_count { 1 };
  52. const Node* m_node { nullptr };
  53. LayoutNode* m_parent_node { nullptr };
  54. LayoutNode* m_first_child { nullptr };
  55. LayoutNode* m_last_child { nullptr };
  56. LayoutNode* m_next_sibling { nullptr };
  57. LayoutNode* m_previous_sibling { nullptr };
  58. LayoutStyle m_style;
  59. Rect m_rect;
  60. };