LineBox.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.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)
  13. : m_direction(direction)
  14. {
  15. }
  16. CSSPixels width() const { return m_width; }
  17. CSSPixels height() const { return m_height; }
  18. CSSPixels bottom() const { return m_bottom; }
  19. CSSPixels baseline() const { return m_baseline; }
  20. 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 = {});
  21. Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
  22. Vector<LineBoxFragment>& fragments() { return m_fragments; }
  23. void trim_trailing_whitespace();
  24. bool is_empty_or_ends_in_whitespace() const;
  25. bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
  26. AvailableSize original_available_width() const { return m_original_available_width; }
  27. private:
  28. friend class BlockContainer;
  29. friend class InlineFormattingContext;
  30. friend class LineBuilder;
  31. Vector<LineBoxFragment> m_fragments;
  32. CSSPixels m_width { 0 };
  33. CSSPixels m_height { 0 };
  34. CSSPixels m_bottom { 0 };
  35. CSSPixels m_baseline { 0 };
  36. CSS::Direction m_direction { CSS::Direction::Ltr };
  37. // The amount of available width that was originally available when creating this line box. Used for text justification.
  38. AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
  39. bool m_has_break { false };
  40. bool m_has_forced_break { false };
  41. };
  42. }