Skip to content

Commit 674e1a5

Browse files
committed
LibWeb: Support transitions between 3D and non-derivative 2D functions
If either of the two transform functions during interpolation is a 3D function, both of them get coerced to a 3D function before deciding what to do next. However, we only supported converting 2D functions to 3D if they had a 2D primitive they could be converted to first. Change our behavior to default to converting to matrix3d() if there is no explicit conversion path. Fixes a crash in `css/css-transforms/animation/transform-interpolation-004.html`.
1 parent 8348c55 commit 674e1a5

File tree

3 files changed

+493
-7
lines changed

3 files changed

+493
-7
lines changed

Libraries/LibWeb/CSS/Interpolation.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,15 @@ static Optional<FloatMatrix4x4> interpolate_matrices(FloatMatrix4x4 const& from,
971971
return recompose(interpolated_decomposed);
972972
}
973973

974+
static StyleValueVector matrix_to_style_value_vector(FloatMatrix4x4 const& matrix)
975+
{
976+
StyleValueVector values;
977+
values.ensure_capacity(16);
978+
for (int i = 0; i < 16; i++)
979+
values.unchecked_append(NumberStyleValue::create(matrix[i % 4, i / 4]));
980+
return values;
981+
}
982+
974983
// https://drafts.csswg.org/css-transforms-1/#interpolation-of-transforms
975984
RefPtr<StyleValue const> interpolate_transform(DOM::Element& element, CalculationContext const& calculation_context,
976985
StyleValue const& from, StyleValue const& to, float delta, AllowDiscrete)
@@ -1153,7 +1162,8 @@ RefPtr<StyleValue const> interpolate_transform(DOM::Element& element, Calculatio
11531162
parameters.append(transform->values()[0]);
11541163
break;
11551164
default:
1156-
VERIFY_NOT_REACHED();
1165+
generic_function = TransformFunction::Matrix3d;
1166+
parameters = matrix_to_style_value_vector(MUST(transform->to_transformation().to_matrix({})));
11571167
}
11581168
return TransformationStyleValue::create(PropertyID::Transform, generic_function, move(parameters));
11591169
};
@@ -1272,12 +1282,8 @@ RefPtr<StyleValue const> interpolate_transform(DOM::Element& element, Calculatio
12721282

12731283
auto maybe_interpolated_matrix = interpolate_matrices(from_matrix, to_matrix, delta);
12741284
if (maybe_interpolated_matrix.has_value()) {
1275-
auto interpolated_matrix = maybe_interpolated_matrix.release_value();
1276-
StyleValueVector values;
1277-
values.ensure_capacity(16);
1278-
for (int i = 0; i < 16; i++)
1279-
values.unchecked_append(NumberStyleValue::create(interpolated_matrix[i % 4, i / 4]));
1280-
result.append(TransformationStyleValue::create(PropertyID::Transform, TransformFunction::Matrix3d, move(values)));
1285+
result.append(TransformationStyleValue::create(PropertyID::Transform, TransformFunction::Matrix3d,
1286+
matrix_to_style_value_vector(maybe_interpolated_matrix.release_value())));
12811287
} else {
12821288
dbgln("Unable to interpolate matrices.");
12831289
}

0 commit comments

Comments
 (0)