LineBuilder.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Layout/InlineFormattingContext.h>
  8. namespace Web::Layout {
  9. class LineBuilder {
  10. AK_MAKE_NONCOPYABLE(LineBuilder);
  11. AK_MAKE_NONMOVABLE(LineBuilder);
  12. public:
  13. explicit LineBuilder(InlineFormattingContext&);
  14. ~LineBuilder();
  15. void break_line();
  16. void begin_new_line();
  17. void append_box(Box&);
  18. void append_text_chunk(TextNode&, size_t offset_in_node, size_t length_in_node, float width, float height);
  19. void break_if_needed(LayoutMode layout_mode, float next_item_width, bool should_force_break)
  20. {
  21. if (should_break(layout_mode, next_item_width, should_force_break))
  22. break_line();
  23. }
  24. float available_width_for_current_line() const { return m_available_width_for_current_line; }
  25. void update_last_line();
  26. private:
  27. bool should_break(LayoutMode, float next_item_width, bool should_force_break);
  28. InlineFormattingContext& m_context;
  29. float m_available_width_for_current_line { 0 };
  30. float m_current_y { 0 };
  31. float m_max_height_on_current_line { 0 };
  32. };
  33. }