Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/CSS/CountersSet.h
Line
Count
Source (jump to first uncovered line)
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/Checked.h>
10
#include <AK/FlyString.h>
11
#include <AK/Optional.h>
12
13
namespace Web::CSS {
14
15
// "UAs may have implementation-specific limits on the maximum or minimum value of a counter.
16
// If a counter reset, set, or increment would push the value outside of that range, the value
17
// must be clamped to that range." - https://drafts.csswg.org/css-lists-3/#auto-numbering
18
// So, we use a Checked<i32> and saturating addition/subtraction.
19
using CounterValue = Checked<i32>;
20
21
// https://drafts.csswg.org/css-lists-3/#counter
22
struct Counter {
23
    FlyString name;
24
    i32 originating_element_id; // "creator"
25
    bool reversed { false };
26
    Optional<CounterValue> value;
27
};
28
29
// https://drafts.csswg.org/css-lists-3/#css-counters-set
30
class CountersSet {
31
public:
32
0
    CountersSet() = default;
33
0
    ~CountersSet() = default;
34
35
    Counter& instantiate_a_counter(FlyString name, i32 originating_element_id, bool reversed, Optional<CounterValue>);
36
    void set_a_counter(FlyString name, i32 originating_element_id, CounterValue value);
37
    void increment_a_counter(FlyString name, i32 originating_element_id, CounterValue amount);
38
    void append_copy(Counter const&);
39
40
    Optional<Counter&> last_counter_with_name(FlyString const& name);
41
    Optional<Counter&> counter_with_same_name_and_creator(FlyString const& name, i32 originating_element_id);
42
43
0
    Vector<Counter> const& counters() const { return m_counters; }
44
0
    bool is_empty() const { return m_counters.is_empty(); }
45
46
private:
47
    Vector<Counter> m_counters;
48
};
49
50
}