2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
2021-08-09 16:28:56 -03:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
#include <LibWeb/Layout/ListItemMarkerBox.h>
|
2022-03-10 10:02:25 -03:00
|
|
|
#include <LibWeb/Painting/MarkerPaintable.h>
|
2019-10-11 18:16:53 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(ListItemMarkerBox);
|
2024-04-06 14:16:04 -03:00
|
|
|
|
2024-10-26 12:42:27 -03:00
|
|
|
ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType style_type, CSS::ListStylePosition style_position, size_t index, CSS::StyleProperties style)
|
2021-09-23 14:47:53 -03:00
|
|
|
: Box(document, nullptr, move(style))
|
2021-04-17 18:10:10 -03:00
|
|
|
, m_list_style_type(style_type)
|
2023-06-02 18:05:15 -03:00
|
|
|
, m_list_style_position(style_position)
|
2021-04-17 18:10:10 -03:00
|
|
|
, m_index(index)
|
2019-10-11 18:16:53 -03:00
|
|
|
{
|
2021-05-11 17:32:54 -03:00
|
|
|
switch (m_list_style_type) {
|
|
|
|
|
case CSS::ListStyleType::Square:
|
|
|
|
|
case CSS::ListStyleType::Circle:
|
|
|
|
|
case CSS::ListStyleType::Disc:
|
2023-05-30 17:50:29 -03:00
|
|
|
case CSS::ListStyleType::DisclosureClosed:
|
|
|
|
|
case CSS::ListStyleType::DisclosureOpen:
|
2021-05-11 17:32:54 -03:00
|
|
|
break;
|
|
|
|
|
case CSS::ListStyleType::Decimal:
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = ByteString::formatted("{}.", m_index);
|
2021-05-11 17:32:54 -03:00
|
|
|
break;
|
|
|
|
|
case CSS::ListStyleType::DecimalLeadingZero:
|
|
|
|
|
// This is weird, but in accordance to spec.
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = m_index < 10 ? ByteString::formatted("0{}.", m_index) : ByteString::formatted("{}.", m_index);
|
2021-05-11 17:32:54 -03:00
|
|
|
break;
|
|
|
|
|
case CSS::ListStyleType::LowerAlpha:
|
|
|
|
|
case CSS::ListStyleType::LowerLatin:
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = ByteString::bijective_base_from(m_index - 1).to_lowercase();
|
2021-05-11 17:32:54 -03:00
|
|
|
break;
|
|
|
|
|
case CSS::ListStyleType::UpperAlpha:
|
|
|
|
|
case CSS::ListStyleType::UpperLatin:
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = ByteString::bijective_base_from(m_index - 1);
|
2021-05-11 17:32:54 -03:00
|
|
|
break;
|
2021-07-04 12:17:23 -03:00
|
|
|
case CSS::ListStyleType::LowerRoman:
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = ByteString::roman_number_from(m_index).to_lowercase();
|
2021-07-04 12:17:23 -03:00
|
|
|
break;
|
|
|
|
|
case CSS::ListStyleType::UpperRoman:
|
2023-12-16 11:19:34 -03:00
|
|
|
m_text = ByteString::roman_number_from(m_index);
|
2021-07-04 12:17:23 -03:00
|
|
|
break;
|
2021-05-11 17:32:54 -03:00
|
|
|
case CSS::ListStyleType::None:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
2019-10-11 18:16:53 -03:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
ListItemMarkerBox::~ListItemMarkerBox() = default;
|
2019-10-11 18:16:53 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Painting::Paintable> ListItemMarkerBox::create_paintable() const
|
2021-10-29 10:00:30 -03:00
|
|
|
{
|
2022-03-10 10:02:25 -03:00
|
|
|
return Painting::MarkerPaintable::create(*this);
|
2021-10-29 10:00:30 -03:00
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|