LayoutBlock.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <LibHTML/Layout/LayoutBox.h>
  3. #include <LibHTML/Layout/LineBox.h>
  4. class Element;
  5. class LayoutBlock : public LayoutBox {
  6. public:
  7. LayoutBlock(const Node*, NonnullRefPtr<StyleProperties>);
  8. virtual ~LayoutBlock() override;
  9. virtual const char* class_name() const override { return "LayoutBlock"; }
  10. virtual void layout() override;
  11. virtual void render(RenderingContext&) override;
  12. virtual LayoutNode& inline_wrapper() override;
  13. Vector<LineBox>& line_boxes() { return m_line_boxes; }
  14. const Vector<LineBox>& line_boxes() const { return m_line_boxes; }
  15. LineBox& ensure_last_line_box();
  16. LineBox& add_line_box();
  17. virtual HitTestResult hit_test(const Point&) const override;
  18. LayoutBlock* previous_sibling() { return to<LayoutBlock>(LayoutNode::previous_sibling()); }
  19. const LayoutBlock* previous_sibling() const { return to<LayoutBlock>(LayoutNode::previous_sibling()); }
  20. LayoutBlock* next_sibling() { return to<LayoutBlock>(LayoutNode::next_sibling()); }
  21. const LayoutBlock* next_sibling() const { return to<LayoutBlock>(LayoutNode::next_sibling()); }
  22. template<typename Callback>
  23. void for_each_fragment(Callback);
  24. template<typename Callback>
  25. void for_each_fragment(Callback) const;
  26. private:
  27. virtual bool is_block() const override { return true; }
  28. NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
  29. void layout_inline_children();
  30. void layout_block_children();
  31. void compute_width();
  32. void compute_position();
  33. void compute_height();
  34. Vector<LineBox> m_line_boxes;
  35. };
  36. template<typename Callback>
  37. void LayoutBlock::for_each_fragment(Callback callback)
  38. {
  39. for (auto& line_box : line_boxes()) {
  40. for (auto& fragment : line_box.fragments()) {
  41. if (callback(fragment) == IterationDecision::Break)
  42. return;
  43. }
  44. }
  45. }
  46. template<typename Callback>
  47. void LayoutBlock::for_each_fragment(Callback callback) const
  48. {
  49. for (auto& line_box : line_boxes()) {
  50. for (auto& fragment : line_box.fragments()) {
  51. if (callback(fragment) == IterationDecision::Break)
  52. return;
  53. }
  54. }
  55. }
  56. template<>
  57. inline bool is<LayoutBlock>(const LayoutNode& node)
  58. {
  59. return node.is_block();
  60. }