mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 12:46:06 +00:00
LibWeb: Mark CalculatedStyleValue::resolve_*
methods as deprecated
The existing resolve methods are not to spec and we are working to replace them with new ones based on the `simplify_a_calculation_tree` method. These are marked as deprecated rather than replaced outright as work will need to be done on the caller side to be made compatible with the new methods, for instance the new methods can fail to resolve (e.g. if we are missing required context), where the existing methods will always resolve (albeit sometimes with an incorrect value). No functionality changes.
This commit is contained in:
parent
a13f6cdf86
commit
afa95c2815
Notes:
github-actions[bot]
2025-07-16 12:06:57 +00:00
Author: https://github.com/Calme1709
Commit: afa95c2815
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5305
Reviewed-by: https://github.com/AtkinsSJ ✅
22 changed files with 69 additions and 70 deletions
|
@ -53,12 +53,11 @@ Optional<double> CSSColorValue::resolve_hue(CSSStyleValue const& style_value, Ca
|
|||
|
||||
if (style_value.is_calculated()) {
|
||||
if (style_value.as_calculated().resolves_to_number())
|
||||
return normalized(style_value.as_calculated().resolve_number(resolution_context).value());
|
||||
return normalized(style_value.as_calculated().resolve_number_deprecated(resolution_context).value());
|
||||
|
||||
if (style_value.as_calculated().resolves_to_angle())
|
||||
return normalized(style_value.as_calculated().resolve_angle(resolution_context).value().to_degrees());
|
||||
return normalized(style_value.as_calculated().resolve_angle_deprecated(resolution_context).value().to_degrees());
|
||||
}
|
||||
|
||||
if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)
|
||||
return 0;
|
||||
|
||||
|
@ -81,9 +80,9 @@ Optional<double> CSSColorValue::resolve_with_reference_value(CSSStyleValue const
|
|||
if (style_value.is_calculated()) {
|
||||
auto const& calculated = style_value.as_calculated();
|
||||
if (calculated.resolves_to_number())
|
||||
return calculated.resolve_number(resolution_context).value();
|
||||
return calculated.resolve_number_deprecated(resolution_context).value();
|
||||
if (calculated.resolves_to_percentage())
|
||||
return normalize_percentage(calculated.resolve_percentage(resolution_context).value());
|
||||
return normalize_percentage(calculated.resolve_percentage_deprecated(resolution_context).value());
|
||||
}
|
||||
|
||||
if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)
|
||||
|
@ -110,9 +109,9 @@ Optional<double> CSSColorValue::resolve_alpha(CSSStyleValue const& style_value,
|
|||
if (style_value.is_calculated()) {
|
||||
auto const& calculated = style_value.as_calculated();
|
||||
if (calculated.resolves_to_number())
|
||||
return normalized(calculated.resolve_number(resolution_context).value());
|
||||
return normalized(calculated.resolve_number_deprecated(resolution_context).value());
|
||||
if (calculated.resolves_to_percentage())
|
||||
return normalized(calculated.resolve_percentage(resolution_context).value().as_fraction());
|
||||
return normalized(calculated.resolve_percentage_deprecated(resolution_context).value().as_fraction());
|
||||
}
|
||||
|
||||
if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)
|
||||
|
|
|
@ -33,9 +33,9 @@ Color CSSRGB::to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolu
|
|||
if (style_value.is_calculated()) {
|
||||
auto const& calculated = style_value.as_calculated();
|
||||
if (calculated.resolves_to_number())
|
||||
return normalized(calculated.resolve_number(resolution_context).value());
|
||||
return normalized(calculated.resolve_number_deprecated(resolution_context).value());
|
||||
if (calculated.resolves_to_percentage())
|
||||
return normalized(calculated.resolve_percentage(resolution_context).value().value() * 255 / 100);
|
||||
return normalized(calculated.resolve_percentage_deprecated(resolution_context).value().value() * 255 / 100);
|
||||
}
|
||||
|
||||
if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)
|
||||
|
|
|
@ -2669,7 +2669,7 @@ bool CalculatedStyleValue::equals(CSSStyleValue const& other) const
|
|||
return m_calculation->equals(*other.as_calculated().m_calculation);
|
||||
}
|
||||
|
||||
Optional<Angle> CalculatedStyleValue::resolve_angle(CalculationResolutionContext const& context) const
|
||||
Optional<Angle> CalculatedStyleValue::resolve_angle_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_angle(m_context.percentages_resolve_as))
|
||||
|
@ -2677,7 +2677,7 @@ Optional<Angle> CalculatedStyleValue::resolve_angle(CalculationResolutionContext
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Flex> CalculatedStyleValue::resolve_flex(CalculationResolutionContext const& context) const
|
||||
Optional<Flex> CalculatedStyleValue::resolve_flex_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_flex(m_context.percentages_resolve_as))
|
||||
|
@ -2685,7 +2685,7 @@ Optional<Flex> CalculatedStyleValue::resolve_flex(CalculationResolutionContext c
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Frequency> CalculatedStyleValue::resolve_frequency(CalculationResolutionContext const& context) const
|
||||
Optional<Frequency> CalculatedStyleValue::resolve_frequency_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_frequency(m_context.percentages_resolve_as))
|
||||
|
@ -2693,7 +2693,7 @@ Optional<Frequency> CalculatedStyleValue::resolve_frequency(CalculationResolutio
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Length> CalculatedStyleValue::resolve_length(CalculationResolutionContext const& context) const
|
||||
Optional<Length> CalculatedStyleValue::resolve_length_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_length(m_context.percentages_resolve_as))
|
||||
|
@ -2701,7 +2701,7 @@ Optional<Length> CalculatedStyleValue::resolve_length(CalculationResolutionConte
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Percentage> CalculatedStyleValue::resolve_percentage(CalculationResolutionContext const& context) const
|
||||
Optional<Percentage> CalculatedStyleValue::resolve_percentage_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_percentage())
|
||||
|
@ -2709,7 +2709,7 @@ Optional<Percentage> CalculatedStyleValue::resolve_percentage(CalculationResolut
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Resolution> CalculatedStyleValue::resolve_resolution(CalculationResolutionContext const& context) const
|
||||
Optional<Resolution> CalculatedStyleValue::resolve_resolution_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_resolution(m_context.percentages_resolve_as))
|
||||
|
@ -2717,7 +2717,7 @@ Optional<Resolution> CalculatedStyleValue::resolve_resolution(CalculationResolut
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Time> CalculatedStyleValue::resolve_time(CalculationResolutionContext const& context) const
|
||||
Optional<Time> CalculatedStyleValue::resolve_time_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_time(m_context.percentages_resolve_as))
|
||||
|
@ -2725,7 +2725,7 @@ Optional<Time> CalculatedStyleValue::resolve_time(CalculationResolutionContext c
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<double> CalculatedStyleValue::resolve_number(CalculationResolutionContext const& context) const
|
||||
Optional<double> CalculatedStyleValue::resolve_number_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (!result.type().has_value() || !result.type()->matches_number(m_context.percentages_resolve_as))
|
||||
|
@ -2740,7 +2740,7 @@ Optional<double> CalculatedStyleValue::resolve_number(CalculationResolutionConte
|
|||
return value;
|
||||
}
|
||||
|
||||
Optional<i64> CalculatedStyleValue::resolve_integer(CalculationResolutionContext const& context) const
|
||||
Optional<i64> CalculatedStyleValue::resolve_integer_deprecated(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_number(m_context.percentages_resolve_as))
|
||||
|
|
|
@ -77,32 +77,32 @@ public:
|
|||
|
||||
bool resolves_to_angle() const { return m_resolved_type.matches_angle(m_context.percentages_resolve_as); }
|
||||
bool resolves_to_angle_percentage() const { return m_resolved_type.matches_angle_percentage(m_context.percentages_resolve_as); }
|
||||
Optional<Angle> resolve_angle(CalculationResolutionContext const&) const;
|
||||
Optional<Angle> resolve_angle_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_flex() const { return m_resolved_type.matches_flex(m_context.percentages_resolve_as); }
|
||||
Optional<Flex> resolve_flex(CalculationResolutionContext const&) const;
|
||||
Optional<Flex> resolve_flex_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_frequency() const { return m_resolved_type.matches_frequency(m_context.percentages_resolve_as); }
|
||||
bool resolves_to_frequency_percentage() const { return m_resolved_type.matches_frequency_percentage(m_context.percentages_resolve_as); }
|
||||
Optional<Frequency> resolve_frequency(CalculationResolutionContext const&) const;
|
||||
Optional<Frequency> resolve_frequency_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_length() const { return m_resolved_type.matches_length(m_context.percentages_resolve_as); }
|
||||
bool resolves_to_length_percentage() const { return m_resolved_type.matches_length_percentage(m_context.percentages_resolve_as); }
|
||||
Optional<Length> resolve_length(CalculationResolutionContext const&) const;
|
||||
Optional<Length> resolve_length_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_percentage() const { return m_resolved_type.matches_percentage(); }
|
||||
Optional<Percentage> resolve_percentage(CalculationResolutionContext const&) const;
|
||||
Optional<Percentage> resolve_percentage_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_resolution() const { return m_resolved_type.matches_resolution(m_context.percentages_resolve_as); }
|
||||
Optional<Resolution> resolve_resolution(CalculationResolutionContext const&) const;
|
||||
Optional<Resolution> resolve_resolution_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_time() const { return m_resolved_type.matches_time(m_context.percentages_resolve_as); }
|
||||
bool resolves_to_time_percentage() const { return m_resolved_type.matches_time_percentage(m_context.percentages_resolve_as); }
|
||||
Optional<Time> resolve_time(CalculationResolutionContext const&) const;
|
||||
Optional<Time> resolve_time_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_number() const { return m_resolved_type.matches_number(m_context.percentages_resolve_as); }
|
||||
Optional<double> resolve_number(CalculationResolutionContext const&) const;
|
||||
Optional<i64> resolve_integer(CalculationResolutionContext const&) const;
|
||||
Optional<double> resolve_number_deprecated(CalculationResolutionContext const&) const;
|
||||
Optional<i64> resolve_integer_deprecated(CalculationResolutionContext const&) const;
|
||||
|
||||
bool resolves_to_dimension() const { return m_resolved_type.matches_dimension(); }
|
||||
|
||||
|
|
|
@ -102,14 +102,14 @@ String ColorFunctionStyleValue::to_string(SerializationMode mode) const
|
|||
CalculationResolutionContext context {};
|
||||
auto const& calculated = value->as_calculated();
|
||||
if (calculated.resolves_to_percentage()) {
|
||||
if (auto resolved_percentage = calculated.resolve_percentage(context); resolved_percentage.has_value()) {
|
||||
if (auto resolved_percentage = calculated.resolve_percentage_deprecated(context); resolved_percentage.has_value()) {
|
||||
auto resolved_number = resolved_percentage->value() / 100;
|
||||
if (!isfinite(resolved_number))
|
||||
resolved_number = 0;
|
||||
return NumberStyleValue::create(resolved_number);
|
||||
}
|
||||
} else if (calculated.resolves_to_number()) {
|
||||
if (auto resolved_number = calculated.resolve_number(context); resolved_number.has_value())
|
||||
if (auto resolved_number = calculated.resolve_number_deprecated(context); resolved_number.has_value())
|
||||
return NumberStyleValue::create(*resolved_number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,10 @@ float FilterOperation::Color::resolved_amount() const
|
|||
if (amount.is_calculated()) {
|
||||
CalculationResolutionContext context {};
|
||||
if (amount.calculated()->resolves_to_number())
|
||||
return amount.calculated()->resolve_number(context).value();
|
||||
return amount.calculated()->resolve_number_deprecated(context).value();
|
||||
|
||||
if (amount.calculated()->resolves_to_percentage())
|
||||
return amount.calculated()->resolve_percentage(context)->as_fraction();
|
||||
return amount.calculated()->resolve_percentage_deprecated(context)->as_fraction();
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
|
@ -68,7 +68,7 @@ String TransformationStyleValue::to_string(SerializationMode mode) const
|
|||
if (value->is_number())
|
||||
return value->as_number().number();
|
||||
if (value->is_calculated() && value->as_calculated().resolves_to_number())
|
||||
return value->as_calculated().resolve_number({});
|
||||
return value->as_calculated().resolve_number_deprecated({});
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue