Coverage Report

Created: 2026-05-16 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/Flex.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Optional.h>
10
#include <AK/String.h>
11
#include <LibWeb/Forward.h>
12
13
namespace Web::CSS {
14
15
// https://drafts.csswg.org/css-grid-2/#typedef-flex
16
class Flex {
17
public:
18
    enum class Type {
19
        Fr,
20
    };
21
22
    static Optional<Type> unit_from_name(StringView);
23
24
    Flex(double value, Type type);
25
    static Flex make_fr(double);
26
    Flex percentage_of(Percentage const&) const;
27
28
    String to_string() const;
29
    double to_fr() 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==(Flex const& other) const
36
0
    {
37
0
        return m_type == other.m_type && m_value == other.m_value;
38
0
    }
39
40
    int operator<=>(Flex const& other) const
41
0
    {
42
0
        auto this_fr = to_fr();
43
0
        auto other_fr = other.to_fr();
44
0
45
0
        if (this_fr < other_fr)
46
0
            return -1;
47
0
        if (this_fr > other_fr)
48
0
            return 1;
49
0
        return 0;
50
0
    }
51
52
private:
53
    Type m_type;
54
    double m_value { 0 };
55
};
56
57
}
58
59
template<>
60
struct AK::Formatter<Web::CSS::Flex> : Formatter<StringView> {
61
    ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Flex const& flex)
62
0
    {
63
0
        return Formatter<StringView>::format(builder, flex.to_string());
64
0
    }
65
};