mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb/CSS: Ensure length is absolute before converting to pixels
Previously, creating a DOMMatrix with a transform that contained non-absolute units would cause a crash.
This commit is contained in:
parent
5136b495a6
commit
c5d1ec4dea
3 changed files with 8 additions and 2 deletions
|
@ -16,3 +16,4 @@
|
|||
16. Exception: SyntaxError
|
||||
17. Exception: SyntaxError
|
||||
18. Exception: SyntaxError
|
||||
19. Exception: SyntaxError
|
||||
|
|
|
@ -64,5 +64,8 @@
|
|||
|
||||
// 18. Creating a DOMMatrix with CSS transform string with error
|
||||
testPart(() => new DOMMatrix('matrix(1.0, 2.0deg, 3.0, 4.0, 5.0, 6.0)'));
|
||||
|
||||
// 19. Creating a DOMMatrix with CSS transform string with non-absolute units should fail
|
||||
testPart(() => new DOMMatrix('translate(1em, 1em)'));
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -24,8 +24,10 @@ ErrorOr<Gfx::FloatMatrix4x4> Transformation::to_matrix(Optional<Painting::Painta
|
|||
[&](CSS::LengthPercentage const& value) -> ErrorOr<float> {
|
||||
if (paintable_box.has_value())
|
||||
return value.resolved(paintable_box->layout_node(), reference_length).to_px(paintable_box->layout_node()).to_float();
|
||||
if (value.is_length())
|
||||
return value.length().absolute_length_to_px().to_float();
|
||||
if (value.is_length()) {
|
||||
if (auto const& length = value.length(); length.is_absolute())
|
||||
return length.absolute_length_to_px().to_float();
|
||||
}
|
||||
return Error::from_string_literal("Transform contains non absolute units");
|
||||
},
|
||||
[&](CSS::AngleOrCalculated const& value) -> ErrorOr<float> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue