LineBoxFragment.h 2.9 KB

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