LayoutNode.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 LineBoxFragment;
  14. class Node;
  15. struct HitTestResult {
  16. RefPtr<LayoutNode> layout_node;
  17. };
  18. class LayoutNode : public TreeNode<LayoutNode> {
  19. public:
  20. virtual ~LayoutNode();
  21. const Rect& rect() const { return m_rect; }
  22. Rect& rect() { return m_rect; }
  23. void set_rect(const Rect& rect) { m_rect = rect; }
  24. BoxModelMetrics& box_model() { return m_style; }
  25. const BoxModelMetrics& box_model() const { return m_style; }
  26. virtual HitTestResult hit_test(const Point&) const;
  27. bool is_anonymous() const { return !m_node; }
  28. const Node* node() const { return m_node; }
  29. const Document& document() const;
  30. template<typename Callback>
  31. inline void for_each_child(Callback callback) const
  32. {
  33. for (auto* node = first_child(); node; node = node->next_sibling())
  34. callback(*node);
  35. }
  36. template<typename Callback>
  37. inline void for_each_child(Callback callback)
  38. {
  39. for (auto* node = first_child(); node; node = node->next_sibling())
  40. callback(*node);
  41. }
  42. virtual const char* class_name() const { return "LayoutNode"; }
  43. virtual bool is_text() const { return false; }
  44. virtual bool is_block() const { return false; }
  45. virtual bool is_replaced() const { return false; }
  46. bool is_inline() const { return m_inline; }
  47. void set_inline(bool b) { m_inline = b; }
  48. virtual void layout();
  49. virtual void render(RenderingContext&);
  50. const LayoutBlock* containing_block() const;
  51. virtual LayoutNode& inline_wrapper() { return *this; }
  52. const StyleProperties& style() const
  53. {
  54. if (m_style_properties)
  55. return *m_style_properties;
  56. return parent()->style();
  57. }
  58. void inserted_into(LayoutNode&) {}
  59. void removed_from(LayoutNode&) {}
  60. virtual void split_into_lines(LayoutBlock& container);
  61. protected:
  62. explicit LayoutNode(const Node*, RefPtr<StyleProperties>);
  63. private:
  64. const Node* m_node { nullptr };
  65. RefPtr<StyleProperties> m_style_properties;
  66. BoxModelMetrics m_style;
  67. Rect m_rect;
  68. bool m_inline { false };
  69. };