LayoutNode.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include <AK/NonnullRefPtr.h>
  3. #include <AK/Vector.h>
  4. #include <LibDraw/Rect.h>
  5. #include <LibHTML/CSS/StyleProperties.h>
  6. #include <LibHTML/Layout/BoxModelMetrics.h>
  7. #include <LibHTML/RenderingContext.h>
  8. #include <LibHTML/TreeNode.h>
  9. class Document;
  10. class Element;
  11. class LayoutBlock;
  12. class LayoutNode;
  13. class Node;
  14. struct HitTestResult {
  15. RefPtr<LayoutNode> layout_node;
  16. };
  17. class LayoutNode : public TreeNode<LayoutNode> {
  18. public:
  19. virtual ~LayoutNode();
  20. const Rect& rect() const { return m_rect; }
  21. Rect& rect() { return m_rect; }
  22. void set_rect(const Rect& rect) { m_rect = rect; }
  23. BoxModelMetrics& box_model() { return m_style; }
  24. const BoxModelMetrics& box_model() const { return m_style; }
  25. virtual HitTestResult hit_test(const Point&) const;
  26. bool is_anonymous() const { return !m_node; }
  27. const Node* node() const { return m_node; }
  28. const Document& document() const;
  29. template<typename Callback>
  30. inline void for_each_child(Callback callback) const
  31. {
  32. for (auto* node = first_child(); node; node = node->next_sibling())
  33. callback(*node);
  34. }
  35. template<typename Callback>
  36. inline void for_each_child(Callback callback)
  37. {
  38. for (auto* node = first_child(); node; node = node->next_sibling())
  39. callback(*node);
  40. }
  41. virtual const char* class_name() const { return "LayoutNode"; }
  42. virtual bool is_text() const { return false; }
  43. virtual bool is_block() const { return false; }
  44. virtual bool is_inline() const { return false; }
  45. virtual void layout();
  46. virtual void render(RenderingContext&);
  47. const LayoutBlock* containing_block() const;
  48. virtual LayoutNode& inline_wrapper() { return *this; }
  49. const StyleProperties& style() const
  50. {
  51. if (m_style_properties)
  52. return *m_style_properties;
  53. return parent()->style();
  54. }
  55. void inserted_into(LayoutNode&) {}
  56. void removed_from(LayoutNode&) {}
  57. protected:
  58. explicit LayoutNode(const Node*, RefPtr<StyleProperties>);
  59. private:
  60. const Node* m_node { nullptr };
  61. RefPtr<StyleProperties> m_style_properties;
  62. BoxModelMetrics m_style;
  63. Rect m_rect;
  64. };