| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +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:09:41 +00:00
										 |  |  |  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ConicGradientStyleValue.h"
 | 
					
						
							| 
									
										
										
										
											2023-11-07 12:16:42 +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:09:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-07 00:59:49 +01:00
										 |  |  | String ConicGradientStyleValue::to_string(SerializationMode mode) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     if (is_repeating()) | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |         builder.append("repeating-"sv); | 
					
						
							|  |  |  |     builder.append("conic-gradient("sv); | 
					
						
							| 
									
										
										
										
											2023-11-07 12:16:42 +00:00
										 |  |  |     bool has_from_angle = m_properties.from_angle.to_degrees() != 0; | 
					
						
							|  |  |  |     bool has_at_position = !m_properties.position->is_center(); | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |     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-11-07 12:16:42 +00:00
										 |  |  |     if (has_from_angle) | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |         builder.appendff("from {}", m_properties.from_angle.to_string()); | 
					
						
							| 
									
										
										
										
											2023-11-07 12:16:42 +00:00
										 |  |  |     if (has_at_position) { | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  |         if (has_from_angle) | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |             builder.append(' '); | 
					
						
							| 
									
										
										
										
											2025-04-08 13:50:50 -04:00
										 |  |  |         builder.appendff("at {}", m_properties.position->to_string(mode)); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-19 21:02:12 +11:00
										 |  |  |     if (has_color_space) { | 
					
						
							|  |  |  |         if (has_from_angle || has_at_position) | 
					
						
							|  |  |  |             builder.append(' '); | 
					
						
							|  |  |  |         builder.append(m_properties.interpolation_method.value().to_string()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (has_from_angle || has_at_position || has_color_space) | 
					
						
							| 
									
										
										
										
											2023-08-22 14:08:15 +01:00
										 |  |  |         builder.append(", "sv); | 
					
						
							| 
									
										
										
										
											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:09:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 16:13:37 +00:00
										 |  |  | void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyle const& node, CSSPixelSize size) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-02-21 16:45:07 +00:00
										 |  |  |     ResolvedDataCacheKey cache_key { | 
					
						
							|  |  |  |         .length_resolution_context = Length::ResolutionContext::for_layout_node(node), | 
					
						
							|  |  |  |         .size = size, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     if (m_resolved_data_cache_key != cache_key) { | 
					
						
							|  |  |  |         m_resolved_data_cache_key = move(cache_key); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  |         m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} }; | 
					
						
							| 
									
										
										
										
											2025-02-21 16:45:07 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-07 12:16:42 +00:00
										 |  |  |     m_resolved->position = m_properties.position->resolved(node, CSSPixelRect { { 0, 0 }, size }); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-31 23:07:26 +02:00
										 |  |  | void ConicGradientStyleValue::paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     VERIFY(m_resolved.has_value()); | 
					
						
							| 
									
										
										
										
											2024-03-03 15:49:53 +01:00
										 |  |  |     auto destination_rect = dest_rect.to_type<int>(); | 
					
						
							|  |  |  |     auto position = context.rounded_device_point(m_resolved->position).to_type<int>(); | 
					
						
							| 
									
										
										
										
											2024-08-06 15:26:47 +03:00
										 |  |  |     context.display_list_recorder().fill_rect_with_conic_gradient(destination_rect, m_resolved->data, position); | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | bool ConicGradientStyleValue::equals(StyleValue const& other) const | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     if (type() != other.type()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     auto& other_gradient = other.as_conic_gradient(); | 
					
						
							|  |  |  |     return m_properties == other_gradient.m_properties; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float ConicGradientStyleValue::angle_degrees() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_properties.from_angle.to_degrees(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |