/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Sam Atkins <sam@ladybird.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/FlyString.h> |
10 | | #include <LibWeb/CSS/CSSStyleValue.h> |
11 | | |
12 | | namespace Web::CSS { |
13 | | |
14 | | // https://drafts.csswg.org/css-lists-3/#counter-functions |
15 | | class CounterStyleValue : public StyleValueWithDefaultOperators<CounterStyleValue> { |
16 | | public: |
17 | | enum class CounterFunction { |
18 | | Counter, |
19 | | Counters, |
20 | | }; |
21 | | |
22 | | static ValueComparingNonnullRefPtr<CounterStyleValue> create_counter(FlyString counter_name, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style) |
23 | 0 | { |
24 | 0 | return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counter, move(counter_name), move(counter_style), {})); |
25 | 0 | } |
26 | | static ValueComparingNonnullRefPtr<CounterStyleValue> create_counters(FlyString counter_name, FlyString join_string, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style) |
27 | 0 | { |
28 | 0 | return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counters, move(counter_name), move(counter_style), move(join_string))); |
29 | 0 | } |
30 | | virtual ~CounterStyleValue() override; |
31 | | |
32 | 0 | CounterFunction function_type() const { return m_properties.function; } |
33 | 0 | auto counter_name() const { return m_properties.counter_name; } |
34 | 0 | auto counter_style() const { return m_properties.counter_style; } |
35 | 0 | auto join_string() const { return m_properties.join_string; } |
36 | | |
37 | | String resolve(DOM::Element&) const; |
38 | | |
39 | | virtual String to_string() const override; |
40 | | |
41 | | bool properties_equal(CounterStyleValue const& other) const; |
42 | | |
43 | | private: |
44 | | explicit CounterStyleValue(CounterFunction, FlyString counter_name, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style, FlyString join_string); |
45 | | |
46 | | struct Properties { |
47 | | CounterFunction function; |
48 | | FlyString counter_name; |
49 | | ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style; |
50 | | FlyString join_string; |
51 | 0 | bool operator==(Properties const&) const = default; |
52 | | } m_properties; |
53 | | }; |
54 | | |
55 | | } |