LineBox.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibWeb/Layout/LineBoxFragment.h>
  9. namespace Web::Layout {
  10. class LineBox {
  11. public:
  12. LineBox(CSS::Direction direction, CSS::WritingMode writing_mode)
  13. : m_direction(direction)
  14. , m_writing_mode(writing_mode)
  15. {
  16. }
  17. CSSPixels width() const;
  18. CSSPixels height() const;
  19. CSSPixels bottom() const;
  20. CSSPixels inline_length() const { return m_inline_length; }
  21. CSSPixels block_length() const { return m_block_length; }
  22. CSSPixels baseline() const { return m_baseline; }
  23. void add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr<Gfx::GlyphRun> glyph_run = {});
  24. Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
  25. Vector<LineBoxFragment>& fragments() { return m_fragments; }
  26. void trim_trailing_whitespace();
  27. bool is_empty_or_ends_in_whitespace() const;
  28. bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
  29. AvailableSize original_available_width() const { return m_original_available_width; }
  30. private:
  31. friend class BlockContainer;
  32. friend class InlineFormattingContext;
  33. friend class LineBuilder;
  34. Vector<LineBoxFragment> m_fragments;
  35. CSSPixels m_inline_length { 0 };
  36. CSSPixels m_block_length { 0 };
  37. CSSPixels m_bottom { 0 };
  38. CSSPixels m_baseline { 0 };
  39. CSS::Direction m_direction { CSS::Direction::Ltr };
  40. CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb };
  41. // The amount of available width that was originally available when creating this line box. Used for text justification.
  42. AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
  43. bool m_has_break { false };
  44. bool m_has_forced_break { false };
  45. };
  46. }