mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Don't crash when calling getBBox() on the outermost SVG element
This commit is contained in:
parent
7a26de7464
commit
b140206a91
Notes:
github-actions[bot]
2024-09-07 12:35:52 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/b140206a91e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1307
3 changed files with 17 additions and 1 deletions
|
@ -0,0 +1 @@
|
|||
Bounding box of empty SVG element - x: 0, y: 0, width: 0, height: 0
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<svg></svg>
|
||||
<script>
|
||||
test(() => {
|
||||
const svgElement = document.querySelector("svg");
|
||||
const boundingBox = svgElement.getBBox();
|
||||
println(`Bounding box of empty SVG element - x: ${boundingBox.x}, y: ${boundingBox.y}, width: ${boundingBox.width}, height: ${boundingBox.height}`);
|
||||
svgElement.remove();
|
||||
});
|
||||
</script>
|
|
@ -262,6 +262,7 @@ Optional<float> SVGGraphicsElement::stroke_width() const
|
|||
return width.to_px(*layout_node(), scaled_viewport_size).to_double();
|
||||
}
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#__svg__SVGGraphicsElement__getBBox
|
||||
JS::NonnullGCPtr<Geometry::DOMRect> SVGGraphicsElement::get_b_box(Optional<SVGBoundingBoxOptions>)
|
||||
{
|
||||
// FIXME: It should be possible to compute this without layout updates. The bounding box is within the
|
||||
|
@ -272,7 +273,10 @@ JS::NonnullGCPtr<Geometry::DOMRect> SVGGraphicsElement::get_b_box(Optional<SVGBo
|
|||
if (!layout_node())
|
||||
return Geometry::DOMRect::create(realm());
|
||||
// Invert the SVG -> screen space transform.
|
||||
auto svg_element_rect = shadow_including_first_ancestor_of_type<SVG::SVGSVGElement>()->paintable_box()->absolute_rect();
|
||||
auto owner_svg_element = this->owner_svg_element();
|
||||
if (!owner_svg_element)
|
||||
return Geometry::DOMRect::create(realm());
|
||||
auto svg_element_rect = owner_svg_element->paintable_box()->absolute_rect();
|
||||
auto inverse_transform = static_cast<Painting::SVGGraphicsPaintable&>(*paintable_box()).computed_transforms().svg_to_css_pixels_transform().inverse();
|
||||
auto translated_rect = paintable_box()->absolute_rect().to_type<float>().translated(-svg_element_rect.location().to_type<float>());
|
||||
if (inverse_transform.has_value())
|
||||
|
|
Loading…
Reference in a new issue