mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Make CSSPerspective correctly clamp its input for toMatrix()
This commit is contained in:
parent
684c543ddb
commit
edccb92da7
Notes:
github-actions[bot]
2025-11-13 14:48:12 +00:00
Author: https://github.com/Psychpsyo
Commit: edccb92da7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6806
Reviewed-by: https://github.com/gmta ✅
2 changed files with 10 additions and 9 deletions
|
|
@ -121,7 +121,7 @@ WebIDL::ExceptionOr<GC::Ref<Geometry::DOMMatrix>> CSSPerspective::to_matrix() co
|
|||
[&matrix](GC::Ref<CSSNumericValue> const& numeric_value) -> WebIDL::ExceptionOr<void> {
|
||||
// NB: to() throws a TypeError if the conversion can't be done.
|
||||
auto distance = TRY(numeric_value->to("px"_fly_string))->value();
|
||||
matrix->set_m34(-1 / (distance <= 0 ? 1 : distance));
|
||||
matrix->set_m34(-1 / max(distance, 1));
|
||||
return {};
|
||||
},
|
||||
[](GC::Ref<CSSKeywordValue> const&) -> WebIDL::ExceptionOr<void> {
|
||||
|
|
|
|||
|
|
@ -66,14 +66,15 @@ test(() => {
|
|||
}, 'CSSSkewY.toMatrix() returns correct matrix');
|
||||
|
||||
test(() => {
|
||||
const length = 10;
|
||||
const component = new CSSPerspective(new CSSUnitValue(length, 'px'));
|
||||
const expectedMatrix = new DOMMatrixReadOnly(
|
||||
[1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, -1/length,
|
||||
0, 0, 0, 1]);
|
||||
assert_matrix_approx_equals(component.toMatrix(), expectedMatrix, gEpsilon);
|
||||
for (const length of [10, 1, 0.5, 0, -10]) {
|
||||
const component = new CSSPerspective(new CSSUnitValue(length, 'px'));
|
||||
const expectedMatrix = new DOMMatrixReadOnly(
|
||||
[1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, -1/Math.max(1, length),
|
||||
0, 0, 0, 1]);
|
||||
assert_matrix_approx_equals(component.toMatrix(), expectedMatrix, gEpsilon);
|
||||
}
|
||||
}, 'CSSPerspective.toMatrix() returns correct matrix');
|
||||
|
||||
test(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue