LineBoxFragment.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.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, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction, CSS::WritingMode, RefPtr<Gfx::GlyphRun>);
  18. Node const& layout_node() const { return m_layout_node; }
  19. int start() const { return m_start; }
  20. int length() const { return m_length; }
  21. CSSPixelPoint offset() const;
  22. CSSPixels inline_offset() const { return m_inline_offset; }
  23. CSSPixels block_offset() const { return m_block_offset; }
  24. void set_inline_offset(CSSPixels inline_offset) { m_inline_offset = inline_offset; }
  25. void set_block_offset(CSSPixels block_offset) { m_block_offset = block_offset; }
  26. // The baseline of a fragment is the number of pixels from the top to the text baseline.
  27. void set_baseline(CSSPixels y) { m_baseline = y; }
  28. CSSPixels baseline() const { return m_baseline; }
  29. CSSPixelSize size() const;
  30. CSSPixels width() const { return size().width(); }
  31. CSSPixels height() const { return size().height(); }
  32. CSSPixels inline_length() const { return m_inline_length; }
  33. CSSPixels block_length() const { return m_block_length; }
  34. void set_inline_length(CSSPixels inline_length) { m_inline_length = inline_length; }
  35. void set_block_length(CSSPixels block_length) { m_block_length = block_length; }
  36. CSSPixels border_box_top() const { return m_border_box_top; }
  37. bool ends_in_whitespace() const;
  38. bool is_justifiable_whitespace() const;
  39. StringView text() const;
  40. bool is_atomic_inline() const;
  41. RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
  42. CSS::WritingMode writing_mode() const { return m_writing_mode; }
  43. void append_glyph_run(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  44. private:
  45. CSS::Direction resolve_glyph_run_direction(Gfx::GlyphRun::TextType) const;
  46. void append_glyph_run_ltr(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  47. void append_glyph_run_rtl(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  48. JS::NonnullGCPtr<Node const> m_layout_node;
  49. int m_start { 0 };
  50. int m_length { 0 };
  51. CSSPixels m_inline_offset;
  52. CSSPixels m_block_offset;
  53. CSSPixels m_inline_length;
  54. CSSPixels m_block_length;
  55. CSSPixels m_border_box_top { 0 };
  56. CSSPixels m_baseline { 0 };
  57. CSS::Direction m_direction { CSS::Direction::Ltr };
  58. CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb };
  59. RefPtr<Gfx::GlyphRun> m_glyph_run;
  60. float m_insert_position { 0 };
  61. CSS::Direction m_current_insert_direction { CSS::Direction::Ltr };
  62. };
  63. }