LibWeb: Simplify interpolation of mixed percentage-dimension values
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This commit is contained in:
Tim Ledbetter 2025-09-10 18:34:29 +01:00 committed by Tim Ledbetter
commit bf8b8c260a
Notes: github-actions[bot] 2025-09-11 05:11:22 +00:00

View file

@ -1100,39 +1100,18 @@ static RefPtr<StyleValue const> interpolate_value_impl(DOM::Element& element, Ca
}
};
auto to_raw_value = [](StyleValue const& value) -> double {
switch (value.type()) {
case StyleValue::Type::Angle:
return value.as_angle().raw_value();
case StyleValue::Type::Frequency:
return value.as_frequency().raw_value();
case StyleValue::Type::Integer:
return value.as_integer().integer();
case StyleValue::Type::Length:
return value.as_length().raw_value();
case StyleValue::Type::Number:
return value.as_number().number();
case StyleValue::Type::Percentage:
return value.as_percentage().raw_value();
case StyleValue::Type::Time:
return value.as_time().raw_value();
default:
VERIFY_NOT_REACHED();
}
};
// https://drafts.csswg.org/css-values-4/#combine-mixed
// The computed value of a percentage-dimension mix is defined as
// FIXME: a computed dimension if the percentage component is zero or is defined specifically to compute to a dimension value
// a computed percentage if the dimension component is zero
// a computed calc() expression otherwise
if (from.type() != StyleValue::Type::Calculated && to.type() == StyleValue::Type::Percentage) {
auto dimension_component = to_raw_value(from) * (1.f - delta);
if (auto const* from_dimension_value = as_if<DimensionStyleValue>(from); from_dimension_value && to.type() == StyleValue::Type::Percentage) {
auto dimension_component = from_dimension_value->raw_value() * (1.f - delta);
auto percentage_component = to.as_percentage().raw_value() * delta;
if (dimension_component == 0.f)
return PercentageStyleValue::create(Percentage { percentage_component });
} else if (from.type() == StyleValue::Type::Percentage && to.type() != StyleValue::Type::Calculated) {
auto dimension_component = to_raw_value(to) * delta;
} else if (auto const* to_dimension_value = as_if<DimensionStyleValue>(to); to_dimension_value && from.type() == StyleValue::Type::Percentage) {
auto dimension_component = to_dimension_value->raw_value() * delta;
auto percentage_component = from.as_percentage().raw_value() * (1.f - delta);
if (dimension_component == 0)
return PercentageStyleValue::create(Percentage { percentage_component });