Coverage Report

Created: 2025-12-18 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/Time.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
14
class Time {
15
public:
16
    enum class Type {
17
        S,
18
        Ms,
19
    };
20
21
    static Optional<Type> unit_from_name(StringView);
22
23
    Time(double value, Type type);
24
    static Time make_seconds(double);
25
    Time percentage_of(Percentage const&) const;
26
27
    String to_string() const;
28
    double to_milliseconds() const;
29
    double to_seconds() const;
30
31
0
    Type type() const { return m_type; }
32
0
    double raw_value() const { return m_value; }
33
    StringView unit_name() const;
34
35
    bool operator==(Time const& other) const
36
0
    {
37
0
        return m_type == other.m_type && m_value == other.m_value;
38
0
    }
39
40
    int operator<=>(Time const& other) const
41
0
    {
42
0
        auto this_seconds = to_seconds();
43
0
        auto other_seconds = other.to_seconds();
44
45
0
        if (this_seconds < other_seconds)
46
0
            return -1;
47
0
        if (this_seconds > other_seconds)
48
0
            return 1;
49
0
        return 0;
50
0
    }
51
52
    static Time resolve_calculated(NonnullRefPtr<CSSMathValue> const&, Layout::Node const&, Time const& reference_value);
53
54
private:
55
    Type m_type;
56
    double m_value { 0 };
57
};
58
59
}
60
61
template<>
62
struct AK::Formatter<Web::CSS::Time> : Formatter<StringView> {
63
    ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Time const& time)
64
0
    {
65
0
        return Formatter<StringView>::format(builder, time.to_string());
66
0
    }
67
};