| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2025-01-22 15:00:13 +00:00
										 |  |  |  * Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "CalculatedOr.h"
 | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-27 17:07:21 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Angle> AngleOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 12:51:53 +01:00
										 |  |  |     return calculated->resolve_angle(context); | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> AngleOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return AngleStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Flex> FlexOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-12-27 12:56:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 13:16:12 +01:00
										 |  |  |     return calculated->resolve_flex(context); | 
					
						
							| 
									
										
										
										
											2023-12-27 12:56:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> FlexOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return FlexStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Frequency> FrequencyOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 13:40:49 +01:00
										 |  |  |     return calculated->resolve_frequency(context); | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> FrequencyOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return FrequencyStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<i64> IntegerOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-12-27 12:56:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 14:06:10 +01:00
										 |  |  |     return calculated->resolve_integer(context); | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> IntegerOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return IntegerStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Length> LengthOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 14:33:18 +01:00
										 |  |  |     return calculated->resolve_length(context); | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> LengthOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return LengthStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-27 17:07:21 +01:00
										 |  |  | Optional<LengthOrAuto> LengthOrAutoOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return calculated->resolve_length(context).map([](auto& length) { return LengthOrAuto { length }; }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NonnullRefPtr<StyleValue const> LengthOrAutoOrCalculated::create_style_value() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto const& length_or_auto = value(); | 
					
						
							|  |  |  |     if (length_or_auto.is_auto()) | 
					
						
							|  |  |  |         return KeywordStyleValue::create(Keyword::Auto); | 
					
						
							|  |  |  |     return LengthStyleValue::create(length_or_auto.length()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool LengthOrAutoOrCalculated::is_auto() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return !is_calculated() && value().is_auto(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LengthOrCalculated LengthOrAutoOrCalculated::without_auto() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(!is_auto()); | 
					
						
							| 
									
										
										
										
											2025-09-08 17:50:49 +02:00
										 |  |  |     if (is_calculated()) | 
					
						
							|  |  |  |         return calculated(); | 
					
						
							| 
									
										
										
										
											2025-08-27 17:07:21 +01:00
										 |  |  |     return value().length(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<double> NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-12-27 12:56:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 14:16:48 +01:00
										 |  |  |     return calculated->resolve_number(context); | 
					
						
							| 
									
										
										
										
											2023-12-27 12:56:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> NumberOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return NumberStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Percentage> PercentageOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 14:25:03 +01:00
										 |  |  |     return calculated->resolve_percentage(context); | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> PercentageOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return PercentageStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Resolution> ResolutionOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 13:49:59 +01:00
										 |  |  |     return calculated->resolve_resolution(context); | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> ResolutionOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return ResolutionStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Optional<Time> TimeOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-24 13:57:37 +01:00
										 |  |  |     return calculated->resolve_time(context); | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | NonnullRefPtr<StyleValue const> TimeOrCalculated::create_style_value() const | 
					
						
							| 
									
										
										
										
											2023-12-28 17:37:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return TimeStyleValue::create(value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 16:57:49 +01:00
										 |  |  | } |