LayoutNode.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. LayoutNode* next_sibling() { return m_next_sibling; }
  21. LayoutNode* previous_sibling() { return m_previous_sibling; }
  22. LayoutNode* first_child() { return m_first_child; }
  23. LayoutNode* last_child() { return m_last_child; }
  24. const LayoutNode* next_sibling() const { return m_next_sibling; }
  25. const LayoutNode* previous_sibling() const { return m_previous_sibling; }
  26. const LayoutNode* first_child() const { return m_first_child; }
  27. const LayoutNode* last_child() const { return m_last_child; }
  28. void append_child(Retained<LayoutNode>);
  29. void set_next_sibling(LayoutNode* node) { m_next_sibling = node; }
  30. void set_previous_sibling(LayoutNode* node) { m_previous_sibling = node; }
  31. template<typename Callback>
  32. inline void for_each_child(Callback callback) const
  33. {
  34. for (auto* node = first_child(); node; node = node->next_sibling())
  35. callback(*node);
  36. }
  37. template<typename Callback>
  38. inline void for_each_child(Callback callback)
  39. {
  40. for (auto* node = first_child(); node; node = node->next_sibling())
  41. callback(*node);
  42. }
  43. virtual const char* class_name() const { return "LayoutNode"; }
  44. virtual bool is_text() const { return false; }
  45. virtual void layout();
  46. protected:
  47. explicit LayoutNode(const Node*);
  48. private:
  49. int m_retain_count { 1 };
  50. const Node* m_node { nullptr };
  51. LayoutNode* m_parent_node { nullptr };
  52. LayoutNode* m_first_child { nullptr };
  53. LayoutNode* m_last_child { nullptr };
  54. LayoutNode* m_next_sibling { nullptr };
  55. LayoutNode* m_previous_sibling { nullptr };
  56. LayoutStyle m_style;
  57. Rect m_rect;
  58. };