LineBoxFragment.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <LibJS/Heap/GCPtr.h>
  9. #include <LibWeb/Forward.h>
  10. #include <LibWeb/PixelUnits.h>
  11. namespace Web::Layout {
  12. class LineBoxFragment {
  13. friend class LineBox;
  14. public:
  15. LineBoxFragment(Node const& layout_node, int start, int length, CSSPixelPoint offset, CSSPixelSize size, CSSPixels border_box_top, CSSPixels border_box_bottom)
  16. : m_layout_node(layout_node)
  17. , m_start(start)
  18. , m_length(length)
  19. , m_offset(offset)
  20. , m_size(size)
  21. , m_border_box_top(border_box_top)
  22. , m_border_box_bottom(border_box_bottom)
  23. {
  24. }
  25. Node const& layout_node() const { return m_layout_node; }
  26. int start() const { return m_start; }
  27. int length() const { return m_length; }
  28. CSSPixelRect const absolute_rect() const;
  29. CSSPixelPoint offset() const
  30. {
  31. return m_offset;
  32. }
  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_height() const
  46. {
  47. return m_border_box_top + height() + m_border_box_bottom;
  48. }
  49. CSSPixels border_box_top() const { return m_border_box_top; }
  50. CSSPixels border_box_bottom() const { return m_border_box_bottom; }
  51. CSSPixels absolute_x() const { return absolute_rect().x(); }
  52. bool ends_in_whitespace() const;
  53. bool is_justifiable_whitespace() const;
  54. StringView text() const;
  55. int text_index_at(CSSPixels x) const;
  56. CSSPixelRect selection_rect(Gfx::Font const&) const;
  57. bool is_atomic_inline() const;
  58. private:
  59. JS::NonnullGCPtr<Node const> m_layout_node;
  60. int m_start { 0 };
  61. int m_length { 0 };
  62. CSSPixelPoint m_offset;
  63. CSSPixelSize m_size;
  64. CSSPixels m_border_box_top { 0 };
  65. CSSPixels m_border_box_bottom { 0 };
  66. CSSPixels m_baseline { 0 };
  67. };
  68. }