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