/* * Copyright (c) 2023-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "CalculatedOr.h" #include #include #include #include #include #include #include #include #include #include namespace Web::CSS { Optional AngleOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_angle(context); } NonnullRefPtr AngleOrCalculated::create_style_value() const { return AngleStyleValue::create(value()); } Optional FlexOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_flex(context); } NonnullRefPtr FlexOrCalculated::create_style_value() const { return FlexStyleValue::create(value()); } Optional FrequencyOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_frequency(context); } NonnullRefPtr FrequencyOrCalculated::create_style_value() const { return FrequencyStyleValue::create(value()); } Optional IntegerOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_integer_deprecated(context); } NonnullRefPtr IntegerOrCalculated::create_style_value() const { return IntegerStyleValue::create(value()); } Optional LengthOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_length_deprecated(context); } NonnullRefPtr LengthOrCalculated::create_style_value() const { return LengthStyleValue::create(value()); } Optional LengthOrAutoOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_length(context).map([](auto& length) { return LengthOrAuto { length }; }); } NonnullRefPtr 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()); if (is_calculated()) return calculated(); return value().length(); } Optional NumberOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_number_deprecated(context); } NonnullRefPtr NumberOrCalculated::create_style_value() const { return NumberStyleValue::create(value()); } Optional PercentageOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_percentage_deprecated(context); } NonnullRefPtr PercentageOrCalculated::create_style_value() const { return PercentageStyleValue::create(value()); } Optional ResolutionOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_resolution(context); } NonnullRefPtr ResolutionOrCalculated::create_style_value() const { return ResolutionStyleValue::create(value()); } Optional