ListItemMarkerBox.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Layout/ListItemMarkerBox.h>
  8. #include <LibWeb/Painting/MarkerPaintable.h>
  9. namespace Web::Layout {
  10. JS_DEFINE_ALLOCATOR(ListItemMarkerBox);
  11. ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType style_type, CSS::ListStylePosition style_position, size_t index, CSS::StyleProperties style)
  12. : Box(document, nullptr, move(style))
  13. , m_list_style_type(style_type)
  14. , m_list_style_position(style_position)
  15. , m_index(index)
  16. {
  17. switch (m_list_style_type) {
  18. case CSS::ListStyleType::Square:
  19. case CSS::ListStyleType::Circle:
  20. case CSS::ListStyleType::Disc:
  21. case CSS::ListStyleType::DisclosureClosed:
  22. case CSS::ListStyleType::DisclosureOpen:
  23. break;
  24. case CSS::ListStyleType::Decimal:
  25. m_text = ByteString::formatted("{}.", m_index);
  26. break;
  27. case CSS::ListStyleType::DecimalLeadingZero:
  28. // This is weird, but in accordance to spec.
  29. m_text = m_index < 10 ? ByteString::formatted("0{}.", m_index) : ByteString::formatted("{}.", m_index);
  30. break;
  31. case CSS::ListStyleType::LowerAlpha:
  32. case CSS::ListStyleType::LowerLatin:
  33. m_text = ByteString::bijective_base_from(m_index - 1).to_lowercase();
  34. break;
  35. case CSS::ListStyleType::UpperAlpha:
  36. case CSS::ListStyleType::UpperLatin:
  37. m_text = ByteString::bijective_base_from(m_index - 1);
  38. break;
  39. case CSS::ListStyleType::LowerRoman:
  40. m_text = ByteString::roman_number_from(m_index).to_lowercase();
  41. break;
  42. case CSS::ListStyleType::UpperRoman:
  43. m_text = ByteString::roman_number_from(m_index);
  44. break;
  45. case CSS::ListStyleType::None:
  46. break;
  47. default:
  48. VERIFY_NOT_REACHED();
  49. }
  50. }
  51. ListItemMarkerBox::~ListItemMarkerBox() = default;
  52. JS::GCPtr<Painting::Paintable> ListItemMarkerBox::create_paintable() const
  53. {
  54. return Painting::MarkerPaintable::create(*this);
  55. }
  56. }