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