LineBoxFragment.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Weakable.h>
  28. #include <LibGfx/Forward.h>
  29. #include <LibGfx/Rect.h>
  30. #include <LibWeb/Forward.h>
  31. namespace Web::Layout {
  32. class LineBoxFragment : public Weakable<LineBoxFragment> {
  33. friend class LineBox;
  34. public:
  35. enum class Type {
  36. Normal,
  37. Leading,
  38. Trailing,
  39. };
  40. LineBoxFragment(Node& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size, Type type)
  41. : m_layout_node(layout_node)
  42. , m_start(start)
  43. , m_length(length)
  44. , m_offset(offset)
  45. , m_size(size)
  46. , m_type(type)
  47. {
  48. }
  49. Node& layout_node() const { return m_layout_node; }
  50. int start() const { return m_start; }
  51. int length() const { return m_length; }
  52. const Gfx::FloatRect absolute_rect() const;
  53. Type type() const { return m_type; }
  54. const Gfx::FloatPoint& offset() const { return m_offset; }
  55. void set_offset(const Gfx::FloatPoint& offset) { m_offset = offset; }
  56. const Gfx::FloatSize& size() const { return m_size; }
  57. void set_width(float width) { m_size.set_width(width); }
  58. void set_height(float height) { m_size.set_height(height); }
  59. float width() const { return m_size.width(); }
  60. float height() const { return m_size.height(); }
  61. float absolute_x() const { return absolute_rect().x(); }
  62. void paint(PaintContext&, PaintPhase);
  63. bool ends_in_whitespace() const;
  64. bool is_justifiable_whitespace() const;
  65. StringView text() const;
  66. int text_index_at(float x) const;
  67. Gfx::FloatRect selection_rect(const Gfx::Font&) const;
  68. private:
  69. Node& m_layout_node;
  70. int m_start { 0 };
  71. int m_length { 0 };
  72. Gfx::FloatPoint m_offset;
  73. Gfx::FloatSize m_size;
  74. Type m_type { Type::Normal };
  75. };
  76. }