LineBoxFragment.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/Weakable.h>
  8. #include <LibGfx/Forward.h>
  9. #include <LibGfx/Rect.h>
  10. #include <LibWeb/Forward.h>
  11. namespace Web::Layout {
  12. class LineBoxFragment : public Weakable<LineBoxFragment> {
  13. friend class LineBox;
  14. public:
  15. enum class Type {
  16. Normal,
  17. Leading,
  18. Trailing,
  19. };
  20. LineBoxFragment(Node& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size, Type type)
  21. : m_layout_node(layout_node)
  22. , m_start(start)
  23. , m_length(length)
  24. , m_offset(offset)
  25. , m_size(size)
  26. , m_type(type)
  27. {
  28. }
  29. Node& layout_node() const { return m_layout_node; }
  30. int start() const { return m_start; }
  31. int length() const { return m_length; }
  32. const Gfx::FloatRect absolute_rect() const;
  33. Type type() const { return m_type; }
  34. const Gfx::FloatPoint& offset() const { return m_offset; }
  35. void set_offset(const Gfx::FloatPoint& offset) { m_offset = offset; }
  36. const Gfx::FloatSize& size() const { return m_size; }
  37. void set_width(float width) { m_size.set_width(width); }
  38. void set_height(float height) { m_size.set_height(height); }
  39. float width() const { return m_size.width(); }
  40. float height() const { return m_size.height(); }
  41. float absolute_x() const { return absolute_rect().x(); }
  42. void paint(PaintContext&, PaintPhase);
  43. bool ends_in_whitespace() const;
  44. bool is_justifiable_whitespace() const;
  45. StringView text() const;
  46. int text_index_at(float x) const;
  47. Gfx::FloatRect selection_rect(const Gfx::Font&) const;
  48. private:
  49. Node& m_layout_node;
  50. int m_start { 0 };
  51. int m_length { 0 };
  52. Gfx::FloatPoint m_offset;
  53. Gfx::FloatSize m_size;
  54. Type m_type { Type::Normal };
  55. };
  56. }