FormattingContext.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Forward.h>
  8. namespace Web::Layout {
  9. class FormattingContext {
  10. public:
  11. virtual void run(Box&, LayoutMode) = 0;
  12. Box& context_box() { return *m_context_box; }
  13. const Box& context_box() const { return *m_context_box; }
  14. FormattingContext* parent() { return m_parent; }
  15. const FormattingContext* parent() const { return m_parent; }
  16. virtual bool is_block_formatting_context() const { return false; }
  17. static bool creates_block_formatting_context(const Box&);
  18. static float compute_width_for_replaced_element(const ReplacedBox&);
  19. static float compute_height_for_replaced_element(const ReplacedBox&);
  20. protected:
  21. FormattingContext(Box&, FormattingContext* parent = nullptr);
  22. virtual ~FormattingContext();
  23. void layout_inside(Box&, LayoutMode);
  24. struct ShrinkToFitResult {
  25. float preferred_width { 0 };
  26. float preferred_minimum_width { 0 };
  27. };
  28. static float tentative_width_for_replaced_element(const ReplacedBox&, const CSS::Length& width);
  29. static float tentative_height_for_replaced_element(const ReplacedBox&, const CSS::Length& width);
  30. ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
  31. void layout_absolutely_positioned_element(Box&);
  32. void compute_width_for_absolutely_positioned_element(Box&);
  33. void compute_width_for_absolutely_positioned_non_replaced_element(Box&);
  34. void compute_width_for_absolutely_positioned_replaced_element(ReplacedBox&);
  35. void compute_height_for_absolutely_positioned_element(Box&);
  36. void compute_height_for_absolutely_positioned_non_replaced_element(Box&);
  37. void compute_height_for_absolutely_positioned_replaced_element(ReplacedBox&);
  38. FormattingContext* m_parent { nullptr };
  39. Box* m_context_box { nullptr };
  40. };
  41. }