mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-25 09:30:01 +00:00 
			
		
		
		
	This reverts 0e3487b9ab.
Back when I made that change, I thought we could make our StyleValue
classes match the typed-om definitions directly. However, they have
different requirements. Typed-om types need to be mutable and GCed,
whereas StyleValues are immutable and ideally wouldn't require a JS VM.
While I was already making such a cataclysmic change, I've moved it into
the StyleValues directory, because it *not* being there has bothered me
for a long time. 😅
		
	
			
		
			
				
	
	
		
			80 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
 | |
|  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
 | |
|  * Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
 | |
|  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include "ConicGradientStyleValue.h"
 | |
| #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 | |
| #include <LibWeb/Layout/Node.h>
 | |
| #include <LibWeb/Painting/DisplayListRecorder.h>
 | |
| 
 | |
| namespace Web::CSS {
 | |
| 
 | |
| String ConicGradientStyleValue::to_string(SerializationMode mode) const
 | |
| {
 | |
|     StringBuilder builder;
 | |
|     if (is_repeating())
 | |
|         builder.append("repeating-"sv);
 | |
|     builder.append("conic-gradient("sv);
 | |
|     bool has_from_angle = m_properties.from_angle.to_degrees() != 0;
 | |
|     bool has_at_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);
 | |
| 
 | |
|     if (has_from_angle)
 | |
|         builder.appendff("from {}", m_properties.from_angle.to_string());
 | |
|     if (has_at_position) {
 | |
|         if (has_from_angle)
 | |
|             builder.append(' ');
 | |
|         builder.appendff("at {}", m_properties.position->to_string(mode));
 | |
|     }
 | |
|     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)
 | |
|         builder.append(", "sv);
 | |
|     serialize_color_stop_list(builder, m_properties.color_stop_list, mode);
 | |
|     builder.append(')');
 | |
|     return MUST(builder.to_string());
 | |
| }
 | |
| 
 | |
| void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyle const& node, CSSPixelSize size) const
 | |
| {
 | |
|     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);
 | |
|         m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} };
 | |
|     }
 | |
|     m_resolved->position = m_properties.position->resolved(node, CSSPixelRect { { 0, 0 }, size });
 | |
| }
 | |
| 
 | |
| void ConicGradientStyleValue::paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering) const
 | |
| {
 | |
|     VERIFY(m_resolved.has_value());
 | |
|     auto destination_rect = dest_rect.to_type<int>();
 | |
|     auto position = context.rounded_device_point(m_resolved->position).to_type<int>();
 | |
|     context.display_list_recorder().fill_rect_with_conic_gradient(destination_rect, m_resolved->data, position);
 | |
| }
 | |
| 
 | |
| bool ConicGradientStyleValue::equals(StyleValue const& other) const
 | |
| {
 | |
|     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();
 | |
| }
 | |
| 
 | |
| }
 |