ListItemBox.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Layout/ListItemBox.h>
  8. #include <LibWeb/Layout/ListItemMarkerBox.h>
  9. namespace Web::Layout {
  10. ListItemBox::ListItemBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
  11. : Layout::BlockContainer(document, &element, move(style))
  12. {
  13. }
  14. ListItemBox::~ListItemBox()
  15. {
  16. }
  17. void ListItemBox::layout_marker()
  18. {
  19. if (m_marker) {
  20. remove_child(*m_marker);
  21. m_marker = nullptr;
  22. }
  23. if (computed_values().list_style_type() == CSS::ListStyleType::None)
  24. return;
  25. if (!m_marker) {
  26. auto* marker_style = dom_node().specified_css_values();
  27. VERIFY(marker_style);
  28. int child_index = parent()->index_of_child<ListItemBox>(*this).value();
  29. m_marker = adopt_ref(*new ListItemMarkerBox(document(), computed_values().list_style_type(), child_index + 1, *marker_style));
  30. if (first_child())
  31. m_marker->set_inline(first_child()->is_inline());
  32. append_child(*m_marker);
  33. }
  34. m_marker->set_offset(-(m_marker->width() + 4), 0);
  35. m_marker->set_height(line_height());
  36. }
  37. }