Coverage Report

Created: 2025-08-28 06:26

/src/serenity/Userland/Libraries/LibWeb/Painting/BorderRadiiData.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
3
 * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <LibGfx/AntiAliasingPainter.h>
11
#include <LibGfx/Forward.h>
12
#include <LibWeb/CSS/ComputedValues.h>
13
14
namespace Web::Painting {
15
16
struct BorderRadiusData {
17
    CSSPixels horizontal_radius { 0 };
18
    CSSPixels vertical_radius { 0 };
19
20
    Gfx::CornerRadius as_corner(PaintContext const& context) const;
21
22
    inline operator bool() const
23
0
    {
24
0
        return horizontal_radius > 0 && vertical_radius > 0;
25
0
    }
26
27
    inline void shrink(CSSPixels horizontal, CSSPixels vertical)
28
0
    {
29
0
        if (horizontal_radius != 0)
30
0
            horizontal_radius = max(CSSPixels(0), horizontal_radius - horizontal);
31
0
        if (vertical_radius != 0)
32
0
            vertical_radius = max(CSSPixels(0), vertical_radius - vertical);
33
0
    }
34
35
    inline void union_max_radii(BorderRadiusData const& other)
36
0
    {
37
0
        horizontal_radius = max(horizontal_radius, other.horizontal_radius);
38
0
        vertical_radius = max(vertical_radius, other.vertical_radius);
39
0
    }
40
};
41
42
using CornerRadius = Gfx::CornerRadius;
43
44
struct CornerRadii {
45
    CornerRadius top_left;
46
    CornerRadius top_right;
47
    CornerRadius bottom_right;
48
    CornerRadius bottom_left;
49
50
    inline bool has_any_radius() const
51
0
    {
52
0
        return top_left || top_right || bottom_right || bottom_left;
53
0
    }
54
};
55
56
struct BorderRadiiData {
57
    BorderRadiusData top_left;
58
    BorderRadiusData top_right;
59
    BorderRadiusData bottom_right;
60
    BorderRadiusData bottom_left;
61
62
    inline bool has_any_radius() const
63
0
    {
64
0
        return top_left || top_right || bottom_right || bottom_left;
65
0
    }
66
67
    inline void union_max_radii(BorderRadiiData const& other)
68
0
    {
69
0
        top_left.union_max_radii(other.top_left);
70
0
        top_right.union_max_radii(other.top_right);
71
0
        bottom_right.union_max_radii(other.bottom_right);
72
0
        bottom_left.union_max_radii(other.bottom_left);
73
0
    }
74
75
    inline void shrink(CSSPixels top, CSSPixels right, CSSPixels bottom, CSSPixels left)
76
0
    {
77
0
        top_left.shrink(left, top);
78
0
        top_right.shrink(right, top);
79
0
        bottom_right.shrink(right, bottom);
80
0
        bottom_left.shrink(left, bottom);
81
0
    }
82
83
    inline void inflate(CSSPixels top, CSSPixels right, CSSPixels bottom, CSSPixels left)
84
0
    {
85
0
        shrink(-top, -right, -bottom, -left);
86
0
    }
87
88
    inline CornerRadii as_corners(PaintContext const& context) const
89
0
    {
90
0
        return CornerRadii {
91
0
            top_left.as_corner(context),
92
0
            top_right.as_corner(context),
93
0
            bottom_right.as_corner(context),
94
0
            bottom_left.as_corner(context)
95
0
        };
96
0
    }
97
};
98
99
}