LineBoxFragment.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, Vector<Gfx::DrawGlyphOrEmoji> glyphs)
  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_glyph_run(adopt_ref(*new Gfx::GlyphRun(move(glyphs))))
  25. {
  26. }
  27. Node const& layout_node() const { return m_layout_node; }
  28. int start() const { return m_start; }
  29. int length() const { return m_length; }
  30. CSSPixelRect const absolute_rect() const;
  31. CSSPixelPoint offset() const { return m_offset; }
  32. void set_offset(CSSPixelPoint offset) { m_offset = offset; }
  33. // The baseline of a fragment is the number of pixels from the top to the text baseline.
  34. void set_baseline(CSSPixels y) { m_baseline = y; }
  35. CSSPixels baseline() const { return m_baseline; }
  36. CSSPixelSize size() const
  37. {
  38. return m_size;
  39. }
  40. void set_width(CSSPixels width) { m_size.set_width(width); }
  41. void set_height(CSSPixels height) { m_size.set_height(height); }
  42. CSSPixels width() const { return m_size.width(); }
  43. CSSPixels height() const { return m_size.height(); }
  44. CSSPixels border_box_top() const { return m_border_box_top; }
  45. bool ends_in_whitespace() const;
  46. bool is_justifiable_whitespace() const;
  47. StringView text() const;
  48. bool is_atomic_inline() const;
  49. Gfx::GlyphRun const& glyph_run() const { return *m_glyph_run; }
  50. private:
  51. JS::NonnullGCPtr<Node const> m_layout_node;
  52. int m_start { 0 };
  53. int m_length { 0 };
  54. CSSPixelPoint m_offset;
  55. CSSPixelSize m_size;
  56. CSSPixels m_border_box_top { 0 };
  57. CSSPixels m_baseline { 0 };
  58. NonnullRefPtr<Gfx::GlyphRun> m_glyph_run;
  59. };
  60. }