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/ConicGradientStyleValue.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3
 * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
4
 * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
5
 * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
6
 *
7
 * SPDX-License-Identifier: BSD-2-Clause
8
 */
9
10
#include "ConicGradientStyleValue.h"
11
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
12
#include <LibWeb/Layout/Node.h>
13
14
namespace Web::CSS {
15
16
String ConicGradientStyleValue::to_string() const
17
0
{
18
0
    StringBuilder builder;
19
0
    if (is_repeating())
20
0
        builder.append("repeating-"sv);
21
0
    builder.append("conic-gradient("sv);
22
0
    bool has_from_angle = m_properties.from_angle.to_degrees() != 0;
23
0
    bool has_at_position = !m_properties.position->is_center();
24
0
    if (has_from_angle)
25
0
        builder.appendff("from {}", m_properties.from_angle.to_string());
26
0
    if (has_at_position) {
27
0
        if (has_from_angle)
28
0
            builder.append(' ');
29
0
        builder.appendff("at {}"sv, m_properties.position->to_string());
30
0
    }
31
0
    if (has_from_angle || has_at_position)
32
0
        builder.append(", "sv);
33
0
    serialize_color_stop_list(builder, m_properties.color_stop_list);
34
0
    builder.append(')');
35
0
    return MUST(builder.to_string());
36
0
}
37
38
void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const& node, CSSPixelSize size) const
39
0
{
40
0
    if (!m_resolved.has_value())
41
0
        m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} };
42
0
    m_resolved->position = m_properties.position->resolved(node, CSSPixelRect { { 0, 0 }, size });
43
0
}
44
45
void ConicGradientStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering, Vector<Gfx::Path> const& clip_paths) const
46
0
{
47
0
    VERIFY(m_resolved.has_value());
48
0
    auto destination_rect = dest_rect.to_type<int>();
49
0
    auto position = context.rounded_device_point(m_resolved->position).to_type<int>();
50
0
    context.display_list_recorder().fill_rect_with_conic_gradient(destination_rect, m_resolved->data, position, clip_paths);
51
0
}
52
53
bool ConicGradientStyleValue::equals(CSSStyleValue const& other) const
54
0
{
55
0
    if (type() != other.type())
56
0
        return false;
57
0
    auto& other_gradient = other.as_conic_gradient();
58
0
    return m_properties == other_gradient.m_properties;
59
0
}
60
61
float ConicGradientStyleValue::angle_degrees() const
62
0
{
63
0
    return m_properties.from_angle.to_degrees();
64
0
}
65
66
}