LineBoxFragment.h 2.4 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, CSS::Direction, 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. CSSPixelRect const absolute_rect() const;
  22. CSSPixelPoint offset() const { return m_offset; }
  23. void set_offset(CSSPixelPoint offset) { m_offset = offset; }
  24. // The baseline of a fragment is the number of pixels from the top to the text baseline.
  25. void set_baseline(CSSPixels y) { m_baseline = y; }
  26. CSSPixels baseline() const { return m_baseline; }
  27. CSSPixelSize size() const
  28. {
  29. return m_size;
  30. }
  31. void set_width(CSSPixels width) { m_size.set_width(width); }
  32. void set_height(CSSPixels height) { m_size.set_height(height); }
  33. CSSPixels width() const { return m_size.width(); }
  34. CSSPixels height() const { return m_size.height(); }
  35. CSSPixels border_box_top() const { return m_border_box_top; }
  36. bool ends_in_whitespace() const;
  37. bool is_justifiable_whitespace() const;
  38. StringView text() const;
  39. bool is_atomic_inline() const;
  40. RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
  41. void append_glyph_run(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  42. private:
  43. CSS::Direction resolve_glyph_run_direction(Gfx::GlyphRun::TextType) const;
  44. void append_glyph_run_ltr(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  45. void append_glyph_run_rtl(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
  46. JS::NonnullGCPtr<Node const> m_layout_node;
  47. int m_start { 0 };
  48. int m_length { 0 };
  49. CSSPixelPoint m_offset;
  50. CSSPixelSize m_size;
  51. CSSPixels m_border_box_top { 0 };
  52. CSSPixels m_baseline { 0 };
  53. CSS::Direction m_direction { CSS::Direction::Ltr };
  54. RefPtr<Gfx::GlyphRun> m_glyph_run;
  55. float m_insert_position { 0 };
  56. CSS::Direction m_current_insert_direction { CSS::Direction::Ltr };
  57. };
  58. }