| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> | 
					
						
							| 
									
										
										
										
											2025-02-21 16:45:07 +00:00
										 |  |  |  |  * Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "RadialGradientStyleValue.h"
 | 
					
						
							| 
									
										
										
										
											2023-11-07 12:11:04 +00:00
										 |  |  |  | #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-16 12:45:23 +01:00
										 |  |  |  | #include <LibWeb/Layout/Node.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-02 15:55:26 +01:00
										 |  |  |  | #include <LibWeb/Painting/DisplayListRecorder.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-07 00:59:49 +01:00
										 |  |  |  | String RadialGradientStyleValue::to_string(SerializationMode mode) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |  |     if (is_repeating()) | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |         builder.append("repeating-"sv); | 
					
						
							| 
									
										
										
										
											2025-04-08 13:50:50 -04:00
										 |  |  |  |     builder.append("radial-gradient("sv); | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     bool has_size = !m_properties.size.has<Extent>() || m_properties.size.get<Extent>() != Extent::FarthestCorner; | 
					
						
							|  |  |  |  |     bool has_position = !m_properties.position->is_center(); | 
					
						
							|  |  |  |  |     bool has_color_space = m_properties.interpolation_method.has_value() && m_properties.interpolation_method.value().color_space != InterpolationMethod::default_color_space(m_properties.color_syntax); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |     m_properties.size.visit( | 
					
						
							|  |  |  |  |         [&](Extent extent) { | 
					
						
							|  |  |  |  |             builder.append([&] { | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |                 switch (extent) { | 
					
						
							|  |  |  |  |                 case Extent::ClosestCorner: | 
					
						
							|  |  |  |  |                     return "closest-corner"sv; | 
					
						
							|  |  |  |  |                 case Extent::ClosestSide: | 
					
						
							|  |  |  |  |                     return "closest-side"sv; | 
					
						
							|  |  |  |  |                 case Extent::FarthestCorner: | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |  |                     // "farthest-corner" is the default value and isn't serialized
 | 
					
						
							|  |  |  |  |                     return ""sv; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |                 case Extent::FarthestSide: | 
					
						
							|  |  |  |  |                     return "farthest-side"sv; | 
					
						
							|  |  |  |  |                 default: | 
					
						
							|  |  |  |  |                     VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             }()); | 
					
						
							|  |  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |         [&](CircleSize const& circle_size) { | 
					
						
							|  |  |  |  |             builder.append(circle_size.radius.to_string()); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |         [&](EllipseSize const& ellipse_size) { | 
					
						
							| 
									
										
										
										
											2025-08-03 15:37:42 +12:00
										 |  |  |  |             builder.appendff("{} {}", ellipse_size.radius_a.to_string(mode), ellipse_size.radius_b.to_string(mode)); | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |  |     if (has_position) { | 
					
						
							|  |  |  |  |         if (has_size) | 
					
						
							|  |  |  |  |             builder.append(' '); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-08 13:50:50 -04:00
										 |  |  |  |         builder.appendff("at {}", m_properties.position->to_string(mode)); | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (has_color_space) { | 
					
						
							|  |  |  |  |         if (has_size || has_position) | 
					
						
							|  |  |  |  |             builder.append(' '); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         builder.append(m_properties.interpolation_method.value().to_string()); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (has_size || has_position || has_color_space) | 
					
						
							|  |  |  |  |         builder.append(", "sv); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-07 00:59:49 +01:00
										 |  |  |  |     serialize_color_stop_list(builder, m_properties.color_stop_list, mode); | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |  |     builder.append(')'); | 
					
						
							|  |  |  |  |     return MUST(builder.to_string()); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  | CSSPixelSize RadialGradientStyleValue::resolve_size(Layout::Node const& node, CSSPixelPoint center, CSSPixelRect const& size) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     auto const side_shape = [&](auto distance_function) { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         auto const distance_from = [&](CSSPixels v, CSSPixels a, CSSPixels b, auto distance_function) { | 
					
						
							|  |  |  |  |             return distance_function(abs(a - v), abs(b - v)); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2023-08-17 21:17:39 +01:00
										 |  |  |  |         auto x_dist = distance_from(center.x(), size.left(), size.right(), distance_function); | 
					
						
							|  |  |  |  |         auto y_dist = distance_from(center.y(), size.top(), size.bottom(), distance_function); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         if (m_properties.ending_shape == EndingShape::Circle) { | 
					
						
							|  |  |  |  |             auto dist = distance_function(x_dist, y_dist); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             return CSSPixelSize { dist, dist }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             return CSSPixelSize { x_dist, y_dist }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     auto const closest_side_shape = [&] { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return side_shape(AK::min<CSSPixels>); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     auto const farthest_side_shape = [&] { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return side_shape(AK::max<CSSPixels>); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |     auto const corner_distance = [&](auto distance_compare, CSSPixelPoint& corner) { | 
					
						
							|  |  |  |  |         auto top_left_distance_squared = square_distance_between(size.top_left(), center); | 
					
						
							|  |  |  |  |         auto top_right_distance_squared = square_distance_between(size.top_right(), center); | 
					
						
							|  |  |  |  |         auto bottom_right_distance_squared = square_distance_between(size.bottom_right(), center); | 
					
						
							|  |  |  |  |         auto bottom_left_distance_squared = square_distance_between(size.bottom_left(), center); | 
					
						
							|  |  |  |  |         auto distance_squared = top_left_distance_squared; | 
					
						
							| 
									
										
										
										
											2023-09-01 17:23:28 -05:00
										 |  |  |  |         corner = size.top_left(); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         if (distance_compare(top_right_distance_squared, distance_squared)) { | 
					
						
							| 
									
										
										
										
											2023-08-17 21:17:39 +01:00
										 |  |  |  |             corner = size.top_right(); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             distance_squared = top_right_distance_squared; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         if (distance_compare(bottom_right_distance_squared, distance_squared)) { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:23:28 -05:00
										 |  |  |  |             corner = size.bottom_right(); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             distance_squared = bottom_right_distance_squared; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         if (distance_compare(bottom_left_distance_squared, distance_squared)) { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:23:28 -05:00
										 |  |  |  |             corner = size.bottom_left(); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             distance_squared = bottom_left_distance_squared; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return sqrt(distance_squared); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |     auto const closest_corner_distance = [&](CSSPixelPoint& corner) { | 
					
						
							|  |  |  |  |         return corner_distance([](CSSPixels a, CSSPixels b) { return a < b; }, corner); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |     auto const farthest_corner_distance = [&](CSSPixelPoint& corner) { | 
					
						
							|  |  |  |  |         return corner_distance([](CSSPixels a, CSSPixels b) { return a > b; }, corner); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     auto const corner_shape = [&](auto corner_distance, auto get_shape) { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         CSSPixelPoint corner {}; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         auto distance = corner_distance(corner); | 
					
						
							|  |  |  |  |         if (m_properties.ending_shape == EndingShape::Ellipse) { | 
					
						
							|  |  |  |  |             auto shape = get_shape(); | 
					
						
							| 
									
										
										
										
											2024-11-18 23:14:45 +04:00
										 |  |  |  |             CSSPixels height = shape.height(); | 
					
						
							|  |  |  |  |             CSSPixels width = shape.width(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             // Prevent division by zero
 | 
					
						
							|  |  |  |  |             // https://w3c.github.io/csswg-drafts/css-images/#degenerate-radials
 | 
					
						
							|  |  |  |  |             if (height == 0) { | 
					
						
							|  |  |  |  |                 // Render as if the ending shape was an ellipse whose width was an arbitrary very large number and whose height
 | 
					
						
							|  |  |  |  |                 // was an arbitrary very small number greater than zero. This will make the gradient look like a solid-color image equal
 | 
					
						
							|  |  |  |  |                 // to the color of the last color-stop, or equal to the average color of the gradient if it’s repeating.
 | 
					
						
							|  |  |  |  |                 constexpr auto arbitrary_small_number = CSSPixels::smallest_positive_value(); | 
					
						
							|  |  |  |  |                 constexpr auto arbitrary_large_number = CSSPixels::max(); | 
					
						
							|  |  |  |  |                 return CSSPixelSize { arbitrary_large_number, arbitrary_small_number }; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             auto aspect_ratio = width / height; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |             auto p = corner - center; | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             auto radius_a = sqrt(p.y() * p.y() * aspect_ratio * aspect_ratio + p.x() * p.x()); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |             auto radius_b = radius_a / aspect_ratio; | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             return CSSPixelSize { radius_a, radius_b }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return CSSPixelSize { distance, distance }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     // https://w3c.github.io/csswg-drafts/css-images/#radial-gradient-syntax
 | 
					
						
							|  |  |  |  |     auto resolved_size = m_properties.size.visit( | 
					
						
							|  |  |  |  |         [&](Extent extent) { | 
					
						
							|  |  |  |  |             switch (extent) { | 
					
						
							|  |  |  |  |             case Extent::ClosestSide: | 
					
						
							|  |  |  |  |                 // The ending shape is sized so that it exactly meets the side of the gradient box closest to the gradient’s center.
 | 
					
						
							|  |  |  |  |                 // If the shape is an ellipse, it exactly meets the closest side in each dimension.
 | 
					
						
							|  |  |  |  |                 return closest_side_shape(); | 
					
						
							|  |  |  |  |             case Extent::ClosestCorner: | 
					
						
							|  |  |  |  |                 // The ending shape is sized so that it passes through the corner of the gradient box closest to the gradient’s center.
 | 
					
						
							|  |  |  |  |                 // If the shape is an ellipse, the ending shape is given the same aspect-ratio it would have if closest-side were specified
 | 
					
						
							|  |  |  |  |                 return corner_shape(closest_corner_distance, closest_side_shape); | 
					
						
							|  |  |  |  |             case Extent::FarthestCorner: | 
					
						
							|  |  |  |  |                 // Same as closest-corner, except the ending shape is sized based on the farthest corner.
 | 
					
						
							|  |  |  |  |                 // If the shape is an ellipse, the ending shape is given the same aspect ratio it would have if farthest-side were specified.
 | 
					
						
							|  |  |  |  |                 return corner_shape(farthest_corner_distance, farthest_side_shape); | 
					
						
							|  |  |  |  |             case Extent::FarthestSide: | 
					
						
							|  |  |  |  |                 // Same as closest-side, except the ending shape is sized based on the farthest side(s).
 | 
					
						
							|  |  |  |  |                 return farthest_side_shape(); | 
					
						
							|  |  |  |  |             default: | 
					
						
							|  |  |  |  |                 VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         [&](CircleSize const& circle_size) { | 
					
						
							|  |  |  |  |             auto radius = circle_size.radius.to_px(node); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             return CSSPixelSize { radius, radius }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         }, | 
					
						
							|  |  |  |  |         [&](EllipseSize const& ellipse_size) { | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |             auto radius_a = ellipse_size.radius_a.resolved(node, size.width()).to_px(node); | 
					
						
							|  |  |  |  |             auto radius_b = ellipse_size.radius_b.resolved(node, size.height()).to_px(node); | 
					
						
							|  |  |  |  |             return CSSPixelSize { radius_a, radius_b }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |         }); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     // Handle degenerate cases
 | 
					
						
							|  |  |  |  |     // https://w3c.github.io/csswg-drafts/css-images/#degenerate-radials
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |     constexpr auto arbitrary_small_number = CSSPixels::smallest_positive_value(); | 
					
						
							|  |  |  |  |     constexpr auto arbitrary_large_number = CSSPixels::max(); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     // If the ending shape is a circle with zero radius:
 | 
					
						
							|  |  |  |  |     if (m_properties.ending_shape == EndingShape::Circle && resolved_size.is_empty()) { | 
					
						
							|  |  |  |  |         // Render as if the ending shape was a circle whose radius was an arbitrary very small number greater than zero.
 | 
					
						
							|  |  |  |  |         // This will make the gradient continue to look like a circle.
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return CSSPixelSize { arbitrary_small_number, arbitrary_small_number }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     // If the ending shape has zero width (regardless of the height):
 | 
					
						
							|  |  |  |  |     if (resolved_size.width() <= 0) { | 
					
						
							|  |  |  |  |         // Render as if the ending shape was an ellipse whose height was an arbitrary very large number
 | 
					
						
							|  |  |  |  |         // and whose width was an arbitrary very small number greater than zero.
 | 
					
						
							|  |  |  |  |         // This will make the gradient look similar to a horizontal linear gradient that is mirrored across the center of the ellipse.
 | 
					
						
							|  |  |  |  |         // It also means that all color-stop positions specified with a percentage resolve to 0px.
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return CSSPixelSize { arbitrary_small_number, arbitrary_large_number }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     // Otherwise, if the ending shape has zero height:
 | 
					
						
							|  |  |  |  |     if (resolved_size.height() <= 0) { | 
					
						
							|  |  |  |  |         // Render as if the ending shape was an ellipse whose width was an arbitrary very large number and whose height
 | 
					
						
							|  |  |  |  |         // was an arbitrary very small number greater than zero. This will make the gradient look like a solid-color image equal
 | 
					
						
							|  |  |  |  |         // to the color of the last color-stop, or equal to the average color of the gradient if it’s repeating.
 | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |         return CSSPixelSize { arbitrary_large_number, arbitrary_small_number }; | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     return resolved_size; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 16:13:37 +00:00
										 |  |  |  | void RadialGradientStyleValue::resolve_for_size(Layout::NodeWithStyle const& node, CSSPixelSize paint_size) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     CSSPixelRect gradient_box { { 0, 0 }, paint_size }; | 
					
						
							| 
									
										
										
										
											2023-11-07 12:11:04 +00:00
										 |  |  |  |     auto center = m_properties.position->resolved(node, gradient_box); | 
					
						
							| 
									
										
										
										
											2023-09-01 17:16:28 -05:00
										 |  |  |  |     auto gradient_size = resolve_size(node, center, gradient_box); | 
					
						
							| 
									
										
										
										
											2025-02-21 16:45:07 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     ResolvedDataCacheKey cache_key { | 
					
						
							|  |  |  |  |         .length_resolution_context = Length::ResolutionContext::for_layout_node(node), | 
					
						
							|  |  |  |  |         .size = paint_size, | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2025-02-21 16:45:07 +00:00
										 |  |  |  |     if (m_resolved_data_cache_key != cache_key) { | 
					
						
							|  |  |  |  |         m_resolved_data_cache_key = move(cache_key); | 
					
						
							|  |  |  |  |         m_resolved = ResolvedData { | 
					
						
							|  |  |  |  |             Painting::resolve_radial_gradient_data(node, gradient_size, *this), | 
					
						
							|  |  |  |  |             gradient_size, | 
					
						
							|  |  |  |  |             center, | 
					
						
							|  |  |  |  |         }; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |  | bool RadialGradientStyleValue::equals(StyleValue const& other) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     if (type() != other.type()) | 
					
						
							|  |  |  |  |         return false; | 
					
						
							|  |  |  |  |     auto& other_gradient = other.as_radial_gradient(); | 
					
						
							|  |  |  |  |     return m_properties == other_gradient.m_properties; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-31 23:07:26 +02:00
										 |  |  |  | void RadialGradientStyleValue::paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     VERIFY(m_resolved.has_value()); | 
					
						
							| 
									
										
										
										
											2024-03-03 15:49:53 +01:00
										 |  |  |  |     auto center = context.rounded_device_point(m_resolved->center).to_type<int>(); | 
					
						
							|  |  |  |  |     auto size = context.rounded_device_size(m_resolved->gradient_size).to_type<int>(); | 
					
						
							| 
									
										
										
										
											2024-08-06 15:26:47 +03:00
										 |  |  |  |     context.display_list_recorder().fill_rect_with_radial_gradient(dest_rect.to_type<int>(), m_resolved->data, center, size); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | } |