mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Simplify interpolation of mixed percentage-dimension values
This commit is contained in:
parent
a46453f234
commit
bf8b8c260a
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user