LineBox.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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() = default;
  13. CSSPixels width() const { return m_width; }
  14. CSSPixels height() const { return m_height; }
  15. CSSPixels bottom() const { return m_bottom; }
  16. CSSPixels baseline() const { return m_baseline; }
  17. 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, Span<Gfx::DrawGlyphOrEmoji const> = {});
  18. Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
  19. Vector<LineBoxFragment>& fragments() { return m_fragments; }
  20. void trim_trailing_whitespace();
  21. bool is_empty_or_ends_in_whitespace() const;
  22. bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
  23. AvailableSize original_available_width() const { return m_original_available_width; }
  24. private:
  25. friend class BlockContainer;
  26. friend class InlineFormattingContext;
  27. friend class LineBuilder;
  28. Vector<LineBoxFragment> m_fragments;
  29. CSSPixels m_width { 0 };
  30. CSSPixels m_height { 0 };
  31. CSSPixels m_bottom { 0 };
  32. CSSPixels m_baseline { 0 };
  33. // The amount of available width that was originally available when creating this line box. Used for text justification.
  34. AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
  35. bool m_has_break { false };
  36. bool m_has_forced_break { false };
  37. };
  38. }