LineBoxFragment.h 2.2 KB

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