Coverage Report

Created: 2025-11-02 07:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/CSSHSL.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include "CSSHSL.h"
8
#include <AK/TypeCasts.h>
9
#include <LibWeb/CSS/Serialize.h>
10
11
namespace Web::CSS {
12
13
Color CSSHSL::to_color(Optional<Layout::NodeWithStyle const&>) const
14
0
{
15
0
    auto const h_val = resolve_hue(m_properties.h).value_or(0);
16
0
    auto const s_val = resolve_with_reference_value(m_properties.s, 100.0).value_or(0);
17
0
    auto const l_val = resolve_with_reference_value(m_properties.l, 100.0).value_or(0);
18
0
    auto const alpha_val = resolve_alpha(m_properties.alpha).value_or(1);
19
20
0
    return Color::from_hsla(h_val, s_val / 100.0f, l_val / 100.0f, alpha_val);
21
0
}
22
23
bool CSSHSL::equals(CSSStyleValue const& other) const
24
0
{
25
0
    if (type() != other.type())
26
0
        return false;
27
0
    auto const& other_color = other.as_color();
28
0
    if (color_type() != other_color.color_type())
29
0
        return false;
30
0
    auto const& other_hsl = verify_cast<CSSHSL>(other_color);
31
0
    return m_properties == other_hsl.m_properties;
32
0
}
33
34
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
35
String CSSHSL::to_string() const
36
0
{
37
    // FIXME: Do this properly, taking unresolved calculated values into account.
38
0
    return serialize_a_srgb_value(to_color({}));
39
0
}
40
41
}