LineBox.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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);
  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. CSSPixels original_available_width() const { return m_original_available_width; }
  24. CSSPixelRect const& absolute_rect() const { return m_absolute_rect; }
  25. void set_absolute_rect(CSSPixelRect const& rect) { m_absolute_rect = rect; }
  26. private:
  27. friend class BlockContainer;
  28. friend class InlineFormattingContext;
  29. friend class LineBuilder;
  30. CSSPixelRect m_absolute_rect;
  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. // The amount of available width that was originally available when creating this line box. Used for text justification.
  37. CSSPixels m_original_available_width { 0 };
  38. bool m_has_break { false };
  39. bool m_has_forced_break { false };
  40. };
  41. }