Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/CSSHSL.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 <LibWeb/CSS/StyleValues/CSSColorValue.h>
10
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
11
12
namespace Web::CSS {
13
14
// https://drafts.css-houdini.org/css-typed-om-1/#csshsl
15
class CSSHSL final : public CSSColorValue {
16
public:
17
    static ValueComparingNonnullRefPtr<CSSHSL> create(ValueComparingNonnullRefPtr<CSSStyleValue> h, ValueComparingNonnullRefPtr<CSSStyleValue> s, ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingRefPtr<CSSStyleValue> alpha = {})
18
0
    {
19
        // alpha defaults to 1
20
0
        if (!alpha)
21
0
            return adopt_ref(*new (nothrow) CSSHSL(move(h), move(s), move(l), NumberStyleValue::create(1)));
22
23
0
        return adopt_ref(*new (nothrow) CSSHSL(move(h), move(s), move(l), alpha.release_nonnull()));
24
0
    }
25
0
    virtual ~CSSHSL() override = default;
26
27
0
    CSSStyleValue const& h() const { return *m_properties.h; }
28
0
    CSSStyleValue const& s() const { return *m_properties.s; }
29
0
    CSSStyleValue const& l() const { return *m_properties.l; }
30
0
    CSSStyleValue const& alpha() const { return *m_properties.alpha; }
31
32
    virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
33
34
    String to_string() const override;
35
36
    virtual bool equals(CSSStyleValue const& other) const override;
37
38
private:
39
    CSSHSL(ValueComparingNonnullRefPtr<CSSStyleValue> h, ValueComparingNonnullRefPtr<CSSStyleValue> s, ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
40
0
        : CSSColorValue(ColorType::HSL)
41
0
        , m_properties { .h = move(h), .s = move(s), .l = move(l), .alpha = move(alpha) }
42
0
    {
43
0
    }
44
45
    struct Properties {
46
        ValueComparingNonnullRefPtr<CSSStyleValue> h;
47
        ValueComparingNonnullRefPtr<CSSStyleValue> s;
48
        ValueComparingNonnullRefPtr<CSSStyleValue> l;
49
        ValueComparingNonnullRefPtr<CSSStyleValue> alpha;
50
0
        bool operator==(Properties const&) const = default;
51
    } m_properties;
52
};
53
54
}