LineBoxFragment.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Utf8View.h>
  7. #include <LibWeb/DOM/Range.h>
  8. #include <LibWeb/Layout/LayoutState.h>
  9. #include <LibWeb/Layout/Viewport.h>
  10. #include <ctype.h>
  11. namespace Web::Layout {
  12. bool LineBoxFragment::ends_in_whitespace() const
  13. {
  14. auto text = this->text();
  15. if (text.is_empty())
  16. return false;
  17. return isspace(text[text.length() - 1]);
  18. }
  19. bool LineBoxFragment::is_justifiable_whitespace() const
  20. {
  21. return text() == " ";
  22. }
  23. StringView LineBoxFragment::text() const
  24. {
  25. if (!is<TextNode>(layout_node()))
  26. return {};
  27. return verify_cast<TextNode>(layout_node()).text_for_rendering().bytes_as_string_view().substring_view(m_start, m_length);
  28. }
  29. CSSPixelRect const LineBoxFragment::absolute_rect() const
  30. {
  31. CSSPixelRect rect { {}, size() };
  32. rect.set_location(m_layout_node->containing_block()->paintable_box()->absolute_position());
  33. rect.translate_by(offset());
  34. return rect;
  35. }
  36. bool LineBoxFragment::is_atomic_inline() const
  37. {
  38. return layout_node().is_replaced_box() || (layout_node().display().is_inline_outside() && !layout_node().display().is_flow_inside());
  39. }
  40. }