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