/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
Line | Count | Source (jump to first uncovered line) |
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 | | #pragma once |
11 | | |
12 | | #include <AK/Vector.h> |
13 | | #include <LibWeb/CSS/Enums.h> |
14 | | #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> |
15 | | #include <LibWeb/Painting/GradientPainting.h> |
16 | | |
17 | | namespace Web::CSS { |
18 | | |
19 | | class RadialGradientStyleValue final : public AbstractImageStyleValue { |
20 | | public: |
21 | | enum class EndingShape { |
22 | | Circle, |
23 | | Ellipse |
24 | | }; |
25 | | |
26 | | enum class Extent { |
27 | | ClosestCorner, |
28 | | ClosestSide, |
29 | | FarthestCorner, |
30 | | FarthestSide |
31 | | }; |
32 | | |
33 | | struct CircleSize { |
34 | | Length radius; |
35 | 0 | bool operator==(CircleSize const&) const = default; |
36 | | }; |
37 | | |
38 | | struct EllipseSize { |
39 | | LengthPercentage radius_a; |
40 | | LengthPercentage radius_b; |
41 | 0 | bool operator==(EllipseSize const&) const = default; |
42 | | }; |
43 | | |
44 | | using Size = Variant<Extent, CircleSize, EllipseSize>; |
45 | | |
46 | | static ValueComparingNonnullRefPtr<RadialGradientStyleValue> create(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating) |
47 | 0 | { |
48 | 0 | VERIFY(color_stop_list.size() >= 2); |
49 | 0 | return adopt_ref(*new (nothrow) RadialGradientStyleValue(ending_shape, size, move(position), move(color_stop_list), repeating)); |
50 | 0 | } |
51 | | |
52 | | virtual String to_string() const override; |
53 | | |
54 | | void paint(PaintContext&, DevicePixelRect const& dest_rect, CSS::ImageRendering, Vector<Gfx::Path> const& clip_paths = {}) const override; |
55 | | |
56 | | virtual bool equals(CSSStyleValue const& other) const override; |
57 | | |
58 | | Vector<LinearColorStopListElement> const& color_stop_list() const |
59 | 0 | { |
60 | 0 | return m_properties.color_stop_list; |
61 | 0 | } |
62 | | |
63 | 0 | bool is_paintable() const override { return true; } |
64 | | |
65 | | void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const override; |
66 | | |
67 | | CSSPixelSize resolve_size(Layout::Node const&, CSSPixelPoint, CSSPixelRect const&) const; |
68 | | |
69 | 0 | bool is_repeating() const { return m_properties.repeating == GradientRepeating::Yes; } |
70 | | |
71 | 0 | virtual ~RadialGradientStyleValue() override = default; |
72 | | |
73 | | private: |
74 | | RadialGradientStyleValue(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating) |
75 | 0 | : AbstractImageStyleValue(Type::RadialGradient) |
76 | 0 | , m_properties { .ending_shape = ending_shape, .size = size, .position = move(position), .color_stop_list = move(color_stop_list), .repeating = repeating } |
77 | 0 | { |
78 | 0 | } |
79 | | |
80 | | struct Properties { |
81 | | EndingShape ending_shape; |
82 | | Size size; |
83 | | ValueComparingNonnullRefPtr<PositionStyleValue> position; |
84 | | Vector<LinearColorStopListElement> color_stop_list; |
85 | | GradientRepeating repeating; |
86 | 0 | bool operator==(Properties const&) const = default; |
87 | | } m_properties; |
88 | | |
89 | | struct ResolvedData { |
90 | | Painting::RadialGradientData data; |
91 | | CSSPixelSize gradient_size; |
92 | | CSSPixelPoint center; |
93 | | }; |
94 | | |
95 | | mutable Optional<ResolvedData> m_resolved; |
96 | | }; |
97 | | |
98 | | } |