Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/Frequency.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/String.h>
10
#include <LibWeb/Forward.h>
11
12
namespace Web::CSS {
13
class Frequency {
14
public:
15
    enum class Type {
16
        Hz,
17
        kHz
18
    };
19
20
    static Optional<Type> unit_from_name(StringView);
21
22
    Frequency(double value, Type type);
23
    static Frequency make_hertz(double);
24
    Frequency percentage_of(Percentage const&) const;
25
26
    String to_string() const;
27
    double to_hertz() const;
28
29
0
    Type type() const { return m_type; }
30
0
    double raw_value() const { return m_value; }
31
    StringView unit_name() const;
32
33
    bool operator==(Frequency const& other) const
34
0
    {
35
0
        return m_type == other.m_type && m_value == other.m_value;
36
0
    }
37
38
    int operator<=>(Frequency const& other) const
39
0
    {
40
0
        auto this_hertz = to_hertz();
41
0
        auto other_hertz = other.to_hertz();
42
0
43
0
        if (this_hertz < other_hertz)
44
0
            return -1;
45
0
        if (this_hertz > other_hertz)
46
0
            return 1;
47
0
        return 0;
48
0
    }
49
50
    static Frequency resolve_calculated(NonnullRefPtr<CSSMathValue> const&, Layout::Node const&, Frequency const& reference_value);
51
52
private:
53
    Type m_type;
54
    double m_value { 0 };
55
};
56
57
}
58
59
template<>
60
struct AK::Formatter<Web::CSS::Frequency> : Formatter<StringView> {
61
    ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Frequency const& frequency)
62
0
    {
63
0
        return Formatter<StringView>::format(builder, frequency.to_string());
64
0
    }
65
};