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:
Callum Law 2025-07-02 19:12:33 +12:00 committed by Sam Atkins
commit afa95c2815
Notes: github-actions[bot] 2025-07-16 12:06:57 +00:00
22 changed files with 69 additions and 70 deletions

View file

@ -88,7 +88,7 @@ Optional<Angle::Type> Angle::unit_from_name(StringView name)
Angle Angle::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Angle const& reference_value) Angle Angle::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Angle const& reference_value)
{ {
return calculated->resolve_angle( return calculated->resolve_angle_deprecated(
{ {
.percentage_basis = reference_value, .percentage_basis = reference_value,
.length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node), .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node),

View file

@ -450,7 +450,7 @@ int CSSStyleValue::to_font_weight() const
return round_to<int>(as_number().number()); return round_to<int>(as_number().number());
} }
if (is_calculated()) { if (is_calculated()) {
auto maybe_weight = as_calculated().resolve_integer({}); auto maybe_weight = as_calculated().resolve_integer_deprecated({});
if (maybe_weight.has_value()) if (maybe_weight.has_value())
return maybe_weight.value(); return maybe_weight.value();
} }

View file

@ -19,7 +19,7 @@ namespace Web::CSS {
Optional<Angle> AngleOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Angle> AngleOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_angle(context); return calculated->resolve_angle_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> AngleOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> AngleOrCalculated::create_style_value() const
@ -29,7 +29,7 @@ NonnullRefPtr<CSSStyleValue const> AngleOrCalculated::create_style_value() const
Optional<Flex> FlexOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Flex> FlexOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_flex(context); return calculated->resolve_flex_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> FlexOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> FlexOrCalculated::create_style_value() const
@ -39,7 +39,7 @@ NonnullRefPtr<CSSStyleValue const> FlexOrCalculated::create_style_value() const
Optional<Frequency> FrequencyOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Frequency> FrequencyOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_frequency(context); return calculated->resolve_frequency_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> FrequencyOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> FrequencyOrCalculated::create_style_value() const
@ -49,7 +49,7 @@ NonnullRefPtr<CSSStyleValue const> FrequencyOrCalculated::create_style_value() c
Optional<i64> IntegerOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<i64> IntegerOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_integer(context); return calculated->resolve_integer_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> IntegerOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> IntegerOrCalculated::create_style_value() const
@ -59,7 +59,7 @@ NonnullRefPtr<CSSStyleValue const> IntegerOrCalculated::create_style_value() con
Optional<Length> LengthOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Length> LengthOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_length(context); return calculated->resolve_length_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> LengthOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> LengthOrCalculated::create_style_value() const
@ -69,7 +69,7 @@ NonnullRefPtr<CSSStyleValue const> LengthOrCalculated::create_style_value() cons
Optional<double> NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<double> NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_number(context); return calculated->resolve_number_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> NumberOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> NumberOrCalculated::create_style_value() const
@ -79,7 +79,7 @@ NonnullRefPtr<CSSStyleValue const> NumberOrCalculated::create_style_value() cons
Optional<Percentage> PercentageOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Percentage> PercentageOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_percentage(context); return calculated->resolve_percentage_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> PercentageOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> PercentageOrCalculated::create_style_value() const
@ -89,7 +89,7 @@ NonnullRefPtr<CSSStyleValue const> PercentageOrCalculated::create_style_value()
Optional<Resolution> ResolutionOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Resolution> ResolutionOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_resolution(context); return calculated->resolve_resolution_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> ResolutionOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> ResolutionOrCalculated::create_style_value() const
@ -99,7 +99,7 @@ NonnullRefPtr<CSSStyleValue const> ResolutionOrCalculated::create_style_value()
Optional<Time> TimeOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const Optional<Time> TimeOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
{ {
return calculated->resolve_time(context); return calculated->resolve_time_deprecated(context);
} }
NonnullRefPtr<CSSStyleValue const> TimeOrCalculated::create_style_value() const NonnullRefPtr<CSSStyleValue const> TimeOrCalculated::create_style_value() const

View file

@ -309,7 +309,7 @@ CSSPixels ComputedProperties::compute_line_height(CSSPixelRect const& viewport_r
.length_resolution_context = Length::ResolutionContext { viewport_rect, font_metrics, root_font_metrics }, .length_resolution_context = Length::ResolutionContext { viewport_rect, font_metrics, root_font_metrics },
}; };
if (line_height.as_calculated().resolves_to_number()) { if (line_height.as_calculated().resolves_to_number()) {
auto resolved = line_height.as_calculated().resolve_number(context); auto resolved = line_height.as_calculated().resolve_number_deprecated(context);
if (!resolved.has_value()) { if (!resolved.has_value()) {
dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height.as_calculated().to_string(SerializationMode::Normal)); dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height.as_calculated().to_string(SerializationMode::Normal));
return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing()); return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing());
@ -317,7 +317,7 @@ CSSPixels ComputedProperties::compute_line_height(CSSPixelRect const& viewport_r
return Length(resolved.value(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); return Length(resolved.value(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
} }
auto resolved = line_height.as_calculated().resolve_length(context); auto resolved = line_height.as_calculated().resolve_length_deprecated(context);
if (!resolved.has_value()) { if (!resolved.has_value()) {
dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height.as_calculated().to_string(SerializationMode::Normal)); dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height.as_calculated().to_string(SerializationMode::Normal));
return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing()); return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing());
@ -347,7 +347,7 @@ Optional<int> ComputedProperties::z_index() const
return clamp(value.as_integer().integer()); return clamp(value.as_integer().integer());
} }
if (value.is_calculated()) { if (value.is_calculated()) {
auto maybe_double = value.as_calculated().resolve_number({}); auto maybe_double = value.as_calculated().resolve_number_deprecated({});
if (maybe_double.has_value()) { if (maybe_double.has_value()) {
return clamp(maybe_double.value()); return clamp(maybe_double.value());
} }
@ -365,13 +365,13 @@ float ComputedProperties::resolve_opacity_value(CSSStyleValue const& value)
auto const& calculated = value.as_calculated(); auto const& calculated = value.as_calculated();
CalculationResolutionContext context {}; CalculationResolutionContext context {};
if (calculated.resolves_to_percentage()) { if (calculated.resolves_to_percentage()) {
auto maybe_percentage = value.as_calculated().resolve_percentage(context); auto maybe_percentage = value.as_calculated().resolve_percentage_deprecated(context);
if (maybe_percentage.has_value()) if (maybe_percentage.has_value())
unclamped_opacity = maybe_percentage->as_fraction(); unclamped_opacity = maybe_percentage->as_fraction();
else else
dbgln("Unable to resolve calc() as opacity (percentage): {}", value.to_string(SerializationMode::Normal)); dbgln("Unable to resolve calc() as opacity (percentage): {}", value.to_string(SerializationMode::Normal));
} else if (calculated.resolves_to_number()) { } else if (calculated.resolves_to_number()) {
auto maybe_number = value.as_calculated().resolve_number(context); auto maybe_number = value.as_calculated().resolve_number_deprecated(context);
if (maybe_number.has_value()) if (maybe_number.has_value())
unclamped_opacity = maybe_number.value(); unclamped_opacity = maybe_number.value();
else else
@ -517,7 +517,7 @@ Length ComputedProperties::border_spacing_horizontal(Layout::Node const& layout_
if (style_value.is_length()) if (style_value.is_length())
return style_value.as_length().length(); return style_value.as_length().length();
if (style_value.is_calculated()) if (style_value.is_calculated())
return style_value.as_calculated().resolve_length({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }).value_or(Length(0, Length::Type::Px)); return style_value.as_calculated().resolve_length_deprecated({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }).value_or(Length(0, Length::Type::Px));
return {}; return {};
}; };
@ -539,7 +539,7 @@ Length ComputedProperties::border_spacing_vertical(Layout::Node const& layout_no
if (style_value.is_length()) if (style_value.is_length())
return style_value.as_length().length(); return style_value.as_length().length();
if (style_value.is_calculated()) if (style_value.is_calculated())
return style_value.as_calculated().resolve_length({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }).value_or(Length(0, Length::Type::Px)); return style_value.as_calculated().resolve_length_deprecated({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }).value_or(Length(0, Length::Type::Px));
return {}; return {};
}; };
@ -1181,7 +1181,7 @@ Vector<ShadowData> ComputedProperties::shadow(PropertyID property_id, Layout::No
if (value->is_length()) if (value->is_length())
return value->as_length().length(); return value->as_length().length();
if (value->is_calculated()) if (value->is_calculated())
return value->as_calculated().resolve_length({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }); return value->as_calculated().resolve_length_deprecated({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) });
return {}; return {};
}; };
@ -1883,7 +1883,7 @@ Vector<CounterData> ComputedProperties::counter_data(PropertyID property_id) con
if (counter.value->is_integer()) { if (counter.value->is_integer()) {
data.value = AK::clamp_to<i32>(counter.value->as_integer().integer()); data.value = AK::clamp_to<i32>(counter.value->as_integer().integer());
} else if (counter.value->is_calculated()) { } else if (counter.value->is_calculated()) {
auto maybe_int = counter.value->as_calculated().resolve_integer({}); auto maybe_int = counter.value->as_calculated().resolve_integer_deprecated({});
if (maybe_int.has_value()) if (maybe_int.has_value())
data.value = AK::clamp_to<i32>(*maybe_int); data.value = AK::clamp_to<i32>(*maybe_int);
} else { } else {

View file

@ -67,7 +67,7 @@ Optional<Frequency::Type> Frequency::unit_from_name(StringView name)
Frequency Frequency::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Frequency const& reference_value) Frequency Frequency::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Frequency const& reference_value)
{ {
return calculated->resolve_frequency( return calculated->resolve_frequency_deprecated(
{ {
.percentage_basis = reference_value, .percentage_basis = reference_value,
.length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node), .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node),

View file

@ -423,7 +423,7 @@ Length Length::absolutized(CSSPixelRect const& viewport_rect, FontMetrics const&
Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Length const& reference_value) Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Length const& reference_value)
{ {
return calculated->resolve_length( return calculated->resolve_length_deprecated(
{ {
.percentage_basis = reference_value, .percentage_basis = reference_value,
.length_resolution_context = ResolutionContext::for_layout_node(layout_node), .length_resolution_context = ResolutionContext::for_layout_node(layout_node),
@ -433,7 +433,7 @@ Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> cons
Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, CSSPixels reference_value) Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, CSSPixels reference_value)
{ {
return calculated->resolve_length( return calculated->resolve_length_deprecated(
{ {
.percentage_basis = make_px(reference_value), .percentage_basis = make_px(reference_value),
.length_resolution_context = ResolutionContext::for_layout_node(layout_node), .length_resolution_context = ResolutionContext::for_layout_node(layout_node),

View file

@ -60,7 +60,7 @@ ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& de
return value.as_percentage().percentage(); return value.as_percentage().percentage();
if (value.is_calculated()) { if (value.is_calculated()) {
// FIXME: These should probably be simplified already? // FIXME: These should probably be simplified already?
return value.as_calculated().resolve_percentage({}); return value.as_calculated().resolve_percentage_deprecated({});
} }
if (value.to_keyword() == Keyword::Normal) if (value.to_keyword() == Keyword::Normal)
return {}; return {};
@ -139,7 +139,7 @@ ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& de
if (setting_value->is_integer()) { if (setting_value->is_integer()) {
settings.set(feature_tag->as_open_type_tagged().tag(), setting_value->as_integer().integer()); settings.set(feature_tag->as_open_type_tagged().tag(), setting_value->as_integer().integer());
} else if (setting_value->is_calculated() && setting_value->as_calculated().resolves_to_number()) { } else if (setting_value->is_calculated() && setting_value->as_calculated().resolves_to_number()) {
if (auto integer = setting_value->as_calculated().resolve_integer({}); integer.has_value()) { if (auto integer = setting_value->as_calculated().resolve_integer_deprecated({}); integer.has_value()) {
settings.set(feature_tag->as_open_type_tagged().tag(), *integer); settings.set(feature_tag->as_open_type_tagged().tag(), *integer);
} }
} }
@ -161,7 +161,7 @@ ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& de
if (setting_value->is_number()) { if (setting_value->is_number()) {
settings.set(variation_tag->as_open_type_tagged().tag(), setting_value->as_number().number()); settings.set(variation_tag->as_open_type_tagged().tag(), setting_value->as_number().number());
} else if (setting_value->is_calculated() && setting_value->as_calculated().resolves_to_number()) { } else if (setting_value->is_calculated() && setting_value->as_calculated().resolves_to_number()) {
if (auto number = setting_value->as_calculated().resolve_number({}); number.has_value()) { if (auto number = setting_value->as_calculated().resolve_number_deprecated({}); number.has_value()) {
settings.set(variation_tag->as_open_type_tagged().tag(), *number); settings.set(variation_tag->as_open_type_tagged().tag(), *number);
} }
} }

View file

@ -188,7 +188,7 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue const>> Parser::parse_descripto
} }
// All calculations in descriptors must be resolvable at parse-time. // All calculations in descriptors must be resolvable at parse-time.
if (percentage_value->is_calculated()) { if (percentage_value->is_calculated()) {
auto percentage = percentage_value->as_calculated().resolve_percentage({}); auto percentage = percentage_value->as_calculated().resolve_percentage_deprecated({});
if (percentage.has_value() && percentage->value() >= 0) if (percentage.has_value() && percentage->value() >= 0)
return PercentageStyleValue::create(percentage.release_value()); return PercentageStyleValue::create(percentage.release_value());
return nullptr; return nullptr;

View file

@ -3629,7 +3629,7 @@ RefPtr<CSSStyleValue const> Parser::parse_opacity_value(PropertyID property_id,
if (value->is_percentage()) if (value->is_percentage())
value = NumberStyleValue::create(value->as_percentage().percentage().as_fraction()); value = NumberStyleValue::create(value->as_percentage().percentage().as_fraction());
if (value->is_calculated() && value->as_calculated().resolves_to_percentage()) { if (value->is_calculated() && value->as_calculated().resolves_to_percentage()) {
auto maybe_percentage = value->as_calculated().resolve_percentage({}); auto maybe_percentage = value->as_calculated().resolve_percentage_deprecated({});
if (maybe_percentage.has_value()) { if (maybe_percentage.has_value()) {
auto resolved_percentage = maybe_percentage->as_fraction(); auto resolved_percentage = maybe_percentage->as_fraction();
CalculationContext context {}; CalculationContext context {};

View file

@ -363,7 +363,7 @@ Optional<Ratio> Parser::parse_ratio(TokenStream<ComponentValue>& tokens)
return maybe_calc->as_number().value(); return maybe_calc->as_number().value();
if (!maybe_calc->is_calculated() || !maybe_calc->as_calculated().resolves_to_number()) if (!maybe_calc->is_calculated() || !maybe_calc->as_calculated().resolves_to_number())
return {}; return {};
if (auto resolved_number = maybe_calc->as_calculated().resolve_number({}); resolved_number.has_value() && resolved_number.value() >= 0) { if (auto resolved_number = maybe_calc->as_calculated().resolve_number_deprecated({}); resolved_number.has_value() && resolved_number.value() >= 0) {
return resolved_number.value(); return resolved_number.value();
} }
} }

View file

@ -1972,7 +1972,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
} else if (font_size.is_length()) { } else if (font_size.is_length()) {
maybe_length = font_size.as_length().length(); maybe_length = font_size.as_length().length();
} else if (font_size.is_calculated()) { } else if (font_size.is_calculated()) {
maybe_length = font_size.as_calculated().resolve_length({ maybe_length = font_size.as_calculated().resolve_length_deprecated({
.percentage_basis = Length::make_px(parent_font_size), .percentage_basis = Length::make_px(parent_font_size),
.length_resolution_context = length_resolution_context, .length_resolution_context = length_resolution_context,
}); });
@ -3196,7 +3196,7 @@ void StyleComputer::compute_math_depth(ComputedProperties& style, DOM::Element c
if (integer_value.is_integer()) if (integer_value.is_integer())
return integer_value.as_integer().integer(); return integer_value.as_integer().integer();
if (integer_value.is_calculated()) if (integer_value.is_calculated())
return integer_value.as_calculated().resolve_integer({}).value(); return integer_value.as_calculated().resolve_integer_deprecated({}).value();
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
}; };

View file

@ -53,12 +53,11 @@ Optional<double> CSSColorValue::resolve_hue(CSSStyleValue const& style_value, Ca
if (style_value.is_calculated()) { if (style_value.is_calculated()) {
if (style_value.as_calculated().resolves_to_number()) 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()) 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) if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)
return 0; return 0;
@ -81,9 +80,9 @@ Optional<double> CSSColorValue::resolve_with_reference_value(CSSStyleValue const
if (style_value.is_calculated()) { if (style_value.is_calculated()) {
auto const& calculated = style_value.as_calculated(); auto const& calculated = style_value.as_calculated();
if (calculated.resolves_to_number()) 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()) 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) 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()) { if (style_value.is_calculated()) {
auto const& calculated = style_value.as_calculated(); auto const& calculated = style_value.as_calculated();
if (calculated.resolves_to_number()) 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()) 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) if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)

View file

@ -33,9 +33,9 @@ Color CSSRGB::to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolu
if (style_value.is_calculated()) { if (style_value.is_calculated()) {
auto const& calculated = style_value.as_calculated(); auto const& calculated = style_value.as_calculated();
if (calculated.resolves_to_number()) 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()) 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) if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)

View file

@ -2669,7 +2669,7 @@ bool CalculatedStyleValue::equals(CSSStyleValue const& other) const
return m_calculation->equals(*other.as_calculated().m_calculation); 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_angle(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_flex(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_frequency(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_length(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_percentage()) if (result.type().has_value() && result.type()->matches_percentage())
@ -2709,7 +2709,7 @@ Optional<Percentage> CalculatedStyleValue::resolve_percentage(CalculationResolut
return {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_resolution(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_time(m_context.percentages_resolve_as)) 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 {}; 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); auto result = m_calculation->resolve(context);
if (!result.type().has_value() || !result.type()->matches_number(m_context.percentages_resolve_as)) 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; 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); auto result = m_calculation->resolve(context);
if (result.type().has_value() && result.type()->matches_number(m_context.percentages_resolve_as)) if (result.type().has_value() && result.type()->matches_number(m_context.percentages_resolve_as))

View file

@ -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() 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); } 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); } 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() 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); } 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() 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); } 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(); } 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); } 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() 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); } 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); } bool resolves_to_number() const { return m_resolved_type.matches_number(m_context.percentages_resolve_as); }
Optional<double> resolve_number(CalculationResolutionContext const&) const; Optional<double> resolve_number_deprecated(CalculationResolutionContext const&) const;
Optional<i64> resolve_integer(CalculationResolutionContext const&) const; Optional<i64> resolve_integer_deprecated(CalculationResolutionContext const&) const;
bool resolves_to_dimension() const { return m_resolved_type.matches_dimension(); } bool resolves_to_dimension() const { return m_resolved_type.matches_dimension(); }

View file

@ -102,14 +102,14 @@ String ColorFunctionStyleValue::to_string(SerializationMode mode) const
CalculationResolutionContext context {}; CalculationResolutionContext context {};
auto const& calculated = value->as_calculated(); auto const& calculated = value->as_calculated();
if (calculated.resolves_to_percentage()) { 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; auto resolved_number = resolved_percentage->value() / 100;
if (!isfinite(resolved_number)) if (!isfinite(resolved_number))
resolved_number = 0; resolved_number = 0;
return NumberStyleValue::create(resolved_number); return NumberStyleValue::create(resolved_number);
} }
} else if (calculated.resolves_to_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); return NumberStyleValue::create(*resolved_number);
} }
} }

View file

@ -34,10 +34,10 @@ float FilterOperation::Color::resolved_amount() const
if (amount.is_calculated()) { if (amount.is_calculated()) {
CalculationResolutionContext context {}; CalculationResolutionContext context {};
if (amount.calculated()->resolves_to_number()) 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()) 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(); VERIFY_NOT_REACHED();

View file

@ -68,7 +68,7 @@ String TransformationStyleValue::to_string(SerializationMode mode) const
if (value->is_number()) if (value->is_number())
return value->as_number().number(); return value->as_number().number();
if (value->is_calculated() && value->as_calculated().resolves_to_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(); VERIFY_NOT_REACHED();
}; };

View file

@ -78,7 +78,7 @@ Optional<Time::Type> Time::unit_from_name(StringView name)
Time Time::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Time const& reference_value) Time Time::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Time const& reference_value)
{ {
return calculated->resolve_time( return calculated->resolve_time_deprecated(
{ {
.percentage_basis = reference_value, .percentage_basis = reference_value,
.length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node), .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node),

View file

@ -43,7 +43,7 @@ ErrorOr<Gfx::FloatMatrix4x4> Transformation::to_matrix(Optional<Painting::Painta
return length.absolute_length_to_px().to_float(); return length.absolute_length_to_px().to_float();
} }
if (value.is_calculated() && value.calculated()->resolves_to_length()) { if (value.is_calculated() && value.calculated()->resolves_to_length()) {
if (auto const& resolved = value.calculated()->resolve_length(context); resolved->is_absolute()) if (auto const& resolved = value.calculated()->resolve_length_deprecated(context); resolved->is_absolute())
return resolved->absolute_length_to_px().to_float(); return resolved->absolute_length_to_px().to_float();
} }
return Error::from_string_literal("Transform contains non absolute units"); return Error::from_string_literal("Transform contains non absolute units");
@ -55,9 +55,9 @@ ErrorOr<Gfx::FloatMatrix4x4> Transformation::to_matrix(Optional<Painting::Painta
return value.percentage().as_fraction(); return value.percentage().as_fraction();
if (value.is_calculated()) { if (value.is_calculated()) {
if (value.calculated()->resolves_to_number()) if (value.calculated()->resolves_to_number())
return value.calculated()->resolve_number(context).value(); return value.calculated()->resolve_number_deprecated(context).value();
if (value.calculated()->resolves_to_percentage()) if (value.calculated()->resolves_to_percentage())
return value.calculated()->resolve_percentage(context)->as_fraction(); return value.calculated()->resolve_percentage_deprecated(context)->as_fraction();
} }
return Error::from_string_literal("Transform contains non absolute units"); return Error::from_string_literal("Transform contains non absolute units");
}); });

View file

@ -563,7 +563,7 @@ void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* co
auto containing_block_size_as_length = width ? containing_block_used_values->content_width() : containing_block_used_values->content_height(); auto containing_block_size_as_length = width ? containing_block_used_values->content_width() : containing_block_used_values->content_height();
context.percentage_basis = CSS::Length::make_px(containing_block_size_as_length); context.percentage_basis = CSS::Length::make_px(containing_block_size_as_length);
} }
resolved_definite_size = clamp_to_max_dimension_value(adjust_for_box_sizing(size.calculated().resolve_length(context)->to_px(node), size, width)); resolved_definite_size = clamp_to_max_dimension_value(adjust_for_box_sizing(size.calculated().resolve_length_deprecated(context)->to_px(node), size, width));
return true; return true;
} }

View file

@ -781,14 +781,14 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
computed_values.set_transition_delay(transition_delay.time()); computed_values.set_transition_delay(transition_delay.time());
} else if (transition_delay_property.is_calculated()) { } else if (transition_delay_property.is_calculated()) {
auto const& transition_delay = transition_delay_property.as_calculated(); auto const& transition_delay = transition_delay_property.as_calculated();
computed_values.set_transition_delay(transition_delay.resolve_time({ .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*this) }).value()); computed_values.set_transition_delay(transition_delay.resolve_time_deprecated({ .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*this) }).value());
} }
auto resolve_border_width = [&](CSS::PropertyID width_property) -> CSSPixels { auto resolve_border_width = [&](CSS::PropertyID width_property) -> CSSPixels {
auto const& value = computed_style.property(width_property); auto const& value = computed_style.property(width_property);
if (value.is_calculated()) if (value.is_calculated())
return max(CSSPixels { 0 }, return max(CSSPixels { 0 },
value.as_calculated().resolve_length({ .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*this) })->to_px(*this)); value.as_calculated().resolve_length_deprecated({ .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*this) })->to_px(*this));
if (value.is_length()) { if (value.is_length()) {
// FIXME: Currently, interpolation can set property values outside of their valid range. // FIXME: Currently, interpolation can set property values outside of their valid range.
// We should instead clamp property values to the valid range when interpolating. // We should instead clamp property values to the valid range when interpolating.