LineBoxFragment.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/Rect.h>
  8. #include <LibJS/Heap/GCPtr.h>
  9. #include <LibWeb/Forward.h>
  10. #include <LibWeb/PixelUnits.h>
  11. namespace Web::Layout {
  12. class LineBoxFragment {
  13. friend class LineBox;
  14. public:
  15. enum class Type {
  16. Normal,
  17. Leading,
  18. Trailing,
  19. };
  20. LineBoxFragment(Node const& layout_node, int start, int length, CSSPixelPoint offset, CSSPixelSize size, CSSPixels border_box_top, CSSPixels border_box_bottom, 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_border_box_top(border_box_top)
  27. , m_border_box_bottom(border_box_bottom)
  28. , m_type(type)
  29. {
  30. }
  31. Node const& layout_node() const { return m_layout_node; }
  32. int start() const { return m_start; }
  33. int length() const { return m_length; }
  34. CSSPixelRect const absolute_rect() const;
  35. Type type() const { return m_type; }
  36. CSSPixelPoint offset() const
  37. {
  38. return m_offset;
  39. }
  40. void set_offset(CSSPixelPoint offset) { m_offset = offset; }
  41. // The baseline of a fragment is the number of pixels from the top to the text baseline.
  42. void set_baseline(CSSPixels y) { m_baseline = y; }
  43. CSSPixels baseline() const { return m_baseline; }
  44. CSSPixelSize size() const
  45. {
  46. return m_size;
  47. }
  48. void set_width(CSSPixels width) { m_size.set_width(width); }
  49. void set_height(CSSPixels height) { m_size.set_height(height); }
  50. CSSPixels width() const { return m_size.width(); }
  51. CSSPixels height() const { return m_size.height(); }
  52. CSSPixels border_box_height() const
  53. {
  54. return m_border_box_top + height() + m_border_box_bottom;
  55. }
  56. CSSPixels border_box_top() const { return m_border_box_top; }
  57. CSSPixels border_box_bottom() const { return m_border_box_bottom; }
  58. CSSPixels absolute_x() const { return absolute_rect().x(); }
  59. bool ends_in_whitespace() const;
  60. bool is_justifiable_whitespace() const;
  61. StringView text() const;
  62. int text_index_at(CSSPixels x) const;
  63. CSSPixelRect selection_rect(Gfx::Font const&) const;
  64. bool is_atomic_inline() const;
  65. private:
  66. JS::NonnullGCPtr<Node const> m_layout_node;
  67. int m_start { 0 };
  68. int m_length { 0 };
  69. CSSPixelPoint m_offset;
  70. CSSPixelSize m_size;
  71. CSSPixels m_border_box_top { 0 };
  72. CSSPixels m_border_box_bottom { 0 };
  73. CSSPixels m_baseline { 0 };
  74. Type m_type { Type::Normal };
  75. };
  76. }